// Case for a "Ceph OSD" from ROCK64 + 3.5" HDD + USB3.0-SATA UASP :)

// Version 1, simplest

// From WD datasheet: https://support.wdc.com/images/kb/2579-771970-A03.pdf + https://www.techpowerup.com/forums/attachments/3_5_emount-jpg.44813/
hdd35_w = 102;
hdd35_l = 147;
hdd35_h = 26.1;
hdd35_screw1_offset = 28.5; // from connector side
hdd35_screw2_offset = 28.5+41.61; // from connector side
hdd35_screw3_offset = 28.5+101.6; // from connector side
hdd35_screw_zpos = 6.35; // from bottom
hdd35_screw_dia = 3.51; // 6-32 screws

// From ROCK64 drawings: https://github.com/TeaPackCZ/Rock64_drawings/blob/master/Rock64 Base.pdf
rock64_w = 56.2;
rock64_l = 88;
rock64_h = 17; // +2mm under for microsd slot
rock64_board_thick = 1.5;
rock64_screw_offset = 3.6; // from back and edges
rock64_screw_distance = 58; // from back screws to front screws
rock64_screw_dia = 2.8; // weird screws
rock64_microsd_offset = 19.2;
rock64_microsd_length = 16;

rock64_zpos = 16;
rock64_screw_post_dia = 6;
wall_thickness = 5;

// 3.5 HDD and screws
color([0.8, 0.6, 1]) cube(size=[hdd35_w, hdd35_l, hdd35_h]);
color([0.5, 0.5, 1]) translate([0, -rock64_w, 0]) cube(size=[50, rock64_w, 13]);
color([1, 1, 1]) translate([ 0, hdd35_screw1_offset, hdd35_screw_zpos ]) rotate([0, -90, 0]) cylinder(r=hdd35_screw_dia/2, h=3, $fn=32);
color([1, 1, 1]) translate([ 0, hdd35_screw2_offset, hdd35_screw_zpos ]) rotate([0, -90, 0]) cylinder(r=hdd35_screw_dia/2, h=3, $fn=32);
color([1, 1, 1]) translate([ 0, hdd35_screw3_offset, hdd35_screw_zpos ]) rotate([0, -90, 0]) cylinder(r=hdd35_screw_dia/2, h=3, $fn=32);
color([1, 1, 1]) translate([ hdd35_w, hdd35_screw1_offset, hdd35_screw_zpos ]) rotate([0, 90, 0]) cylinder(r=hdd35_screw_dia/2, h=3, $fn=32);
color([1, 1, 1]) translate([ hdd35_w, hdd35_screw2_offset, hdd35_screw_zpos ]) rotate([0, 90, 0]) cylinder(r=hdd35_screw_dia/2, h=3, $fn=32);
color([1, 1, 1]) translate([ hdd35_w, hdd35_screw3_offset, hdd35_screw_zpos ]) rotate([0, 90, 0]) cylinder(r=hdd35_screw_dia/2, h=3, $fn=32);

// ROCK64
color([0.6, 0.8, 1]) translate([rock64_l/2+1, -rock64_w/2-3, rock64_zpos]) rotate([-90, 180, 90]) import("./ROCK64.stl");

