First keys on slave half actually type! Still needs a bit of work

This commit is contained in:
Kyle Brown 2018-10-19 03:36:24 -07:00
parent 49da93e436
commit af3eccd715
2 changed files with 22 additions and 16 deletions

View File

@ -65,6 +65,7 @@ class Firmware:
split_type = None split_type = None
split_offsets = () split_offsets = ()
split_master_left = True split_master_left = True
uart = None
def __init__(self): def __init__(self):
self._state = InternalState(self) self._state = InternalState(self)
@ -83,8 +84,8 @@ class Firmware:
self._send_hid() self._send_hid()
def _handle_update(self, update): def _handle_update(self, update):
if self.split_type is not None and not self.split_master_left: # if self.split_type is not None and not self.split_master_left:
update[1] += self.split_offsets[update[1]] # update[1] += self.split_offsets[update[1]]
if update is not None: if update is not None:
self._state.matrix_changed( self._state.matrix_changed(
@ -112,20 +113,20 @@ class Firmware:
def _send_to_master(self, update): def _send_to_master(self, update):
if self.split_type == "UART": if self.split_type == "UART":
if self.uart is None: if self.uart is None:
self.uart = busio.UART(board.TX, board.RX, timeout=0) self.uart = busio.UART(board.TX, board.RX, timeout=1)
# Update column with offset # Update column with offset
if self.split_master_left: # if self.split_master_left:
update[1] += self.split_offsets[update[1]] # update[1] += self.split_offsets[update[1]]
self.uart.write(update) self.uart.write(update)
def _receive_from_slave(self): def _receive_from_slave(self):
if self.split_type == "UART": if self.split_type == "UART":
if self.uart is None: if self.uart is None:
self.uart = busio.UART(board.TX, board.RX, timeout=0) self.uart = busio.UART(board.TX, board.RX, timeout=1)
update = self.uart.read() update = self.uart.read(nbytes=3)
return update return update
return None return None
@ -150,14 +151,17 @@ class Firmware:
print("Firin' lazers. Keyboard is booted.") print("Firin' lazers. Keyboard is booted.")
while True: while True:
if self.split_type is not None: if self.split_type is not None and supervisor.runtime.serial_connected:
update = self._receive_from_slave() update = self._receive_from_slave()
print(str(update))
if update is not None: if update is not None:
self._handle_update(update) self._handle_update(update)
for update in self.matrix.scan_for_changes(): for update in self.matrix.scan_for_changes():
if update is not None:
# Abstract this later. Bluetooth will fail here # Abstract this later. Bluetooth will fail here
if supervisor.runtime.serial_connected: if supervisor.runtime.serial_connected:
if update is not None:
self._handle_update(update) self._handle_update(update)
else: else:

View File

@ -9,8 +9,8 @@ from kmk.types import AttrDict
keyboard = Firmware() keyboard = Firmware()
keyboard.col_pins = (P.A0, P.A1, P.A2, P.A3, P.A4, P.A5, P.SCK, P.MOSI, P.MISO, P.RX, P.TX, P.D4) keyboard.col_pins = (P.D10, P.D9, P.D7, P.D5, P.A4, P.A5)
keyboard.row_pins = (P.D10, P.D11, P.D12, P.D13) keyboard.row_pins = (P.A0, P.A1, P.A2, P.A3)
keyboard.diode_orientation = DiodeOrientation.COLUMNS keyboard.diode_orientation = DiodeOrientation.COLUMNS
@ -19,6 +19,8 @@ keyboard.unicode_mode = UnicodeModes.LINUX
keyboard.tap_time = 900 keyboard.tap_time = 900
keyboard.leader_timeout = 2000 keyboard.leader_timeout = 2000
keyboard.debug_enabled = True keyboard.debug_enabled = True
keyboard.split_type = "UART"
keyboard.split_offsets = [5, 5, 5, 5]
emoticons = compile_unicode_string_sequences({ emoticons = compile_unicode_string_sequences({
# Emoticons, but fancier # Emoticons, but fancier