Work out some bugs where I could get stuck on layers. Add more debugging output
This commit is contained in:
parent
6c5a111d65
commit
9089106316
@ -94,26 +94,28 @@ class Firmware:
|
|||||||
print("Firin' lazers. Keyboard is booted.")
|
print("Firin' lazers. Keyboard is booted.")
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
update = self.matrix.scan_for_pressed()
|
for update in self.matrix.scan_for_pressed():
|
||||||
|
if update is not None:
|
||||||
|
self._state.matrix_changed(
|
||||||
|
update[0],
|
||||||
|
update[1],
|
||||||
|
update[2],
|
||||||
|
)
|
||||||
|
|
||||||
if update is not None:
|
if self._state.hid_pending:
|
||||||
self._state.matrix_changed(
|
self._send_hid()
|
||||||
update[0],
|
|
||||||
update[1],
|
|
||||||
update[2],
|
|
||||||
)
|
|
||||||
|
|
||||||
if self._state.hid_pending:
|
for key in self._state.pending_keys:
|
||||||
self._send_hid()
|
|
||||||
|
|
||||||
for key in self._state.pending_keys:
|
|
||||||
self._send_key(key)
|
|
||||||
self._state.pending_key_handled()
|
|
||||||
|
|
||||||
if self._state.macro_pending:
|
|
||||||
for key in self._state.macro_pending(self):
|
|
||||||
self._send_key(key)
|
self._send_key(key)
|
||||||
|
self._state.pending_key_handled()
|
||||||
|
|
||||||
self._state.resolve_macro()
|
if self._state.macro_pending:
|
||||||
|
for key in self._state.macro_pending(self):
|
||||||
|
self._send_key(key)
|
||||||
|
|
||||||
|
self._state.resolve_macro()
|
||||||
|
|
||||||
|
if self.debug_enabled:
|
||||||
|
print('New State: {}'.format(self._state._to_dict()))
|
||||||
|
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from kmk.keycodes import FIRST_KMK_INTERNAL_KEYCODE, Keycodes, RawKeycodes
|
from kmk.keycodes import FIRST_KMK_INTERNAL_KEYCODE, Keycodes, RawKeycodes
|
||||||
from kmk.kmktime import sleep_ms, ticks_diff, ticks_ms
|
from kmk.kmktime import sleep_ms, ticks_diff, ticks_ms
|
||||||
|
from kmk.util import intify_coordinate
|
||||||
|
|
||||||
GESC_TRIGGERS = {
|
GESC_TRIGGERS = {
|
||||||
Keycodes.Modifiers.KC_LSHIFT, Keycodes.Modifiers.KC_RSHIFT,
|
Keycodes.Modifiers.KC_LSHIFT, Keycodes.Modifiers.KC_RSHIFT,
|
||||||
@ -9,6 +10,7 @@ GESC_TRIGGERS = {
|
|||||||
|
|
||||||
class InternalState:
|
class InternalState:
|
||||||
keys_pressed = set()
|
keys_pressed = set()
|
||||||
|
coord_keys_pressed = {}
|
||||||
pending_keys = []
|
pending_keys = []
|
||||||
macro_pending = None
|
macro_pending = None
|
||||||
leader_pending = None
|
leader_pending = None
|
||||||
@ -52,8 +54,6 @@ class InternalState:
|
|||||||
ret = {
|
ret = {
|
||||||
'keys_pressed': self.keys_pressed,
|
'keys_pressed': self.keys_pressed,
|
||||||
'active_layers': self.active_layers,
|
'active_layers': self.active_layers,
|
||||||
'unicode_mode': self.unicode_mode,
|
|
||||||
'tap_time': self.config.tap_time,
|
|
||||||
'leader_mode_history': self.leader_mode_history,
|
'leader_mode_history': self.leader_mode_history,
|
||||||
'start_time': self.start_time,
|
'start_time': self.start_time,
|
||||||
}
|
}
|
||||||
@ -69,17 +69,18 @@ class InternalState:
|
|||||||
if not layer_key or layer_key == Keycodes.KMK.KC_TRNS:
|
if not layer_key or layer_key == Keycodes.KMK.KC_TRNS:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if layer_key == Keycodes.KMK.KC_NO:
|
if self.config.debug_enabled:
|
||||||
return layer_key
|
print('Resolved key: {}'.format(layer_key))
|
||||||
|
|
||||||
return layer_key
|
return layer_key
|
||||||
|
|
||||||
def matrix_changed(self, row, col, is_pressed):
|
def matrix_changed(self, row, col, is_pressed):
|
||||||
if self.config.debug_enabled:
|
if self.config.debug_enabled:
|
||||||
print('Matrix changed (col, row, pressed?): {}, {}, {}'.format(
|
print('Matrix changed (col, row, pressed?): {}, {}, {}'.format(
|
||||||
row, col, is_pressed,
|
col, row, is_pressed,
|
||||||
))
|
))
|
||||||
|
|
||||||
|
int_coord = intify_coordinate(row, col)
|
||||||
kc_changed = self._find_key_in_map(row, col)
|
kc_changed = self._find_key_in_map(row, col)
|
||||||
|
|
||||||
if kc_changed is None:
|
if kc_changed is None:
|
||||||
@ -94,8 +95,11 @@ class InternalState:
|
|||||||
else:
|
else:
|
||||||
if is_pressed:
|
if is_pressed:
|
||||||
self.keys_pressed.add(kc_changed)
|
self.keys_pressed.add(kc_changed)
|
||||||
|
self.coord_keys_pressed[int_coord] = kc_changed
|
||||||
else:
|
else:
|
||||||
self.keys_pressed.discard(kc_changed)
|
self.keys_pressed.discard(kc_changed)
|
||||||
|
self.keys_pressed.discard(self.coord_keys_pressed[int_coord])
|
||||||
|
self.coord_keys_pressed[int_coord] = None
|
||||||
|
|
||||||
self.hid_pending = True
|
self.hid_pending = True
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import digitalio
|
import digitalio
|
||||||
|
|
||||||
from kmk.consts import DiodeOrientation
|
from kmk.consts import DiodeOrientation
|
||||||
|
from kmk.util import intify_coordinate
|
||||||
|
|
||||||
|
|
||||||
class MatrixScanner:
|
class MatrixScanner:
|
||||||
@ -47,8 +48,8 @@ class MatrixScanner:
|
|||||||
self.swap_indicies = {}
|
self.swap_indicies = {}
|
||||||
if swap_indicies is not None:
|
if swap_indicies is not None:
|
||||||
for k, v in swap_indicies.items():
|
for k, v in swap_indicies.items():
|
||||||
self.swap_indicies[self._intify_coordinate(*k)] = v
|
self.swap_indicies[intify_coordinate(*k)] = v
|
||||||
self.swap_indicies[self._intify_coordinate(*v)] = k
|
self.swap_indicies[intify_coordinate(*v)] = k
|
||||||
|
|
||||||
self.rollover_cols_every_rows = rollover_cols_every_rows
|
self.rollover_cols_every_rows = rollover_cols_every_rows
|
||||||
if self.rollover_cols_every_rows is None:
|
if self.rollover_cols_every_rows is None:
|
||||||
@ -58,9 +59,6 @@ class MatrixScanner:
|
|||||||
self.state = bytearray(self.len_state_arrays)
|
self.state = bytearray(self.len_state_arrays)
|
||||||
self.report = bytearray(3)
|
self.report = bytearray(3)
|
||||||
|
|
||||||
def _intify_coordinate(self, row, col):
|
|
||||||
return row << 8 | col
|
|
||||||
|
|
||||||
def scan_for_pressed(self):
|
def scan_for_pressed(self):
|
||||||
ba_idx = 0
|
ba_idx = 0
|
||||||
any_changed = False
|
any_changed = False
|
||||||
@ -85,7 +83,7 @@ class MatrixScanner:
|
|||||||
self.report[0] = oidx
|
self.report[0] = oidx
|
||||||
self.report[1] = iidx
|
self.report[1] = iidx
|
||||||
|
|
||||||
swap_src = self._intify_coordinate(self.report[0], self.report[1])
|
swap_src = intify_coordinate(self.report[0], self.report[1])
|
||||||
if swap_src in self.swap_indicies:
|
if swap_src in self.swap_indicies:
|
||||||
tgt_row, tgt_col = self.swap_indicies[swap_src]
|
tgt_row, tgt_col = self.swap_indicies[swap_src]
|
||||||
self.report[0] = tgt_row
|
self.report[0] = tgt_row
|
||||||
@ -94,14 +92,12 @@ class MatrixScanner:
|
|||||||
self.report[2] = new_val
|
self.report[2] = new_val
|
||||||
self.state[ba_idx] = new_val
|
self.state[ba_idx] = new_val
|
||||||
any_changed = True
|
any_changed = True
|
||||||
break
|
|
||||||
|
yield self.report
|
||||||
|
|
||||||
ba_idx += 1
|
ba_idx += 1
|
||||||
|
|
||||||
opin.value(False)
|
opin.value(False)
|
||||||
|
|
||||||
if any_changed:
|
if not any_changed:
|
||||||
break
|
yield None
|
||||||
|
|
||||||
if any_changed:
|
|
||||||
return self.report
|
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
def intify_coordinate(row, col):
|
||||||
|
return row << 8 | col
|
||||||
|
|
||||||
|
|
||||||
def get_wide_ordinal(char):
|
def get_wide_ordinal(char):
|
||||||
if len(char) != 2:
|
if len(char) != 2:
|
||||||
return ord(char)
|
return ord(char)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user