provide default coord_mapping from scanners

This commit is contained in:
xs5871 2022-04-09 23:54:23 +00:00 committed by Kyle Brown
parent 8ac497d99b
commit e395e89864
4 changed files with 18 additions and 10 deletions

View File

@ -282,16 +282,11 @@ class KMKKeyboard:
To save RAM on boards that don't use Split, we don't import Split To save RAM on boards that don't use Split, we don't import Split
and do an isinstance check, but instead do string detection and do an isinstance check, but instead do string detection
''' '''
if self.matrix and self.matrix.coord_mapping:
self.coord_mapping = self.matrix.coord_mapping
if any(x.__class__.__module__ == 'kmk.modules.split' for x in self.modules): if any(x.__class__.__module__ == 'kmk.modules.split' for x in self.modules):
return return
if not self.coord_mapping: if not self.coord_mapping:
rows_to_calc = len(self.row_pins) self.coord_mapping = self.matrix.coord_mapping
cols_to_calc = len(self.col_pins)
self.coord_mapping = list(range(cols_to_calc * rows_to_calc))
def _init_hid(self): def _init_hid(self):
if self.hid_type == HIDModes.NOOP: if self.hid_type == HIDModes.NOOP:
@ -420,9 +415,9 @@ class KMKKeyboard:
self.secondary_hid_type = secondary_hid_type self.secondary_hid_type = secondary_hid_type
self._init_sanity_check() self._init_sanity_check()
self._init_coord_mapping()
self._init_hid() self._init_hid()
self._init_matrix() self._init_matrix()
self._init_coord_mapping()
for module in self.modules: for module in self.modules:
try: try:

View File

@ -24,6 +24,10 @@ class Scanner:
coord_mapping = None coord_mapping = None
@property
def key_count(self):
raise NotImplementedError
def scan_for_changes(self): def scan_for_changes(self):
''' '''
Scan for key events and return a key report if an event exists. Scan for key events and return a key report if an event exists.

View File

@ -77,8 +77,13 @@ class MatrixScanner(Scanner):
if self.rollover_cols_every_rows is None: if self.rollover_cols_every_rows is None:
self.rollover_cols_every_rows = self.len_rows self.rollover_cols_every_rows = self.len_rows
self.len_state_arrays = self.len_cols * self.len_rows self._key_count = self.len_cols * self.len_rows
self.state = bytearray(self.len_state_arrays) self.coord_mapping = tuple(range(self.key_count))
self.state = bytearray(self.key_count)
@property
def key_count(self):
return self._key_count
def scan_for_changes(self): def scan_for_changes(self):
''' '''

View File

@ -16,10 +16,14 @@ class NativeKeypadScanner(Scanner):
self.keypad = kp self.keypad = kp
# for split keyboards, the offset value will be assigned in Split module # for split keyboards, the offset value will be assigned in Split module
self.offset = 0 self.offset = 0
self.coord_mapping = list(range(len(pin_map))) self.coord_mapping = tuple(range(self.key_count))
self.curr_event = keypad.Event() self.curr_event = keypad.Event()
@property
def key_count(self):
return self.keypad.key_count
def scan_for_changes(self): def scan_for_changes(self):
''' '''
Scan for key events and return a key report if an event exists. Scan for key events and return a key report if an event exists.