From 0a06e733d200ed2c6956f398c26182f3fa4cb354 Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Sat, 2 Mar 2019 15:44:04 -0800 Subject: [PATCH] Solved. Added uart buffer on the master to free up the uart bus buffer --- kmk/firmware.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/kmk/firmware.py b/kmk/firmware.py index 20a057e..ab653b0 100644 --- a/kmk/firmware.py +++ b/kmk/firmware.py @@ -70,6 +70,7 @@ class Firmware: col_pins = None diode_orientation = None matrix_scanner = MatrixScanner + uart_buffer = [] unicode_mode = UnicodeMode.NOOP tap_time = 300 @@ -171,19 +172,22 @@ class Firmware: self.uart.write(update) def _receive_from_slave(self): - if self.uart is not None and self.uart.in_waiting > 0: + if self.uart is not None and self.uart.in_waiting > 0 or self.uart_buffer: if self.uart.in_waiting >= 60: # This is a dirty hack to prevent crashes in unrealistic cases import microcontroller microcontroller.reset() - update = bytearray(self.uart.read(3)) + while self.uart.in_waiting >=3: + self.uart_buffer.append(self.uart.read(3)) + if self.uart_buffer: + update = bytearray(self.uart_buffer.pop(0)) - # Built in debug mode switch - if update == b'DEB': - print(self.uart.readline()) - return None - return update + # Built in debug mode switch + if update == b'DEB': + print(self.uart.readline()) + return None + return update return None