firmware: make sure PWM output pin is zero before suspend
[heater.git] / case.scad
index 2b5a351..f96549a 100644 (file)
--- a/case.scad
+++ b/case.scad
-// 18650 is ~18mm diameter, ~65mm length, 
-batt_diam = 18 + 0.3;
-batt_len = 65+1;
-batt_clip_h = 0.75 * batt_diam;
-wall = 2.2;
-base_h = 4;
-cable_sep = 2.5;
+lowres = 0; // fast rendering or fine printing with print-friendly orientation
 
 eps = 0.01;
 infty = 300;
 
-pcb_len = 36;
-pcb_thick = 1.3;
-pcb_groove = 2;
-pcb_width = 11;
+wall = 1.5; // generic wall thickness
 
-wire_thick = 2;
-wire_sep = 3;
-cable_out_diam = 4;
+// 18650 is ~18mm diameter, ~65mm length, 
+batt_diam = 18 + 0.8;
+batt_len = 65 + 2.0;
 
-side_protrusion_len = 10;
-side_protrusion_diam = 2;
+cable_sep = 1.5;
 
-base_batt_extend = wall+pcb_thick; // extend the base on the battery side
+// front flat area
+front_flat_len = batt_len + 4*wall + 2*cable_sep;
 
-cover_sep = 0.2;
+// PCB-related dimensions
+pcb_len = 36 + 1;      // length of the board
+pcb_width = 11 + 0.5;  // width of the board
+pcb_thick = 1.2 + 0.3;         // thickness of the board
+pcb_comp_h = 2.2;      // height of the components on board
+pcb_groove = 1;
 
-uswitch_diam = 2.5;
-led_diam = 3.2;
-s2_xoff = -160 * 25.4/1000;
-led_xoff = 90 * 25.4/1000;
-s1_xoff = 340 * 25.4/1000;
+body_top_h = 0.35 * batt_diam; // cube-shaped part of the body
 
-pcb_clip_w = 7;
-pcb_clip_off = led_xoff + pcb_clip_w/2;
+wire_thick = 2.2;
+wire_sep = 3.5;
 
-module base() {
-       translate([0, 0, base_h/2]) {
-               hull() {
-                       cube([batt_len + 2*wall + 2*cable_sep, batt_diam + 2*wall, base_h], center=true);
-                       // under the PCB
-                       translate([0, -batt_diam/2-wall-pcb_thick/2-wall/2, 0])
-                               cube([pcb_len + 2*wall, pcb_thick + wall + eps, base_h], center=true);
-                       // battery-side extension
-                       translate([0, batt_diam/2 + wall + base_batt_extend, -base_h/4+side_protrusion_diam/4])
-                               cube([batt_len + 2*wall, eps, base_h/2+side_protrusion_diam/2], center=true);
-               };
-       };
-}
-module base_protrusions() {
-       // pcb-side side protrusion
-       translate([-side_protrusion_len/2, -batt_diam/2-2*wall-pcb_thick, base_h/2])
-               rotate([0, 90, 0])
-               cylinder(r = side_protrusion_diam/2, h = side_protrusion_len, $fn = 6);
-       
-       // battery-side side protrusion
-       translate([-side_protrusion_len/2, batt_diam/2+wall+base_batt_extend, base_h/2])
-               rotate([0, 90, 0])
-               cylinder(r = side_protrusion_diam/2, h = side_protrusion_len, $fn = 6);
-};
+batt_end_h = wire_sep/2 + wire_thick/2 + 1.5;;
 
-module pcb_clips() {
-       // rear part of the PCB holder (behind S1)
-       translate([pcb_clip_off, -batt_diam/2-wall-pcb_thick+eps, 0])
-               cube([pcb_clip_w, pcb_thick+wall, pcb_width + wall + base_h - pcb_groove]);
-       // side part of the PCB holder (near the battery wires)
-       translate([-pcb_len/2-wall, -batt_diam/2-pcb_thick-2*wall, 0])
-               cube([pcb_groove+wall, pcb_thick+2*wall+eps, pcb_width + wall + base_h - pcb_groove]);
-};
+lid_sep = 0.2; // the lid is made this much smaller to separate from the body
 
