Pip-Boy inspired phone holder built around the PINE64 PinePhone
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

426 lines
13 KiB

  1. include <export.scad>
  2. // dependency: https://github.com/revarbat/BOSL
  3. include <BOSL/constants.scad>
  4. use <BOSL/transforms.scad>
  5. use <BOSL/shapes.scad>
  6. use <BOSL/masks.scad>
  7. use <BOSL/sliders.scad>
  8. use <specs_phone.scad>
  9. use <specs_harness.scad>
  10. use <specs_platform.scad>
  11. // DEBUG:
  12. //validation = 1;
  13. XRAY_POSITIVE=1;
  14. XRAY_BACKPLANE=2;
  15. XRAY_BOTTOM=3;
  16. //xray = 2;
  17. function use_slideout_backplane() = is_model_strict(MODEL_HARNESS_BOTTOM_PIP) || is_model_strict(MODEL_HARNESS_LEFT) || is_model_strict(MODEL_HARNESS_RIGHT);
  18. backplane_pip_slideout=10;
  19. use <common.scad>
  20. module dotted_grill_cutout(vents_area, vents_x=10, vents_y=10, mesh=1.5, cut_corners=false) {
  21. function is_corner(x, y, xm, ym) = (x == 0 || x == xm) && (y == 0 || y == ym);
  22. vent_size=[vents_area.x/vents_x-mesh, vents_area.y/vents_y-mesh, vents_area.z];
  23. translate([-vents_area.x/2 - vent_size.x/2, vents_area.y/2 - vent_size.y/2, 0])
  24. for (x=[0:vents_x-1]) {
  25. for (y=[0:vents_y-1]) {
  26. if (!cut_corners || !is_corner(x, y, vents_x-1, vents_y-1)) {
  27. right(x*(vent_size.x+mesh))
  28. fwd(y*(vent_size.y+mesh))
  29. cubi(vent_size, fillet=min(vent_size.x/2, vent_size.y/2));
  30. }
  31. }
  32. }
  33. }
  34. module phone() {
  35. s=get_phone_size();
  36. color("gray")
  37. cubi(s, fillet=5);
  38. }
  39. module arm() {
  40. $fn=6;
  41. s=[210, 55, 50];
  42. color("SaddleBrown")
  43. down(s.z/2 + get_phone_size().z/2) cubi(s, fillet=20);
  44. }
  45. module phone_harness() {
  46. ops=get_phone_size();
  47. ps=[ops.x+0.2, ops.y+0.2, ops.z+0.2];
  48. shell_wall=3;
  49. shell_rim_wall=3;
  50. rim_edge_thickness=1.5;
  51. rim_edge_tolerance=0.4;
  52. expose_back_camera=true;
  53. screwmount_screw=3;
  54. harness_divider=[1, 0, 1.3];
  55. harness_size=[ps.x+shell_wall*2, ps.y+shell_wall*2, ps.z+shell_wall*2];
  56. rim_size=[harness_size.x+2*shell_rim_wall, harness_size.y+2*shell_rim_wall, 8];
  57. w=shell_wall;
  58. f=2;
  59. rf=5;
  60. hs=harness_size;
  61. backplane_rim_size=[40, ps.y*0.95, shell_wall/2];
  62. backplane_teeth=6;
  63. // ==== SHELL ====
  64. module shell() {
  65. $fn = $preview ? 6 : 30;
  66. difference() {
  67. cubi(hs, fillet=f);
  68. cubi(ps, fillet=f);
  69. }
  70. shell_rim();
  71. shell_screwmounts();
  72. }
  73. module shell_rim() {
  74. $fn = $preview ? 6 : 30;
  75. w=shell_rim_wall;
  76. s=rim_size;
  77. intersection() {
  78. difference() {
  79. cubi(s, fillet=rf, edges=EDGES_Z_ALL);
  80. cubi(ps, fillet=f, edges=EDGES_Z_ALL);
  81. }
  82. cubi(s, fillet=1);
  83. }
  84. rail_extension=10;
  85. fwd(hs.y/2) xrot(90) harness_rail(slider_len_front+rail_extension);
  86. back(hs.y/2) xrot(-90) harness_rail(slider_len_back+rail_extension);
  87. }
  88. module shell_rim_edge(thickness, groove, tolerance=rim_edge_tolerance) {
  89. $fn = $preview ? 6 : 30;
  90. w=thickness + (groove ? tolerance : 0);
  91. offset=(groove ? 0 : tolerance/2);
  92. res=[hs.x+2*(w+offset), hs.y+2*(w+offset), 3];
  93. resi=[hs.x+2*offset, hs.y+2*offset, res.z+1];
  94. up(0.0) difference() {
  95. intersection() {
  96. cubi(res, fillet=rf, edges=EDGES_Z_ALL);
  97. cubi(res, fillet=(groove?1:1.5), edges=EDGES_BOTTOM);
  98. }
  99. cubi(resi, fillet=rf, edges=EDGES_Z_ALL);
  100. }
  101. }
  102. module foreach_screwmount() {
  103. for(x = [0:1]) for (y = [0:1]) {
  104. translate([(-0.5+x)*ps.x, (-0.5+y)*ps.y, -hs.z/2])
  105. children();
  106. }
  107. }
  108. module shell_screwmounts() {
  109. $fn = $preview ? 6 : 30;
  110. r=3;
  111. foreach_screwmount() {
  112. cylinder(r=r, h=hs.z);
  113. }
  114. }
  115. module shell_screwmounts_holes() {
  116. $fn = $preview ? 6 : 30;
  117. foreach_screwmount() {
  118. up(w) cylinder(d2=screwmount_screw, d1=screwmount_screw*0.5, h=hs.z+1);
  119. up(hs.z-1) cylinder(d=screwmount_screw+1.5, h=5);
  120. }
  121. }
  122. module shell_backplane(groove) {
  123. module groove_scale() { scale([groove?1.05:1, groove?1.05:1, groove?1.2:1]) children(); }
  124. if (use_slideout_backplane()) {
  125. down(hs.z/2 - shell_wall/3) up(backplane_rim_size.z/2) right(harness_divider.x) {
  126. back(backplane_rim_size.y/2) {
  127. teeth=backplane_teeth;
  128. segment=backplane_rim_size.y/teeth;
  129. tooth_size=[backplane_rim_size.x, segment/2, backplane_rim_size.z];
  130. joiner_base=5;
  131. joiner_size=[joiner_base + (groove?backplane_pip_slideout:0), segment*1.5, backplane_rim_size.z];
  132. for (i = [0:teeth-1]) {
  133. fwd(i*segment) fwd(tooth_size.y) {
  134. groove_scale() cubi(tooth_size, fillet=0.5, edges=EDGES_X_ALL);
  135. if (i%2 == 0) {
  136. left(backplane_rim_size.x/2 + joiner_base/2) fwd(joiner_size.y/3) left(-joiner_size.x/2) groove_scale() cubi(joiner_size, fillet=2, edges=EDGES_Z_ALL);
  137. }
  138. }
  139. }
  140. }
  141. }
  142. }
  143. }
  144. // ==== SHELL SLIDER AND RAIL ====
  145. rail_angle=36;
  146. rail_wall=1;
  147. slider_slop=0.1;
  148. slider_len_back=hs.x*0.3;
  149. slider_len_front=hs.x*0.15;
  150. module harness_slider(l) {
  151. base=2;
  152. ss=[l, shell_rim_wall, rim_size.z+rail_wall*2];
  153. up(ss.y + base) xrot(180) difference() {
  154. slider(l=ss.x, w=ss.z, h=ss.y, base=base, chamfer=0.9, wall=2, ang=rail_angle, slop=slider_slop, orient=ORIENT_X, align=V_UP);
  155. screws=2;
  156. screws_area_l=0.7*l;
  157. for (i=[0:screws-1]) {
  158. $fn=$preview ? 6 : 16;
  159. right(-screws_area_l/2 + screws_area_l/(screws-1) * i) cylinder(d2=screwmount_screw*0.5, d1=screwmount_screw, h=ss.y*0.7);
  160. }
  161. }
  162. }
  163. module harness_rail(l) {
  164. sw=2;
  165. ss=[l, shell_rim_wall, rim_size.z+rail_wall*2];
  166. rail(l=ss.x, w=ss.z, h=ss.y, chamfer=0.5, ang=rail_angle, orient=ORIENT_X, align=V_UP);
  167. }
  168. // ==== SHELL CUTOUTS ====
  169. module shell_cutouts() {
  170. top_cutout();
  171. bottom_cutout();
  172. left_cutout();
  173. right_cutout();
  174. front_cutout();
  175. shell_screwmounts_holes();
  176. }
  177. // -- TOP --
  178. module screen_cutout() {
  179. $fn=$preview ? 4 : 12;
  180. s=[138, 69, 12];
  181. b = 10;
  182. s1=[s.x, s.y];
  183. s2=[s.x+b, s.y+b];
  184. h=s.z;
  185. up(5) rounded_prismoid(size1=s1, size2=s2, h=h, r1=1, r2=15);
  186. }
  187. top_offset=6.5;
  188. module top_speaker_cutout() {
  189. s=[3, 12, 100];
  190. right(ps.x/2 - top_offset) up(s.z/2 - ps.z/3) cubi(s, fillet=1);
  191. }
  192. module front_camera_cutout() {
  193. $fn = $preview ? 6 : 30;
  194. d=5;
  195. s=[d, d, 100];
  196. right(ps.x/2 - top_offset) fwd(11.5) cylinder(d=s.x, h=s.z);
  197. }
  198. module leds_cutout() {
  199. s=[4, 14, 100];
  200. right(ps.x/2 - top_offset) up(s.z/2 - ps.z/3) back(23) cubi(s, fillet=1);
  201. }
  202. module top_cutout() {
  203. screen_cutout();
  204. top_speaker_cutout();
  205. front_camera_cutout();
  206. leds_cutout();
  207. }
  208. // -- BOTTOM --
  209. module back_camera_cutout() {
  210. s=[13, 25, expose_back_camera ? 100 : 11];
  211. right(ps.x/2 - 7.5) fwd(ps.y/2 - 24.5) down(s.z/2 - ps.z/3) cubi(s, fillet=6, edges=EDGES_Z_ALL);
  212. }
  213. module bottom_speaker_cutout() {
  214. s=[8, 49, 100];
  215. left(ps.x/2 - 13)
  216. down(s.z/2 - ps.z/3)
  217. dotted_grill_cutout(s, vents_x=4, vents_y=8, cut_corners=true, mesh=1);
  218. }
  219. module bottom_vents_cutout() {
  220. vents_x=10;
  221. vents_y=6;
  222. vents_area=[35, 50, 10];
  223. vents_pos=[45, 0, -ps.z/2];
  224. mesh=1.5;
  225. translate(vents_pos)
  226. dotted_grill_cutout(vents_area, vents_x=vents_x, vents_y=vents_y, mesh=mesh, cut_corners=true);
  227. }
  228. module bottom_cutout() {
  229. back_camera_cutout();
  230. bottom_speaker_cutout();
  231. bottom_vents_cutout();
  232. }
  233. // -- RIGHT --
  234. module headphones_cutout() {
  235. $fn = $preview ? 10 : 30;
  236. d1=8.8;
  237. d2=14;
  238. p=[ps.x/2, ps.y/2-24, -0.88];
  239. h=22;
  240. translate(p) yrot(90) down(10) cylinder(h=h, d1=d1, d2=d2);
  241. }
  242. module right_cutout() {
  243. headphones_cutout();
  244. }
  245. // -- LEFT --
  246. module usbc_cutout() {
  247. s=[20, 20, 7];
  248. left(ps.x/2) down(2) cubi(s, fillet=1);
  249. }
  250. module left_cutout() {
  251. usbc_cutout();
  252. }
  253. // -- FRONT --
  254. buttons_cutout_size=[42, 100, 4.5];
  255. buttons_cutout_pos=[ps.x/2 - 44.5, -ps.y/2 - 3, 0.25];
  256. module buttons_cutout() {
  257. s=buttons_cutout_size;
  258. p=buttons_cutout_pos;
  259. translate(p) cubi(s, fillet=1);
  260. }
  261. module front_cutout() {
  262. buttons_cutout();
  263. }
  264. module front_buttons(socket) {
  265. s=[buttons_cutout_size.x-2, 4, buttons_cutout_size.z-0.5];
  266. p=buttons_cutout_pos;
  267. t=socket ? 0.2 : 0;
  268. pin_size=[3 + t, 3 + t, s.z+2 + t/2];
  269. touch_size=[2, s.y, 2];
  270. touch_power_size=[3, touch_size.y, touch_size.z];
  271. translate(p) {
  272. cs=[4, s.y, s.z];
  273. left(5) {
  274. bs=[13, s.y, s.z];
  275. left(bs.x/6) cubi(pin_size);
  276. left(bs.x/2) {
  277. difference() {
  278. cubi(bs);
  279. back(1) cubi(cs);
  280. }
  281. }
  282. fwd(1) left(bs.x*0.8) cubi(touch_power_size, fillet=1);
  283. }
  284. right(8) {
  285. bs=[18, s.y, s.z];
  286. cubi(pin_size);
  287. difference() {
  288. cubi(bs);
  289. back(1) {
  290. left(bs.x/4) cubi(cs);
  291. right(bs.x/4) cubi(cs);
  292. }
  293. }
  294. fwd(1) {
  295. left(bs.x*0.4) cubi(touch_size, fillet=1);
  296. right(bs.x*0.4) cubi(touch_size, fillet=1);
  297. }
  298. }
  299. }
  300. }
  301. // ==== MODEL ====
  302. divider=harness_divider;
  303. module model_harness_left() {
  304. intersection() {
  305. intersection() {
  306. translate(divider) downcube([1000, 1000, 1000]);
  307. translate(divider) leftcube([1000, 1000, 1000]);
  308. }
  309. difference() {
  310. shell();
  311. shell_rim_edge(rim_edge_thickness, groove=true, tolerance=rim_edge_tolerance);
  312. shell_cutouts();
  313. shell_backplane(groove=true);
  314. }
  315. }
  316. }
  317. module model_harness_right() {
  318. intersection() {
  319. intersection() {
  320. translate(divider) downcube([1000, 1000, 1000]);
  321. translate(divider) rightcube([1000, 1000, 1000]);
  322. }
  323. difference() {
  324. shell();
  325. shell_rim_edge(rim_edge_thickness, groove=true, tolerance=rim_edge_tolerance);
  326. shell_cutouts();
  327. front_buttons(socket=true);
  328. }
  329. }
  330. shell_backplane(groove=false);
  331. }
  332. module model_harness_top() {
  333. intersection() {
  334. translate(divider) upcube([1000, 1000, 1000]);
  335. difference() {
  336. shell();
  337. shell_cutouts();
  338. front_buttons(socket=true);
  339. }
  340. }
  341. difference() {
  342. shell_rim_edge(rim_edge_thickness, groove=false);
  343. shell_cutouts();
  344. front_buttons(socket=true);
  345. }
  346. }
  347. module model_harness_slider_front() {
  348. difference() {
  349. fwd(hs.y/2) xrot(90) harness_slider(slider_len_front);
  350. front_cutout();
  351. }
  352. }
  353. module model_harness_slider_back() {
  354. back(hs.y/2) xrot(-90) harness_slider(slider_len_back);
  355. }
  356. module model_harness_buttons() {
  357. front_buttons(socket=false);
  358. }
  359. if (is_model(MODEL_HARNESS_LEFT)) model_harness_left();
  360. if (is_model(MODEL_HARNESS_RIGHT)) model_harness_right();
  361. if (is_model_strict(MODEL_HARNESS_BOTTOM)) {
  362. model_harness_left();
  363. model_harness_right();
  364. }
  365. if (is_model_strict(MODEL_HARNESS_BOTTOM_PIP)) {
  366. model_harness_left();
  367. right(backplane_pip_slideout) model_harness_right();
  368. }
  369. if (is_model(MODEL_HARNESS_TOP)) model_harness_top();
  370. if (is_model(MODEL_HARNESS_SLIDER_FRONT)) model_harness_slider_front();
  371. if (is_model(MODEL_HARNESS_SLIDER_BACK)) model_harness_slider_back();
  372. if (is_model(MODEL_HARNESS_BUTTONS)) model_harness_buttons();
  373. }
  374. module model() {
  375. up(get_harness_size().z/2) phone_harness();
  376. }
  377. if (!is_undef(validation)) {
  378. intersection() {
  379. phone();
  380. model();
  381. }
  382. } else {
  383. intersection() {
  384. if (!is_undef(xray)) {
  385. if (xray == XRAY_POSITIVE) {
  386. span_cube([0,1000], [0,1000], [-1000,1000]);
  387. } else if (abs(xray) == XRAY_BACKPLANE) {
  388. span_cube([-1000,1000], [-1000,1000], [-1000*sign(xray),-6]);
  389. } else if (xray == XRAY_BOTTOM) {
  390. span_cube([-1000,1000], [-1000,1000], [-1000,0]);
  391. }
  392. }
  393. union() {
  394. if (is_not_export()) {
  395. //phone();
  396. //arm();
  397. }
  398. model();
  399. }
  400. }
  401. }