From 15fea0189b9265fc60e819eb158f70277796afd0 Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Fri, 26 Oct 2018 14:26:15 -0700 Subject: [PATCH] Added remote debugger and cleaned up several things Looks good to merge --- .gitignore | 3 ++ docs/split_keyboards.md | 2 +- kmk/firmware.py | 47 ++++++++++++++++++++---------- user_keymaps/kdb424/levinson_m4.py | 17 ++++++----- 4 files changed, 44 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 3e4a0f3..5e7a62f 100644 --- a/.gitignore +++ b/.gitignore @@ -112,3 +112,6 @@ venv.bak/ # Pycharms cruft .idea + +# Personal dev scripts +.scripts diff --git a/docs/split_keyboards.md b/docs/split_keyboards.md index ea83ac7..67b421f 100644 --- a/docs/split_keyboards.md +++ b/docs/split_keyboards.md @@ -4,7 +4,6 @@ UART is supported, though other modes will come later such as Bluetooth and i2c. Useful config options: ```python -keyboard.split_type = "UART" # Sets split mode to UART keyboard.split_flip = True # If your boards are identical but one is flipped, this option is for you keyboard.split_offsets = [6, 6, 6, 6] # This is the how many keys are on each column on the "Master" half ``` @@ -34,5 +33,6 @@ from kmk_side import split_side # UART To enable uart it's as simple as adding this line, of course changing the pin ```python +keyboard.split_type = "UART" keyboard.uart = keyboard.init_uart(tx=board.SCL) ``` diff --git a/kmk/firmware.py b/kmk/firmware.py index c21de5c..b7d05d4 100644 --- a/kmk/firmware.py +++ b/kmk/firmware.py @@ -63,7 +63,9 @@ class Firmware: split_offsets = () split_flip = False + split_side = None split_master_left = True + is_master = None uart = None uart_flip = True @@ -84,6 +86,10 @@ class Firmware: self._send_hid() def _handle_update(self, update): + ''' + Bulk processing of update code for each cycle + :param update: + ''' if update is not None: self._state.matrix_changed( update[0], @@ -110,26 +116,39 @@ class Firmware: self._state.resolve_macro() def _send_to_master(self, update): + if self.split_master_left: + update[1] += self.split_offsets[update[0]] + else: + update[1] -= self.split_offsets[update[0]] if self.uart is not None: - - if self.split_master_left: - update[1] += self.split_offsets[update[0]] - self.uart.write(update) def _receive_from_slave(self): if self.uart is not None and self.uart.in_waiting > 0: update = bytearray(self.uart.read(3)) - if self.split_master_left: - update[1] -= self.split_offsets[update[0]] + # Built in debug mode switch + if update == b'DEB': + # TODO Pretty up output + print(self.uart.readline()) + return None return update return None + def _send_debug(self, message): + ''' + Prepends DEB and appends a newline to allow debug messages to + be detected and handled differently than typical keypresses. + :param message: Debug message + ''' + if self.uart is not None: + self.uart.write('DEB') + self.uart.write(message, '\n') + def _master_half(self): return supervisor.runtime.serial_connected - def init_uart(self, tx=None, rx=None, timeout=1): + def init_uart(self, tx=None, rx=None, timeout=20): if self._master_half(): # If running with one wire, only receive on master if rx is None or self.uart_flip: @@ -146,19 +165,15 @@ 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.is_master == self._master_half() + if self.split_flip and not self._master_half(): self.col_pins = list(reversed(self.col_pins)) if self.split_side == "Left": - if supervisor.runtime.serial_connected: - self.split_master_left = True - else: - self.split_master_left = False - else: - if supervisor.runtime.serial_connected: - self.split_master_left = False - else: - self.split_master_left = True + self.split_master_left = self.is_master + elif self.split_side == "Right": + self.split_master_left = not self.is_master self.matrix = MatrixScanner( cols=self.col_pins, diff --git a/user_keymaps/kdb424/levinson_m4.py b/user_keymaps/kdb424/levinson_m4.py index 9560964..b20f8ce 100644 --- a/user_keymaps/kdb424/levinson_m4.py +++ b/user_keymaps/kdb424/levinson_m4.py @@ -1,7 +1,7 @@ import board import busio -from kmk.consts import DiodeOrientation, UnicodeModes +from kmk.consts import DiodeOrientation, LeaderMode, UnicodeModes from kmk.keycodes import KC from kmk.keycodes import generate_leader_dictionary_seq as glds from kmk.macros.simple import send_string @@ -16,17 +16,18 @@ keyboard.col_pins = (P.D10, P.D9, P.D7, P.D5, P.A4, P.A5) keyboard.row_pins = (P.A0, P.A1, P.A2, P.A3) keyboard.diode_orientation = DiodeOrientation.COLUMNS - -# ------------------User level config variables --------------------------------------- -keyboard.unicode_mode = UnicodeModes.LINUX -keyboard.tap_time = 350 -keyboard.leader_timeout = 2000 -keyboard.debug_enabled = False keyboard.split_type = "UART" keyboard.split_flip = True keyboard.split_offsets = [6, 6, 6, 6] -keyboard.uart = keyboard.init_uart(tx=board.TX, rx=board.RX) keyboard.uart_flip = False +keyboard.uart = keyboard.init_uart(tx=board.TX, rx=board.RX) + +# ------------------User level config variables --------------------------------------- +keyboard.leader_mode = LeaderMode.TIMEOUT +keyboard.unicode_mode = UnicodeModes.LINUX +keyboard.tap_time = 150 +keyboard.leader_timeout = 2000 +keyboard.debug_enabled = True emoticons = compile_unicode_string_sequences({ # Emoticons, but fancier