From e395e89864587e877ede2f82af8b083333b10e21 Mon Sep 17 00:00:00 2001 From: xs5871 Date: Sat, 9 Apr 2022 23:54:23 +0000 Subject: [PATCH] provide default coord_mapping from scanners --- kmk/kmk_keyboard.py | 9 ++------- kmk/scanners/__init__.py | 4 ++++ kmk/scanners/digitalio_matrix.py | 9 +++++++-- kmk/scanners/native_keypad_scanner.py | 6 +++++- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/kmk/kmk_keyboard.py b/kmk/kmk_keyboard.py index ffc4d0e..1b7c2ab 100644 --- a/kmk/kmk_keyboard.py +++ b/kmk/kmk_keyboard.py @@ -282,16 +282,11 @@ class KMKKeyboard: 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 ''' - 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): return if not self.coord_mapping: - rows_to_calc = len(self.row_pins) - cols_to_calc = len(self.col_pins) - self.coord_mapping = list(range(cols_to_calc * rows_to_calc)) + self.coord_mapping = self.matrix.coord_mapping def _init_hid(self): if self.hid_type == HIDModes.NOOP: @@ -420,9 +415,9 @@ class KMKKeyboard: self.secondary_hid_type = secondary_hid_type self._init_sanity_check() - self._init_coord_mapping() self._init_hid() self._init_matrix() + self._init_coord_mapping() for module in self.modules: try: diff --git a/kmk/scanners/__init__.py b/kmk/scanners/__init__.py index db0f8d5..73ae277 100644 --- a/kmk/scanners/__init__.py +++ b/kmk/scanners/__init__.py @@ -24,6 +24,10 @@ class Scanner: coord_mapping = None + @property + def key_count(self): + raise NotImplementedError + def scan_for_changes(self): ''' Scan for key events and return a key report if an event exists. diff --git a/kmk/scanners/digitalio_matrix.py b/kmk/scanners/digitalio_matrix.py index 7612f38..880e5c0 100644 --- a/kmk/scanners/digitalio_matrix.py +++ b/kmk/scanners/digitalio_matrix.py @@ -77,8 +77,13 @@ class MatrixScanner(Scanner): if self.rollover_cols_every_rows is None: self.rollover_cols_every_rows = self.len_rows - self.len_state_arrays = self.len_cols * self.len_rows - self.state = bytearray(self.len_state_arrays) + self._key_count = self.len_cols * self.len_rows + 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): ''' diff --git a/kmk/scanners/native_keypad_scanner.py b/kmk/scanners/native_keypad_scanner.py index 5c575a0..620baac 100644 --- a/kmk/scanners/native_keypad_scanner.py +++ b/kmk/scanners/native_keypad_scanner.py @@ -16,10 +16,14 @@ class NativeKeypadScanner(Scanner): self.keypad = kp # for split keyboards, the offset value will be assigned in Split module self.offset = 0 - self.coord_mapping = list(range(len(pin_map))) + self.coord_mapping = tuple(range(self.key_count)) self.curr_event = keypad.Event() + @property + def key_count(self): + return self.keypad.key_count + def scan_for_changes(self): ''' Scan for key events and return a key report if an event exists.