// 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.
//

$fs = 1.0/64.0;

// ...
//

// 1/8 inch sheet thickness
//
//_MATERIAL_THICKNESS = 3.175

// 1/4 inch sheet thickness
//
_MATERIAL_THICKNESS = 6.35;

_M2 = 2.0;
_M2r = 2.0/2;

_M3 = 3.0;
_M3r = 3.0/2;

_M4 = 4.0;
_M4r = 4.0/2;

_M5 = 5.0;
_M5r = 5.0/2;

// in mm
//
POPUFARE_HOUSING_WIDTH = 190;
POPUFARE_HOUSING_DEPTH = 165;
POPUFARE_HOUSING_HEIGHT = 135;

POPUFARE_SCREEN_WIDTH_CAPACITIVE = 122;
POPUFARE_SCREEN_HEIGHT_CAPACITIVE = 78;

POPUFARE_SCREEN_WIDTH_RESISTIVE = 119;
POPUFARE_SCREEN_HEIGHT_RESISTIVE = 71;


POPUFARE_GLAND_DIAMETER = 37;
POPUFARE_SCREEN_OUTER_WIDTH = 122;

//POPUFARE_SCREEN_WIDTH = 118 + 1;
//POPUFARE_SCREEN_HEIGHT = 70 + 1;

POPUFARE_SCREEN_OUTER_HEIGHT = 78;

POPUFARE_FRONT_HEIGHT = 60;

POPUFARE_FIXTURE_DX = 65;
POPUFARE_FIXTURE_DY = 65;
POPUFARE_FIXTURE_SCREW_D = 7.5;

// bracket
//

POPUFARE_BRACKET_CX = 20;
POPUFARE_BRACKET_D = 5;

POPUFARE_BRACKET_DS = 100;
POPUFARE_BRACKET_DE = 40;
POPUFARE_BRACKET_DE_SHORT = 20;

// 117 - 111 = 6
// 111 + 3 = 114
//
// 87 - 81 = 6
// 81 + 3 = 84

// inner plates
//
POPUFARE_INNER_PLATE_WIDTH = 90;
POPUFARE_INNER_PLATE_HEIGHT = 70;

//POPUFARE_INNER_PLATE_HOLE_WIDTH = POPUFARE_SCREEN_OUTER_WIDTH + 0;
//POPUFARE_INNER_PLATE_HOLE_HEIGHT = POPUFARE_SCREEN_OUTER_HEIGHT + 20;

POPUFARE_INNER_PLATE_HOLE_WIDTH = 114;
POPUFARE_INNER_PLATE_HOLE_HEIGHT = 84;


// hinge
//
POPUFARE_HINGE_TOP_HOLE_WIDTH = 32;
POPUFARE_HINGE_TOP_HOLE_DE = 36;

POPUFARE_HINGE_BACK_HOLE_WIDTH = 45;
POPUFARE_HINGE_BACK_HOLE_DE = 28;

POPUFARE_HINGE_D = _M4;

// Raspberry Pi measurements
//
_RASPBERRY_PI_B_HOLE_DX = 58;
_RASPBERRY_PI_B_HOLE_DY = 48;

_SCREEN_HOLE_DX = 93;
_SCREEN_HOLE_DY = 69;


// Center for raspberry pi from screen
// that sits on top of it.
//
_SCREEN_OUTER_CENTER = [ POPUFARE_SCREEN_OUTER_WIDTH/2, POPUFARE_SCREEN_OUTER_HEIGHT/2 ];

// offset of left screen m2 screws
// as seen from the back, front ribbon down
//
_SCREEN_LL_M2_C = [ 5,5 ];
_SCREEN_UL_M2_C = [ 5, POPUFARE_SCREEN_OUTER_HEIGHT - 4 ];

_SCREEN_CX = _SCREEN_HOLE_DX/2 + _SCREEN_LL_M2_C[0] - _SCREEN_OUTER_CENTER[0];
_SCREEN_CY = _SCREEN_HOLE_DY/2 + _SCREEN_LL_M2_C[1] - _SCREEN_OUTER_CENTER[1];

_RASPBERRY_PI_B_CX = (_SCREEN_HOLE_DX - _RASPBERRY_PI_B_HOLE_DX/2) + _SCREEN_LL_M2_C[0] - _SCREEN_OUTER_CENTER[0];
_RASPBERRY_PI_B_CY = (_SCREEN_HOLE_DY - _RASPBERRY_PI_B_HOLE_DY/2) + _SCREEN_LL_M2_C[1] - _SCREEN_OUTER_CENTER[1];


// Bounding box width of rouned rect is w and h,
// so this function compensates for the rounded corner
// radius.
//
// w - width or rectangle
// h - height of rectangle
// r - corner radius
//
// rounded rectangle has center of mass (center) at (0,0)
//
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);
    translate([ x2, y2]) circle(r);
    translate([ x2,-y2]) circle(r);
    translate([-x2,-y2]) circle(r);
  }
}