-module batt_clips() {
-       difference() {
-               union() {
-                       // rear part of the battery clip
-                       translate([-(batt_len/2-pcb_len/2+pcb_groove+wall)/2-pcb_len/2+pcb_groove, 0, batt_clip_h/2+wall/2])
-                               cube([batt_len/2-pcb_len/2+pcb_groove + wall, batt_diam + 2*wall, batt_clip_h + wall], center=true);
-                       // front (+) part of the battery clip
-                       translate([batt_len/2+wall/2, 0, batt_clip_h/2+wall/2])
-                               hull() {
-                                       cube([wall, batt_diam + 2*wall, batt_clip_h + wall], center=true); 
-                                       translate([-10/2, 0, -batt_clip_h/2])
-                                       cube([10, batt_diam+2*wall, wall], center=true);
-                               };
-                       // middle clips
-                       translate([pcb_clip_off+pcb_clip_w/2, 0, batt_clip_h/2+wall/2])
-                               hull() {
-                                       cube([pcb_clip_w, batt_diam + 2*wall, batt_clip_h + wall], center=true);
-                                       translate([0, 0, -batt_clip_h/2])
-                                       cube([2*pcb_clip_w, batt_diam+2*wall, wall], center=true);
-                               };
-               }
-               // top part rounded
+sw_diam = 2.5 + 0.5;
+led_diam = 3 + 0.5;
+sw_xoff =  250 * 25.4/1000; // x offset of microswitches
+pcb_xoff = 90 * 25.4/1000; // offset of the LED from the middle of the PCB
+
+prg_len = 10; // programming connector
+prg_width = 7;
+
+outcable_h = 4.5;
+outcable_w = 2.5;
+
+// mounting cylinder + holes
+mounthole_w = 5;
+mounthole_h = 3;
+mountcyl_w = mounthole_w + 4*wall;
+mountcyl_h = 2*wall;
+mountcone_h = mounthole_h + 2*wall;
+
+clip_pretension = 0.5;
+
+plus_width = 4.5; // width of the + sign
+
+module case_body() {
+       hull() {
+               translate([-batt_len/2-2*wall-cable_sep, -batt_diam/2-wall, 0])
+                       cube([batt_len + 4*wall + 2*cable_sep,
+                               batt_diam+2*wall, body_top_h]);
                difference() {
-                       translate([0, 0, infty/4 + wall + batt_diam/2])
-                               cube([infty/2, infty/2, infty/2], center=true);
-                       translate([-infty/2, 0, batt_diam/2+wall])
+                       translate([-batt_len/2-2*wall-cable_sep, 0, 0])
                                rotate([0, 90, 0])
-                               cylinder(r=batt_diam/2+wall, h = infty);
+                               cylinder(r=batt_diam/2+wall,
+                                       h = batt_len + 4*wall + 2*cable_sep);
+                       translate([-infty/2, -infty/2, eps]) cube(infty);
                };
+               translate([-front_flat_len/2,
+                       batt_diam/2 - pcb_width,
+                       -batt_diam/2-2*pcb_comp_h-pcb_thick-wall])
+                       cube([front_flat_len, pcb_width+wall, eps]);
+       };
+       // mounting cylinders
+       for (x = [-1, 1]) translate([x*(batt_len/2-mounthole_w/2),
+               batt_diam/2+wall, 0]) {
+                       translate([0, 0, -batt_diam/2-wall-2*pcb_comp_h-pcb_thick])
+                               mount_cyl(); // front
+                       translate([0, 0, body_top_h]) // rear
+                               scale([1, 1, -1])
+                               mount_cyl();
        };
 };
 
-module battery() {
-       // battery
-       translate([-batt_len/2, 0, batt_diam/2+wall])
-               rotate([0, 90, 0])
-               cylinder(r=batt_diam/2, h = batt_len);
+module mount_cyl() {
+       assign(h = mounthole_h+wall)
+       hull () {
+               translate([0, -mountcyl_w/2+mounthole_h + wall])
+                       cylinder(r = mountcyl_w/2, h = mountcyl_h);
+               assign(l = 2*sqrt(h*(mountcyl_w-h)))
+               translate([-l/2, 0, mountcyl_h + mountcone_h])
+                       cube([l, eps, eps]);
+       };
 };
-
-module main() {
+       
+module case() {
        difference() {
-               union() {
-                       base();
-                       base_protrusions();
-                       pcb_clips();
-                       batt_clips();
-               };
-               // the PCB itself
-               translate([0, -batt_diam/2-wall-pcb_thick/2, base_h - pcb_groove + pcb_width/2])
-                       cube([pcb_len, pcb_thick, pcb_width], center=true);
-               // battery
-               battery();
-               // 4 wire holes at the battery ends
-               for (j=[-wire_sep/2, wire_sep/2]) 
-               for (i=[-wire_sep/2, wire_sep/2]) 
-               translate([-infty/2, i, batt_diam/2 + wall+j])
-                       rotate([0, 90, 0])
-                       rotate([0, 0, 90])
-                       cylinder(r=wire_thick/2, h = infty, $fn=6);
+               case_body();
+               // upper cube-shaped part
+               // rotate([20, 0, 0])
+               translate([-batt_len/2, -batt_diam/2, 0])
+                       cube([batt_len, batt_diam, batt_diam]);
 
-               // holes for wire from battery to the PCB
-               translate([-infty/2, -batt_diam/2, wall + pcb_groove + wire_thick/2])
+               // battery cylinder for the lower part
+               translate([-batt_len/2, 0, 0])
                        rotate([0, 90, 0])
-                       rotate([0, 0, 90])
-                       cylinder(r=wire_thick/2, h = infty, $fn=6);
-               // hole for the cable outlet
-               translate([-pcb_len/2+pcb_groove+cable_out_diam/2, -batt_diam/2-pcb_thick-2*wall, -infty/2])
-                       cylinder(r=cable_out_diam/2, h = infty, $fn=6);
-               // holes for binding to the shoe
-               for (x = [
-                        pcb_len/2 + wall + wire_thick/2 + wire_sep,
-                        pcb_len/2 + wall + wire_thick/2,
-                       -pcb_len/2 - wall - wire_thick/2 - wire_sep,,
-                       -pcb_len/2 - wall - wire_thick/2 ]) {
-                       for (y = [-1,1]) {
-                               translate([x, y*(batt_diam/2 + wall + wire_thick/2), -infty/2])
-                                       cylinder(r=wire_thick/2, h=infty, $fn=6);
+                       cylinder(r=batt_diam/2, h = batt_len);
+
+               // hole for PCB
+               translate([-pcb_len/2-pcb_xoff,
+                       batt_diam/2-pcb_width,
+                       -batt_diam/2-pcb_thick - pcb_comp_h])
+                       cube([pcb_len, pcb_width,
+                               batt_diam/2 + pcb_thick + pcb_comp_h + eps]);
+               // hole above the PCB for the outgoing cable
+               translate([-pcb_len/2-pcb_xoff-2*wall-outcable_w,
+                       batt_diam/2-pcb_width,
+                       -batt_diam/2-pcb_comp_h])
+                       cube([pcb_len, pcb_width,
+                               batt_diam/2 + pcb_comp_h + eps]);
+               // cable outlet
+               translate([-pcb_xoff-pcb_len/2-wall-outcable_w,
+                       -pcb_width+batt_diam/2,
+                       -batt_diam/2-outcable_h])
+                       cube([outcable_w, infty, outcable_h]);
+               // hole under the PCB
+               translate([-pcb_len/2+pcb_groove-pcb_xoff,
+                       batt_diam/2-pcb_width + pcb_groove,
+                       -batt_diam/2-pcb_thick - 2*pcb_comp_h])
+                       cube([pcb_len-2*pcb_groove, pcb_width-2*pcb_groove,
+                               batt_diam/2 + pcb_thick + pcb_comp_h + eps]);
+               // hole for prog connector
+               translate([pcb_len/2-pcb_xoff-pcb_groove-eps,
+                       batt_diam/2-pcb_width/2-prg_width/2,
+                       -batt_diam/2-pcb_thick - 2*pcb_comp_h])
+                       difference() {
+                               cube([prg_len+pcb_groove+eps, prg_width,
+                                       batt_diam/2 + pcb_thick + pcb_comp_h + eps]);
+                               translate([prg_len/2+pcb_groove, -eps, pcb_comp_h])
+                                       cube([prg_len/2+eps, prg_width+2*eps, pcb_thick]);
                        };
+                // LED hole
+               translate([0, batt_diam/2-pcb_width/2, -infty/2]) {
+                       cylinder(r=led_diam/2, h=infty, $fn=6);
+                       translate([sw_xoff, 0, 0])
+                               cylinder(r=sw_diam/2, h=infty, $fn=6);
+                       translate([-sw_xoff, 0, 0])
+                               cylinder(r=sw_diam/2, h=infty, $fn=6);
                };
+               // space under the wire holes for battery contacts
+               translate([-batt_len/2-2*wall-cable_sep-eps, 0, 0])
+                       difference() {
+                               rotate([0, 90, 0])
+                                       cylinder(r = batt_diam/2-wall, h = batt_len + 4*wall + 2*cable_sep + 2*eps);
+                               translate([-infty/2, -infty/2, -batt_end_h])
+                                       cube(infty);
+                       };
+               // space above the wire holes for battery contacts
+               translate([-batt_len/2-2*wall-cable_sep-eps, -batt_diam/2, batt_end_h])
+                       cube([batt_len + 4*wall + 2*cable_sep + 2*eps, 
+                               batt_diam,
+                               batt_end_h]);
+               // wire holes for battery contacts
+               for (x = [-1, 1])
+               for (y = [-1, 1])
+                       translate([-batt_len/2-wall-eps, x*wire_sep/2, y*wire_sep/2])
+                       rotate([0, 90, 0])
+                               cylinder(r = wire_thick/2, h = batt_len + 2*wall + 2*eps, $fn=6);
+               // wire hole from PCB to battery contacts
+               // translate([-batt_len/2-wall-eps, 0, -batt_diam/2-pcb_comp_h + wire_thick/2])
+               rotate([40, 0, 0])
+               translate([-batt_len/2-wall-eps, 0, -batt_diam/2 - wall/2 - wire_thick/2])
+                       rotate([0, 90, 0])
+                               cylinder(r = wire_thick/2, h = batt_len + 2*wall + 2*eps, $fn=6);
+               // hole behind the battery contacts
+               for(x=[1, -1])
+               scale([x, 1, 1]) translate([batt_len/2+wall+cable_sep, 0, 0]) hull() {
+                       translate([0, -batt_diam/2, 0])
+                               cube([wall + eps, batt_diam, infty]);
+                       rotate([0, 90, 0])
+                               cylinder(r = batt_diam/2, h = wall+eps);
+                       translate([0, batt_diam/2 - pcb_width,
+                               -batt_diam/2-pcb_comp_h-pcb_thick])
+                               cube([wall + eps, pcb_width, eps]);
+                       translate([0, batt_diam/2 - pcb_width + 0.5*wall,
+                               -batt_diam/2-2*pcb_comp_h-pcb_thick])
+                               cube([wall + eps, pcb_width-0.5*wall, eps]);
+               };
+               // inner hole behind the battery contacts
+               for(x=[1, -1])
+               scale([x, 1, 1]) translate([batt_len/2+wall, 0, 0]) hull() {
+                       translate([0, -batt_diam/2+wall, 0])
+                               cube([cable_sep + eps, batt_diam-2*wall, infty]);
+                       rotate([0, 90, 0])
+                               cylinder(r = batt_diam/2-wall, h = cable_sep+eps);
+               };
+               // cable lead to battery contacts
+               for (x=[1, -1]) scale([x, 1, 1])
+                       rotate([-140, 0, 0])
+                       translate([batt_len/2-eps, -wire_thick/2, batt_diam/2-2.7])
+                               cube([wall+cable_sep+2*eps, wire_thick, 5.4]);
+               
+               // mounting holes
+               for(x=[-1,1]) scale([x, 1, 1])
+               translate([batt_len/2-mounthole_w/2, batt_diam/2+wall+mounthole_h/2, -infty/2])
+                       scale([1, mounthole_h/mounthole_w, 1])
+                       cylinder(r = mounthole_w/2, h = infty);
+               // grabbing gap
+               for(x=[-1,1]) scale([x, 1, 1])
+               translate([batt_len/2+cable_sep+wall+10, batt_diam/2-pcb_width/2, -batt_diam/2-2*pcb_comp_h-pcb_thick-wall-eps])
+                       cylinder(r1 = 10, r2 = 10 - wall, h = wall + 2*eps);
+               // plus sign - vertical line
+               translate([batt_len/2 - 1.5*wall-plus_width/2, -plus_width/2, -batt_diam/2-wall])
+                       cube([wall, plus_width, infty]);
+               // plus and minus signs - horizontal line
+               for(x=[-1,1]) scale([x, 1, 1])
+               translate([batt_len/2 - wall - plus_width, -wall/2, -batt_diam/2-wall])
+                       cube([plus_width, wall, infty]);
+       };
+       // clip barrier
+       for (x = [-1, 1]) scale([x, 1, 1]) hull () {
+               translate([batt_len/2+wall+cable_sep-eps, batt_diam/2-pcb_width+wall/2+lid_sep,
+                       -batt_diam/2-pcb_thick-pcb_comp_h + wall + lid_sep])
+                       cube([wall+eps, pcb_width-2*wall-2*lid_sep, wall]);
+               translate([batt_len/2+wall+cable_sep-eps, batt_diam/2-pcb_width+3*wall/2+lid_sep,
+                       -batt_diam/2-pcb_thick-pcb_comp_h + 3*wall + lid_sep])
+                       cube([eps, pcb_width-4*wall-2*lid_sep, eps]);
        };
 };
 
-module cover_internal() {
-       hull() { 
-               base();
-               // battery + wall + cable space
-               translate([-batt_len/2-wall, 0, batt_diam/2+wall])
+module lid_body() {
+       translate([-batt_len/2 - wall - cable_sep - lid_sep, -batt_diam/2+lid_sep, -batt_diam/2 -wall])
+               cube([batt_len + 2*wall + 2*cable_sep + 2*lid_sep, batt_diam-2*lid_sep, batt_diam/2 - batt_end_h + wall - lid_sep]);
+       hull () {
+               translate([-batt_len/2 - 2*wall - cable_sep,
+                       -batt_diam/2, -batt_diam/2-wall])
+                       cube([batt_len + 4*wall + 2*cable_sep,
+                               batt_diam, eps]);
+               translate([-batt_len/2 - 3*wall - cable_sep,
+                       -batt_diam/2 - wall, -body_top_h-wall/2-lid_sep])
+                       cube([batt_len + 6*wall + 2*cable_sep,
+                               batt_diam + 2*wall, wall/2]);
+       };
+       // clip behind the battery contacts
+       for(x=[1, -1])
+               scale([x, 1, 1]) translate([batt_len/2+wall+cable_sep+lid_sep, 0, 0]) hull() {
+                       translate([0, -batt_diam/2+lid_sep, -batt_diam/2])
+                               cube([wall-lid_sep, batt_diam-2*lid_sep, eps]);
                        rotate([0, 90, 0])
-                       cylinder(r=batt_diam/2+wall, h = batt_len + 2*wall);
-               // space for PCB
-               translate([-pcb_len/2-wall, -batt_diam/2-2*wall-pcb_thick, base_h-pcb_groove])
-                       cube([pcb_len+2*wall, wall+pcb_thick, pcb_width+wall]);
+                               cylinder(r = batt_diam/2-lid_sep, h = wall-lid_sep);
+                       translate([-clip_pretension, batt_diam/2 - pcb_width + 0.5*wall + lid_sep,
+                               batt_diam/2+2*pcb_comp_h+pcb_thick-lid_sep])
+                               cube([wall+clip_pretension, pcb_width-0.5*wall-1.5*lid_sep, eps]);
+               };
+       // outer part of the clip behind the battery contacts
+       for (x=[1, -1]) scale([x, 1, 1]) translate([batt_len/2+2*wall+cable_sep+lid_sep, 0, 0]) hull() {
+               translate([0, -batt_diam/2 - wall, -body_top_h-wall/2-lid_sep])
+                       cube([wall-lid_sep, batt_diam + 2*wall, wall/2]);
+               difference() {
+                       scale([0.3, 1, 1])
+                               sphere(batt_diam/2+wall);
+                       translate([-infty/2, -infty/2, -infty-body_top_h-lid_sep+2*wall])
+                               cube(infty);
+                       translate([-infty-clip_pretension, -infty/2, -infty/2])
+                               cube(infty);
+               };
+               translate([-clip_pretension,
+                       batt_diam/2 - pcb_width,
+                       batt_diam/2+2*pcb_comp_h+pcb_thick+wall])
+                       cube([wall-lid_sep, pcb_width+wall, eps]);
        };
 };
 
-module cover_hole() {
+module lid() {
        difference() {
-               cover_internal();
-               translate([-infty/2, -infty/2, wall + batt_clip_h])
-                       cube(infty);
+               lid_body();
+               translate([-batt_len/2+eps, 0, 0]) rotate([0, 90, 0])
+                       cylinder(r=batt_diam/2, h=batt_len-2*eps);
+       // clip barrier
+       for (x = [-1, 1]) scale([x, 1, 1]) hull () {
+               translate([batt_len/2+wall+cable_sep-clip_pretension, batt_diam/2-pcb_width+wall/2,
+                       batt_diam/2+pcb_thick+pcb_comp_h-2*wall])
+                       cube([wall+clip_pretension+eps, pcb_width-2*wall, wall]);
+               translate([batt_len/2+wall+cable_sep-eps, batt_diam/2-pcb_width+wall/2,
+                       batt_diam/2+pcb_thick+pcb_comp_h-4*wall + lid_sep])
+                       cube([eps, pcb_width-2*wall, eps]);
        };
-       base_protrusions();
-       // battery();
-       translate([-batt_len/2-cable_sep, 0, batt_diam/2+wall])
-               rotate([0, 90, 0])
-               cylinder(r=batt_diam/2, h = batt_len + 2*cable_sep);
-};
-
-module cover() {
-       difference() {
-               minkowski() {
-                       cover_internal();
-                       sphere(wall+cover_sep, $fn=16);
-               }
-               minkowski() {
-                       cover_hole();
-                       sphere(cover_sep, $fn=8);
+/*
+               hull() {
+                       difference() {
+                               translate([-batt_len/2-cable_sep-wall, 0, 0]) rotate([0, 90, 0])
+                                       cylinder(r=batt_diam/2-wall-lid_sep, h=batt_len+2*wall+2*cable_sep);
+                               translate([-infty/2, -batt_diam/2, -infty-wire_sep/2-wire_thick/2])
+                                       cube([infty, batt_diam, infty]);
+                       };
+                       translate([-batt_len/2-cable_sep-wall, batt_diam/2-pcb_width+0.5*wall+0.5*lid_sep, batt_diam/2 + pcb_comp_h+pcb_thick-wall-lid_sep])
+                       cube([batt_len + 2*wall + 2* cable_sep, pcb_width-1.5*wall-1.5*lid_sep, eps]);
                };
-               // s2 hole
-               translate([s2_xoff, 0, base_h-pcb_groove + pcb_width/2])
-                       rotate([90, 0, 0])
-                       cylinder(r=uswitch_diam/2, h = infty, $fn=6);
-               // LED hole
-               translate([led_xoff, 0, base_h-pcb_groove + pcb_width/2])
-                       rotate([90, 0, 0])
-                       cylinder(r=led_diam/2, h = infty, $fn=6);
-               // s1 hole
-               translate([s1_xoff, 0, base_h-pcb_groove + pcb_width/2])
-                       rotate([90, 0, 0])
-                       cylinder(r=uswitch_diam/2, h = infty, $fn=6);
-               // xy plane
-               translate([0, 0, -infty/2]) cube(infty, center=true);
-       }
+*/
+       };
 };
 
-translate([0, -19, 0])
-       main($fn=128);
-
-// translate([0, -40, 0])
-//     cover_hole();
-
-// cover($fn=128);
-// translate([0, 17, batt_diam + 3*wall + cover_sep])
-// rotate([180, 0, 0])
-//     cover($fn=128);
+if (lowres) {
+       translate([0, 15, 0]) case();
+       translate([0, -15, 0]) rotate([180, 0, 0]) lid();
+} else {
+       translate([0, 15, batt_diam/2+pcb_thick+2*pcb_comp_h+wall])
+               case($fn=128);
+       translate([0, -15, batt_diam/2+wall])
+               lid($fn=128);
+}
 
-translate([0, 19, 0])
-       cover($fn=128);