2019-06-08 17:10:47 -04:00
|
|
|
//
|
|
|
|
// NopSCADlib Copyright Chris Palmer 2018
|
|
|
|
// nop.head@gmail.com
|
|
|
|
// hydraraptor.blogspot.com
|
|
|
|
//
|
|
|
|
// This file is part of NopSCADlib.
|
|
|
|
//
|
|
|
|
// NopSCADlib is free software: you can redistribute it and/or modify it under the terms of the
|
|
|
|
// GNU General Public License as published by the Free Software Foundation, either version 3 of
|
|
|
|
// the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// NopSCADlib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along with NopSCADlib.
|
|
|
|
// If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
2020-01-10 03:26:20 -05:00
|
|
|
//! Rocker switch. Also used for neon indicator in the same form factor.
|
2019-06-08 17:10:47 -04:00
|
|
|
//
|
2020-02-29 12:52:36 -05:00
|
|
|
include <../utils/core/core.scad>
|
2019-06-08 17:10:47 -04:00
|
|
|
use <spade.scad>
|
|
|
|
|
|
|
|
function rocker_part(type) = type[1]; //! Part description
|
|
|
|
function rocker_slot_w(type) = type[2]; //! Panel slot width
|
2020-01-26 02:33:11 -05:00
|
|
|
function rocker_slot_h(type) = type[3]; //! Panel slot height
|
2019-06-08 17:10:47 -04:00
|
|
|
function rocker_flange_w(type) = type[4]; //! Flange width
|
|
|
|
function rocker_flange_h(type) = type[5]; //! Flange height
|
|
|
|
function rocker_flange_t(type) = type[6]; //! Flange thickness
|
|
|
|
function rocker_width(type) = type[7]; //! Body width
|
|
|
|
function rocker_height(type) = type[8]; //! Body height
|
|
|
|
function rocker_depth(type) = type[9]; //! Body depth
|
|
|
|
function rocker_bezel(type) = type[10]; //! Bezel width
|
|
|
|
function rocker_pivot(type) = type[11]; //! Pivot distance from the back of the flange
|
|
|
|
function rocker_button(type) = type[12]; //! How far the button extends from the bezel
|
|
|
|
function rocker_spades(type) = type[13]; //! Spade types and positions
|
|
|
|
|
2020-01-26 02:33:11 -05:00
|
|
|
module rocker(type, colour) { //! Draw the specified rocker switch
|
2019-06-08 17:10:47 -04:00
|
|
|
vitamin(str("rocker(", type[0], "): ", rocker_part(type)));
|
|
|
|
|
|
|
|
bezel = rocker_bezel(type);
|
|
|
|
clearance = 0.2;
|
|
|
|
rocker_w = rocker_flange_w(type) - 2 * bezel - clearance;
|
|
|
|
rocker_h = rocker_flange_h(type) - 2 * bezel - clearance;
|
|
|
|
rocker_r = sqrt(sqr(rocker_h / 2) + sqr(rocker_flange_t(type) - rocker_pivot(type)));
|
|
|
|
y = rocker_button(type) + rocker_flange_t(type) - rocker_pivot(type);
|
|
|
|
x = sqrt(sqr(rocker_r) - sqr(y));
|
|
|
|
|
|
|
|
x2 = rocker_h /2 + x;
|
|
|
|
y2 = rocker_button(type);
|
|
|
|
rocker_r2 = (sqr(x2) + sqr(y2)) / (2 * y2);
|
|
|
|
|
|
|
|
explode(30) {
|
2020-06-20 05:17:29 -04:00
|
|
|
color(grey(20)) {
|
2020-03-29 15:18:57 -04:00
|
|
|
linear_extrude(rocker_flange_t(type))
|
2019-06-08 17:10:47 -04:00
|
|
|
difference() {
|
|
|
|
rounded_square([rocker_flange_w(type), rocker_flange_h(type)], 0.5);
|
|
|
|
|
|
|
|
square([rocker_w + clearance, rocker_h + clearance], center = true);
|
|
|
|
}
|
|
|
|
|
|
|
|
translate_z(-rocker_depth(type))
|
|
|
|
rounded_rectangle([rocker_width(type), rocker_height(type), rocker_depth(type) + eps], 0.5, center = false);
|
|
|
|
}
|
|
|
|
if(rocker_pivot(type))
|
2020-06-20 05:17:29 -04:00
|
|
|
color(colour ? colour : grey(30))
|
2019-06-08 17:10:47 -04:00
|
|
|
translate_z(rocker_pivot(type))
|
|
|
|
rotate([90, 0, 90])
|
2020-03-29 15:18:57 -04:00
|
|
|
linear_extrude(rocker_w, center = true)
|
2019-06-08 17:10:47 -04:00
|
|
|
difference() {
|
|
|
|
circle(rocker_r, $fa = 1);
|
|
|
|
|
|
|
|
translate([rocker_h / 2, rocker_flange_t(type) + rocker_r2 - rocker_pivot(type)])
|
|
|
|
circle(rocker_r2, $fa = 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
2020-01-26 02:33:11 -05:00
|
|
|
color(colour ? colour : "red") cube([rocker_w, rocker_h, 2 * (rocker_flange_t(type) + rocker_button(type))], center = true);
|
2019-06-08 17:10:47 -04:00
|
|
|
|
|
|
|
for(spade = rocker_spades(type))
|
|
|
|
translate([spade[2], spade[3], -rocker_depth(type)])
|
|
|
|
rotate([180, 0, spade[4]])
|
|
|
|
spade(spade[0], spade[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module rocker_hole(type, h = 0) //! Make a hole to accept a rocker switch, by default 2D, set h for 3D
|
|
|
|
extrude_if(h)
|
|
|
|
rounded_square([rocker_slot_w(type), rocker_slot_h(type)], 1, center = true);
|