xantronix-z32/case/top.scad

312 lines
9.9 KiB
OpenSCAD
Raw Normal View History

$fn = 72;
2023-11-15 13:03:23 -05:00
include <keyboard.scad>
2023-11-14 18:25:37 -05:00
/*
* Top screw holes are 15mm from top of case
* Side screws are 6.5mm from side of case
* Top middle screw post is 29.3mm long
* Other screw posts are 12mm long
* Screw post outer diameter 6.25mm
* Screw post inner diameter 3mm
* Horizontal ridge interval: 55.5mm
* Vertical ridge interval: 31.3mm
* Ridge thickness: 1.25mm
* First horizontal ridge: Starts at keyboard X offset
*/
2023-11-14 16:29:51 -05:00
module top_case(key_switch_sizes, pcb_screw_holes) {
2023-11-14 12:46:52 -05:00
case_width_top = 317.5000;
case_width_bottom = 320.0000;
case_length_top = 150.0000;
case_length_bottom = 151.5000;
wall_width = 2.5000;
wall_height = 17.2500;
2023-11-15 13:13:45 -05:00
keyboard_width = keyboard_switch_width * 13.5;
keyboard_length = keyboard_switch_length * 5.0;
2023-11-14 12:46:52 -05:00
keyboard_x_offset = 12.2500;
keyboard_y_offset = 12.2500;
2023-11-15 17:56:39 -05:00
keyboard_deck_z_offset = wall_height - wall_width - keyboard_switch_height;
2023-11-14 12:46:52 -05:00
accent_width = 1.0000;
accent_depth = 0.5;
accent_y_stride = (keyboard_length - accent_width) / 5.0;
accent_y_bottom = keyboard_y_offset;
2023-11-15 13:09:01 -05:00
vent_width = 2.0000;
vent_length = wall_width;
vent_height = 12.0000;
vent_count = 32;
vent_x_first = keyboard_x_offset + keyboard_width - vent_count * (vent_width + vent_width);
vent_y_offset = case_length_bottom - vent_length;
2023-11-14 12:46:52 -05:00
2023-11-15 19:01:27 -05:00
support_width = 2.0000;
2023-11-14 12:46:52 -05:00
module fascia() {
linear_extrude(wall_width)
difference() {
square([case_width_bottom, case_length_bottom], false);
translate([keyboard_x_offset, keyboard_y_offset, 0])
square([keyboard_width, keyboard_length], false);
}
2023-11-13 23:19:15 -05:00
}
2023-11-13 21:43:43 -05:00
2023-11-15 13:09:01 -05:00
module vents() {
for (i = [0:vent_count]) {
x = vent_x_first + (i * (vent_width + vent_width));
2023-11-14 12:35:19 -05:00
2023-11-15 13:09:01 -05:00
translate([x, vent_y_offset, wall_height - vent_height])
cube([vent_width, vent_length, vent_height], false);
2023-11-14 12:46:52 -05:00
}
}
2023-11-13 21:43:43 -05:00
2023-11-14 12:46:52 -05:00
module accents() {
for (y = [accent_y_bottom: accent_y_stride: case_length_bottom]) {
/* Top */
translate([0, y, wall_height - accent_depth])
cube([case_width_bottom, accent_width, accent_depth], false);
2023-11-14 12:35:19 -05:00
2023-11-14 12:46:52 -05:00
/* Right */
translate([case_width_bottom - accent_depth, y, 0])
cube([accent_depth, accent_width, wall_height], false);
2023-11-14 12:35:19 -05:00
2023-11-14 12:46:52 -05:00
/* Left */
translate([0, y, 0])
cube([accent_depth, accent_width, wall_height], false);
}
}
2023-11-15 17:56:39 -05:00
2023-11-15 17:56:52 -05:00
module support(dimensions, width) {
2023-11-15 15:11:51 -05:00
length = dimensions[0];
height = dimensions[1];
2023-11-15 17:56:39 -05:00
2023-11-15 15:11:51 -05:00
module right_triangle(base) {
2023-11-15 17:56:39 -05:00
hypot = sqrt(2 * (base ^ 2 ));
difference() {
square([base, base], false);
2023-11-15 15:11:51 -05:00
2023-11-15 17:56:39 -05:00
translate([base, 0, 0])
rotate([0, 0, 45])
square([hypot, hypot], false);
2023-11-15 15:11:51 -05:00
}
}
2023-11-15 17:56:39 -05:00
2023-11-15 15:11:51 -05:00
module shape() {
/* Height ratio of lower aspect to upper aspect */
aspect_ratio = 3.75 / 12.0;
2023-11-15 17:56:39 -05:00
2023-11-15 15:11:51 -05:00
aspect_upper_height = height;
aspect_lower_height = aspect_ratio * height;
2023-11-15 17:56:39 -05:00
2023-11-15 15:11:51 -05:00
/* The length of each individual support aspect */
aspect_length = 1/3 * length;
hypotenuse = sqrt(2*(aspect_length^2));
lower_x_offset = aspect_length - (hypotenuse - aspect_length);
2023-11-15 17:56:39 -05:00
right_triangle(height);
square([length, aspect_lower_height], false);
2023-11-15 15:11:51 -05:00
translate([3 * aspect_length, 0, 0])
mirror([1, 0, 0])
2023-11-15 17:56:39 -05:00
right_triangle(height);
2023-11-15 15:11:51 -05:00
}
2023-11-15 17:56:39 -05:00
2023-11-15 18:48:50 -05:00
translate([0, length, 0])
rotate([-90, 0, -90])
linear_extrude(width)
intersection() {
shape();
2023-11-15 20:02:49 -05:00
square([length, height], false);
2023-11-15 18:48:50 -05:00
}
2023-11-15 15:11:51 -05:00
}
2023-11-15 17:56:39 -05:00
2023-11-15 19:10:38 -05:00
module supports() {
2023-11-15 19:01:27 -05:00
support_x_interval = (keyboard_width + 2 * wall_width - support_width) / 6;
2023-11-15 20:02:49 -05:00
support_x_offset = keyboard_x_offset - wall_width;
support_y_interval = (keyboard_length + 2 * wall_width - support_width) / 4;
support_y_offset = keyboard_y_offset;
2023-11-15 18:16:58 -05:00
2023-11-15 18:48:50 -05:00
/* Upper vertical supports */
2023-11-15 17:56:39 -05:00
upper_support_length = case_length_bottom
- keyboard_length
- keyboard_y_offset
- 2 * wall_width;
upper_support_y_offset = keyboard_y_offset
+ keyboard_length
+ wall_width;
2023-11-15 18:48:50 -05:00
/* Lower vertical supports */
2023-11-15 20:02:49 -05:00
lower_support_length = keyboard_y_offset - 2 * wall_width;
2023-11-15 18:48:50 -05:00
lower_support_y_offset = wall_width;
2023-11-15 20:02:49 -05:00
/* Left horizontal supports */
left_support_length = keyboard_x_offset - 2 * wall_width;
left_support_x_offset = wall_width;
/* Right horizontal supports */
right_support_length = case_width_bottom
- keyboard_width
- keyboard_x_offset
- 2 * wall_width;
right_support_x_offset = keyboard_x_offset
+ keyboard_width
+ wall_width;
2023-11-15 18:48:50 -05:00
for (x = [0: support_x_interval: keyboard_width + 2 * wall_width]) {
translate([support_x_offset + x,
2023-11-15 18:16:58 -05:00
upper_support_y_offset,
wall_height - wall_width])
2023-11-15 19:01:27 -05:00
support([upper_support_length, keyboard_switch_height], support_width);
2023-11-15 18:48:50 -05:00
translate([support_x_offset + x,
lower_support_y_offset,
wall_height - wall_width])
2023-11-15 19:01:27 -05:00
support([lower_support_length, keyboard_switch_height], support_width);
2023-11-15 18:16:58 -05:00
}
2023-11-15 20:02:49 -05:00
for (y = [0: support_y_interval: keyboard_length + 2 * wall_width]) {
translate([right_support_x_offset,
support_y_offset + y - wall_width + support_width,
wall_height - wall_width])
rotate([0, 0, -90])
support([right_support_length, keyboard_switch_height], support_width);
2023-11-15 20:50:36 -05:00
translate([left_support_x_offset,
2023-11-15 20:02:49 -05:00
support_y_offset + y - wall_width + support_width,
wall_height - wall_width])
rotate([0, 0, -90])
2023-11-15 20:50:36 -05:00
support([left_support_length, keyboard_switch_height], support_width);
2023-11-15 20:02:49 -05:00
}
2023-11-14 12:46:52 -05:00
}
2023-11-15 19:10:38 -05:00
module body() {
translate([0, 0, wall_height - wall_width])
fascia();
/* Upper */
translate([0, case_length_bottom - wall_width, 0])
cube([case_width_bottom, wall_width, wall_height - wall_width], false);
/* Right */
translate([case_width_bottom - wall_width, 0, 0])
cube([wall_width, case_length_bottom, wall_height - wall_width], false);
/* Lower */
cube([case_width_bottom, wall_width, wall_height - wall_width], false);
/* Left */
cube([wall_width, case_length_bottom, wall_height - wall_width], false);
}
2023-11-14 16:29:51 -05:00
module screw_holes() {
2023-11-14 18:52:26 -05:00
pcb_screw_diameter = 2.5;
2023-11-14 16:29:51 -05:00
for (screw_hole = pcb_screw_holes) {
translate([screw_hole[0], screw_hole[1], 0])
cylinder(h=wall_width, d=pcb_screw_diameter);
}
}
2023-11-14 16:15:35 -05:00
module keyboard_deck() {
2023-11-14 18:52:26 -05:00
key_switch_footprint = [15.25, 15.25];
2023-11-14 16:15:35 -05:00
function add(v) = [for(p=v) 1]*v;
function slice(v, x, y) = [for (i=[x:y]) v[i]];
function addrange(v, x, y) = add(slice(v, x, y));
module key_switch_plate(key_switch_size) {
2023-11-15 13:13:45 -05:00
plate_width = keyboard_switch_width * key_switch_size;
plate_length = keyboard_switch_length;
2023-11-14 16:15:35 -05:00
if (key_switch_size <= 0.5) {
2023-11-15 13:13:45 -05:00
cube([keyboard_switch_width * key_switch_size,
keyboard_switch_length,
2023-11-14 16:15:35 -05:00
wall_width], false);
} else {
hole_width = key_switch_footprint[0];
hole_length = key_switch_footprint[1];
hole_x = plate_width / 2 - hole_width / 2;
hole_y = plate_length / 2 - hole_length / 2;
linear_extrude(wall_width)
difference() {
square([plate_width, plate_length], false);
2023-11-15 17:56:39 -05:00
2023-11-14 16:15:35 -05:00
translate([hole_x, hole_y, 0])
square([hole_width, hole_length], false);
}
}
}
2023-11-14 17:33:44 -05:00
module walls() {
/* Upper */
translate([-wall_width, keyboard_length, 0])
2023-11-15 13:03:23 -05:00
cube([keyboard_width + 2 * wall_width, wall_width, keyboard_switch_height], false);
2023-11-14 17:33:44 -05:00
/* Right */
translate([keyboard_width, -wall_width, 0])
2023-11-15 13:03:23 -05:00
cube([wall_width, keyboard_length + 2 * wall_width, keyboard_switch_height], false);
2023-11-14 17:33:44 -05:00
/* Lower */
translate([-wall_width, -wall_width, 0])
2023-11-15 13:03:23 -05:00
cube([keyboard_width + 2 * wall_width, wall_width, keyboard_switch_height], false);
2023-11-14 17:33:44 -05:00
/* Left */
translate([-wall_width, -wall_width, 0])
2023-11-15 13:03:23 -05:00
cube([wall_width, keyboard_length + 2 * wall_width, keyboard_switch_height], false);
2023-11-14 17:33:44 -05:00
}
2023-11-14 16:29:51 -05:00
module body() {
rows = len(key_switch_sizes);
for (i = [0: rows-1]) {
2023-11-15 13:13:45 -05:00
y = keyboard_switch_length * (rows - 1 - i);
2023-11-14 16:29:51 -05:00
key_switch_row = key_switch_sizes[i];
cols = len(key_switch_row);
2023-11-14 16:15:35 -05:00
2023-11-14 16:29:51 -05:00
for (j = [0: cols-1]) {
2023-11-15 13:13:45 -05:00
x = keyboard_switch_width * ((j == 0)?
2023-11-14 16:29:51 -05:00
0:
addrange(key_switch_row, 0, j-1));
2023-11-14 16:15:35 -05:00
2023-11-14 16:29:51 -05:00
key_switch_size = key_switch_row[j];
2023-11-14 16:15:35 -05:00
2023-11-14 16:29:51 -05:00
translate([x, y, 0])
key_switch_plate(key_switch_size);
}
2023-11-14 16:15:35 -05:00
}
}
2023-11-14 16:29:51 -05:00
difference() {
body();
screw_holes();
}
2023-11-14 17:33:44 -05:00
walls();
2023-11-14 16:15:35 -05:00
}
2023-11-14 12:46:52 -05:00
difference() {
body();
accents();
2023-11-15 13:09:01 -05:00
vents();
2023-11-14 12:46:52 -05:00
}
2023-11-14 16:29:51 -05:00
2023-11-15 19:10:38 -05:00
supports();
2023-11-14 17:33:44 -05:00
translate([keyboard_x_offset, keyboard_y_offset, keyboard_deck_z_offset])
2023-11-14 16:29:51 -05:00
keyboard_deck();
2023-11-14 12:35:19 -05:00
}
2023-11-14 12:46:52 -05:00
2023-11-15 17:56:39 -05:00
top_case(keyboard_switch_sizes, keyboard_pcb_screw_holes);