chiark / gitweb /
e6629371fce1e41202700c0f8c374bca619d649a
[reprap-play.git] / fairphone-case.scad
1 // -*- C -*-
2
3 include <utils.scad>
4
5 phone = [ 75.0, 145.0 ];
6
7 prop_buildout_less = 3;
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.35; // one side only
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 in case
248
249 prop_x_pos = phone_width/2;
250
251 prop_recess_hw = 0.5 * prop_main_width + prop_side_gap;
252
253 prc_r1 = prop_end_dia/2;
254 prc_r3 = prc_r1 + prop_recess_slop;
255
256 prcp2 = [ epp4[0] + prop_buildout_less,
257           case_bottom_z ];
258
259 prop_caserecess_buildout_r = -1; // prcp2[0] - epp2o[0];
260
261 echo(prc_r3);
262
263 prcp1 = [ epp2o[0],
264           epp2i[1] - prc_r3 ];
265
266 // ---------- modules ----------
267
268 module KeeperProfile(slant=0){
269   use_e = kppe + [0,-1] * slant * keeper_inner_width / keeper_slant_slope;
270   polygon([use_e, kppd, kppc, kppb, kppa, kppf]);
271 }
272
273 module EdgeProfile(){
274   difference(){
275     hull(){
276       translate(epp3) square(case_th_bottom*2, center=true);
277       circleat(epp2o, r=case_th_bottom);
278       circleat(epp1, r=case_th_side);
279       rectfromto(epp0, epp4);
280     }
281     polygon([ epp5 + [0,10],
282               epp1,
283               epp2i,
284               epp3 + [10,0] ]);
285   }
286 }
287
288 module LidEdgeProfile(){
289   polygon([ lpp10,
290             lpp11,
291             lpp12,
292             lpp13,
293             lpp13 + [10, 0],
294             lpp10 + [10, 0]
295             ]);
296   intersection(){
297     circleat(lpp12, r=lp_r12);
298     rectfromto( lpp12 + [-10,   0],
299                 lpp12 + [+10, +10] );
300   }
301 }
302
303 module ButtonCoverProfile(){
304   intersection(){
305     polygon([ bppM, bppP, bppO, bppJ, bppL, bppK ]);
306     hull(){
307       EdgeProfile();
308       LidEdgeProfile();
309     }
310   }
311 }
312
313 module ButtonPlan(l, deep, cut){
314   epsilon =
315     (cut  ? 0 : lid_buttoncover_gap);
316
317   delta =
318     (deep ? lid_buttoncover_overlap : 0);
319
320   C = [0,0]; // by definition
321   T = [ 0, epp4[1] ];
322   G = T + [0,10];
323
324   B0 = C + [0,-1] * button_cutout_depth;
325   B1 = B0 + [0,1] * epsilon;
326
327   r0 = 0.5 * (T[1] - B0[1]);
328   A = [  -(l + button_l_fudge)/2 + r0, 0.5 * (T[1] + B0[1]) ];
329   H = A + [0,-1] * delta;
330
331   D = A + [-2,0] * r0;
332   F = D + [0,10];
333
334   E0 = 0.5 * (D + A);
335   E1 = E0 + [1,0] * epsilon;
336
337   I0 = [ E0[0], H[1] ];
338   I1 = [ E1[0], H[1] ];
339
340   hull(){
341     for (m=[0,1]) mirror([m,0])
342       circleat(H, r0 - epsilon);
343   }
344   for (m=[0,1]) mirror([m,0]) {
345     difference(){
346       polygon([ E1,
347                 I1,
348                 H,
349                 B1,
350                 G,
351                 F,
352                 D
353                 ]);
354       circleat(D, r0 + epsilon);
355     }
356   }
357 }
358
359 module CatchCatchProfile(){
360   hull(){
361     for (c=[ cppR, cppQ ])
362       circleat(c, cp_rQ);
363   }
364   hull(){
365     circleat(lpp12, lp_r12);
366     circleat(lpp12 + [5,0], lp_r12);
367     rectfromto(cppP, cppP + [5,0.1]);
368   }
369   polygon([cppJ, cppS, cppT, cppU, cppV, cppQ, cppR]);
370 }
371
372 module CatchCutProfile(){
373   polygon([ cppB,
374             cppA,
375             cppD,
376             cppF,
377             cppF + [0,-10],
378             cppF + [-10,-10],
379             lpp12 + [-10,0],
380             lpp12 + [10,0]
381             ]);
382 }
383
384 module Flip_rhs(yn=[0,1]) {
385   for ($rhsflip=yn) {
386     translate([phone_width/2, 0, 0])
387       mirror([$rhsflip,0,0])
388       translate([-phone_width/2, 0, 0])
389       children();
390   }
391 }
392
393 module Flip_bot(yn=[0,1]) {
394   for ($botflip=yn) {
395     translate([0, -phone_height/2, 0])
396       mirror([0, $botflip, 0])
397       translate([0, phone_height/2, 0])
398       children();
399   }
400 }  
401
402 module AroundEdges(fill_zstart, fill_th, fill_downwards=0){
403   // sides
404   Flip_rhs(){
405     translate([0, -phone_cnr_rad, 0])
406       rotate([90,0,0])
407       linear_extrude(height = phone_height - phone_cnr_rad*2)
408       children(0);
409   }
410   // corners
411   Flip_rhs() Flip_bot() {
412     translate([+1,-1] * phone_cnr_rad)
413       intersection(){
414         rotate_extrude()
415           intersection(){
416             mirror([1,0,0])
417               translate([-1,0] * phone_cnr_rad)
418               children(0);
419             rectfromto([0,-20],[10,20]);
420           }
421         translate([-10, 0, -20] + 0.01 * [+1,-1, 0] )
422           cube([10,10,40]);
423       }
424   }
425   // top and bottom
426   Flip_bot(){
427     translate([ phone_width - phone_cnr_rad, 0,0 ])
428       rotate([90,0,-90])
429       linear_extrude(height = phone_width - phone_cnr_rad*2)
430       children(0);
431   }
432   // fill
433   translate([0,0, fill_zstart])
434     mirror([0,0, fill_downwards])
435     linear_extrude(height = fill_th)
436     rectfromto([+1,-1] * phone_cnr_rad,
437                [phone_width, -phone_height] + [-1,+1] * phone_cnr_rad);
438 }
439
440 module CaseAperture(pos, dia, $fn) {
441   theta = 180/$fn;
442   translate([ pos[0] + bumper[0],
443               -epp2i[0],
444               -pos[1] ])
445     rotate([-90, theta, 0])
446     cylinder(r = dia/2 / cos(theta),
447              h = 60);
448 }
449
450 module SideButton(y, y_ref_sign, l){
451   // y_ref_sign:
452   //   +1  measured from top    of actual phone to top    of button
453   //   -1  measured from bottom of actual phone to bottom of button
454   //    0  y is centre of button in coordinate system
455   $button_l= l;
456   eff_y = y_ref_sign > 0 ?         -bumper [1] -y -l/2 :
457           y_ref_sign < 0 ? (-phone -bumper)[1] +y +l/2 :
458           y;
459   //echo(eff_y);
460   translate([0, eff_y, 0])
461     children();
462 }
463
464 module LidButtonishLeg(y, y_ref_sign, l=buttonishleg_default_l_is_fudge) {
465   $button_leg_only = true;
466   SideButton(y, y_ref_sign, l) children();
467 }
468
469 module Buttons(){
470   Flip_rhs(1) SideButton(15.580, +1, 8.9) children(); // power
471   Flip_rhs(1) SideButton(48.700, -1, 8.920) children(); // camera
472   Flip_rhs(0) SideButton(30.800, +1, 21.96) children(); // volume
473   Flip_rhs(   ) LidButtonishLeg(14, -1) children();
474 //  Flip_rhs(0) LidButtonishLeg(20, +1, 20) children();
475 }
476
477 module Struts(x_start, z_min, th){
478   // if th is negative, starts at z_min and works towards -ve z
479   // and object should then be printed other way up
480   for (i= [1 : 1 : case_struts_count]) {
481     translate([0,
482                0,
483                z_min])
484       mirror([0,0, th<0 ? 1 : 0])
485       translate([0,
486                  -phone_height * i / (case_struts_count+1),
487                  case_struts_solid_below])
488       linear_extrude(height= abs(th)
489                      -(case_struts_solid_below+case_struts_solid_above))
490       rectfromto([               x_start, -0.5 * case_struts_width ],
491                  [ phone_width - x_start, +0.5 * case_struts_width ]);
492   }
493 }
494
495 module OrdinaryRearAperture(rhs,bot, pos){
496   Flip_rhs(rhs) Flip_bot(bot)
497     linextr(-20, 20)
498     mirror([0,1])
499     translate(pos + bumper)
500     children();
501 }
502
503 module MicroUSB(){
504   Flip_bot(1){
505     rotate([90,0,0])
506       mirror([0,0,1])
507       linextr(-epp2i[0], 60)
508       translate([0.5 * phone_width, 0, 0])
509       rectfromto([-microusb_width/2, epp2i[1] + microusb_below],
510                  [+microusb_width/2, epp0[1] + -microusb_above]);
511   }
512 }
513
514 module OrdinaryRearApertures(){
515   // rear speaker
516   OrdinaryRearAperture(1,1, rearspeaker_pos_bl)
517     rectfromto(-rearspeaker_gap,
518                rearspeaker_size + rearspeaker_gap);
519
520   // finger hole to remove phone
521   if (len(fingerpushhole_dias))
522     OrdinaryRearAperture(1,0, [ fingerpushhole_dias[0]/2 + epp2i[0],
523                                 phone[1]/2 ])
524     scale(fingerpushhole_dias)
525     circle(r= 0.5 );
526 }
527
528 module RearCameraAperture(){
529   Flip_rhs(1)
530     mirror([0, 0, 1])
531     linear_extrude(height = 20)
532     mirror([0, 1, 0])
533     translate(bumper)
534     rectfromto(camera_pos_tl, camera_pos_br);
535 }
536
537 module HingeLidProfile(){
538   hull(){
539     circleat(hppT, hp_r1);
540     circleat(lpp12, lp_r12);
541     polygon([lpp10,
542              lpp13 + [2,0],
543              lpp12,
544              hppT]);
545   }
546 }
547
548 module HingeBaseProfile(){
549   difference(){
550     hull(){
551       circleat(hppB, hp_r1);
552       circleat(hppE, hp_r1);
553       circleat(epp2o, case_th_bottom);
554       circleat(hppB + [10,0], hp_r1);
555     }
556     polygon([epp5, epp1, epp2i, epp3, bppL]);
557   }
558 }
559
560 module HingeLeverOuterProfile(){
561   hull(){
562     circleat(hppT, hp_r2);
563     circleat(hppB, hp_r2);
564   }
565 }
566
567 module HingeLeverInnerProfile(){
568   for (c = [hppT, hppB]) {
569     hull()
570       for (x=[-20,20])
571         for (y=[0, c[1] - hppM[1]])
572           translate([x,y])
573             circleat(c, hp_rn);
574   }
575 }
576
577 module Flip_hinge(){
578   hinge_origin = [0, -(phone_height - hppB[0]), hppB[1]];
579   translate(hinge_origin)
580     rotate([180,0,0])
581     translate(-hinge_origin)
582     children();
583 }
584
585 module HingePortion(x0,x1){
586   Flip_rhs() Flip_bot(1)
587     translate([x0,0,0])
588     mirror([1,0,0])
589     rotate([90,0,-90])
590     linear_extrude(height=x1-x0)
591     children(0);
592 }
593
594 module CatchPortion(width){
595   translate([phone_width/2, 0,0])
596     rotate([90,0,-90])
597     linextr(-width/2, width/2)
598     children(0);
599 }
600
601 module CaseBase(){
602   AroundEdges(epp3[1], case_th_bottom, 1)
603     EdgeProfile();
604 }
605
606 module Case(){ ////toplevel
607   difference(){
608     union(){
609       CaseBase();
610
611       // ledge (fixed keeper)
612       Flip_rhs(1-keeper_side) intersection(){
613         rotate([90, 0, 0])
614           linear_extrude(height = phone_height + phone_cnr_rad * 2)
615           KeeperProfile(1);
616
617         // outline of the whole case, to stop it protruding
618         translate([0,0, -25])
619           linear_extrude(height = 50)
620           hull()
621           Flip_bot()
622           circleat([+1,-1] * phone_cnr_rad, phone_cnr_rad + case_th_side/2);
623       }
624
625       // hinge
626       HingePortion(hex20, hex21) HingeBaseProfile();
627
628       // buildout for prop recess
629       if (prop_caserecess_buildout_r > 0) Flip_rhs(1)
630         linextr(case_bottom_z, epp2i[1])
631         hull() {
632           for (dxs = [-1,+1])
633             circleat([ prop_x_pos + dxs * prop_caserecess_buildout_r,
634                        -epp2o[0] ],
635                      r = epp2o[0] - prcp2[0]);
636         }
637     }
638
639     // slot for keeper
640     Flip_rhs(keeper_side)
641       translate([0, -phone_cnr_rad, 0])
642       rotate([90, 0, 0])
643       linear_extrude(height = phone_height + phone_cnr_rad * 2)
644       minkowski(){
645         KeeperProfile();
646         rectfromto([ -keeper_gap_x,    -keeper_gap_z_bot ],
647                    [ keeper_gap_x_holes,    +keeper_gap_z_top ]);
648       }
649
650     // front camera
651     RearCameraAperture();
652
653     // struts (invisible, because they're buried in the case)
654     Struts(epp2i[0], epp2i[1] - case_th_bottom, case_th_bottom);
655
656     Buttons(){
657       mirror([1,0,0])
658         rotate([90,0,90]) {
659           if (!($button_leg_only && enable_support))
660           intersection(){
661             translate([0,0,-10])
662               linear_extrude(height= 20)
663               ButtonPlan($button_l, 0,1);
664             if ($button_leg_only)
665               rotate([-90,90,0])
666                 translate([phone_width/2, -400, kppe[1]])
667                 mirror([1-abs($rhsflip - keeper_side),0,0])
668                 cube([400, 800, 50]);
669             if (enable_support)
670               rotate([-90,90,0])
671               translate([-400, -400, kppd[1]])
672                 mirror([0,0,1])
673                 cube([800,800,100]);
674           }
675           translate([0,0, -bppR[0]])
676             linear_extrude(height= 20)
677             ButtonPlan($button_l, 1,1);
678         }
679       
680     }
681
682     // apertures along top edge
683     CaseAperture(jack_pos, jack_dia, 8);
684     Flip_rhs(1)
685       CaseAperture(noisecancelmic_pos, noisecancelmic_dia, 8);
686
687     OrdinaryRearApertures();
688
689     MicroUSB();
690
691     // gaps for the lid's hinge arms
692     HingePortion(hex20 - hinge_x_arms_gap,
693                  hex21 + hinge_x_arms_gap)
694       minkowski(){
695         HingeLidProfile();
696         circle(r= hinge_r_arms_gap, $fn= 8);
697       }
698
699     // screw holes in the hinge arms
700     HingeScrews();
701
702     // catch striker
703     CatchPortion(catch_width + catch_side_gap*2)
704       CatchCutProfile();
705
706     // prop recess
707     Flip_rhs(1)
708       translate([prop_x_pos,0,0])
709       rotate([90,0,90])
710       linextr(-prop_recess_hw, +prop_recess_hw)
711       mirror([1,0])
712       hull(){
713         for (d=[ [0,0], [0,-1], [+1,-1/prop_caserecess_taper] ])
714           circleat(prcp1 + 20*d,
715                    prc_r3);
716       }
717   }
718 }
719
720 module Lid(){ ////toplevel
721   difference(){
722     union(){
723       AroundEdges(lpp10[1], lpp13[1] - lpp10[1], 0)
724         LidEdgeProfile();
725
726       // button covers
727       Buttons(){
728         intersection(){
729           rotate([90,0,90])
730             translate([0,0,-10])
731             linear_extrude(height= 20)
732             ButtonPlan($button_l, 1,0);
733           rotate([90,0,0])
734              translate([0,0,-100])
735             linear_extrude(height= 200)
736             ButtonCoverProfile();
737         }
738       }
739
740       // hinge arms
741       HingePortion(hex20, hex21) HingeLidProfile();
742
743       // catch
744       CatchPortion(catch_width)
745         CatchCatchProfile();
746     }
747     Struts(lpp10[0] + strut_min_at_end, lpp13[1], -case_th_lid);
748
749     // screw holes in the hinge arms
750     HingeScrews();
751   }
752 }
753
754 module HingeLever(){ ////toplevel
755   difference() {
756     // outer body, positive
757     HingePortion(hex22, hex22 + phone_width/2)
758       HingeLeverOuterProfile();
759
760     // space for the screws
761     HingePortion(hex23, hex24)
762       HingeLeverInnerProfile();
763
764     // bores for the screws
765     HingeScrews();
766
767     // space for the charging cable
768     MicroUSB();
769     Flip_hinge() MicroUSB();
770   }
771 }
772
773 module HingeLeverPrint(){ ////toplevel
774   rotate([90,0,0])
775     HingeLever();
776 }
777
778 module TestSelectLength(){
779   translate([-30, -200, -20])
780     cube([30 + 15, 250, 40]);
781 }
782
783 module TestLength(){ ////toplevel
784   intersection(){
785     Case();
786     TestSelectLength();
787   }
788 }
789
790 module TestLengthRight(){ ////toplevel
791   intersection(){
792     Case();
793     Flip_rhs(1)
794       TestSelectLength();
795   }
796 }
797
798 module TestSelectWidth(){
799   translate([-30, -(phone_height - 25), -20])
800     mirror([0, 1, 0])
801     cube([200, 50, 40]);
802 }
803
804 module TestWidth(){ ////toplevel
805   intersection(){
806     Case();
807     TestSelectWidth();
808   }
809 }
810
811 module TestLidWidthPrint(){ ////toplevel
812   rotate([0,180.0]) intersection(){
813     Lid();
814     TestSelectWidth();
815   }
816 }
817
818 module TestSelectRearAperture(){
819   minkowski(){
820     union() children();
821     translate([20, 0,0])
822       cube([42, 2, 1], center=true);
823   }
824 }
825
826 module TestSelectCamera(){
827   minkowski(){
828     TestSelectRearAperture()
829       RearCameraAperture();
830     cube([0.1, 50, 0.1]);
831   }
832 }
833
834 module TestSelectOrdinaryRearApertures(){
835   TestSelectRearAperture()
836     OrdinaryRearApertures();
837 }
838
839 module TestCamera(){ ////toplevel
840   intersection(){
841     Case();
842     TestSelectCamera();
843   }
844 }
845
846 module TestLidByCamera(){ ////toplevel
847   intersection(){
848     Lid();
849     TestSelectCamera();
850   }
851 }
852
853 module TestLidByCameraPrint(){ ////toplevel
854   rotate([180,0,0]) TestLidByCamera();
855 }
856
857 module DemoByCamera(){ ////toplevel
858   color("blue") TestLidByCamera();
859   color("red")  TestCamera();
860 }
861
862 module OneKeeper(){ ////toplevel
863   translate([0, -phone_cnr_rad, 0])
864     rotate([90, 0, 0])
865     linear_extrude(height = phone_height - phone_cnr_rad * 2)
866     KeeperProfile();
867 }
868
869 module OneKeeperPrint(){ ////toplevel
870   rotate([0,180,0])
871     OneKeeper();
872 }
873
874 module LidPrint(){ ////toplevel
875   rotate([0,180,0])
876     Lid();
877 }
878
879 module TestSelectPropRecesses(posns){
880   linextr(-100,100){
881     translate([phone_width/2, -phone_height]){
882       square([ 3, 500 ], center=true);
883       for (y=posns)
884         hull()
885           for (dy=[ -prp5[0], -prp2[0] ])
886             translate([0,y+dy])
887               square([prop_main_width+5, 5], center=true);
888     }
889   }
890 }
891
892 module TestSelectFrame(){
893   include = [1,-1] * (epp2i[0] + 4);
894
895   difference(){
896     cube(1000, center=true);
897     translate([0,0, -100])
898       linear_extrude(height=200)
899       rectfromto(include,  inside_br - include);
900   }
901 }
902
903 module TestSelectLidFrame(){
904   TestSelectFrame();
905   TestSelectPropRecesses(prop_lid_posns);
906 }
907
908 module TestFrameCase(){ ////toplevel
909   intersection(){
910     Case();
911     union(){
912       TestSelectFrame();
913       TestSelectCamera();
914       TestSelectOrdinaryRearApertures();
915     }
916   }
917 }
918
919 module TestFrameLidPrint(){ ////toplevel
920   rotate([0,180,0]) intersection(){
921     Lid();
922     TestSelectLidFrame();
923   }
924 }
925
926 module ButtonPlanForDemo(z, deep, cut){
927   translate([0,0,z])
928     ButtonPlan(8, deep, cut);
929 }
930
931 module HingeScrews(){
932   Flip_rhs() Flip_bot(1){
933     for (c= [ hppT, hppB ])
934       translate([ hex20,
935                   -c[0],
936                   c[1] ]){
937         rotate([0,90,0])
938           translate([0,0,-.2])
939           cylinder( r= hingescrew_shaft_dia/2,
940                     h = hingescrew_shaft_len+0.2 );
941         rotate([0,-90,0])
942           translate([0,0,+.1])
943           cylinder( r= hingescrew_head_dia/2, h = hingescrew_head_th );
944       }
945   }
946 }
947
948 module DemoFrame(){ ////toplevel
949   color("red") TestFrameCase();
950   color("blue") intersection(){ Lid(); TestSelectLidFrame(); }
951   color("black") HingeScrews();
952   %HingeLever();
953 }
954
955 module DemoHingedFrame(){ ///toplevel
956   color("red") TestFrameCase();
957   translate([0,0, -2*hp_k])
958   color("blue") intersection(){ Lid(); TestSelectLidFrame(); }
959
960   Flip_hinge(){
961     color("orange") HingeLever();
962     color("black") HingeScrews();
963   }
964 }
965
966 module DemoHinge(){ ////toplevel
967   DemoFrame();
968   translate([0,0, -hp_k*3])
969     DemoHingedFrame();
970 }
971
972 module DemoProfiles(){ ////toplevel
973   LidEdgeProfile();
974   %EdgeProfile();
975   KeeperProfile();
976   translate([0,0,-1]) color("black") KeeperProfile(1);
977
978   translate([20,0]) {
979     LidEdgeProfile();
980     %EdgeProfile();
981
982     demopoint_QR = [ bppS[0], bppQ[1] - 0.1];
983   
984     color("blue") ButtonCoverProfile();
985     color("red") {
986       rectfromto(bppQ, demopoint_QR);
987       rectfromto(bppR, demopoint_QR);
988     }
989   }
990
991   translate([-20,0]) {
992     color("black") ButtonPlanForDemo(-2, 0,1);
993     color("red" )  ButtonPlanForDemo(-4, 1,1);
994     color("blue")  ButtonPlanForDemo(-6, 1,0);
995   }
996
997   translate([0, -30]) {
998     %LidEdgeProfile();
999     %EdgeProfile();
1000     color("blue") HingeLidProfile();
1001     color("red")  HingeBaseProfile();
1002     color("black") translate([0,0,-2]) HingeLeverOuterProfile();
1003     color("orange") translate([0,0,-1]) HingeLeverInnerProfile();
1004   }
1005
1006   translate([20,-30]) {
1007     %EdgeProfile();
1008     %LidEdgeProfile();
1009     //translate([0,0,1]) CatchCutProfile();
1010     color("blue") CatchCatchProfile();
1011     color("red") difference(){ EdgeProfile(); CatchCutProfile(); }
1012   }
1013 }
1014
1015 //EdgeProfile();
1016 //KeeperProfile();
1017 //CaseBase();
1018 //%Case();
1019 //Keeper();
1020 //LidEdgeProfile();
1021 //KeeperProfile();
1022 //DemoProfiles();
1023 //PropRecess();