-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgen_configs.py
128 lines (109 loc) · 3.81 KB
/
gen_configs.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
import math
import hashlib
import json
from enum import IntEnum
from typing import Optional, Tuple
class Shape(IntEnum):
LEAN = 0
HULL = 1
class Config:
nRows: int
nCols: int
thumbKeys: Optional[list]
columnSpacing: float
rowSpacing: float
staggering: Optional[list]
switchHoleSize: float
angle: float # degrees
hOffset: float
plateThickness: float
shape: Shape
screwHoleDiameter: float
spacerThickness: float
split: bool
mcu_footprint = Optional[Tuple[float, float]]
def __init__(self, nc, nr, cs=19, rs=19, switchHoleSize=13.97,
angle=10, hOffset=None, plateThickness=1.5,
spacerThickness=8.0, screwHoleDiameter=3.0,
shape=Shape.LEAN, split=False,
staggering=[0, 5, 11, 6, 3],
thumbKeys=None,
cnc=False,
notched=True,
mcu_footprint=(30, 60)
):
self.nCols = nc
self.nRows = nr
self.angle = angle
self.columnSpacing = cs
self.rowSpacing = rs
self.switchHoleSize = switchHoleSize
if not hOffset:
self.hOffset = (self.nRows * (self.rowSpacing + self.switchHoleSize) /
2) * math.sin(math.radians(self.angle)) * 2
if self.hOffset < 45:
self.hOffset = 45
else:
self.hOffset = hOffset
self.plateThickness = plateThickness
self.spacerThickness = spacerThickness
self.screwHoleDiameter = screwHoleDiameter
self.shape = shape
self.split = split
self.staggering = staggering
self.thumbKeys = thumbKeys
self.cnc = cnc
self.notched = notched
self.update_name()
self.mcu_footprint = mcu_footprint
def update_name(self):
name = 'atreus_{}{}_{}'.format(
2 * (self.nCols * self.nRows +
(len(self.thumbKeys) if self.thumbKeys else 0)),
('h' if self.shape == Shape.HULL else 'l') +
('s' if self.split else ''),
'cnc' if self.cnc else 'print')
name2 = str(self.angle) + str(self.staggering)
m = hashlib.sha1()
m.update(name2.encode('utf-8'))
self.name = name + "_" + m.hexdigest()[:7]
configs = [
# some minimal configs :)
Config(3, 3, angle=5),
Config(4, 4, angle=5),
# the original
Config(5, 4),
Config(5, 5, hOffset=70, thumbKeys=[
(-1, 1), (-1, 0), (-2, 1), (-2, 0)],
staggering=[-12, -3, 0, 5, 11, 6, 3]),
Config(5, 6, hOffset=65, thumbKeys=[
(-1, 1), (-1, 0), (-2, 1), (-2, 0), (0, -1)],
staggering=[10, 15, 0, 5, 11, 6, 3]),
# my favourite configs
Config(6, 3, hOffset=50, angle=18.5,
staggering=[8, 0, 5, 11, 6, 3, 2],
thumbKeys=[(-1, -1), (0, -1), (-1, -2), (1, -1)]),
Config(6, 4, angle=18.5,
staggering=[0, 5, 11, 6, 3, 2]),
Config(6, 4, angle=18.5,
staggering=[0, 0, 5, 11, 6, 3, 2],
thumbKeys=[(-1, 0), (1, -1)]),
Config(6, 4, hOffset=55, angle=15.0,
staggering=[-12, 0, 5, 11, 6, 3, 2],
thumbKeys=[(-1, 0), (-1, 1)]),
# # some bigger edge case :)
Config(10, 10, angle=18.5,
staggering=[0, 0, 5, 11, 6, 3, 2],
thumbKeys=[(0, -1), (-1, 0)])
]
if __name__ == "__main__":
for config in configs:
for cnc in [False, True]:
for split in [False, True]:
for shape in [Shape.LEAN]:
config.cnc = cnc
config.split = split
config.shape = shape
config.update_name()
with open("configs/" + config.name + ".json", 'w', encoding='utf-8') as f:
json.dump(config.__dict__, f)