Prepare things for the event loop, also abstract gross stuff from end users

This commit is contained in:
Josh Klar
2018-09-03 03:22:11 -07:00
parent 1df2012c7a
commit d5de2601d9
9 changed files with 72 additions and 35 deletions

View File

@@ -1,9 +1,10 @@
import digitalio
from kmk.common.abstract.matrix_scanner import AbstractMatrixScanner
from kmk.common.consts import DiodeOrientation
class MatrixScanner:
class MatrixScanner(AbstractMatrixScanner):
def __init__(self, cols, rows, diode_orientation=DiodeOrientation.COLUMNS):
# A pin cannot be both a row and column, detect this by combining the
# two tuples into a set and validating that the length did not drop
@@ -35,20 +36,7 @@ class MatrixScanner:
pin.switch_to_input(pull=digitalio.Pull.DOWN)
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))
]
return super()._normalize_matrix(matrix)
def raw_scan(self):
matrix = []

View File

@@ -1,7 +1,8 @@
import sys
import time
import board
import digitalio
import time
import sys
def feather_signal_error_with_led_flash(rate=0.5):