// This file contains the components used in Fabula.
// This is for test-fitting and shouldn't be printed.

/*
// 50mm speaker
module speaker_50() {
    translate([0, 0, -2]) {
        union() {
            difference() {
                // Mounting Plaque
                cube([55, 55, 4], true);
                // Screw holes
                translate([-20, -20, 0]) cylinder(h = 100, d = 4, center = true);
                translate([20, -20, 0]) cylinder(h = 100, d = 4, center = true);
                translate([-20, 20, 0]) cylinder(h = 100, d = 4, center = true);
                translate([20, 20, 0]) cylinder(h = 100, d = 4, center = true);
                // Speaker cone (cosmetic)
                translate([0, 0, 2]) cylinder(h = 1, d = 49, center = true);
            }
            translate([0, 0, - 16 - 2]) cylinder(h = 32, d = 44, center = true);
        }
    }
}
*/

// 80mm flat speaker
module speaker_80() {
    cylinder(h = 12, d1 = 78, d2 = 34);
    translate([0, 0, 12]) cylinder(h = 12, d = 22);
}


// 4056-based li-ion charging module
module li_ion_4056_charger_module() {
    cube([28, 17, 2], true);
    translate([-14 + 3.25, 0, 2]) cube([6.5, 8.9, 3], true);
}

// 14x12mm rocker switch with 21x15mm flange
module switch() {
    // Body
    cube([14, 12, 11], true);
    // Flange
    translate([0, 0, 11/2]) cube([21, 15, 2], true);
    // Rocker
    translate([0, 0, 6]) rotate([0, 15, 0]) cube([12, 10, 5], true);
}

// Cherry MX (compatible) mechanical keyboard switch, i.e. Gatheron Blue
module mechanical_switch() {
    // Body
    cube([15.5, 15.5, 11.5], true);
    // Stem
    translate([0, 0, (11.5 + 3.5) / 2]){
        cube([1, 3.8, 3.5], true);
        cube([3.8, 1, 3.5], true);
    }
}

// Mainboard. The highest component is the capacitor with a total height of 18mm, but we round to 20 for good measure.
module pcb() {
    // Board
    translate([-77.89 / 2 - 19.20, -148.35 / 2 - 49.71, 0]) {
        linear_extrude(height = 1.4) {
            difference() {
                hull() {
                    /*
                    Center svg
                    Bounding box:
                    Min:  19.20, 49.71
                    Max:  97.09, 198.06
                    Size: 77.89, 148.35
                    */
                    import("pcb.svg");
                }
                import("pcb.svg");
            }
        }    
    }
    // Keys
    translate([-13.4, -20.1, 11.5/2 + 1.4]) mechanical_switch();
    translate([-23.4, -44.6, 11.5/2 + 1.4]) mechanical_switch();
    translate([12.6, -35.6, 11.5/2 + 1.4]) mechanical_switch();
    translate([2.05, -61.05, 11.5/2 + 1.4]) mechanical_switch();
    // Box to account for the other various components
    translate([-28, 4, 0]) cube([53, 70, 18]);
}

module battery_18650() {
    cylinder(d = 18, h = 65, center = true);
}

//speaker_50();
//speaker_80();
//li_ion_4056_charger_module();
switch();
//pcb();
//battery_18650();
//mechanical_switch();
