chiark / gitweb /
a434efeaa9ee506c84ff91e49f79671f773321ce
[reprap-play.git] / fairphone-case.scad
1 // -*- C -*-
2
3 include <utils.scad>
4
5 phone = [ 75.0, 145.0 ];
6
7 prop_x_pos = 18;
8
9 prop_angles = [ 15, 30, 45, 60 ];
10
11 bumper = [ 0.250, -0.025 ];
12 // ^ One side.  Overall size is increased by twice this.
13 // If no bumpers, is the gap around the phone.
14
15 enable_support = 1;
16
17 phone_cnr_rad = 6.0;
18
19 button_cutout_depth = 9;
20
21 phone_edge_thick = 9.0;
22 phone_total_thick = 12.0;
23 phone_backside_slope_inner = 1.5; // larger means shallower
24 phone_backside_slope_outer = 1.0; // larger means shallower
25
26 camera_pos_tl = [  6.450, 12.750 ]; // measured from tl corner
27 camera_pos_br = [ 22.300, 37.600 ]; // tl/br as seen from back
28
29 jack_pos = [ 14.38, 7.96 ];
30 jack_dia = 10.64 + .5; // some jack I had lying around
31
32 noisecancelmic_pos = [ 19.54, 7.37 ];   // from rhs
33 noisecancelmic_dia = 4.00;
34
35 //fingerpushhole_dias = [ 15, 18 ];
36 fingerpushhole_dias = [];
37
38 rearspeaker_pos_bl = [ 12.64, 18.72 ];
39 rearspeaker_size   = [  3.76,  7.36 ];
40
41 microusb_above = 3.27 - 0.25;
42 microusb_below = 0.0;
43 microusb_width = 16.12 + 1.25;
44
45 case_th_bottom = 2.5;
46 case_th_lid = 2.5;
47 case_th_side = 2;
48 case_th_lip = 1.2;
49
50 case_struts_count = 6;
51 case_struts_solid_below = 1.00;
52 case_struts_solid_above = 0.75;
53 case_struts_width = 0.10;
54
55 keeper_th_z = 0.75;
56 keeper_th_x = 0.75;
57 keeper_inner_width = 2.75;
58 keeper_inner_height = 2.75;
59 keeper_slant_slope = 2; // larger means steeper
60
61 keeper_gap_z_top = 0.25;
62 keeper_gap_z_bot = 0.75;
63 keeper_gap_x     = 0.25;
64 keeper_gap_x_holes = 0.75;
65
66 keeper_side = 0; // 0 = lhs; 1 = rhs
67
68 case_lip = 1.25;
69
70 lid_gap_x = 0.25;
71 lid_gap_z = 0.25;
72 lid_lip = 1.75;
73
74 catch_slop = 0.50;
75
76 foldover_gap = 0.50;
77 foldover_lever_gap = 0.50;
78
79 hingescrew_shaft_dia = 2.0 + 0.25; // M2 x 12mm machine screw
80 hingescrew_shaft_len = 12;
81 hingescrew_nut_thick = 1.93 + 0.20; // incl. washer
82 hingescrew_nut_dia = 4.72 + 0.50; // washer, actually
83 hingescrew_head_th = 1.38 + 0.75;
84 hingescrew_head_dia = 3.92;
85 lever_cover_th = 0.75;
86 hingemount_th = 2.5;
87
88 $fa = 5;
89 $fs = 0.1;
90
91 button_l_fudge = 4.4;
92 buttonishleg_default_l_is_fudge = 10;
93
94 hinge_base_slope = 1.5; // bigger is steeper
95
96 strut_min_at_end = 1.5;
97
98 hinge_x_gap = 0.125;
99 hinge_x_postscrew_gap = 0.75;
100 hinge_x_arms_gap = 0.35;
101 hinge_r_arms_gap = 0.55;
102
103 rearspeaker_gap    = [ 2.0, 2.0 ]; // each side
104
105 catch_len = 7.5;
106 catch_width = 15;
107 catch_thickness = 1.0;
108 catch_side_gap = 0.75; // each side
109
110 catch_depth = 0.75;
111 catch_height = 0.35;
112 catch_finger_height = 1.5;
113 catch_finger_depth = 2.5;
114
115 prop_recess_under = 0.50;
116 prop_recess_slop = 0.200; // each side
117 prop_end_dia = 0.5;
118 prop_main_th = 3;
119 prop_taper_len = 6;
120 prop_main_width = 3;
121 prop_side_gap = 0.75; // each side
122 prop_caserecess_behind = 0.75;
123 prop_caserecess_taper = 0.25; // each side
124
125 // ---------- calculated ----------
126
127 phone_width =  (phone + bumper*2)[0];
128 phone_height = (phone + bumper*2)[1];
129
130 inside_br = [phone_width, -phone_height];
131
132 //echo(camera_pos_tl + bumper,
133 //     camera_pos_br + bumper);
134
135 // ----- could be changed -----
136 lid_buttoncover_gap = lid_gap_x;
137 lid_buttoncover_overlap = case_th_lip + keeper_gap_z_top;
138
139 phone_backside_slope_thick = phone_total_thick - phone_edge_thick;
140
141 //prop_lidrecess_depth = case_th_lid - prop_recess_under;
142
143 //prop_nose_len = case_th_lid - prop_recess_under;
144 //prop_recess_slope = tan(prop_max_angle); // bigger means steeper
145 //prop_recess_width = prop_main_th / cos(prop_max_angle) + prop_backfwd_gap;
146
147
148 //lid_lip_overlap_width xxx bad name = ;
149 //lid_lip_inner_slope = [ 5, 5 ]; // xxx
150
151 epp0 = [0,0];
152 epp1 = [0, -phone_edge_thick];
153 epp2i = epp1 + phone_backside_slope_thick * [ phone_backside_slope_inner, -1 ];
154 epp2o = epp1 + phone_backside_slope_thick * [ phone_backside_slope_outer, -1 ];
155 epp3 = epp2i + [10, 0];
156 epp5 = epp0 + [0,1] * (keeper_th_z + keeper_gap_z_top + case_lip);
157 epp4 = epp5 + [-1,0] * case_th_side;
158
159 kppe = [0,0];
160 kppd = kppe + [1,0] * keeper_inner_width;
161 kppc = kppd + [0,1] * keeper_th_z;
162 kppb = [ kppe[0] - keeper_th_x, kppc[1] ];
163 kppf = kppe - [0,1] * keeper_inner_height;
164 kppa = [ kppb[0], kppf[1] ];
165
166 lpp10 = [ epp5[0] + lid_gap_x, kppc[1] + lid_gap_z ];
167 lpp11 = [ lpp10[0],            epp5[1] + lid_gap_z ];
168
169 lp_r12 = case_th_lid - (lpp11[1] - lpp10[1]);
170
171 lpp12 = [ epp4[0] + lp_r12,    lpp11[1] ];
172 lpp13 = [ lpp12[0],            lpp12[1] + lp_r12 ];
173
174 case_bottom_z = epp2o[1] - case_th_bottom;
175
176 // button profile
177 bppM = epp4 + [0,5];
178 bppN = [ 0.5 * (epp0[0] + epp4[0]), bppM[1] ];
179 bppR = [ bppN[0] + lid_buttoncover_gap, -button_cutout_depth ];
180 bppS = [ epp1[0], bppR[1] ];
181 bppQ = [ bppM[0], bppR[1] - lid_buttoncover_overlap ];
182 bppP = bppQ + [0,1] * lid_buttoncover_gap;
183 bppO = [ bppN[0], bppP[1] ];
184 bppL = lpp10 + [5,0];
185 bppK = [ bppL[0], bppN[1] ];
186 bppJ = [ bppN[0], bppL[1] ];
187
188 // hinge plan
189 hp_rn = hingescrew_nut_dia/2;
190 hp_r2_min = hp_rn + lever_cover_th;
191 hp_rs = hingescrew_shaft_dia/2;
192 hp_r1_min = hp_rs + hingemount_th;
193
194 hp_r1 = max(hp_r1_min, hp_r2_min);
195 hp_r2 = hp_r1;
196
197 hppU = lpp13;
198 hppS = epp2o + [0,-1] * case_th_bottom;
199 hp_k = 0.5 * (hppU[1] - hppS[1] + foldover_gap);
200
201 hppM = [ epp4[0] - foldover_lever_gap - hp_r2,
202          0.5 * (hppU + hppS)[1] ];
203 hppT = [ hppM[0], hppU[1] - hp_r1 ];
204 hppB = hppT + [0,-1] * hp_k;
205
206 hppE_y = epp2o[1] - case_th_bottom + hp_r1;
207 hppE_x = hppB[0] + (hppB[1] - hppE_y) * hinge_base_slope;
208 hppE = [ hppE_x, hppE_y ];
209
210 // hinge elevation x coords
211
212 hingescrew_portion_len =
213   0.5* (hingescrew_shaft_len - hingescrew_nut_thick - hinge_x_gap);
214
215 hex20 = max(epp2o[0],
216             phone_cnr_rad,
217             kppd[0] + hingescrew_head_th + keeper_gap_x_holes);
218 hex21 = hex20 + hingescrew_portion_len;
219 hex22 = hex21 + hinge_x_gap;
220 hex23 = hex22 + hingescrew_portion_len
221   - hingescrew_nut_thick; // bodge, need to divvy this up more sensibly
222 hex24 = hex20 + hingescrew_shaft_len + hinge_x_postscrew_gap;
223 //echo(hex20, hex21, hex22, hex23, hex24);
224 //echo(hingescrew_portion_len);
225
226 // catch
227
228 cppJ = [ epp4[0] + catch_thickness, lpp10[1] ];
229 cppA = cppJ + [lid_gap_x, -lid_gap_z];
230 cppB = [ epp0[0], cppA[1] ];
231 cppP = [ epp4[0], cppJ[1] ];
232
233 cppS = cppJ + [0,-1] * catch_len;
234 cppD = [ cppA[0], cppS[1] + catch_slop ];
235 cppC = [ cppB[0], cppD[1] ];
236 cppT = cppS + [1,0] * catch_depth;
237 cppU = cppT + [0,-1] * catch_height;
238 cppV = [ cppS[0], cppU[1] - catch_depth ];
239
240 cppR = 0.5*(cppP + cppJ);
241
242 cp_rQ = 0.5 * (cppJ[0] - cppP[0]);
243 cppQ = [ cppR[0],
244          cppV[1] - (catch_finger_height - cp_rQ) ];
245 cppF = [ cppV[0] + catch_finger_depth, cppC[1] ];
246
247 // prop recess
248
249 prop_recess_hw = 0.5 * prop_main_width + prop_side_gap;
250
251 prcp2 = [ epp4[0], case_bottom_z ];
252
253 prop_caserecess_buildout_r = prcp2[0] - epp2o[0];
254
255 prc_r1 = prop_end_dia/2;
256 prc_r3 = prc_r1 + prop_recess_slop;
257 echo(prc_r3);
258
259 prcp1 = [ prcp2[0] + prop_caserecess_behind + prc_r3,
260           epp2i[1] - prc_r3 ];
261
262 // ---------- modules ----------
263
264 module KeeperProfile(slant=0){
265   use_e = kppe + [0,-1] * slant * keeper_inner_width / keeper_slant_slope;
266   polygon([use_e, kppd, kppc, kppb, kppa, kppf]);
267 }
268
269 module EdgeProfile(){
270   difference(){
271     hull(){
272       translate(epp3) square(case_th_bottom*2, center=true);
273       circleat(epp2o, r=case_th_bottom);
274       circleat(epp1, r=case_th_side);
275       rectfromto(epp0, epp4);
276     }
277     polygon([ epp5 + [0,10],
278               epp1,
279               epp2i,
280               epp3 + [10,0] ]);
281   }
282 }
283
284 module LidEdgeProfile(){
285   polygon([ lpp10,
286             lpp11,
287             lpp12,
288             lpp13,
289             lpp13 + [10, 0],
290             lpp10 + [10, 0]
291             ]);
292   intersection(){
293     circleat(lpp12, r=lp_r12);
294     rectfromto( lpp12 + [-10,   0],
295                 lpp12 + [+10, +10] );
296   }
297 }
298
299 module ButtonCoverProfile(){
300   intersection(){
301     polygon([ bppM, bppP, bppO, bppJ, bppL, bppK ]);
302     hull(){
303       EdgeProfile();
304       LidEdgeProfile();
305     }
306   }
307 }
308
309 module ButtonPlan(l, deep, cut){
310   epsilon =
311     (cut  ? 0 : lid_buttoncover_gap);
312
313   delta =
314     (deep ? lid_buttoncover_overlap : 0);
315
316   C = [0,0]; // by definition
317   T = [ 0, epp4[1] ];
318   G = T + [0,10];
319
320   B0 = C + [0,-1] * button_cutout_depth;
321   B1 = B0 + [0,1] * epsilon;
322
323   r0 = 0.5 * (T[1] - B0[1]);
324   A = [  -(l + button_l_fudge)/2 + r0, 0.5 * (T[1] + B0[1]) ];
325   H = A + [0,-1] * delta;
326
327   D = A + [-2,0] * r0;
328   F = D + [0,10];
329
330   E0 = 0.5 * (D + A);
331   E1 = E0 + [1,0] * epsilon;
332
333   I0 = [ E0[0], H[1] ];
334   I1 = [ E1[0], H[1] ];
335
336   hull(){
337     for (m=[0,1]) mirror([m,0])
338       circleat(H, r0 - epsilon);
339   }
340   for (m=[0,1]) mirror([m,0]) {
341     difference(){
342       polygon([ E1,
343                 I1,
344                 H,
345                 B1,
346                 G,
347                 F,
348                 D
349                 ]);
350       circleat(D, r0 + epsilon);
351     }
352   }
353 }
354
355 module CatchCatchProfile(){
356   hull(){
357     for (c=[ cppR, cppQ ])
358       circleat(c, cp_rQ);
359   }
360   hull(){
361     circleat(lpp12, lp_r12);
362     circleat(lpp12 + [5,0], lp_r12);
363     rectfromto(cppP, cppP + [5,0.1]);
364   }
365   polygon([cppJ, cppS, cppT, cppU, cppV, cppQ, cppR]);
366 }
367
368 module CatchCutProfile(){
369   polygon([ cppB,
370             cppA,
371             cppD,
372             cppF,
373             cppF + [0,-10],
374             cppF + [-10,-10],
375             lpp12 + [-10,0],
376             lpp12 + [10,0]
377             ]);
378 }
379
380 module Flip_rhs(yn=[0,1]) {
381   for ($rhsflip=yn) {
382     translate([phone_width/2, 0, 0])
383       mirror([$rhsflip,0,0])
384       translate([-phone_width/2, 0, 0])
385       children();
386   }
387 }
388
389 module Flip_bot(yn=[0,1]) {
390   for ($botflip=yn) {
391     translate([0, -phone_height/2, 0])
392       mirror([0, $botflip, 0])
393       translate([0, phone_height/2, 0])
394       children();
395   }
396 }  
397
398 module AroundEdges(fill_zstart, fill_th, fill_downwards=0){
399   // sides
400   Flip_rhs(){
401     translate([0, -phone_cnr_rad, 0])
402       rotate([90,0,0])
403       linear_extrude(height = phone_height - phone_cnr_rad*2)
404       children(0);
405   }
406   // corners
407   Flip_rhs() Flip_bot() {
408     translate([+1,-1] * phone_cnr_rad)
409       intersection(){
410         rotate_extrude()
411           intersection(){
412             mirror([1,0,0])
413               translate([-1,0] * phone_cnr_rad)
414               children(0);
415             rectfromto([0,-20],[10,20]);
416           }
417         translate([-10, 0, -20] + 0.01 * [+1,-1, 0] )
418           cube([10,10,40]);
419       }
420   }
421   // top and bottom
422   Flip_bot(){
423     translate([ phone_width - phone_cnr_rad, 0,0 ])
424       rotate([90,0,-90])
425       linear_extrude(height = phone_width - phone_cnr_rad*2)
426       children(0);
427   }
428   // fill
429   translate([0,0, fill_zstart])
430     mirror([0,0, fill_downwards])
431     linear_extrude(height = fill_th)
432     rectfromto([+1,-1] * phone_cnr_rad,
433                [phone_width, -phone_height] + [-1,+1] * phone_cnr_rad);
434 }
435
436 module CaseAperture(pos, dia, $fn) {
437   theta = 180/$fn;
438   translate([ pos[0] + bumper[0],
439               -epp2i[0],
440               -pos[1] ])
441     rotate([-90, theta, 0])
442     cylinder(r = dia/2 / cos(theta),
443              h = 60);
444 }
445
446 module SideButton(y, y_ref_sign, l){
447   // y_ref_sign:
448   //   +1  measured from top    of actual phone to top    of button
449   //   -1  measured from bottom of actual phone to bottom of button
450   //    0  y is centre of button in coordinate system
451   $button_l= l;
452   eff_y = y_ref_sign > 0 ?         -bumper [1] -y -l/2 :
453           y_ref_sign < 0 ? (-phone -bumper)[1] +y +l/2 :
454           y;
455   //echo(eff_y);
456   translate([0, eff_y, 0])
457     children();
458 }
459
460 module LidButtonishLeg(y, y_ref_sign, l=buttonishleg_default_l_is_fudge) {
461   $button_leg_only = true;
462   SideButton(y, y_ref_sign, l) children();
463 }
464
465 module Buttons(){
466   Flip_rhs(1) SideButton(15.580, +1, 8.9) children(); // power
467   Flip_rhs(1) SideButton(48.700, -1, 8.920) children(); // camera
468   Flip_rhs(0) SideButton(30.800, +1, 21.96) children(); // volume
469   Flip_rhs(   ) LidButtonishLeg(14, -1) children();
470 //  Flip_rhs(0) LidButtonishLeg(20, +1, 20) children();
471 }
472
473 module Struts(x_start, z_min, th){
474   // if th is negative, starts at z_min and works towards -ve z
475   // and object should then be printed other way up
476   for (i= [1 : 1 : case_struts_count]) {
477     translate([0,
478                0,
479                z_min])
480       mirror([0,0, th<0 ? 1 : 0])
481       translate([0,
482                  -phone_height * i / (case_struts_count+1),
483                  case_struts_solid_below])
484       linear_extrude(height= abs(th)
485                      -(case_struts_solid_below+case_struts_solid_above))
486       rectfromto([               x_start, -0.5 * case_struts_width ],
487                  [ phone_width - x_start, +0.5 * case_struts_width ]);
488   }
489 }
490
491 module OrdinaryRearAperture(rhs,bot, pos){
492   Flip_rhs(rhs) Flip_bot(bot)
493     linextr(-20, 20)
494     mirror([0,1])
495     translate(pos + bumper)
496     children();
497 }
498
499 module MicroUSB(){
500   Flip_bot(1){
501     rotate([90,0,0])
502       mirror([0,0,1])
503       linextr(-epp2i[0], 60)
504       translate([0.5 * phone_width, 0, 0])
505       rectfromto([-microusb_width/2, epp2i[1] + microusb_below],
506                  [+microusb_width/2, epp0[1] + -microusb_above]);
507   }
508 }
509
510 module OrdinaryRearApertures(){
511   // rear speaker
512   OrdinaryRearAperture(1,1, rearspeaker_pos_bl)
513     rectfromto(-rearspeaker_gap,
514                rearspeaker_size + rearspeaker_gap);
515
516   // finger hole to remove phone
517   if (len(fingerpushhole_dias))
518     OrdinaryRearAperture(1,0, [ fingerpushhole_dias[0]/2 + epp2i[0],
519                                 phone[1]/2 ])
520     scale(fingerpushhole_dias)
521     circle(r= 0.5 );
522 }
523
524 module RearCameraAperture(){
525   Flip_rhs(1)
526     mirror([0, 0, 1])
527     linear_extrude(height = 20)
528     mirror([0, 1, 0])
529     translate(bumper)
530     rectfromto(camera_pos_tl, camera_pos_br);
531 }
532
533 module HingeLidProfile(){
534   hull(){
535     circleat(hppT, hp_r1);
536     circleat(lpp12, lp_r12);
537     polygon([lpp10,
538              lpp13 + [2,0],
539              lpp12,
540              hppT]);
541   }
542 }
543
544 module HingeBaseProfile(){
545   difference(){
546     hull(){
547       circleat(hppB, hp_r1);
548       circleat(hppE, hp_r1);
549       circleat(epp2o, case_th_bottom);
550       circleat(hppB + [10,0], hp_r1);
551     }
552     polygon([epp5, epp1, epp2i, epp3, bppL]);
553   }
554 }
555
556 module HingeLeverOuterProfile(){
557   hull(){
558     circleat(hppT, hp_r2);
559     circleat(hppB, hp_r2);
560   }
561 }
562
563 module HingeLeverInnerProfile(){
564   for (c = [hppT, hppB]) {
565     hull()
566       for (x=[-20,20])
567         for (y=[0, c[1] - hppM[1]])
568           translate([x,y])
569             circleat(c, hp_rn);
570   }
571 }
572
573 module Flip_hinge(){
574   hinge_origin = [0, -(phone_height - hppB[0]), hppB[1]];
575   translate(hinge_origin)
576     rotate([180,0,0])
577     translate(-hinge_origin)
578     children();
579 }
580
581 module HingePortion(x0,x1){
582   Flip_rhs() Flip_bot(1)
583     translate([x0,0,0])
584     mirror([1,0,0])
585     rotate([90,0,-90])
586     linear_extrude(height=x1-x0)
587     children(0);
588 }
589
590 module CatchPortion(width){
591   translate([phone_width/2, 0,0])
592     rotate([90,0,-90])
593     linextr(-width/2, width/2)
594     children(0);
595 }
596
597 module CaseBase(){
598   AroundEdges(epp3[1], case_th_bottom, 1)
599     EdgeProfile();
600 }
601
602 module Case(){ ////toplevel
603   difference(){
604     union(){
605       CaseBase();
606
607       // ledge (fixed keeper)
608       Flip_rhs(1-keeper_side) intersection(){
609         rotate([90, 0, 0])
610           linear_extrude(height = phone_height + phone_cnr_rad * 2)
611           KeeperProfile(1);
612
613         // outline of the whole case, to stop it protruding
614         translate([0,0, -25])
615           linear_extrude(height = 50)
616           hull()
617           Flip_bot()
618           circleat([+1,-1] * phone_cnr_rad, phone_cnr_rad + case_th_side/2);
619       }
620
621       // hinge
622       HingePortion(hex20, hex21) HingeBaseProfile();
623
624       // buildout for prop recess
625       Flip_rhs(1)
626         linextr(case_bottom_z, epp2i[1])
627         hull() {
628           for (dxs = [-1,+1])
629             circleat([ prop_x_pos + dxs * prop_caserecess_buildout_r,
630                        -epp2o[0] ],
631                      r = epp2o[0] - prcp2[0]);
632         }
633     }
634
635     // slot for keeper
636     Flip_rhs(keeper_side)
637       translate([0, -phone_cnr_rad, 0])
638       rotate([90, 0, 0])
639       linear_extrude(height = phone_height + phone_cnr_rad * 2)
640       minkowski(){
641         KeeperProfile();
642         rectfromto([ -keeper_gap_x,    -keeper_gap_z_bot ],
643                    [ keeper_gap_x_holes,    +keeper_gap_z_top ]);
644       }
645
646     // front camera
647     RearCameraAperture();
648
649     // struts (invisible, because they're buried in the case)
650     Struts(epp2i[0], epp2i[1] - case_th_bottom, case_th_bottom);
651
652     Buttons(){
653       mirror([1,0,0])
654         rotate([90,0,90]) {
655           if (!($button_leg_only && enable_support))
656           intersection(){
657             translate([0,0,-10])
658               linear_extrude(height= 20)
659               ButtonPlan($button_l, 0,1);
660             if ($button_leg_only)
661               rotate([-90,90,0])
662                 translate([phone_width/2, -400, kppe[1]])
663                 mirror([1-abs($rhsflip - keeper_side),0,0])
664                 cube([400, 800, 50]);
665             if (enable_support)
666               rotate([-90,90,0])
667               translate([-400, -400, kppd[1]])
668                 mirror([0,0,1])
669                 cube([800,800,100]);
670           }
671           translate([0,0, -bppR[0]])
672             linear_extrude(height= 20)
673             ButtonPlan($button_l, 1,1);
674         }
675       
676     }
677
678     // apertures along top edge
679     CaseAperture(jack_pos, jack_dia, 8);
680     Flip_rhs(1)
681       CaseAperture(noisecancelmic_pos, noisecancelmic_dia, 8);
682
683     OrdinaryRearApertures();
684
685     MicroUSB();
686
687     // gaps for the lid's hinge arms
688     HingePortion(hex20 - hinge_x_arms_gap,
689                  hex21 + hinge_x_arms_gap)
690       minkowski(){
691         HingeLidProfile();
692         circle(r= hinge_r_arms_gap, $fn= 8);
693       }
694
695     // screw holes in the hinge arms
696     HingeScrews();
697
698     // catch striker
699     CatchPortion(catch_width + catch_side_gap*2)
700       CatchCutProfile();
701
702     // prop recess
703     Flip_rhs(1)
704       translate([0,0,1])
705       rotate([90,0,90])
706       linextr(-prop_recess_hw, +prop_recess_hw)
707       hull(){
708         for (zs=[ -1,0,+1 ])
709           circleat(prcp2 + 20*(abs(zs) * [0,-1] +
710                                zs * [1,0] * prop_caserecess_taper),
711                    prc_r3);
712       }
713   }
714 }
715
716 module Lid(){ ////toplevel
717   difference(){
718     union(){
719       AroundEdges(lpp10[1], lpp13[1] - lpp10[1], 0)
720         LidEdgeProfile();
721
722       // button covers
723       Buttons(){
724         intersection(){
725           rotate([90,0,90])
726             translate([0,0,-10])
727             linear_extrude(height= 20)
728             ButtonPlan($button_l, 1,0);
729           rotate([90,0,0])
730              translate([0,0,-100])
731             linear_extrude(height= 200)
732             ButtonCoverProfile();
733         }
734       }
735
736       // hinge arms
737       HingePortion(hex20, hex21) HingeLidProfile();
738
739       // catch
740       CatchPortion(catch_width)
741         CatchCatchProfile();
742     }
743     Struts(lpp10[0] + strut_min_at_end, lpp13[1], -case_th_lid);
744
745     // screw holes in the hinge arms
746     HingeScrews();
747   }
748 }
749
750 module HingeLever(){ ////toplevel
751   difference() {
752     // outer body, positive
753     HingePortion(hex22, hex22 + phone_width/2)
754       HingeLeverOuterProfile();
755
756     // space for the screws
757     HingePortion(hex23, hex24)
758       HingeLeverInnerProfile();
759
760     // bores for the screws
761     HingeScrews();
762
763     // space for the charging cable
764     MicroUSB();
765     Flip_hinge() MicroUSB();
766   }
767 }
768
769 module HingeLeverPrint(){ ////toplevel
770   rotate([90,0,0])
771     HingeLever();
772 }
773
774 module TestSelectLength(){
775   translate([-30, -200, -20])
776     cube([30 + 15, 250, 40]);
777 }
778
779 module TestLength(){ ////toplevel
780   intersection(){
781     Case();
782     TestSelectLength();
783   }
784 }
785
786 module TestLengthRight(){ ////toplevel
787   intersection(){
788     Case();
789     Flip_rhs(1)
790       TestSelectLength();
791   }
792 }
793
794 module TestSelectWidth(){
795   translate([-30, -(phone_height - 25), -20])
796     mirror([0, 1, 0])
797     cube([200, 50, 40]);
798 }
799
800 module TestWidth(){ ////toplevel
801   intersection(){
802     Case();
803     TestSelectWidth();
804   }
805 }
806
807 module TestLidWidthPrint(){ ////toplevel
808   rotate([0,180.0]) intersection(){
809     Lid();
810     TestSelectWidth();
811   }
812 }
813
814 module TestSelectRearAperture(){
815   minkowski(){
816     union() children();
817     translate([20, 0,0])
818       cube([42, 2, 1], center=true);
819   }
820 }
821
822 module TestSelectCamera(){
823   minkowski(){
824     TestSelectRearAperture()
825       RearCameraAperture();
826     cube([0.1, 50, 0.1]);
827   }
828 }
829
830 module TestSelectOrdinaryRearApertures(){
831   TestSelectRearAperture()
832     OrdinaryRearApertures();
833 }
834
835 module TestCamera(){ ////toplevel
836   intersection(){
837     Case();
838     TestSelectCamera();
839   }
840 }
841
842 module TestLidByCamera(){ ////toplevel
843   intersection(){
844     Lid();
845     TestSelectCamera();
846   }
847 }
848
849 module TestLidByCameraPrint(){ ////toplevel
850   rotate([180,0,0]) TestLidByCamera();
851 }
852
853 module DemoByCamera(){ ////toplevel
854   color("blue") TestLidByCamera();
855   color("red")  TestCamera();
856 }
857
858 module OneKeeper(){ ////toplevel
859   translate([0, -phone_cnr_rad, 0])
860     rotate([90, 0, 0])
861     linear_extrude(height = phone_height - phone_cnr_rad * 2)
862     KeeperProfile();
863 }
864
865 module OneKeeperPrint(){ ////toplevel
866   rotate([0,180,0])
867     OneKeeper();
868 }
869
870 module LidPrint(){ ////toplevel
871   rotate([0,180,0])
872     Lid();
873 }
874
875 module TestSelectPropRecesses(posns){
876   linextr(-100,100){
877     translate([phone_width/2, -phone_height]){
878       square([ 3, 500 ], center=true);
879       for (y=posns)
880         hull()
881           for (dy=[ -prp5[0], -prp2[0] ])
882             translate([0,y+dy])
883               square([prop_main_width+5, 5], center=true);
884     }
885   }
886 }
887
888 module TestSelectFrame(){
889   include = [1,-1] * (epp2i[0] + 4);
890
891   difference(){
892     cube(1000, center=true);
893     translate([0,0, -100])
894       linear_extrude(height=200)
895       rectfromto(include,  inside_br - include);
896   }
897 }
898
899 module TestSelectLidFrame(){
900   TestSelectFrame();
901   TestSelectPropRecesses(prop_lid_posns);
902 }
903
904 module TestFrameCase(){ ////toplevel
905   intersection(){
906     Case();
907     union(){
908       TestSelectFrame();
909       TestSelectCamera();
910       TestSelectOrdinaryRearApertures();
911     }
912   }
913 }
914
915 module TestFrameLidPrint(){ ////toplevel
916   rotate([0,180,0]) intersection(){
917     Lid();
918     TestSelectLidFrame();
919   }
920 }
921
922 module ButtonPlanForDemo(z, deep, cut){
923   translate([0,0,z])
924     ButtonPlan(8, deep, cut);
925 }
926
927 module HingeScrews(){
928   Flip_rhs() Flip_bot(1){
929     for (c= [ hppT, hppB ])
930       translate([ hex20,
931                   -c[0],
932                   c[1] ]){
933         rotate([0,90,0])
934           translate([0,0,-.2])
935           cylinder( r= hingescrew_shaft_dia/2,
936                     h = hingescrew_shaft_len+0.2 );
937         rotate([0,-90,0])
938           translate([0,0,+.1])
939           cylinder( r= hingescrew_head_dia/2, h = hingescrew_head_th );
940       }
941   }
942 }
943
944 module DemoFrame(){ ////toplevel
945   color("red") TestFrameCase();
946   color("blue") intersection(){ Lid(); TestSelectLidFrame(); }
947   color("black") HingeScrews();
948   %HingeLever();
949 }
950
951 module DemoHingedFrame(){ ///toplevel
952   color("red") TestFrameCase();
953   translate([0,0, -2*hp_k])
954   color("blue") intersection(){ Lid(); TestSelectLidFrame(); }
955
956   Flip_hinge(){
957     color("orange") HingeLever();
958     color("black") HingeScrews();
959   }
960 }
961
962 module DemoHinge(){ ////toplevel
963   DemoFrame();
964   translate([0,0, -hp_k*3])
965     DemoHingedFrame();
966 }
967
968 module DemoProfiles(){ ////toplevel
969   LidEdgeProfile();
970   %EdgeProfile();
971   KeeperProfile();
972   translate([0,0,-1]) color("black") KeeperProfile(1);
973
974   translate([20,0]) {
975     LidEdgeProfile();
976     %EdgeProfile();
977
978     demopoint_QR = [ bppS[0], bppQ[1] - 0.1];
979   
980     color("blue") ButtonCoverProfile();
981     color("red") {
982       rectfromto(bppQ, demopoint_QR);
983       rectfromto(bppR, demopoint_QR);
984     }
985   }
986
987   translate([-20,0]) {
988     color("black") ButtonPlanForDemo(-2, 0,1);
989     color("red" )  ButtonPlanForDemo(-4, 1,1);
990     color("blue")  ButtonPlanForDemo(-6, 1,0);
991   }
992
993   translate([0, -30]) {
994     %LidEdgeProfile();
995     %EdgeProfile();
996     color("blue") HingeLidProfile();
997     color("red")  HingeBaseProfile();
998     color("black") translate([0,0,-2]) HingeLeverOuterProfile();
999     color("orange") translate([0,0,-1]) HingeLeverInnerProfile();
1000   }
1001
1002   translate([20,-30]) {
1003     %EdgeProfile();
1004     %LidEdgeProfile();
1005     //translate([0,0,1]) CatchCutProfile();
1006     color("blue") CatchCatchProfile();
1007     color("red") difference(){ EdgeProfile(); CatchCutProfile(); }
1008   }
1009 }
1010
1011 //EdgeProfile();
1012 //KeeperProfile();
1013 //CaseBase();
1014 //%Case();
1015 //Keeper();
1016 //LidEdgeProfile();
1017 //KeeperProfile();
1018 //DemoProfiles();
1019 //PropRecess();