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