summaryrefslogtreecommitdiffstats
path: root/case/keyboard.scad
blob: e9dbde0ca1435e7e8de863cf89f649ef01a8b77c (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
117
118
119
120
121
122
123
124
125
126
127
128
keyboard_switch_width      = 19.0500;
keyboard_switch_length     = 19.0500;
keyboard_switch_leg_length =  3.30;
keyboard_switch_height     = 11.10;
keyboard_switch_sizes      = [
    [0.5,  1.0,  1.0,  1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
    [1.0,  1.0,  1.0,  1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.5],
    [1.25, 1.0,  1.0,  1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.25],
    [1.75, 1.0,  1.0,  1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.75],
    [1.0,  1.25, 1.25, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
];

keyboard_pcb_width  = 13.5 * keyboard_switch_width;
keyboard_pcb_length =  5.0 * keyboard_switch_length;
keyboard_pcb_height =  1.600;

keyboard_pcb_screw_holes = [
    [  4.7625, 85.7250],
    [ 66.6750, 85.7250],
    [161.9250, 85.7250],
    [238.1250, 85.7250],
    [ 61.9125, 47.6250],
    [138.1125, 47.6250],
    [214.3125, 47.6250],
    [ 20.2406,  9.5250],
    [123.8250,  9.5250],
    [238.1250,  9.5250]
];

module keyboard_switch() {
    width  = 14.00;
    length = 14.92;
    height = 11.10;

    cube([width, length, height], true);
}

module keyboard_deck(wall_width) {
    key_switch_footprint = [15.25, 15.25];

    eps = 0.01;

    function add(v)            = [for(p=v) 1]*v;
    function slice(v, x, y)    = [for (i=[x:y]) v[i]];
    function addrange(v, x, y) = add(slice(v, x, y));

    module screw_holes() {
        pcb_screw_diameter = 2.5;

        for (screw_hole = keyboard_pcb_screw_holes) {
            translate([screw_hole[0], screw_hole[1], -eps])
            cylinder(h=wall_width+2*eps, d=pcb_screw_diameter);
        }
    }

    module key_switch_plate(key_switch_size) {
        plate_width  = keyboard_switch_width * key_switch_size;
        plate_length = keyboard_switch_length;

        if (key_switch_size <= 0.5) {
            cube([keyboard_switch_width  * key_switch_size,
                    keyboard_switch_length,
                    wall_width], false);
        } else {
            hole_width  = key_switch_footprint[0];
            hole_length = key_switch_footprint[1];

            hole_x = plate_width  / 2 - hole_width  / 2;
            hole_y = plate_length / 2 - hole_length / 2;

            difference() {
                cube([plate_width + eps, plate_length + eps, wall_width], false);

                translate([hole_x, hole_y, -eps])
                cube([hole_width, hole_length, wall_width + 2*eps], false);
            }
        }
    }

    module walls() {
        wall_height = keyboard_switch_height - wall_width;

        /* Upper */
        translate([-wall_width, keyboard_pcb_length, 0])
        cube([keyboard_pcb_width + 2 * wall_width, wall_width, wall_height + eps], false);

        /* Right */
        translate([keyboard_pcb_width, -wall_width, 0])
        cube([wall_width, keyboard_pcb_length + 2 * wall_width, wall_height + eps], false);

        /* Lower */
        translate([-wall_width, -wall_width, 0])
        cube([keyboard_pcb_width + 2 * wall_width, wall_width, wall_height + eps], false);

        /* Left */
        translate([-wall_width, -wall_width, 0])
        cube([wall_width, keyboard_pcb_length + 2 * wall_width, wall_height + eps], false);
    }

    module body() {
        rows = len(keyboard_switch_sizes);

        for (i = [0: rows-1]) {
            y = keyboard_switch_length * (rows - 1 - i);

            key_switch_row = keyboard_switch_sizes[i];
            cols           = len(key_switch_row);

            for (j = [0: cols-1]) {
                x = keyboard_switch_width * ((j == 0)?
                    0:
                    addrange(key_switch_row, 0, j-1));

                key_switch_size = key_switch_row[j];

                translate([x, y, 0])
                key_switch_plate(key_switch_size);
            }
        }
    }

    difference() {
        body();
        screw_holes();
    }

    walls();
}