// ============================================
// SaltyLab — ESC Mount
// 150×100×15mm PETG
// Hoverboard ESC, mounts to 2020 extrusion
// ============================================
include <dimensions.scad>

mount_w = 150;
mount_d = 100;
mount_h = 15;
base_h = 3;

module esc_mount() {
    difference() {
        union() {
            // Base plate
            translate([-mount_w/2, -mount_d/2, 0])
                cube([mount_w, mount_d, base_h]);
            
            // ESC retaining walls (low lip on 3 sides)
            // Left
            translate([-mount_w/2, -mount_d/2, 0])
                cube([wall, mount_d, mount_h]);
            // Right
            translate([mount_w/2 - wall, -mount_d/2, 0])
                cube([wall, mount_d, mount_h]);
            // Back
            translate([-mount_w/2, mount_d/2 - wall, 0])
                cube([mount_w, wall, mount_h]);
            
            // Front clips (snap-fit tabs to hold ESC)
            for (x = [-30, 30]) {
                translate([x - 5, -mount_d/2, 0])
                    cube([10, wall, mount_h]);
                // Clip overhang
                translate([x - 5, -mount_d/2, mount_h - 2])
                    cube([10, wall + 3, 2]);
            }
            
            // 2020 mount tabs (back)
            for (x = [-25, 25]) {
                translate([x - 10, mount_d/2 - wall, 0])
                    cube([20, wall + 8, base_h + 8]);
            }
        }
        
        // Extrusion bolt holes (M5)
        for (x = [-25, 25]) {
            translate([x, mount_d/2 + 3, base_h + 4])
                rotate([90, 0, 0])
                    cylinder(d=m5_clear, h=wall + 12, $fn=30);
        }
        
        // Ventilation holes in base
        for (x = [-40, -20, 0, 20, 40]) {
            for (y = [-25, 0, 25]) {
                translate([x, y, -1])
                    cylinder(d=8, h=base_h + 2, $fn=20);
            }
        }
        
        // Wire routing slots (front and back)
        translate([-15, -mount_d/2 - 1, base_h])
            cube([30, wall + 2, 10]);
        translate([-15, mount_d/2 - wall - 1, base_h])
            cube([30, wall + 2, 10]);
    }
}

esc_mount();
