xantronix-z32/case/case.scad

255 lines
8.2 KiB
OpenSCAD

$fn = 72;
pcb_width = 257.175;
pcb_length = 95.250;
pcb_height = 1.600;
pcb_screw_holes = [
[ 4.7625, 85.7250],
[ 66.6750, 85.7250],
[161.9250, 85.7250],
[238.1250, 85.7250],
[ 61.9125, 47.6250],
[138.1125, 47.6250],
[214.3125, 47.6250],
[ 19.0500, 9.5250],
[123.8250, 9.5250],
[238.1250, 9.5250]
];
switch_leg_length = 3.30;
switch_height = 11.10;
module keyboard_base_plate(pcb_dimensions, pcb_screw_holes, switch_z_range) {
pcb_width = pcb_dimensions[0];
pcb_length = pcb_dimensions[1];
pcb_height = pcb_dimensions[2];
switch_z_min = switch_z_range[0];
switch_z_max = switch_z_range[1];
pcb_clearance_edge = 1.0;
pcb_clearance_bottom = -switch_z_min - pcb_height + 0.5;
pcb_screw_diameter = 1.5;
pcb_screw_hole_diameter = 1.5;
pcb_screw_height = 3.0;
thickness = 1.75;
corner_radius = 0.2;
case_color = [0.5, 0.5, 0.5, 1.0];
wall_width = pcb_width + 2 * (pcb_clearance_edge + thickness) - 2 * corner_radius;
wall_length = pcb_length + 2 * (pcb_clearance_edge + thickness) - 2 * corner_radius;
wall_height = pcb_screw_height + pcb_height + switch_z_max;
bottom_width = 2 * (pcb_clearance_edge) + pcb_width;
bottom_length = 2 * (pcb_clearance_edge) + pcb_length;
bottom_height = thickness;
module round_corner(translation, rotation) {
color(case_color)
translate(translation)
rotate(rotation)
rotate_extrude(angle=90) {
intersection() {
circle(r=corner_radius);
square(corner_radius*2);
}
}
}
module round_edge(translation, rotation, length) {
color(case_color)
translate(translation)
rotate(rotation)
linear_extrude(length)
intersection() {
circle(r=corner_radius);
square(corner_radius*2);
}
}
module panel(translation, dimensions) {
color(case_color)
translate(translation)
linear_extrude(dimensions[2])
square([dimensions[0], dimensions[1]], false);
}
module wall_corner(translation, rotation, radius, length) {
color(case_color)
translate(translation)
rotate(rotation)
linear_extrude(length)
intersection() {
circle(r=radius);
square([radius, radius], false);
}
}
module screw_post(translation, h, d) {
diameter_outer = 3 * d;
diameter_inner = d;
color(case_color)
translate(translation)
difference() {
cylinder(h=h, r1 = (diameter_outer / 2.0) * 1.5);
cylinder(h=h, r = diameter_inner / 2.0);
}
}
module ridges(width, height) {
horizontal = [
(bottom_length / 3),
(bottom_length / 3) * 2
];
vertical = [
(bottom_width / 3),
(bottom_width / 3) * 2
];
for (y = horizontal) {
panel([0 - pcb_clearance_edge, y, 0],
[bottom_width, width, height]);
}
for (x = vertical) {
panel([x, 0 - pcb_clearance_edge, 0],
[width, bottom_length, height]);
}
}
/* Upper wall */
panel([-pcb_clearance_edge - thickness + corner_radius,
pcb_clearance_edge + pcb_length,
-thickness + corner_radius],
[wall_width, thickness, wall_height + thickness - corner_radius]);
/* Right wall */
panel([ pcb_clearance_edge + pcb_width,
-pcb_clearance_edge - thickness + corner_radius,
-thickness + corner_radius],
[thickness, wall_length, wall_height + thickness - corner_radius]);
/* Lower wall */
panel([-pcb_clearance_edge - thickness + corner_radius,
-pcb_clearance_edge - thickness,
-thickness + corner_radius],
[wall_width, thickness, wall_height + thickness - corner_radius]);
/* Left wall */
panel([-pcb_clearance_edge - thickness,
-pcb_clearance_edge - thickness + corner_radius,
-thickness + corner_radius],
[thickness, wall_length, wall_height + thickness - corner_radius]);
/* Upper right wall corner */
wall_corner([pcb_clearance_edge + thickness + pcb_width - corner_radius,
pcb_clearance_edge + thickness + pcb_length - corner_radius,
-thickness + corner_radius],
[0, 0, 0],
corner_radius,
wall_height + thickness - corner_radius);
/* Lower right wall corner */
wall_corner([ pcb_clearance_edge + thickness + pcb_width - corner_radius,
-pcb_clearance_edge - thickness + corner_radius,
-thickness + corner_radius],
[0, 0, 270],
corner_radius,
wall_height + thickness - corner_radius);
/* Lower left wall corner */
wall_corner([-pcb_clearance_edge - thickness + corner_radius,
-pcb_clearance_edge - thickness + corner_radius,
-thickness + corner_radius],
[0, 0, 180],
corner_radius,
wall_height + thickness - corner_radius);
/* Upper left wall corner */
wall_corner([-pcb_clearance_edge - thickness + corner_radius,
pcb_clearance_edge + pcb_length + thickness - corner_radius,
-thickness + corner_radius],
[0, 0, 90],
corner_radius,
wall_height + thickness - corner_radius);
/* Bottom plate */
panel([-pcb_clearance_edge - thickness + corner_radius,
-pcb_clearance_edge - thickness + corner_radius,
-thickness],
[bottom_width + 2 * thickness - 2 * corner_radius,
bottom_length + 2 * thickness - 2 * corner_radius,
thickness]);
/* Upper edge */
round_edge([-pcb_clearance_edge - thickness + corner_radius,
pcb_clearance_edge + thickness + pcb_length - corner_radius,
-thickness + corner_radius],
[0, 90, 0],
wall_width);
/* Right edge */
round_edge([ pcb_clearance_edge + thickness + pcb_width - corner_radius,
-pcb_clearance_edge - thickness + corner_radius,
-thickness + corner_radius],
[270, 0, 0],
wall_length);
/* Lower edge */
round_edge([-pcb_clearance_edge - thickness + corner_radius,
-pcb_clearance_edge - thickness + corner_radius,
-thickness + corner_radius],
[90, 180, 90],
wall_width);
/* Left edge */
round_edge([-pcb_clearance_edge - thickness + corner_radius,
-pcb_clearance_edge - thickness + corner_radius,
-thickness + corner_radius],
[270, 90, 0],
wall_length);
/* Upper right corner */
round_corner([pcb_clearance_edge + thickness + pcb_width - corner_radius,
pcb_clearance_edge + thickness + pcb_length - corner_radius,
-thickness + corner_radius],
[90, 90, 90]);
/* Lower right corner */
round_corner([ pcb_clearance_edge + thickness + pcb_width - corner_radius,
-pcb_clearance_edge - thickness + corner_radius,
-thickness + corner_radius],
[180, 90, 90]);
/* Lower left corner */
round_corner([-pcb_clearance_edge - thickness + corner_radius,
-pcb_clearance_edge - thickness + corner_radius,
-thickness + corner_radius],
[-90, 90, 90]);
/* Upper left corner */
round_corner([-pcb_clearance_edge - thickness + corner_radius,
pcb_clearance_edge + thickness + pcb_length - corner_radius,
-thickness + corner_radius],
[0, 90, 90]);
/* Screw holes */
for (screw_hole = pcb_screw_holes) {
screw_post([screw_hole[0], screw_hole[1], 0],
pcb_screw_height,
pcb_screw_diameter);
}
/* Ridges (for rigidity!) */
ridges(thickness * 2, pcb_clearance_bottom / 2);
}
keyboard_base_plate([pcb_width, pcb_length, pcb_height],
pcb_screw_holes,
[-switch_leg_length, switch_height]);