Skip to content

Commit 08322ab

Browse files
committed
fix(KMKKeyboard)!: use __init__ to initialize the keyboard class
KMKKeyboard has used class attributes instead of instance attributes. That is fundamentally incorrect, but hasn't caused issues in situ, where there's only ever one keyboard instance and the VM is reset with each restart. It does however cause issues in unit tests, where erroneous internal states can bleed over from failed tests to normally passing tests.
1 parent b83c80c commit 08322ab

File tree

13 files changed

+255
-216
lines changed

13 files changed

+255
-216
lines changed

boards/a_dux/kb.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,19 @@
1414

1515

1616
class KMKKeyboard(_KMKKeyboard):
17-
data_pin = pins[4]
17+
def __init__(self):
18+
super().__init__()
1819

19-
# fmt: off
20-
coord_mapping = [
21-
0, 1, 2, 3, 4, 21, 20, 19, 18, 17,
22-
5, 6, 7, 8, 9, 26, 25, 24, 23, 22,
23-
10, 11, 12, 13, 14, 31, 30, 29, 28, 27,
24-
15, 16, 33, 32
25-
]
26-
# fmt: on
20+
self.data_pin = pins[4]
21+
22+
# fmt: off
23+
self.coord_mapping = [
24+
0, 1, 2, 3, 4, 21, 20, 19, 18, 17,
25+
5, 6, 7, 8, 9, 26, 25, 24, 23, 22,
26+
10, 11, 12, 13, 14, 31, 30, 29, 28, 27,
27+
15, 16, 33, 32
28+
]
29+
# fmt: on
2730

28-
def __init__(self):
2931
# create and register the scanner
3032
self.matrix = KeysScanner(_KEY_CFG_LEFT, value_when_pressed=False)

