diff --git a/.gitignore b/.gitignore index 5e7a62f..6292408 100644 --- a/.gitignore +++ b/.gitignore @@ -115,3 +115,7 @@ venv.bak/ # Personal dev scripts .scripts + +# Mountpoints +mnt/ +mnt2/ diff --git a/kmk/firmware.py b/kmk/firmware.py index 4225bfb..a905dcb 100644 --- a/kmk/firmware.py +++ b/kmk/firmware.py @@ -139,7 +139,14 @@ class Firmware: if self.is_master is not None: return self.is_master - return supervisor.runtime.serial_connected + # Working around https://github.com/adafruit/circuitpython/issues/1769 + try: + self._hid_helper_inst.create_report([]).send() + self.is_master = True + except OSError: + self.is_master = False + + return self.is_master def init_uart(self, pin, timeout=20): if self._master_half(): @@ -153,6 +160,8 @@ class Firmware: assert self.col_pins, 'no GPIO pins defined for matrix columns' assert self.diode_orientation is not None, 'diode orientation must be defined' + self._hid_helper_inst = self.hid_helper() + # Split keyboard Init if self.split_flip and not self._master_half(): self.col_pins = list(reversed(self.col_pins)) @@ -173,8 +182,6 @@ class Firmware: swap_indicies=getattr(self, 'swap_indicies', None), ) - self._hid_helper_inst = self.hid_helper() - # Compile string leader sequences for k, v in self.leader_dictionary.items(): if not isinstance(k, tuple): diff --git a/kmk/matrix.py b/kmk/matrix.py index e1be0d5..754cc7b 100644 --- a/kmk/matrix.py +++ b/kmk/matrix.py @@ -73,8 +73,19 @@ class MatrixScanner: opin.value(True) for iidx, ipin in enumerate(self.inputs): + # cast to int to avoid + # + # >>> xyz = bytearray(3) + # >>> xyz[2] = True + # Traceback (most recent call last): + # File "", line 1, in + # OverflowError: value would overflow a 1 byte buffer + # + # I haven't dived too far into what causes this, but it's + # almost certainly because bool types in Python aren't just + # aliases to int values, but are proper pseudo-types + new_val = int(ipin.value()) old_val = self.state[ba_idx] - new_val = ipin.value() if old_val != new_val: if self.translate_coords: @@ -97,6 +108,7 @@ class MatrixScanner: self.report[2] = new_val self.state[ba_idx] = new_val + any_changed = True break