chiark / gitweb /
76b905b32eb2a244f9c9ccf1861719fbd6c283bc
[reprap-play.git] / digispark-with-cable.scad
1 // -*- C -*-
2 //
3 // Print (fine detail settings):
4 //
5 //   * Bottom
6 //   * MiddlePrint
7 //   * CoverPrint
8
9 include <utils.scad>
10
11 usb_w = 12.01 + 0.19;
12 usb_wall_w = 0.51;
13 usb_tongue_d = 8.97 - 0.2;
14 usb_tongue_w_slop = +0.5;
15 usb_wall_h = 4.54 - 2.04;
16 usb_ceil_th = 0.425;
17
18 wall_th = 1.5; // XXXX rename wall_th
19
20 board_l = 17.56 + 0.2;
21 board_w = 19.14 + 0.2;
22 board_th = 1.92 + 0.1;
23
24 sw_to_edge = board_w/2 + 0.1;
25
26 front_wall_th = 0.75;
27 // egress_w = 8.0;
28
29 wall_y_min = -board_l - wall_th;
30 ceil_y_min = wall_y_min - 5;;
31
32 small_walls = [
33                [ [0, 0], [-sw_to_edge, -1.0] ],
34                [ [sw_to_edge-4.5, -4.5], [sw_to_edge, -5.7] ],
35 //             [ [3.0, -11.72],              [sw_to_edge, -13.38] ],
36                [ [-sw_to_edge+3.85, -14.90], [sw_to_edge, -13.38] ],
37                ];
38 chip_cutout = [[ -sw_to_edge + 4.20,    -3.75 ],
39                [ -sw_to_edge + 11.95,  -11.90 ]];
40
41 strain_w = 2.0 + 0.5;
42 strain_t = 1.0 + 0.5;
43 strain_pitch_across = 5;
44 strain_pitch_along = 10;
45 strain_groove_d = 2;
46 strain_groove_w = 3;
47
48 cover_strap_c_d_y = 5.5; // from front of board
49 cover_registration_sz_y = 2;
50 cover_registration_sz_z = 3;
51 midbot_registraton_sz_x = 3;
52
53 cable_space_z = 6;
54 cable_dia = 5;
55 bottom_floor_th = 1.5;
56
57 fit_gap_z = 0.5;
58 fit_gap_y = 0.25;
59 side_x_gap = 0.5;
60
61 cover_ceil_th = 0.9;
62
63 cover_strap_sz_x = wall_th * 3.5;
64
65 // calculated
66
67 strap_w = strain_w;
68 cover_strap_cutout_z = wall_th;
69
70 middle_top_z = usb_wall_h;
71 middle_base_z = -board_th;
72 bottom_base_z = middle_base_z - cable_space_z - bottom_floor_th;;
73
74 front_y_max = front_wall_th;
75 main_y_min = -board_l - wall_th;
76
77 strain_0_y_c = main_y_min - strain_w/2;
78 strain_1_y_c = strain_0_y_c - strain_pitch_along;
79 total_y_min = strain_1_y_c - strain_w/2 - wall_th;
80
81 bottom_wall_top_z = (middle_top_z + middle_base_z) * 0.5 - fit_gap_z/2;
82 cover_wall_bot_z  = (middle_top_z + middle_base_z) * 0.5 + fit_gap_z/2;
83 cover_top_z  = middle_top_z + cover_ceil_th;
84
85 middle_side_wall_x = +board_w/2 + wall_th;
86 total_side_wall_x = middle_side_wall_x + wall_th + side_x_gap;
87
88 cover_registration_c_dy = -cover_strap_c_d_y - strap_w/2
89   - wall_th - cover_registration_sz_y/2;
90
91 midbot_registration_sz_y = cover_registration_sz_y;
92 midbot_registration_sz_z = cover_registration_sz_z;
93 midbot_registration_y_min = total_y_min + wall_th*2;
94 midbot_registration_y_max = midbot_registration_y_min
95   + midbot_registration_sz_y;
96 midbot_registration_y_around_max = midbot_registration_y_max
97   + wall_th*2;
98 midbot_registration_bottom_x = board_w/2 - midbot_registraton_sz_x;
99
100 midbot_strap_c_y = 0.5 * (strain_0_y_c + strain_1_y_c);
101
102 module BothSides(){
103   for (m=[0,1]) {
104     mirror([m,0,0]) {
105       children();
106     }
107   }
108 }
109
110 module NormalStrapCutouts(y_c, z, rot){
111   BothSides(){
112     translate([ -total_side_wall_x, y_c, z ])
113       rotate([0, rot, 0])
114       cube([ wall_th,
115              strap_w,
116              10 ],
117            center=true);
118   }
119 }
120 module BottomStrapCutouts(y_c){
121   NormalStrapCutouts(y_c, bottom_base_z, -45);
122 }
123 // XXXX check strap width
124 // XXXX check cable diameter
125 module CoverStrapCutouts(){
126   BothSides(){
127     translate([ -total_side_wall_x, -cover_strap_c_d_y, cover_top_z ])
128       cube([ cover_strap_sz_x*2,
129              strap_w,
130              cover_strap_cutout_z*2 ],
131            center=true);
132   }
133 }
134
135 module FrontWallsPlan(slop) {
136   BothSides(){
137     rectfromto([ -board_w/2 - wall_th,    0             ],
138                [ -usb_w/2 - slop,         front_wall_th ]);
139   }
140 }
141 module MiddleSmallWallsPlan() {
142   for (m=[0,1]) {
143     mirror([m,0]) {
144       rectfromto([ -usb_w/2,              -0.01        ],
145                  [ -usb_w/2 + usb_wall_w, usb_tongue_d ]);
146     }
147   }
148   FrontWallsPlan(0);
149   for (w=small_walls) {
150     rectfromto(w[0], w[1]);
151   }
152 }
153 module MiddleCeilPlan() {
154   difference(){
155     BothSides(){
156       rectfromto([ -usb_w/2,              -0.01        ],
157                  [ 0.1,                   usb_tongue_d ]);
158       rectfromto([ -board_w/2 - wall_th, 0            ],
159                  [ 0.1,                  ceil_y_min   ]);
160     }
161     rectfromto(chip_cutout[0], chip_cutout[1]);
162   }
163 }
164 module MiddleMainWallsPlan() {
165   BothSides(){
166     rectfromto([ -board_w/2 - wall_th, 0          ],
167                [ -board_w/2,           wall_y_min ]);
168   }
169   FrontWallsPlan(usb_tongue_w_slop);
170   rectfromto([ -board_w/2 - wall_th + 0, -      board_l   ],
171              [ +board_w/2 + wall_th,            total_y_min ]);
172 }
173
174 module RegistrationsMinkowski(){
175   minkowski(){
176     cube([ 1, fit_gap_y*2, fit_gap_z*2 ], center=true);
177     children();
178   }
179 }
180 module CoverRegistrations(){
181   linextr_y_xz(cover_registration_c_dy - strap_w/2,
182                cover_registration_c_dy + strap_w/2) {
183     difference(){
184       rectfromto([ -total_side_wall_x,
185                           cover_wall_bot_z - cover_registration_sz_z  ],
186                  [ +total_side_wall_x, cover_top_z ]);
187       hull(){
188         MiddleElevationForCutout();
189         translate([0, -20]) MiddleElevationForCutout();
190       }
191     }
192   }
193 }
194 module MidBotRegistrations(){
195   linextr_y_xz(midbot_registration_y_min,
196                midbot_registration_y_max) {
197     BothSides(){
198       rectfromto([ midbot_registration_bottom_x, middle_base_z + 0.1 ],
199                  [ middle_side_wall_x, middle_base_z
200                         - midbot_registration_sz_z ]);
201     }
202   }
203 }
204
205 module Middle(){ ////toplevel
206   difference(){
207     union(){
208       linextr(0, usb_wall_h)
209         MiddleSmallWallsPlan();
210       linextr(usb_wall_h - usb_ceil_th, usb_wall_h)
211         MiddleCeilPlan();
212       linextr(-board_th, usb_wall_h)
213         MiddleMainWallsPlan();
214       BothSides()
215         linextr(cover_wall_bot_z, middle_top_z)
216         rectfromto([ -(board_w/2 + 0.1),  total_y_min             ],
217                    [ -total_side_wall_x,  main_y_min - fit_gap_y  ]);
218       MidBotRegistrations();
219     }
220
221     for (y_c = [strain_0_y_c, strain_1_y_c]) {
222       for (x_c = [-1,+1] * strain_pitch_across/2) {
223         translate([x_c, y_c, 0])
224           linextr(-20, 20)
225           square([ strain_t, strain_w ], center=true);
226       }
227     }
228     linextr_y_xz(total_y_min-1, main_y_min)
229       translate([0, middle_base_z])
230       scale([1, strain_groove_d/strain_groove_w])
231       circle(strain_groove_w/2, $fn = 8);
232     NormalStrapCutouts(midbot_strap_c_y,
233                        middle_top_z, 45);
234   }
235 }
236 module MiddlePrint(){ ////toplevel
237   rotate([180,0,0]) Middle();
238 }
239
240 module MiddleElevationForCutout(){
241     rectfromto([ -(middle_side_wall_x + side_x_gap),
242                     middle_base_z - fit_gap_z ],
243                [ +(middle_side_wall_x + side_x_gap), middle_top_z  ]);
244 }
245 module BottomMainElevation(){
246   difference(){
247     rectfromto([ -total_side_wall_x, bottom_base_z        ],
248                [ +total_side_wall_x, bottom_wall_top_z    ]);
249
250     MiddleElevationForCutout();
251   }
252 }
253 module Bottom(){ ////toplevel
254   difference(){
255     union(){
256       linextr_y_xz(total_y_min, front_y_max)
257         BottomMainElevation();
258     }
259
260     linextr_y_xz(midbot_registration_y_around_max,
261                  front_y_max - wall_th)
262       rectfromto([ -board_w/2, bottom_base_z + bottom_floor_th ],
263                  [ +board_w/2, 20         ]);
264
265     linextr_y_xz(total_y_min + wall_th,
266                  front_y_max - wall_th)
267       rectfromto([ -midbot_registration_bottom_x,
268                      bottom_base_z + bottom_floor_th ],
269                  [ +midbot_registration_bottom_x, 20         ]);
270
271     linextr_y_xz(total_y_min - 1,
272                  total_y_min + wall_th + 1){
273       translate([ 0, middle_base_z ]){
274         hull(){
275           translate([ 0, -cable_dia/2 ])
276             circle(r = cable_dia/2, $fa = 10, $fs = 1);
277           square([ cable_dia, 0.1 ], center=true);
278         }
279       }
280     }
281     RegistrationsMinkowski()
282       CoverRegistrations();
283     RegistrationsMinkowski()
284       MidBotRegistrations();
285     BottomStrapCutouts(-cover_strap_c_d_y);
286     BottomStrapCutouts(midbot_strap_c_y);
287   }
288 }
289
290 module CoverMainElevation(){
291   difference(){
292     rectfromto([ -total_side_wall_x, cover_wall_bot_z        ],
293                [ +total_side_wall_x, cover_top_z    ]);
294
295     MiddleElevationForCutout();
296   }
297 }
298 module Cover(){ ////toplevel
299   difference(){
300     union(){
301       linextr_y_xz(main_y_min, front_y_max)
302         CoverMainElevation();
303       CoverRegistrations();
304     }
305     CoverStrapCutouts();
306   }
307 }
308 module CoverPrint(){ ////toplevel
309   rotate([180,0,0]) Cover();
310 }
311
312 module BottomDemo(){ ////toplevel
313   translate([0, 0, -0.25]) Bottom();
314   %Middle();
315   translate([0, 0, +0.25]) Cover();
316 }