-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayout.py
executable file
·139 lines (106 loc) · 3.96 KB
/
layout.py
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
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env python3
import numpy as np
import sys
import utils
matrix_rows = 5
matrix_cols = 7
num_switches = matrix_rows * matrix_cols
thumb_cluster_switch_angle = 30.
switch_spacing = 19.5
mounting_hole_diameter = 3.5
split_offset = np.array([80., 0.])
def generate_switch_positions():
positions = np.ndarray((matrix_cols, matrix_rows, 2), dtype=float)
for x in range(matrix_cols):
positions[x, :, 0] = switch_spacing * x
for y in range(matrix_rows):
positions[:, y, 1] = -switch_spacing * y
positions[6, :4, 1] += -17.
positions[5, :4, 1] += -17.
positions[4, :4, 1] += -15.
positions[3, :4, 1] += -1.
positions[2, :4, 1] += 5.
positions[1, :4, 1] += 0.
positions[0, :4, 1] += -1.
positions[0, 4] = positions[0, 2] + np.array([-switch_spacing, 0])
positions[1:3, 4] += np.array([-switch_spacing / 2., -1.])
d = positions[0, 3] - (switch_spacing * np.array([1.2, 0.3]))
positions[3, 4] = d
positions[4, 4] = utils.rotate(
d + np.array([-switch_spacing, 0]), d, thumb_cluster_switch_angle
)
positions[5, 4] = utils.rotate(
d + np.array([0, -switch_spacing]), d, thumb_cluster_switch_angle
)
positions[6, 4] = utils.rotate(
d + np.array([-switch_spacing, -switch_spacing]), d, 30
)
return positions
def generate_switch_orientations():
orientations = np.zeros(shape=(matrix_cols, matrix_rows), dtype=float)
orientations[3:, 4] = thumb_cluster_switch_angle
return orientations
def generate_partial_board_outline():
switch_positions = generate_switch_positions()
return np.array(
[
switch_positions[6, 4],
switch_positions[6, 3],
switch_positions[6, 0],
switch_positions[2, 0],
]
)
def generate_board_outline():
switch_positions = generate_switch_positions()
return np.array(
[
switch_positions[0, 0] + np.array([-20., 0.]),
switch_positions[4, 4],
switch_positions[6, 4],
switch_positions[6, 3],
switch_positions[6, 0],
switch_positions[2, 0],
]
)
def generate_mounting_holes():
switch_positions = generate_switch_positions()
return np.array(
[
utils.midpoint(switch_positions[6, 0], switch_positions[6, 1]) +
np.array([10., 0.]),
utils.midpoint(switch_positions[6, 2], switch_positions[6, 3]) +
np.array([10., 0.]),
utils.midpoint(switch_positions[5, 0], switch_positions[4, 1]),
utils.midpoint(switch_positions[5, 2], switch_positions[4, 3]),
utils.midpoint(switch_positions[2, 0], switch_positions[3, 1]),
utils.midpoint(switch_positions[2, 2], switch_positions[3, 3]),
utils.midpoint(switch_positions[0, 0], switch_positions[1, 1]),
utils.midpoint(switch_positions[0, 2], switch_positions[1, 3]),
switch_positions[4, 0] + np.array([0., 15.]),
switch_positions[3, 3] + np.array([0., -26.]),
switch_positions[1, 0] + np.array([0., 12.]),
switch_positions[1, 4] + np.array([-10., -17.]),
switch_positions[0, 4] + np.array([-20., -10.]),
utils.midpoint(switch_positions[4, 4], switch_positions[5, 4]),
]
)
def generate_mcu_position():
switch_positions = generate_switch_positions()
return switch_positions[0, 0] + np.array([-22., -10.])
if __name__ == "__main__":
import json
display_mode = sys.argv[1]
var = sys.argv[2]
offset = np.array(json.loads(sys.argv[3]))
data = {
"board_outline": generate_board_outline,
"mounting_holes": generate_mounting_holes,
}[var]() + offset
if display_mode == "human":
print(f"{var}\n{data}")
elif display_mode == "freecad":
for point in data:
print(f"={point[0]}mm\t={point[1]}mm")
else:
print(f"Unknown display mode: {display_mode}")
sys.exit(1)