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