1include <BOSL/constants.scad>
  2use <BOSL/masks.scad>
  3use <fonts/Rubik-VariableFont_wght.ttf>
  4
  5// Start config
  6// Pi Board
  7pi_board_size = [51,21]; //mm
  8pi_board_screw_holes_center_from_board_edge_distance = [3.7/2/*3.7 is the difference between screen and pi pcb height 21-24.7 */+4.8,2]; //mm
  9pi_board_screw_holes_diameter = 2.1; //mm
 10pi_board_padding = 1; //mm
 11
 12// Screen
 13screen_pcb_size = [24.7,27,13.3]; //mm (+- 0.2) 13.3mm are pin headers.
 14screen_pcb_screw_holes_center_from_board_edge_distance = 2.1; //mm
 15screen_pcb_screw_holes_diameter=2.8; //mm
 16screen_pcb_screw_holes_spacing=[20.5,23]; //mm
 17active_screen_area = [24.7,16.9,3.5]; //mm (old: 13.86)
 18active_screen_area_offset_from_corner = [0,5.08]; //mm
 19
 20// Screws
 21m2_screw_head_size = [4,4,1];
 22
 23// Text Position
 24text_offset_from_corner = [5.5,3.7];
 25text_size = 4.2;
 26text_depth = 1; //mm
 27
 28
 29// Misc
 30walls_thickness = 2; //mm
 31rounding_radius=1.5; //mm
 32
 33resolution = 80;
 34// End config
 35
 36// Modules
 37module sector(radius, angles, fn = resolution) {
 38    r = radius / cos(180 / fn);
 39    step = -360 / fn;
 40
 41    points = concat([[0, 0]],
 42        [for(a = [angles[0] : step : angles[1] - 360]) 
 43            [r * cos(a), r * sin(a)]
 44        ],
 45        [[r * cos(angles[1]), r * sin(angles[1])]]
 46    );
 47
 48    difference() {
 49        circle(radius, $fn = fn);
 50        polygon(points);
 51    }
 52}
 53
 54module arc(radius, angles, width = 1, fn = resolution) {
 55    difference() {
 56        sector(radius + width, angles, fn);
 57        sector(radius, angles, fn);
 58    }
 59}
 60
 61// Modeling
 62difference(){
 63// Body
 64cube(size=[pi_board_size.x+2*pi_board_padding,screen_pcb_size.x+2*pi_board_padding,walls_thickness]);
 65   // Fillet Edge
 66    fillet_mask_z(l=walls_thickness, r=rounding_radius, align=V_UP, $fn=resolution);
 67    
 68   translate([pi_board_size.x+2*pi_board_padding,screen_pcb_size.x+2*pi_board_padding,0])
 69    fillet_mask_z(l=walls_thickness, r=rounding_radius, align=V_UP, $fn=resolution);
 70    
 71   translate([pi_board_size.x+2*pi_board_padding,0,0]) fillet_mask_z(l=walls_thickness, r=rounding_radius, align=V_UP, $fn=resolution);
 72    
 73   translate([0,screen_pcb_size.x+2*pi_board_padding,0]) fillet_mask_z(l=walls_thickness, r=rounding_radius, align=V_UP, $fn=resolution);
 74    // Screen
 75    translate([pi_board_size.x/2+screen_pcb_size.x/2+pi_board_padding,screen_pcb_size.x/2+pi_board_padding,0])
 76    translate([-screen_pcb_size.x,-active_screen_area.y/2,0])
 77    cube([screen_pcb_size.x,active_screen_area.y,walls_thickness]);
 78    // Screws + Heads
 79    translate([pi_board_screw_holes_center_from_board_edge_distance.y+pi_board_padding,pi_board_screw_holes_center_from_board_edge_distance.x+pi_board_padding,0]) cylinder(walls_thickness,pi_board_screw_holes_diameter/2,pi_board_screw_holes_diameter/2,$fn=resolution);
 80    
 81    translate([pi_board_screw_holes_center_from_board_edge_distance.y+pi_board_padding,pi_board_screw_holes_center_from_board_edge_distance.x+pi_board_padding,walls_thickness-m2_screw_head_size.z]) cylinder(m2_screw_head_size.z,m2_screw_head_size.x/2,m2_screw_head_size.x/2,$fn=resolution);
 82    
 83    translate([pi_board_screw_holes_center_from_board_edge_distance.y+pi_board_padding,screen_pcb_size.x-pi_board_screw_holes_center_from_board_edge_distance.x+pi_board_padding,0]) cylinder(walls_thickness,pi_board_screw_holes_diameter/2,pi_board_screw_holes_diameter/2,$fn=resolution);
 84    
 85    translate([pi_board_screw_holes_center_from_board_edge_distance.y+pi_board_padding,screen_pcb_size.x-pi_board_screw_holes_center_from_board_edge_distance.x+pi_board_padding,walls_thickness-m2_screw_head_size.z]) cylinder(m2_screw_head_size.z,m2_screw_head_size.x/2,m2_screw_head_size.x/2,$fn=resolution);
 86    
 87    translate([pi_board_size.x-pi_board_screw_holes_center_from_board_edge_distance.y+pi_board_padding,pi_board_screw_holes_center_from_board_edge_distance.x+pi_board_padding,0]) cylinder(walls_thickness,pi_board_screw_holes_diameter/2,pi_board_screw_holes_diameter/2,$fn=resolution);
 88    
 89    translate([pi_board_size.x-pi_board_screw_holes_center_from_board_edge_distance.y+pi_board_padding,pi_board_screw_holes_center_from_board_edge_distance.x+pi_board_padding,walls_thickness-m2_screw_head_size.z]) cylinder(m2_screw_head_size.z,m2_screw_head_size.x/2,m2_screw_head_size.x/2,$fn=resolution);
 90    
 91    translate([pi_board_size.x-pi_board_screw_holes_center_from_board_edge_distance.y+pi_board_padding,screen_pcb_size.x-pi_board_screw_holes_center_from_board_edge_distance.x+pi_board_padding,0]) cylinder(walls_thickness,pi_board_screw_holes_diameter/2,pi_board_screw_holes_diameter/2,$fn=resolution);
 92    
 93    translate([pi_board_size.x-pi_board_screw_holes_center_from_board_edge_distance.y+pi_board_padding,screen_pcb_size.x-pi_board_screw_holes_center_from_board_edge_distance.x+pi_board_padding,walls_thickness-m2_screw_head_size.z]) cylinder(m2_screw_head_size.z,m2_screw_head_size.x/2,m2_screw_head_size.x/2,$fn=resolution);
 94   }
 95   
 96   translate([text_offset_from_corner.x+text_size,text_offset_from_corner.y,walls_thickness]) rotate ([0,0,90]) linear_extrude(height = text_depth) { text("pTuna",font = "Rubik-VariableFont_wght:style=Bold",size = text_size);
 97   }
 98   relative_sub_text_size = text_size*0.5;
 99   translate([text_offset_from_corner.x+text_size+relative_sub_text_size+1,text_offset_from_corner.y+5,walls_thickness]) rotate ([0,0,90]) linear_extrude(height = text_depth) { text("by OnTake",font = "Rubik-VariableFont_wght:style=Bold",size = relative_sub_text_size);
100   }