use <box.scad>
use <supports.scad>
use <cutouts.scad>

// FABULA open source storyteller enclosure

// TODO: open hardware logo, Fabula logo, tag slot with led mount

box_cut_height = 10;
pcb_screw_size = 3;

module fabula_enclosure_bottom() {
    difference() {
        union() {
            cap();
            
            // Supports
            translate([-30, 0, 21.6]) supports_speaker();
            translate([28, 0, 16.6]) rotate([0, 180, 90]) supports_battery();
            translate([70.4, 29, 20.1]) rotate([0, 0, 180]) supports_charging_module();
        }
    
        // Cutouts
        translate([98.4, 29, 17]) rotate([0, -90, 0]) usb_cutout();
        translate([90, 5, 10]) rotate([90, 0, 0]) rotate([0, 90, 0]) switch_cutout();
        translate([-65, -40, 25]) speaker_grille();
        translate([75, 55, 16]) rotate([90, 0, 0]) cylinder(d = 3, h = 20, $fn = 4);
        
        // Logos
        translate([45, -18, 28.1]) linear_extrude(height = 1, center = true) rotate([0, 0, 90]) scale([0.15, 0.15, 0.15]) import("oshw-logo-filled-black.svg");
        translate([66, -25, 28.1]) linear_extrude(height = 1, center = true) rotate([0, 0, 90]) text("a Luna, con ♥", size = 6);
    }
    
    // Speaker grille reinforcements
    translate([-59, -40, 22.5]) {
        for (i = [0 : 10]) {
            translate([i*5.8, 0, 0]) cube([2, 80, 2]);            
        }
    }
}

module fabula_enclosure_top() {
    difference() {
        union() {
            box();
            
            // Supports
            translate([-66.1, 30.1, -14.5]) pcb_support(pcb_screw_size);
            translate([-66.1, -27.8, -14.5]) pcb_support(pcb_screw_size);
            translate([64.1, 24.2, -14.5]) pcb_support(pcb_screw_size);
            translate([64.1, -26.8, -14.5]) pcb_support(pcb_screw_size);
            
            // Url
            //translate([-80, -42, -22.5]) linear_extrude(height = 1.5, center = true) text("git.ichibi.eu/penguin86/Fabula", size = 6);
        }
    
        // Cutouts
        translate([90, 5, 10]) rotate([90, 0, 0]) rotate([0, 90, 0]) switch_cutout();
        translate([20, 13.5, -30]) keycap();
        translate([35.5, -12.5, -30]) keycap();
        translate([44.5, 23.5, -30]) keycap();
        translate([61, -2, -30]) keycap();
        translate([-50, 0, -30.5]) rotate([0, 0, 90]) character_retainer_cutout();
        translate([-10, -51, -10]) rotate([-90, 0, 0]) sdcard_access_port_cutout();
        
        // Logos
        translate([0, 30, -27.6]) rotate ([180, 0, -90]) linear_extrude(height=1) text("ƒabula", font="URW Bookman", size=13);
    }
}

translate([0, -60, 0]) rotate([180, 0, 0]) fabula_enclosure_bottom();
translate([0, 60, 0]) fabula_enclosure_top();
