summaryrefslogtreecommitdiff
path: root/mech/pcb_case/shell.scad
blob: bb4c554ab580f5ce7dbceb992a168267e846dc3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
include <bolt.scad>
include <nut.scad>
include <panel.scad>

use <conversion.scad>
use <rounded_cube.scad>

module shell_base(pcb_dim, margins, t) {
	dim = dim_pcb_to_case(pcb_dim, margins, t);

	difference() {
		// full body
		rounded_cube(dim=dim, radius=t);

		// cut away upper half
		translate([0,0,dim[2]/2])
			cube([dim[0], dim[1], dim[2]/2]);

		// main PCB space
		translate([3*t, t, t])
			rounded_cube([dim[0]-6*t, dim[1]-2*t, dim[2]-2*t], t);

		// remove front and back
		translate([0, 2*t, 2*t])
			rounded_cube([dim[0], dim[1]-4*t, dim[2]-4*t], t);

		// panel holder
		for (x_off = [t-panel_dim_0_tol/2, dim[0]-2*t-panel_dim_0_tol/2]) {
			translate([x_off, t-panel_dim_0_tol/2, t-panel_dim_0_tol/2]) {
				rounded_cube(
					[
						t+panel_dim_0_tol,
						dim[1]-2*t+panel_dim_1_2_tol,
						dim[2]-2*t+panel_dim_1_2_tol
					],
					t
				);
			}
		}

		// bolt drillings
		for (x = [dim[0]/4, dim[0]-dim[0]/4]) {
			translate([x,0,dim[2]/2-1.5*bolt_ds])
				rotate([-90,0,0])
					cylinder(d=bolt_ds+bolt_ds_tol, h=1.1*t, $fn=30);
		}
	}
}

module shell_connector(pcb_dim, margins, t) {
	dim = dim_pcb_to_case(pcb_dim, margins, t);

	size_x = dim[0]-6*t;
	size_y = 2*nut_h;
	size_z = dim[2]/2+3*bolt_ds;

	difference () {
		// base body
		translate([3*t,dim[1]-t-size_y,0])
			cube([size_x,size_y,size_z]);

		// bolt holes
		for (x = [dim[0]/4, dim[0]-dim[0]/4]) {
			translate([x,dim[1]-t,dim[2]/2+1.5*bolt_ds])
				rotate([90,0,0])
					cylinder(d=bolt_ds+bolt_ds_tol, h=size_y, $fn=30);
		}

		// nut holes
		for (x = [dim[0]/4, dim[0]-dim[0]/4]) {
			translate([x,dim[1]-t-size_y,dim[2]/2+1.5*bolt_ds])
				rotate([-90,0,0])
					cylinder(d=nut_d+nut_d_tol, h=nut_h, $fn=30);
		}
	}

	echo(min_shell_bolt_length=t+size_y);
}

module pcb_case_shell(pcb_dim, drillings, margins, t) {
	difference () {
		union() {
			shell_base(pcb_dim, margins, t);
			shell_connector(pcb_dim, margins, t);
			for (drilling = drillings) {
				translate([
					2*t+margins[0][0]+drilling[0],
					t+2*nut_h+margins[1][0]+drilling[1],
					0
				]) cylinder(d=nut_d+2, h=t+margins[2][0], $fn=30);
			}
		}
		for (drilling = drillings) {
			translate([
				2*t+margins[0][0]+drilling[0],
				t+2*nut_h+margins[1][0]+drilling[1],
				0
			]) {
				cylinder(d=bolt_ds+bolt_ds_tol, h=t+margins[2][0], $fn=30);
				cylinder(d=nut_d+nut_d_tol, h=nut_h, $fn=30);
			}
		}
	}
}

module pcb_case_shell_bottom(pcb_dim, drillings, margins, t) {
	pcb_case_shell(pcb_dim, drillings, margins, t);
}

module pcb_case_shell_top(pcb_dim, margins, t) {
	dim = dim_pcb_to_case(pcb_dim, margins, t);

	translate([0, dim[1], dim[2]])
		rotate([180,0,0])
			pcb_case_shell(pcb_dim, [], margins, t);
}