From df2e0aaecebd5b99908e74b623cf291519d10148 Mon Sep 17 00:00:00 2001 From: "Azzam S.A" Date: Tue, 3 Dec 2024 19:49:07 +0700 Subject: [PATCH] feat(case): make the cover rounded --- case/cheapino-top-left.scad | 10 +++---- case/cheapino-top-right.scad | 5 ++-- case/modules.scad | 53 ++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 9 deletions(-) diff --git a/case/cheapino-top-left.scad b/case/cheapino-top-left.scad index 8439852..658dd56 100644 --- a/case/cheapino-top-left.scad +++ b/case/cheapino-top-left.scad @@ -49,11 +49,10 @@ rotate([0,180,0]) // -10.6 is the initial size of left/right // 4.1 is the intial value of the PCB translate([29.2 + (-2), -10.6 - 2, 4.1]) - // +2 is for top cover - linear_extrude(rj45_height + 2) // width = front/back, height = left/right // Add thickness of 4. 2 left 2 right. - square([30 - 7, 16.6 + 4]); + // +2 is for top cover + roundedcube([30 - 7, 16.6 + 4, rj45_height + 2], false, 0.5, "all"); // repeat the difference() for initial rj45 translate([29.2, -10.6, 4.1]) linear_extrude(rj45_height) @@ -68,11 +67,10 @@ rotate([0,180,0]) difference() { // x = left/right, y = front/back translate([29.5 - 2, 10.2 - 2, 4.1]) - // +2 is for top cover - linear_extrude(mcu_height + 2) // width = left/right, height = front/back // Add thickness of 4. 2 left 2 right. - square([19.5 + 4, 25 + 2]); + // +2 is for top cover + roundedcube([19.5 + 4, 25 + 2, mcu_height + 2], false, 0.5, "all"); // repeat the difference() for initial mcu cutout translate([29.2, 10.2, 4.1]) diff --git a/case/cheapino-top-right.scad b/case/cheapino-top-right.scad index 4308935..ea2f1b0 100644 --- a/case/cheapino-top-right.scad +++ b/case/cheapino-top-right.scad @@ -64,11 +64,10 @@ mirror() { // -9.7 is the initial size of left/right // 4.1 is the intial value of the PCB translate([29.2 + (-2), -9.33 - 2, 4.1]) - // +2 is for top cover - linear_extrude(rj45_height + 2) // width = front/back, height = left/right // Add thickness of 4. 2 left 2 right. - square([30 - 7, 16.6 + 4]); + // +2 is for top cover + roundedcube([30 - 7, 16.6 + 4, rj45_height + 2], false, 0.5, "all"); // repeat the difference() for initial rj45 translate([29.2, -9.33, 4.1]) linear_extrude(rj45_height) diff --git a/case/modules.scad b/case/modules.scad index 9018b95..f75756e 100644 --- a/case/modules.scad +++ b/case/modules.scad @@ -411,3 +411,56 @@ module mcu_cutout() { square([10, 20]); } } + +// More information: https://danielupshaw.com/openscad-rounded-corners/ +// License: Unlicense +module roundedcube(size = [1, 1, 1], center = false, radius = 0.5, apply_to = "all") { + // If single value, convert to [x, y, z] vector + size = (size[0] == undef) ? [size, size, size] : size; + + translate_min = radius; + translate_xmax = size[0] - radius; + translate_ymax = size[1] - radius; + translate_zmax = size[2] - radius; + + diameter = radius * 2; + + obj_translate = (center == false) ? + [0, 0, 0] : [ + -(size[0] / 2), + -(size[1] / 2), + -(size[2] / 2) + ]; + + translate(v = obj_translate) { + hull() { + for (translate_x = [translate_min, translate_xmax]) { + x_at = (translate_x == translate_min) ? "min" : "max"; + for (translate_y = [translate_min, translate_ymax]) { + y_at = (translate_y == translate_min) ? "min" : "max"; + for (translate_z = [translate_min, translate_zmax]) { + z_at = (translate_z == translate_min) ? "min" : "max"; + + translate(v = [translate_x, translate_y, translate_z]) + if ( + (apply_to == "all") || + (apply_to == "xmin" && x_at == "min") || (apply_to == "xmax" && x_at == "max") || + (apply_to == "ymin" && y_at == "min") || (apply_to == "ymax" && y_at == "max") || + (apply_to == "zmin" && z_at == "min") || (apply_to == "zmax" && z_at == "max") + ) { + sphere(r = radius); + } else { + rotate = + (apply_to == "xmin" || apply_to == "xmax" || apply_to == "x") ? [0, 90, 0] : ( + (apply_to == "ymin" || apply_to == "ymax" || apply_to == "y") ? [90, 90, 0] : + [0, 0, 0] + ); + rotate(a = rotate) + cylinder(h = diameter, r = radius, center = true); + } + } + } + } + } + } +}