boards/anavi/anavi-arrows/arrows.py

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class AnaviArrows(KMKKeyboard):
1717
'''
1818

1919
def __init__(self):
20+
super().__init__()
2021
self.matrix = KeysScanner(
2122
[board.D1, board.D2, board.D3, board.D6],
2223
value_when_pressed=False,

boards/boardsource/Lulu/kb.py

+48-46
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,54 @@
88

99
class KMKKeyboard(_KMKKeyboard):
1010
def __init__(self):
11+
super().__init__()
12+
13+
self.col_pins = (
14+
board.GP02,
15+
board.GP03,
16+
board.GP04,
17+
board.GP05,
18+
board.GP06,
19+
board.GP07,
20+
)
21+
self.row_pins = (board.GP14, board.GP15, board.GP16, board.GP17, board.GP18)
22+
self.diode_orientation = DiodeOrientation.COLUMNS
23+
self.rx = board.RX
24+
self.tx = board.TX
25+
self.rgb_pixel_pin = board.GP29
26+
self.i2c = board.I2C
27+
self.data_pin = board.RX
28+
self.rgb_pixel_pin = board.GP29
29+
self.i2c = board.I2C
30+
self.SCL = board.SCL
31+
self.SDA = board.SDA
32+
self.encoder_a = board.GP08
33+
self.encoder_b = board.GP09
34+
# fmt:off
35+
self.led_key_pos = [
36+
11, 10, 9, 8, 7, 6, 41, 42, 43, 44, 45, 46,
37+
12, 13, 14, 15, 16, 17, 52, 51, 50, 49, 48, 47,
38+
23, 22, 21, 20, 19, 18, 53, 54, 55, 56, 57, 58,
39+
24, 25, 26, 27, 28, 29, 30, 65, 64, 63, 62, 61, 60, 59,
40+
34, 33, 32, 31, 66, 67, 68, 69,
41+
3, 4, 5, 40, 39, 38,
42+
2, 1, 0, 35, 36, 37,
43+
]
44+
# fmt:on
45+
self.brightness_limit = 0.5
46+
self.num_pixels = 70
47+
48+
# fmt:off
49+
self.coord_mapping = [
50+
0, 1, 2, 3, 4, 5, 37, 36, 35, 34, 33, 32,
51+
6, 7, 8, 9, 10, 11, 43, 42, 41, 40, 39, 38,
52+
12, 13, 14, 15, 16, 17, 49, 48, 47, 46, 45, 44,
53+
18, 19, 20, 21, 22, 23, 29, 61, 55, 54, 53, 52, 51, 50,
54+
25, 26, 27, 28, 60, 59, 58, 57,
55+
30, 31, 62, 63,
56+
]
57+
# fmt:on
58+
1159
# create and register the scanner
1260
self.matrix = [
1361
MatrixScanner(
@@ -26,49 +74,3 @@ def __init__(self):
2674
divisor=4,
2775
),
2876
]
29-
30-
col_pins = (
31-
board.GP02,
32-
board.GP03,
33-
board.GP04,
34-
board.GP05,
35-
board.GP06,
36-
board.GP07,
37-
)
38-
row_pins = (board.GP14, board.GP15, board.GP16, board.GP17, board.GP18)
39-
diode_orientation = DiodeOrientation.COLUMNS
40-
rx = board.RX
41-
tx = board.TX
42-
rgb_pixel_pin = board.GP29
43-
i2c = board.I2C
44-
data_pin = board.RX
45-
rgb_pixel_pin = board.GP29
46-
i2c = board.I2C
47-
SCL = board.SCL
48-
SDA = board.SDA
49-
encoder_a = board.GP08
50-
encoder_b = board.GP09
51-
# fmt:off
52-
led_key_pos = [
53-
11, 10, 9, 8, 7, 6, 41, 42, 43, 44, 45, 46,
54-
12, 13, 14, 15, 16, 17, 52, 51, 50, 49, 48, 47,
55-
23, 22, 21, 20, 19, 18, 53, 54, 55, 56, 57, 58,
56-
24, 25, 26, 27, 28, 29, 30, 65, 64, 63, 62, 61, 60, 59,
57-
34, 33, 32, 31, 66, 67, 68, 69,
58-
3, 4, 5, 40, 39, 38,
59-
2, 1, 0, 35, 36, 37,
60-
]
61-
# fmt:on
62-
brightness_limit = 0.5
63-
num_pixels = 70
64-
65-
# fmt:off
66-
coord_mapping = [
67-
0, 1, 2, 3, 4, 5, 37, 36, 35, 34, 33, 32,
68-
6, 7, 8, 9, 10, 11, 43, 42, 41, 40, 39, 38,
69-
12, 13, 14, 15, 16, 17, 49, 48, 47, 46, 45, 44,
70-
18, 19, 20, 21, 22, 23, 29, 61, 55, 54, 53, 52, 51, 50,
71-
25, 26, 27, 28, 60, 59, 58, 57,
72-
30, 31, 62, 63,
73-
]
74-
# fmt:on

boards/budgy/kb.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,19 @@
4040

4141
class KMKKeyboard(_KMKKeyboard):
4242
def __init__(self):
43+
super().__init__()
44+
4345
# create and register the scanner
4446
self.matrix = KeysScanner(
4547
pins=_KEY_CFG_RIGHT if isRight else _KEY_CFG_LEFT,
4648
value_when_pressed=False,
4749
)
4850

49-
# fmt: off
50-
coord_mapping = [
51-
0, 1, 2, 3, 4, 17, 18, 19, 20, 21,
52-
5, 6, 7, 8, 9, 22, 23, 24, 25, 26,
53-
10, 11, 12, 13, 14, 27, 28, 29, 30, 31,
54-
15, 16, 32, 33
55-
]
56-
# fmt: on
51+
# fmt: off
52+
self.coord_mapping = [
53+
0, 1, 2, 3, 4, 17, 18, 19, 20, 21,
54+
5, 6, 7, 8, 9, 22, 23, 24, 25, 26,
55+
10, 11, 12, 13, 14, 27, 28, 29, 30, 31,
56+
15, 16, 32, 33
57+
]
58+
# fmt: on

boards/draculad/kb.py

+43-36
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,49 @@
1111

1212
class KMKKeyboard(_KMKKeyboard):
1313
def __init__(self):
14+
super().__init__()
15+
16+
self.col_pins = (
17+
pins[avr['F4']],
18+
pins[avr['F5']],
19+
pins[avr['F6']],
20+
pins[avr['F7']],
21+
pins[avr['B1']],
22+
)
23+
self.row_pins = (
24+
pins[avr['D4']],
25+
pins[avr['C6']],
26+
pins[avr['D7']],
27+
pins[avr['E6']],
28+
)
29+
self.data_pin = pins[avr['D2']]
30+
self.rgb_pixel_pin = pins[avr['D3']]
31+
self.rgb_num_pixels = 20
32+
self.i2c = board.I2C
33+
self.SCL = pins[5]
34+
self.SDA = pins[4]
35+
self.pin_a1 = pins[avr['B2']]
36+
self.pin_a2 = pins[avr['B4']]
37+
self.pin_b1 = pins[avr['B6']]
38+
self.pin_b2 = pins[avr['B5']]
39+
# fmt: off
40+
self.led_key_pos = [
41+
5, 6, 7, 8, 9, 19, 18, 17, 16, 15,
42+
14, 13, 12, 11, 10, 0, 1, 2, 3, 4
43+
]
44+
# fmt: on
45+
self.brightness_limit = 1.0
46+
self.num_pixels = 20
47+
48+
# fmt: off
49+
self.coord_mapping = [
50+
0, 1, 2, 3, 4, 24, 23, 22, 21, 20,
51+
5, 6, 7, 8, 9, 29, 28, 27, 26, 25,
52+
10, 11, 12, 13, 14, 34, 33, 32, 31, 30,
53+
17, 18, 19, 39, 38, 37
54+
]
55+
# fmt: on
56+
1457
# create and register the scanner
1558
self.matrix = [
1659
MatrixScanner(
@@ -35,39 +78,3 @@ def __init__(self):
3578
# divisor=4,
3679
# )
3780
]
38-
39-
col_pins = (
40-
pins[avr['F4']],
41-
pins[avr['F5']],
42-
pins[avr['F6']],
43-
pins[avr['F7']],
44-
pins[avr['B1']],
45-
)
46-
row_pins = (
47-
pins[avr['D4']],
48-
pins[avr['C6']],
49-
pins[avr['D7']],
50-
pins[avr['E6']],
51-
)
52-
data_pin = pins[avr['D2']]
53-
rgb_pixel_pin = pins[avr['D3']]
54-
rgb_num_pixels = 20
55-
i2c = board.I2C
56-
SCL = pins[5]
57-
SDA = pins[4]
58-
pin_a1 = pins[avr['B2']]
59-
pin_a2 = pins[avr['B4']]
60-
pin_b1 = pins[avr['B6']]
61-
pin_b2 = pins[avr['B5']]
62-
led_key_pos = [5, 6, 7, 8, 9, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 0, 1, 2, 3, 4]
63-
brightness_limit = 1.0
64-
num_pixels = 20
65-
66-
# fmt: off
67-
coord_mapping = [
68-
0, 1, 2, 3, 4, 24, 23, 22, 21, 20,
69-
5, 6, 7, 8, 9, 29, 28, 27, 26, 25,
70-
10, 11, 12, 13, 14, 34, 33, 32, 31, 30,
71-
17, 18, 19, 39, 38, 37
72-
]
73-
# fmt: on

boards/ferris_sweep/kb.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@
1818

1919
class KMKKeyboard(_KMKKeyboard):
2020
def __init__(self):
21+
super().__init__()
22+
2123
# create and register the scanner
2224
self.matrix = KeysScanner(_KEY_CFG_LEFT, value_when_pressed=False)
2325

24-
# fmt: off
25-
coord_mapping = [
26-
0, 1, 2, 3, 4, 21, 20, 19, 18, 17,
27-
5, 6, 7, 8, 9, 26, 25, 24, 23, 22,
28-
10, 11, 12, 13, 14, 31, 30, 29, 28, 27,
29-
15, 16, 33, 32
30-
]
31-
# fmt: on
26+
# fmt: off
27+
self.coord_mapping = [
28+
0, 1, 2, 3, 4, 21, 20, 19, 18, 17,
29+
5, 6, 7, 8, 9, 26, 25, 24, 23, 22,
30+
10, 11, 12, 13, 14, 31, 30, 29, 28, 27,
31+
15, 16, 33, 32
32+
]
33+
# fmt: on

boards/isopad/kb.py

+2
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@
1414
# fmt: on
1515
class KMKKeyboard(_KMKeyboard):
1616
def __init__(self):
17+
super().__init__()
18+
1719
# create and register the scanner
1820
self.matrix = KeysScanner(_KEY_CFG, value_when_pressed=False)

boards/nullbitsco/tidbit/kb.py

+20-20
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,29 @@ class KMKKeyboard(_KMKKeyboard):
2525
landscape_layout=True to orient USB port top right rather than left (default)
2626
'''
2727

