chiark / gitweb /
sleepphone-cable-box: refactor, nfc
[reprap-play.git] / sleepphone-cable-box.scad
1 // -*- C -*-
2
3 include <funcs.scad>
4
5 wall = 0.75 * [1,1,1];
6 phone = [ 76.40, 30.96, 6.00 ]; // includes socket
7 phone_button_z = 6.58;
8 minwall = 0.50;
9
10 button_dz = 1.35;
11
12 button_dy_outer = 28.42;
13 button_dy_inner = 19.05;
14 button_dy_centre = 5.65;
15
16 phone_slop = 0.5 * [1,1,0]
17            + 0.5 * [0,0,1];
18
19 led = [25.9, 9.44]; // y is from edge
20 led_dia = 4.4;
21
22 // next values include slop
23 plug_maxw = 10.95 + 0.35;
24 plug_minw=   6.53 + 0.35;
25 plug_sllen=  6.50;
26 plug_totlen = 84.90; // to maxw, including phone
27
28 plug_h = 6.5;
29 plug_tooth_h = 0.5;
30 plug_tooth_dy = 0.5;
31
32 keeper_prong = 2;
33 keeper_stalk_basewidth = 4;
34 keeper_stalk_len = 70;
35 keeper_stalk_gap = 2;
36
37 // calculated
38
39 top_z = max( phone[2] + wall[2],
40              phone_button_z + minwall )
41   + phone_slop[2];
42
43 plugkeeper_x_maxw = phone[0] - plug_totlen;
44
45 plugkeeper_p_max = [ 0, plug_maxw/2 ];
46 plugkeeper_p_min = [ -plug_sllen, plug_minw/2 ];;
47 plugkeeper_d_u = unitvector2d(
48                  clockwise2d(
49                  vecdiff2d( plugkeeper_p_max, plugkeeper_p_min )
50                              )
51                              );
52
53 module MainProfileInnerHalf(){
54   p = phone + phone_slop;
55   pb = phone_button_z + phone_slop[2];
56   polygon([[ -2,                 0    ],
57            [ p[1]/2,             0    ],
58            [ p[1]/2,             p[2] ],
59            [ button_dy_outer/2,  p[2] ],
60            [ button_dy_outer/2,  pb   ],
61            [ button_dy_inner/2,  pb   ],
62            [ button_dy_inner/2,  p[2] ],
63            [ button_dy_centre/2, p[2] ],
64            [ button_dy_centre/2, pb   ],
65            [ -2,                 pb   ]]);
66 }
67
68 module MainProfile(){
69   p = phone + phone_slop;
70   difference(){
71     for (m=[0,1]) mirror([m,0]) {
72         translate([-1, -wall[2] ])
73           square([ p[1]/2 + wall[1] + 1, top_z + wall[2] ]);
74       }
75     for (m=[0,1]) mirror([m,0]) {
76         MainProfileInnerHalf();
77       }
78   }
79 }
80
81 module BoxMain(){
82   rotate([0,0,90]) rotate([90,0,0]) {
83     linear_extrude(height = phone[0] + wall[0], convexity=20)
84       MainProfile();
85     translate([0,0, phone[0]])
86       linear_extrude(height = wall[0], convexity=20)
87       hull() MainProfile();
88   }
89 }
90
91 module PlugKeeperProfileHalf(){
92   p_max = plugkeeper_p_max;
93   p_min = plugkeeper_p_min;
94   d = plugkeeper_d_u * keeper_prong;
95   
96   translate([ plugkeeper_x_maxw, 0 ]) {
97     polygon([ p_min,
98               p_max,
99               p_max + d,
100               p_min + d ]);
101   }
102 }
103
104 module PlugKeeperStalkProfile(){
105   hull(){
106     for (m=[0,1]) mirror([0,m,0]) PlugKeeperProfileHalf();
107     translate([ plugkeeper_x_maxw + keeper_stalk_len, 0,0 ])
108       square([ 0.1, keeper_stalk_basewidth/2 ], center=true);
109   }
110 }
111
112 module PlugKeeper(){
113   for (m=[0,1]) mirror([0,m,0]) {
114       translate([0,0, -wall[2]])
115         linear_extrude(height=plug_h + wall[2])
116         PlugKeeperProfileHalf();
117
118       translate([0, 0, plug_h - plug_tooth_h])
119         linear_extrude(height= plug_tooth_h)
120         translate(plugkeeper_d_u * -plug_tooth_dy)
121         PlugKeeperProfileHalf();
122
123     }
124
125   translate([0,0, -wall[2]])
126     linear_extrude(height = wall[2])
127     PlugKeeperStalkProfile();
128 }
129
130 module Box(){
131   difference(){
132     BoxMain();
133
134     translate([ led[0], phone[1]/2 - led[1], 1 ])
135       cylinder(r = led_dia/2, h= phone[2]*2, $fn=20);
136
137     for (ys=[-1,+1])
138       translate([ -0.1, ys * keeper_stalk_gap, -wall[2]*2])
139         linear_extrude(height = wall[2]*3)
140         PlugKeeperStalkProfile();
141   }
142
143   PlugKeeper();
144 }
145
146 //MainProfileInner();
147 Box();
148