color([0, 0.8, 0.5]) {
    translate([rock64_screw_offset+2.4, -rock64_screw_offset-3, rock64_zpos+rock64_board_thick]) difference() {
        cylinder(r=rock64_screw_post_dia/2, h=rock64_h, $fn=32);
        translate([0, 0, -1]) cylinder(r=1.45, h=10, $fn=32);
    }
    translate([rock64_screw_offset+2.4, -rock64_w+rock64_screw_offset-3, rock64_zpos+rock64_board_thick]) difference() {
        cylinder(r=rock64_screw_post_dia/2, h=rock64_h, $fn=32);
        translate([0, 0, -1]) cylinder(r=1.45, h=10, $fn=32);
    }
    translate([rock64_screw_distance+rock64_screw_offset+2.4, -rock64_screw_offset-3, rock64_zpos+rock64_board_thick]) difference() {
        cylinder(r=rock64_screw_post_dia/2, h=rock64_h, $fn=32);
        translate([0, 0, -1]) cylinder(r=1.45, h=10, $fn=32);
    }
    translate([rock64_screw_distance+rock64_screw_offset+2.4, -rock64_w+rock64_screw_offset-3, rock64_zpos+rock64_board_thick]) difference() {
        cylinder(r=rock64_screw_post_dia/2, h=rock64_h, $fn=32);
        translate([0, 0, -1]) cylinder(r=1.45, h=10, $fn=32);
    }
    difference()
    {
        union() {
            translate([-wall_thickness, -rock64_w-10, -2]) cube(size=[wall_thickness, rock64_w+10+hdd35_l+wall_thickness, rock64_zpos+rock64_board_thick+rock64_h+2]);
            translate([-wall_thickness, -rock64_w-10, rock64_zpos+rock64_board_thick+rock64_h]) cube(size=[wall_thickness*2+hdd35_w, rock64_w+10+hdd35_l+wall_thickness, 2]);
            translate([hdd35_w, 0, -2]) cube(size=[wall_thickness, hdd35_l+wall_thickness, rock64_zpos+rock64_board_thick+rock64_h+2]);
            translate([0, hdd35_l+1, -2]) cube(size=[hdd35_w, wall_thickness-1, rock64_zpos+rock64_board_thick+rock64_h+2]);
        }

        translate([ -wall_thickness-1, -3-rock64_microsd_offset-rock64_microsd_length, rock64_zpos-3 ]) cube(size=[wall_thickness+2, rock64_microsd_length, 5]);
        translate([ 0, hdd35_screw1_offset, hdd35_screw_zpos ]) rotate([0, -90, 0]) cylinder(r=hdd35_screw_dia/2, h=10, $fn=32);
        //translate([ 0, hdd35_screw2_offset, hdd35_screw_zpos ]) rotate([0, -90, 0]) cylinder(r=hdd35_screw_dia/2, h=10, $fn=32);
        translate([ 0, hdd35_screw3_offset, hdd35_screw_zpos ]) rotate([0, -90, 0]) cylinder(r=hdd35_screw_dia/2, h=10, $fn=32);
        translate([ -1, hdd35_screw1_offset, hdd35_screw_zpos ]) rotate([0, -90, 0]) cylinder(r=hdd35_screw_dia/2+2.5, h=10, $fn=32);
        //translate([ -1, hdd35_screw2_offset, hdd35_screw_zpos ]) rotate([0, -90, 0]) cylinder(r=hdd35_screw_dia/2+2.5, h=10, $fn=32);
        translate([ -1, hdd35_screw3_offset, hdd35_screw_zpos ]) rotate([0, -90, 0]) cylinder(r=hdd35_screw_dia/2+2.5, h=10, $fn=32);

        translate([ hdd35_w, hdd35_screw1_offset, hdd35_screw_zpos ]) rotate([0, 90, 0]) cylinder(r=hdd35_screw_dia/2, h=10, $fn=32);
        //translate([ hdd35_w, hdd35_screw2_offset, hdd35_screw_zpos ]) rotate([0, 90, 0]) cylinder(r=hdd35_screw_dia/2, h=10, $fn=32);
        translate([ hdd35_w, hdd35_screw3_offset, hdd35_screw_zpos ]) rotate([0, 90, 0]) cylinder(r=hdd35_screw_dia/2, h=10, $fn=32);
        translate([ hdd35_w+1, hdd35_screw1_offset, hdd35_screw_zpos ]) rotate([0, 90, 0]) cylinder(r=hdd35_screw_dia/2+2.5, h=10, $fn=32);
        //translate([ hdd35_w+1, hdd35_screw2_offset, hdd35_screw_zpos ]) rotate([0, 90, 0]) cylinder(r=hdd35_screw_dia/2+2.5, h=10, $fn=32);
        translate([ hdd35_w+1, hdd35_screw3_offset, hdd35_screw_zpos ]) rotate([0, 90, 0]) cylinder(r=hdd35_screw_dia/2+2.5, h=10, $fn=32);
    }
}
