// ============================================
// SaltyLab — Flight Controller Mount
// Vibration-isolated, 30.5mm pattern
// TPU dampers + PETG frame
// ============================================
include <dimensions.scad>

// FC mount attaches to 2020 extrusion via T-slot
// Rubber/TPU grommets isolate FC from frame vibration

mount_w = 45;    // Overall width
mount_d = 45;    // Overall depth  
mount_h = 15;    // Total height (base + standoffs)
base_h = 4;      // Base plate thickness

// TPU grommet dimensions
grommet_od = 7;
grommet_id = 3.2;  // M3 clearance
grommet_h = 5;     // Soft mount height

module fc_mount() {
    difference() {
        union() {
            // Base plate
            translate([-mount_w/2, -mount_d/2, 0])
                cube([mount_w, mount_d, base_h]);
            
            // Standoff posts (PETG, FC sits on TPU grommets on top)
            for (x = [-fc_hole_spacing/2, fc_hole_spacing/2]) {
                for (y = [-fc_hole_spacing/2, fc_hole_spacing/2]) {
                    translate([x, y, 0])
                        cylinder(d=8, h=base_h + grommet_h, $fn=30);
                }
            }
            
            // 2020 extrusion clamp tabs (sides)
            for (side = [-1, 1]) {
                translate([side * (extrusion_w/2 + wall), -15, 0])
                    cube([wall, 30, base_h + 10]);
            }
        }
        
        // FC mounting holes (M3 through standoffs)
        for (x = [-fc_hole_spacing/2, fc_hole_spacing/2]) {
            for (y = [-fc_hole_spacing/2, fc_hole_spacing/2]) {
                translate([x, y, -1])
                    cylinder(d=fc_hole_dia, h=base_h + grommet_h + 2, $fn=25);
            }
        }
        
        // Extrusion channel (20mm wide slot through base)
        translate([-extrusion_w/2 - tol, -20, -1])
            cube([extrusion_w + tol*2, 40, base_h + 2]);
        
        // Clamp bolt holes (M3, horizontal through side tabs)
        for (side = [-1, 1]) {
            translate([side * (extrusion_w/2 + wall + 1), 0, base_h + 5])
                rotate([0, 90, 0])
                    cylinder(d=m3_clear, h=wall + 2, center=true, $fn=25);
        }
        
        // Center cutout for airflow / weight reduction
        translate([0, 0, -1])
            cylinder(d=15, h=base_h + 2, $fn=30);
    }
}

// TPU grommet (print separately in TPU)
module tpu_grommet() {
    difference() {
        cylinder(d=grommet_od, h=grommet_h, $fn=30);
        translate([0, 0, -1])
            cylinder(d=grommet_id, h=grommet_h + 2, $fn=25);
    }
}

// Show assembled
fc_mount();

// Show grommets in position (for visualization)
%for (x = [-fc_hole_spacing/2, fc_hole_spacing/2]) {
    for (y = [-fc_hole_spacing/2, fc_hole_spacing/2]) {
        translate([x, y, base_h])
            tpu_grommet();
    }
}
