Skip to content

Commit

Permalink
fix(KMKKeyboard)!: use __init__ to initialize the keyboard class (#1077)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
xs5871 authored Feb 3, 2025
1 parent c551dbf commit e1f3642
Show file tree
Hide file tree
Showing 13 changed files with 255 additions and 216 deletions.
22 changes: 12 additions & 10 deletions boards/a_dux/kb.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@


class KMKKeyboard(_KMKKeyboard):
data_pin = pins[4]
def __init__(self):
super().__init__()

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

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

def __init__(self):
# create and register the scanner
self.matrix = KeysScanner(_KEY_CFG_LEFT, value_when_pressed=False)
1 change: 1 addition & 0 deletions boards/anavi/anavi-arrows/arrows.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class AnaviArrows(KMKKeyboard):
'''

def __init__(self):
super().__init__()
self.matrix = KeysScanner(
[board.D1, board.D2, board.D3, board.D6],
value_when_pressed=False,
Expand Down
94 changes: 48 additions & 46 deletions boards/boardsource/Lulu/kb.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,54 @@

class KMKKeyboard(_KMKKeyboard):
def __init__(self):
super().__init__()

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

# fmt:off
self.coord_mapping = [
0, 1, 2, 3, 4, 5, 37, 36, 35, 34, 33, 32,
6, 7, 8, 9, 10, 11, 43, 42, 41, 40, 39, 38,
12, 13, 14, 15, 16, 17, 49, 48, 47, 46, 45, 44,
18, 19, 20, 21, 22, 23, 29, 61, 55, 54, 53, 52, 51, 50,
25, 26, 27, 28, 60, 59, 58, 57,
30, 31, 62, 63,
]
# fmt:on

# create and register the scanner
self.matrix = [
MatrixScanner(
Expand All @@ -26,49 +74,3 @@ def __init__(self):
divisor=4,
),
]

col_pins = (
board.GP02,
board.GP03,
board.GP04,
board.GP05,
board.GP06,
board.GP07,
)
row_pins = (board.GP14, board.GP15, board.GP16, board.GP17, board.GP18)
diode_orientation = DiodeOrientation.COLUMNS
rx = board.RX
tx = board.TX
rgb_pixel_pin = board.GP29
i2c = board.I2C
data_pin = board.RX
rgb_pixel_pin = board.GP29
i2c = board.I2C
SCL = board.SCL
SDA = board.SDA
encoder_a = board.GP08
encoder_b = board.GP09
# fmt:off
led_key_pos = [
11, 10, 9, 8, 7, 6, 41, 42, 43, 44, 45, 46,
12, 13, 14, 15, 16, 17, 52, 51, 50, 49, 48, 47,
23, 22, 21, 20, 19, 18, 53, 54, 55, 56, 57, 58,
24, 25, 26, 27, 28, 29, 30, 65, 64, 63, 62, 61, 60, 59,
34, 33, 32, 31, 66, 67, 68, 69,
3, 4, 5, 40, 39, 38,
2, 1, 0, 35, 36, 37,
]
# fmt:on
brightness_limit = 0.5
num_pixels = 70

# fmt:off
coord_mapping = [
0, 1, 2, 3, 4, 5, 37, 36, 35, 34, 33, 32,
6, 7, 8, 9, 10, 11, 43, 42, 41, 40, 39, 38,
12, 13, 14, 15, 16, 17, 49, 48, 47, 46, 45, 44,
18, 19, 20, 21, 22, 23, 29, 61, 55, 54, 53, 52, 51, 50,
25, 26, 27, 28, 60, 59, 58, 57,
30, 31, 62, 63,
]
# fmt:on
18 changes: 10 additions & 8 deletions boards/budgy/kb.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,19 @@

class KMKKeyboard(_KMKKeyboard):
def __init__(self):
super().__init__()

# create and register the scanner
self.matrix = KeysScanner(
pins=_KEY_CFG_RIGHT if isRight else _KEY_CFG_LEFT,
value_when_pressed=False,
)

# fmt: off
coord_mapping = [
0, 1, 2, 3, 4, 17, 18, 19, 20, 21,
5, 6, 7, 8, 9, 22, 23, 24, 25, 26,
10, 11, 12, 13, 14, 27, 28, 29, 30, 31,
15, 16, 32, 33
]
# fmt: on
# fmt: off
self.coord_mapping = [
0, 1, 2, 3, 4, 17, 18, 19, 20, 21,
5, 6, 7, 8, 9, 22, 23, 24, 25, 26,
10, 11, 12, 13, 14, 27, 28, 29, 30, 31,
15, 16, 32, 33
]
# fmt: on
79 changes: 43 additions & 36 deletions boards/draculad/kb.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,49 @@

class KMKKeyboard(_KMKKeyboard):
def __init__(self):
super().__init__()

self.col_pins = (
pins[avr['F4']],
pins[avr['F5']],
pins[avr['F6']],
pins[avr['F7']],
pins[avr['B1']],
)
self.row_pins = (
pins[avr['D4']],
pins[avr['C6']],
pins[avr['D7']],
pins[avr['E6']],
)
self.data_pin = pins[avr['D2']]
self.rgb_pixel_pin = pins[avr['D3']]
self.rgb_num_pixels = 20
self.i2c = board.I2C
self.SCL = pins[5]
self.SDA = pins[4]
self.pin_a1 = pins[avr['B2']]
self.pin_a2 = pins[avr['B4']]
self.pin_b1 = pins[avr['B6']]
self.pin_b2 = pins[avr['B5']]
# fmt: off
self.led_key_pos = [
5, 6, 7, 8, 9, 19, 18, 17, 16, 15,
14, 13, 12, 11, 10, 0, 1, 2, 3, 4
]
# fmt: on
self.brightness_limit = 1.0
self.num_pixels = 20

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

# create and register the scanner
self.matrix = [
MatrixScanner(
Expand All @@ -35,39 +78,3 @@ def __init__(self):
# divisor=4,
# )
]

col_pins = (
pins[avr['F4']],
pins[avr['F5']],
pins[avr['F6']],
pins[avr['F7']],
pins[avr['B1']],
)
row_pins = (
pins[avr['D4']],
pins[avr['C6']],
pins[avr['D7']],
pins[avr['E6']],
)
data_pin = pins[avr['D2']]
rgb_pixel_pin = pins[avr['D3']]
rgb_num_pixels = 20
i2c = board.I2C
SCL = pins[5]
SDA = pins[4]
pin_a1 = pins[avr['B2']]
pin_a2 = pins[avr['B4']]
pin_b1 = pins[avr['B6']]
pin_b2 = pins[avr['B5']]
led_key_pos = [5, 6, 7, 8, 9, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 0, 1, 2, 3, 4]
brightness_limit = 1.0
num_pixels = 20

# fmt: off
coord_mapping = [
0, 1, 2, 3, 4, 24, 23, 22, 21, 20,
5, 6, 7, 8, 9, 29, 28, 27, 26, 25,
10, 11, 12, 13, 14, 34, 33, 32, 31, 30,
17, 18, 19, 39, 38, 37
]
# fmt: on
18 changes: 10 additions & 8 deletions boards/ferris_sweep/kb.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@

class KMKKeyboard(_KMKKeyboard):
def __init__(self):
super().__init__()

# create and register the scanner
self.matrix = KeysScanner(_KEY_CFG_LEFT, value_when_pressed=False)

# fmt: off
coord_mapping = [
0, 1, 2, 3, 4, 21, 20, 19, 18, 17,
5, 6, 7, 8, 9, 26, 25, 24, 23, 22,
10, 11, 12, 13, 14, 31, 30, 29, 28, 27,
15, 16, 33, 32
]
# fmt: on
# fmt: off
self.coord_mapping = [
0, 1, 2, 3, 4, 21, 20, 19, 18, 17,
5, 6, 7, 8, 9, 26, 25, 24, 23, 22,
10, 11, 12, 13, 14, 31, 30, 29, 28, 27,
15, 16, 33, 32
]
# fmt: on
2 changes: 2 additions & 0 deletions boards/isopad/kb.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@
# fmt: on
class KMKKeyboard(_KMKeyboard):
def __init__(self):
super().__init__()

# create and register the scanner
self.matrix = KeysScanner(_KEY_CFG, value_when_pressed=False)
40 changes: 20 additions & 20 deletions boards/nullbitsco/tidbit/kb.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,29 @@ class KMKKeyboard(_KMKKeyboard):
landscape_layout=True to orient USB port top right rather than left (default)
'''

# led = digitalio.DigitalInOut(board.D21)
# led.direction = digitalio.Direction.OUTPUT
# led.value = False
row_pins = (
pins[15],
pins[9],
pins[8],
pins[7],
pins[6],
)
col_pins = (
pins[19],
pins[18],
pins[17],
pins[16],
)
pixel_pin = pins[12]
diode_orientation = DiodeOrientation.ROW2COL
i2c = board.I2C # TODO ??

def __init__(self, active_encoders=[0], landscape_layout=False):
super().__init__()

# led = digitalio.DigitalInOut(board.D21)
# led.direction = digitalio.Direction.OUTPUT
# led.value = False
self.row_pins = (
pins[15],
pins[9],
pins[8],
pins[7],
pins[6],
)
self.col_pins = (
pins[19],
pins[18],
pins[17],
pins[16],
)
self.pixel_pin = pins[12]
self.diode_orientation = DiodeOrientation.ROW2COL
self.i2c = board.I2C # TODO ??

if landscape_layout:
self.coord_mapping = [
row * len(self.col_pins) + col
Expand Down
5 changes: 3 additions & 2 deletions boards/pimoroni/keybow/keybow.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ class Keybow(KMKKeyboard):
Default keyboard config for the Keybow.
'''

extensions = [rgb]

def __init__(self):
super().__init__()

self.extensions = [rgb]
self.matrix = KeysScanner(_KEY_CFG, value_when_pressed=False)
2 changes: 2 additions & 0 deletions boards/pimoroni/keybow_2040/keybow_2040.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ class Keybow2040(KMKKeyboard):
'''

def __init__(self):
super().__init__()

self.matrix = KeysScanner(_KEY_CFG, value_when_pressed=False)
Loading

0 comments on commit e1f3642

Please sign in to comment.