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.

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