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