]> git.armaanb.net Git - atreides.git/blobdiff - case/openscad/atreus_case.scad
Fix indentation
[atreides.git] / case / openscad / atreus_case.scad
index 7ba69786d32c664cd5d9704d61dbec0fa1bef3ba..2c9a9253f070c56e2ea7c24975d2b32a5cbaa3b8 100644 (file)
@@ -9,8 +9,8 @@ column_spacing   = 19;
 row_spacing      = column_spacing;
 
 /* This number should exceed row_spacing and column_spacing. The
- default gives a 1mm = (20mm - 19mm) gap between keycaps and cuts in
- the top plate.*/
  default gives a 1mm = (20mm - 19mm) gap between keycaps and cuts in
  the top plate.*/
 key_hole_size = 20;
 
 /* rotation angle; the angle between the halves is twice this
@@ -47,20 +47,29 @@ use_notched_holes = true;
 n_rows = 4;
 n_cols = 5;
 
+/* Number of thumb keys (per hand), try 1 or 2. */
+n_thumb_keys = 1;
+
 /* The width of the USB cable hole in the spacer. */
-cable_hole_width = 4;
+cable_hole_width = 12;
 
 /* Vertical column staggering offsets. The first element should
    be zero. */
 staggering_offsets = [0, 5, 11, 6, 3];
 
+/* Whether or not to split the spacer into quarters. */
+quarter_spacer = false;
+
+/* Where the top/bottom split of a quartered spacer will be. */
+spacer_quartering_offset = 60;
+
 module rz(angle, center=undef) {
   /* Rotate children `angle` degrees around `center`. */
   translate(center) {
     rotate(angle) {
       translate(-center) {
         for (i=[0:$children-1])
-          child(i);
+          children(i);
       }
     }
   }
@@ -70,7 +79,7 @@ module rz(angle, center=undef) {
    around center. Used to compute locations of screw holes near the
    USB cable hole. */
 function rz_fun(p, angle, center) = [cos(angle) * (p[0] - center[0]) - sin(angle) * (p[1] - center[1]) + center[0],
-                                     sin(angle) * (p[0] - center[0]) + cos(angle) * (p[1] - center[1])+ center[1]];
+         sin(angle) * (p[0] - center[0]) + cos(angle) * (p[1] - center[1])+ center[1]];
 
 module switch_hole(position, notches=use_notched_holes) {
   /* Cherry MX switch hole with the center at `position`. Sizes come
@@ -132,7 +141,7 @@ module rotate_half() {
   rotation_y_offset = 1.75 * column_spacing;
   for (i=[0:$children-1]) {
     rz(angle, [hand_separation, rotation_y_offset]) {
-      child(i);
+      children(i);
     }
   }
 }
@@ -142,7 +151,7 @@ module add_hand_separation() {
   for (i=[0:$children-1]) {
     translate([0.5*hand_separation, /* we get back the full separation
                                        because of mirroring */
-               0]) child(i);
+        0]) children(i);
   }
 }
 
@@ -155,13 +164,15 @@ module right_half (switch_holes=true, key_size=key_hole_size) {
   thumb_key_offset = y_offset + 0.5 * column_spacing;
   rotate_half() {
     add_hand_separation() {
-      if (switch_holes == true) {
-        switch_hole([x_offset, thumb_key_offset]);
-      } else {
-        thumb_key([x_offset, thumb_key_offset], key_size);
+      for (j=[0:(n_thumb_keys-1)]) {
+        if (switch_holes == true) {
+          switch_hole([x_offset + j*row_spacing, thumb_key_offset]);
+        } else {
+          thumb_key([x_offset + j*row_spacing, thumb_key_offset], key_size);
+        }
       }
       for (j=[0:(n_cols-1)]) {
-        column([x_offset + (j+1)*row_spacing, y_offset + staggering_offsets[j]], switch_holes, key_size);
+        column([x_offset + (j+n_thumb_keys)*row_spacing, y_offset + staggering_offsets[j]], switch_holes, key_size);
       }
     }
   }
@@ -189,8 +200,8 @@ module screw_hole(radius, offset_radius, position, direction) {
 
 module right_screw_holes(hole_radius) {
   /* coordinates of the back right screw hole before rotation... */
-  back_right = [(n_cols+1)*row_spacing,
-               staggering_offsets[n_cols-1] + n_rows * column_spacing];
+  back_right = [(n_cols+n_thumb_keys)*row_spacing,
+             staggering_offsets[n_cols-1] + n_rows * column_spacing];
   /* and after */
   tmp = rz_fun(back_right, angle, [0, 2.25*column_spacing]);
 
@@ -199,26 +210,26 @@ module right_screw_holes(hole_radius) {
   rotate_half() {
     add_hand_separation() {
       screw_hole(hole_radius, washer_radius,
-                 [row_spacing, 0],
-                 [-nudge, -nudge]);
+          [row_spacing, 0],
+          [-nudge, -nudge]);
       screw_hole(hole_radius, washer_radius,
-                 [(n_cols+1)*row_spacing, staggering_offsets[n_cols-1]],
-                 [nudge, -nudge]);
+          [(n_cols+n_thumb_keys)*row_spacing, staggering_offsets[n_cols-1]],
+          [nudge, -nudge]);
       screw_hole(hole_radius, washer_radius,
-                 back_right,
-                 [nudge, nudge]);
+          back_right,
+          [nudge, nudge]);
     }
   }
 
   /* add the screw hole near the cable hole */
-  translate([cable_hole_width + washer_radius - tmp[0],
-             back_screw_hole_offset]) {
+  translate([washer_radius - tmp[0] - 0.5*hand_separation,
+      back_screw_hole_offset]) {
     rotate_half() {
       add_hand_separation() {
         screw_hole(hole_radius,
-                   washer_radius,
-                   back_right,
-                   [nudge, nudge]);
+            washer_radius,
+            back_right,
+            [nudge, nudge]);
       }
     }
   }
@@ -270,19 +281,45 @@ module spacer() {
           right_half(switch_holes=false, key_size=switch_hole_size + 3);
           left_half(switch_holes=false, key_size=switch_hole_size + 3);
         }
+        /* add the USB cable hole: */
+        translate([-0.5*cable_hole_width, 2*column_spacing]) {
+          square([cable_hole_width, (2*n_rows) * column_spacing]);
+        }
       }
       screw_holes(washer_radius);
     }
     screw_holes(screw_hole_radius);
-    /* add the USB cable hole: */
-    translate([-0.5*cable_hole_width, 2*column_spacing]) {
-      square([cable_hole_width, (2*n_rows) * column_spacing]);
+  }
+}
+
+module spacer_quadrant(spacer_quadrant_number) {
+  /* Cut a quarter of a spacer. */
+  translate([0, spacer_quartering_offset]) {
+    intersection() {
+      translate([0, -spacer_quartering_offset]) { spacer(); }
+      rotate([0, 0, spacer_quadrant_number * 90]) { square([1000, 1000]); }
     }
   }
 }
 
+module quartered_spacer()
+{
+  /* Assemble all four quarters of a spacer. */
+  spacer_quadrant(0);
+  spacer_quadrant(1);
+  translate([-5,-10]) spacer_quadrant(2);
+  translate([5,-10]) spacer_quadrant(3);
+}
+
 /* Create all four layers. */
 top_plate();
-translate([300, 150]) { spacer(); }
 translate([300, 0]) { switch_plate(); }
 translate([0, 150]) { bottom_plate(); }
+translate([300, 150]) {
+  if (quarter_spacer == true) {
+    quartered_spacer();
+  }
+  else {
+    spacer();
+  }
+}