// License: CC0
//
// To the extent possible under law, Clementine Computing LLC has waived
// all copyright and related or neighboring rights to this file.
//
// This work is published from: United States.
//

include <PopufareHousingCommon.scad>

// when looking down (to negative z-axis)
// it's as if you're looking at the back of the panel,
// screen facing outwards, front ribbon on screen
// going 'down' (negative y-axis).
//
module PopufareHousingInnerBackPlate() {
  _r = 3;
  _outr = 16;
  
  hole_width  = POPUFARE_INNER_PLATE_HOLE_WIDTH;
  hole_height = POPUFARE_INNER_PLATE_HOLE_HEIGHT;

  w2 = hole_width/2;
  h2 = hole_height/2;
  x = hole_width + _outr;
  y = hole_height + _outr;
  
  rpi_hole_c = [_RASPBERRY_PI_B_CX, _RASPBERRY_PI_B_CY];
  rpi_hole_dx = _RASPBERRY_PI_B_HOLE_DX;
  rpi_hole_dy = _RASPBERRY_PI_B_HOLE_DY;
  
  screen_hole_c = [_SCREEN_CX,_SCREEN_CY];
  screen_hole_dx = _SCREEN_HOLE_DX;
  screen_hole_dy = _SCREEN_HOLE_DY;
  
  
  d_pi_screen = [screen_hole_dx - rpi_hole_dx, screen_hole_dy - rpi_hole_dy];

  access_left_w = 25;
  access_left_h = screen_hole_dy - 10;
  access_left_c = [ rpi_hole_c[0] - rpi_hole_dx/2  - d_pi_screen[0]/2, screen_hole_c[1] ];

  access_middle_w = rpi_hole_dx - 16;
  access_middle_h = rpi_hole_dy - 16;
  access_middle_c = [_RASPBERRY_PI_B_CX,_RASPBERRY_PI_B_CY];

  access_right_w = hole_width/2 - (rpi_hole_c[0] + rpi_hole_dx/2);
  access_right_h = 5*hole_height/8;
  access_right_c = [ (rpi_hole_c[0] + rpi_hole_dx/2) + access_right_w/2 + _r, 0];
  
  access_top_w = rpi_hole_dx - 25;
  access_top_h = 6;
  access_top_c  = [rpi_hole_c[0], rpi_hole_c[1] + rpi_hole_dy/2 + access_top_h/2 + 4];
  
  access_bottom_w = rpi_hole_dx - 25;
  access_bottom_h = 24;
  access_bottom_c  = [rpi_hole_c[0], rpi_hole_c[1] - rpi_hole_dy/2 - access_bottom_h/2 - 8];

  sx2 = hole_width/2;
  sy2 = hole_height/2;
  difference() {
    rounded_rect(x,y,_r);

    // RPi m2 joining holes
    //
    translate(rpi_hole_c) translate([ rpi_hole_dx/2, rpi_hole_dy/2]) circle(_M2r);
    translate(rpi_hole_c) translate([ rpi_hole_dx/2,-rpi_hole_dy/2]) circle(_M2r);
    translate(rpi_hole_c) translate([-rpi_hole_dx/2,-rpi_hole_dy/2]) circle(_M2r);
    translate(rpi_hole_c) translate([-rpi_hole_dx/2, rpi_hole_dy/2]) circle(_M2r);
    
    // opening access points in case we need them (heat sinks, USB cables, etc.)
    //
    translate(rpi_hole_c) rounded_rect(3*rpi_hole_dx/4, 3*rpi_hole_dy/4, _r);
    translate(access_left_c) rounded_rect(access_left_w,access_left_h, _r);
    translate(access_right_c) rounded_rect(access_right_w, access_right_h, _r);
    translate(access_top_c) rounded_rect(access_top_w, access_top_h, _r);
    translate(access_bottom_c) rounded_rect(access_bottom_w, access_bottom_h, _r);

    // screen m2 joining holes
    //
    translate(screen_hole_c) translate([ screen_hole_dx/2, screen_hole_dy/2]) circle(_M2r);
    translate(screen_hole_c) translate([ screen_hole_dx/2,-screen_hole_dy/2]) circle(_M2r);
    translate(screen_hole_c) translate([-screen_hole_dx/2,-screen_hole_dy/2]) circle(_M2r);
    translate(screen_hole_c) translate([-screen_hole_dx/2, screen_hole_dy/2]) circle(_M2r);

    // Joining for outer angle plate
    //
    translate([-hole_width/2, -hole_height/2]) circle(_M3r);
    translate([ hole_width/2, -hole_height/2]) circle(_M3r);
    translate([ hole_width/2,  hole_height/2]) circle(_M3r);
    translate([-hole_width/2,  hole_height/2]) circle(_M3r);

  }
}

//PopufareHousingInnerBackPlate();
