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