// Licnese - CC0

FN=20;

m5r = 5.2/2;
m2r = 2.2/2;

fix_width = 152.5;
lip_height = 30;

speaker_r = 65/2;
speaker_screw_d = 52;

speaker_vol_d = 32.5;

gps_d = 30;
gps_ant_d = 16;

module rounded_rect(w,h,r) {
  _w = w-2*r;
  _h = h-2*r;

  x2 = _w/2;
  y2 = _h/2;

  hull() {
    translate([-x2, y2]) circle(r, $fn=FN);
    translate([ x2, y2]) circle(r, $fn=FN);
    translate([ x2,-y2]) circle(r, $fn=FN);
    translate([-x2,-y2]) circle(r, $fn=FN);
  }
}

module speaker_tab() {
  _r=3;
  w = 2*speaker_r + 20;
  h = 2*speaker_r + 20 + lip_height/2;
  d = speaker_screw_d /2;
  
  cx = 0;
  cy = lip_height/2 ;
  difference() {
    rounded_rect(w,h,_r);
    translate([cx,cy]) circle(speaker_r, $fn=2*FN);
    translate([cx + d, cy + d]) circle(m2r, $fn=FN);
    translate([cx + d, cy - d]) circle(m2r, $fn=FN);
    translate([cx - d, cy - d]) circle(m2r, $fn=FN);
    translate([cx - d, cy + d]) circle(m2r, $fn=FN);
  }
}

//speaker_tab();

module plate() {
  _r = 3;

  difference() {
    union() {
      rounded_rect(fix_width + 4*m5r, lip_height, _r);
      translate([-fix_width/2, lip_height+10]) speaker_tab();
      translate([5,lip_height-4]) rounded_rect(80,30,_r);
      translate([-15,30+lip_height]) rounded_rect(46,60,_r);
    }
    
    
    translate([-30,lip_height]) circle(m2r, $fn=FN);
    translate([-30+speaker_vol_d,lip_height]) circle(m2r, $fn=FN);
    
    
    translate([0,60]) square([5,20], center=true);
    translate([-gps_d,60]) square([5,20], center=true);
    
    translate([-15,77]) square([20,5], center=true);
    
    
    translate([-fix_width/2,0]) circle(m5r, $fn=FN);
    translate([ fix_width/2,0]) circle(m5r, $fn=FN);
  }  
  
}

plate();