Prepare things for the event loop, also abstract gross stuff from end users
This commit is contained in:
0
kmk/common/abstract/__init__.py
Normal file
0
kmk/common/abstract/__init__.py
Normal file
25
kmk/common/abstract/matrix_scanner.py
Normal file
25
kmk/common/abstract/matrix_scanner.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from kmk.common.consts import DiodeOrientation
|
||||
|
||||
|
||||
class AbstractMatrixScanner():
|
||||
def __init__(self, cols, rows, diode_orientation=DiodeOrientation.COLUMNS):
|
||||
raise NotImplementedError('Abstract implementation')
|
||||
|
||||
def _normalize_matrix(self, matrix):
|
||||
'''
|
||||
We always want to internally look at a keyboard as a list of rows,
|
||||
where a "row" is a list of keycodes (columns).
|
||||
|
||||
This will convert DiodeOrientation.COLUMNS matrix scans into a
|
||||
ROWS scan, so we never have to think about these things again.
|
||||
'''
|
||||
if self.diode_orientation == DiodeOrientation.ROWS:
|
||||
return matrix
|
||||
|
||||
return [
|
||||
[col[col_entry] for col in matrix]
|
||||
for col_entry in range(max(len(col) for col in matrix))
|
||||
]
|
||||
|
||||
def raw_scan(self):
|
||||
raise NotImplementedError('Abstract implementation')
|
@@ -10,9 +10,9 @@ class Keymap:
|
||||
for ridx, row in enumerate(matrix):
|
||||
for cidx, col in enumerate(row):
|
||||
if col != self.state[ridx][cidx]:
|
||||
print('{}: {}'.format(
|
||||
yield '{}: {}'.format(
|
||||
'KEYDOWN' if col else 'KEYUP',
|
||||
self.map[ridx][cidx],
|
||||
))
|
||||
)
|
||||
|
||||
self.state = matrix
|
||||
|
Reference in New Issue
Block a user