implement support for multiple scanners at once

fixup
This commit is contained in:
xs5871 2022-04-16 20:04:42 +00:00 committed by Kyle Brown
parent c7490087b6
commit 7ff77b97bb
5 changed files with 31 additions and 17 deletions

View File

@ -286,7 +286,10 @@ class KMKKeyboard:
return
if not self.coord_mapping:
self.coord_mapping = self.matrix.coord_mapping
cm = []
for m in self.matrix:
cm.extend(m.coord_mapping)
self.coord_mapping = tuple(cm)
def _init_hid(self):
if self.hid_type == HIDModes.NOOP:
@ -313,6 +316,15 @@ class KMKKeyboard:
if self.debug_enabled:
print('Matrix scanner already set, not overwriting.')
try:
self.matrix = tuple(iter(self.matrix))
offset = 0
for matrix in self.matrix:
matrix.offset = offset
offset += matrix.key_count
except TypeError:
self.matrix = (self.matrix,)
return self
def before_matrix_scan(self):
@ -442,7 +454,11 @@ class KMKKeyboard:
self.before_matrix_scan()
self.matrix_update = self.sandbox.matrix_update = self.matrix.scan_for_changes()
for matrix in self.matrix:
update = matrix.scan_for_changes()
if update:
self.matrix_update = update
break
self.sandbox.secondary_matrix_update = self.secondary_matrix_update
self.after_matrix_scan()

View File

@ -9,7 +9,6 @@ from storage import getmount
from kmk.hid import HIDModes
from kmk.kmktime import check_deadline
from kmk.modules import Module
from kmk.scanners import intify_coordinate
class SplitSide:
@ -123,7 +122,7 @@ class Split(Module):
keyboard._hid_send_enabled = False
if self.split_offset is None:
self.split_offset = len(keyboard.col_pins) * len(keyboard.row_pins)
self.split_offset = keyboard.matrix[-1].coord_mapping[-1] + 1
if self.split_type == SplitType.UART and self.data_pin is not None:
if self._is_target or not self.uart_flip:
@ -143,7 +142,7 @@ class Split(Module):
# Attempt to sanely guess a coord_mapping if one is not provided.
if not keyboard.coord_mapping:
keyboard.coord_mapping = []
cm = []
rows_to_calc = len(keyboard.row_pins)
cols_to_calc = len(keyboard.col_pins)
@ -155,13 +154,11 @@ class Split(Module):
for ridx in range(rows_to_calc):
for cidx in range(cols_to_calc):
keyboard.coord_mapping.append(
intify_coordinate(ridx, cidx, cols_to_calc)
)
cm.append(cols_to_calc * ridx + cidx)
for cidx in cols_rhs:
keyboard.coord_mapping.append(
intify_coordinate(rows_to_calc + ridx, cidx, cols_to_calc)
)
cm.append(cols_to_calc * (rows_to_calc + ridx) + cidx)
keyboard.coord_mapping = tuple(cm)
if self.split_side == SplitSide.RIGHT:
keyboard.matrix.offset = self.split_offset

View File

@ -22,7 +22,12 @@ class Scanner:
Base class for scanners.
'''
coord_mapping = None
# for split keyboards, the offset value will be assigned in Split module
offset = 0
@property
def coord_mapping(self):
return tuple(range(self.offset, self.offset + self.key_count))
@property
def key_count(self):
@ -34,4 +39,4 @@ class Scanner:
The key report is a byte array with contents [row, col, True if pressed else False]
'''
pass
raise NotImplementedError

View File

@ -78,7 +78,6 @@ class MatrixScanner(Scanner):
self.rollover_cols_every_rows = self.len_rows
self._key_count = self.len_cols * self.len_rows
self.coord_mapping = tuple(range(self.key_count))
self.state = bytearray(self.key_count)
@property

View File

@ -12,9 +12,6 @@ class KeypadScanner(Scanner):
'''
def __init__(self):
# for split keyboards, the offset value will be assigned in Split module
self.offset = 0
self.coord_mapping = tuple(range(self.key_count))
self.curr_event = keypad.Event()
@property