28-
# led = digitalio.DigitalInOut(board.D21)
29-
# led.direction = digitalio.Direction.OUTPUT
30-
# led.value = False
31-
row_pins = (
32-
pins[15],
33-
pins[9],
34-
pins[8],
35-
pins[7],
36-
pins[6],
37-
)
38-
col_pins = (
39-
pins[19],
40-
pins[18],
41-
pins[17],
42-
pins[16],
43-
)
44-
pixel_pin = pins[12]
45-
diode_orientation = DiodeOrientation.ROW2COL
46-
i2c = board.I2C # TODO ??
47-
4828
def __init__(self, active_encoders=[0], landscape_layout=False):
4929
super().__init__()
5030

31+
# led = digitalio.DigitalInOut(board.D21)
32+
# led.direction = digitalio.Direction.OUTPUT
33+
# led.value = False
34+
self.row_pins = (
35+
pins[15],
36+
pins[9],
37+
pins[8],
38+
pins[7],
39+
pins[6],
40+
)
41+
self.col_pins = (
42+
pins[19],
43+
pins[18],
44+
pins[17],
45+
pins[16],
46+
)
47+
self.pixel_pin = pins[12]
48+
self.diode_orientation = DiodeOrientation.ROW2COL
49+
self.i2c = board.I2C # TODO ??
50+
5151
if landscape_layout:
5252
self.coord_mapping = [
5353
row * len(self.col_pins) + col

boards/pimoroni/keybow/keybow.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ class Keybow(KMKKeyboard):
107107
Default keyboard config for the Keybow.
108108
'''
109109

110-
extensions = [rgb]
111-
112110
def __init__(self):
111+
super().__init__()
112+
113+
self.extensions = [rgb]
113114
self.matrix = KeysScanner(_KEY_CFG, value_when_pressed=False)

boards/pimoroni/keybow_2040/keybow_2040.py

+2
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,6 @@ class Keybow2040(KMKKeyboard):
4343
'''
4444

4545
def __init__(self):
46+
super().__init__()
47+
4648
self.matrix = KeysScanner(_KEY_CFG, value_when_pressed=False)

0 commit comments

Comments
 (0)