Clean up and standardize print() debug stuff
This commit is contained in:
parent
edcb681169
commit
1fe80fec92
@ -15,16 +15,18 @@
|
|||||||
# chain to import _every single thing_ KMK eventually uses in a normal
|
# chain to import _every single thing_ KMK eventually uses in a normal
|
||||||
# workflow, in order from fewest to least nested dependencies.
|
# workflow, in order from fewest to least nested dependencies.
|
||||||
|
|
||||||
# First, stuff that has no dependencies, or only C/MPY deps
|
# First, system-provided deps
|
||||||
|
import busio # isort:skip
|
||||||
import collections # isort:skip
|
import collections # isort:skip
|
||||||
|
import gc # isort:skip
|
||||||
|
import supervisor # isort:skip
|
||||||
|
|
||||||
|
# Now "light" KMK stuff with few/no external deps
|
||||||
import kmk.consts # isort:skip
|
import kmk.consts # isort:skip
|
||||||
import kmk.kmktime # isort:skip
|
import kmk.kmktime # isort:skip
|
||||||
import kmk.types # isort:skip
|
import kmk.types # isort:skip
|
||||||
import kmk.util # isort:skip
|
import kmk.util # isort:skip
|
||||||
|
|
||||||
import busio # isort:skip
|
|
||||||
|
|
||||||
import supervisor # isort:skip
|
|
||||||
from kmk.consts import LeaderMode, UnicodeMode # isort:skip
|
from kmk.consts import LeaderMode, UnicodeMode # isort:skip
|
||||||
from kmk.hid import USB_HID # isort:skip
|
from kmk.hid import USB_HID # isort:skip
|
||||||
from kmk.internal_state import InternalState # isort:skip
|
from kmk.internal_state import InternalState # isort:skip
|
||||||
@ -100,6 +102,71 @@ class Firmware:
|
|||||||
|
|
||||||
self._state = InternalState(self)
|
self._state = InternalState(self)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return (
|
||||||
|
'Firmware('
|
||||||
|
'debug_enabled={} '
|
||||||
|
'keymap=truncated '
|
||||||
|
'coord_mapping=truncated '
|
||||||
|
'row_pins=truncated '
|
||||||
|
'col_pins=truncated '
|
||||||
|
'diode_orientation={} '
|
||||||
|
'matrix_scanner={} '
|
||||||
|
'unicode_mode={} '
|
||||||
|
'tap_time={} '
|
||||||
|
'leader_mode={} '
|
||||||
|
'leader_dictionary=truncated '
|
||||||
|
'leader_timeout={} '
|
||||||
|
'hid_helper={} '
|
||||||
|
'extra_data_pin={} '
|
||||||
|
'split_offsets={} '
|
||||||
|
'split_flip={} '
|
||||||
|
'split_side={} '
|
||||||
|
'split_type={} '
|
||||||
|
'split_master_left={} '
|
||||||
|
'is_master={} '
|
||||||
|
'uart={} '
|
||||||
|
'uart_flip={} '
|
||||||
|
'uart_pin={}'
|
||||||
|
')'
|
||||||
|
).format(
|
||||||
|
self.debug_enabled,
|
||||||
|
# self.keymap,
|
||||||
|
# self.coord_mapping,
|
||||||
|
# self.row_pins,
|
||||||
|
# self.col_pins,
|
||||||
|
self.diode_orientation,
|
||||||
|
self.matrix_scanner,
|
||||||
|
self.unicode_mode,
|
||||||
|
self.tap_time,
|
||||||
|
self.leader_mode,
|
||||||
|
# self.leader_dictionary,
|
||||||
|
self.leader_timeout,
|
||||||
|
self.hid_helper.__name__,
|
||||||
|
self.extra_data_pin,
|
||||||
|
self.split_offsets,
|
||||||
|
self.split_flip,
|
||||||
|
self.split_side,
|
||||||
|
self.split_type,
|
||||||
|
self.split_master_left,
|
||||||
|
self.is_master,
|
||||||
|
self.uart,
|
||||||
|
self.uart_flip,
|
||||||
|
self.uart_pin,
|
||||||
|
)
|
||||||
|
|
||||||
|
def _print_debug_cycle(self, init=False):
|
||||||
|
if self.debug_enabled:
|
||||||
|
if init:
|
||||||
|
print('KMKInit()')
|
||||||
|
|
||||||
|
print(self)
|
||||||
|
print(self._state)
|
||||||
|
print('GCStats(alloc={} free={})'.format(
|
||||||
|
gc.mem_alloc(),
|
||||||
|
gc.mem_free(),
|
||||||
|
))
|
||||||
|
|
||||||
def _send_hid(self):
|
def _send_hid(self):
|
||||||
self._hid_helper_inst.create_report(self._state.keys_pressed).send()
|
self._hid_helper_inst.create_report(self._state.keys_pressed).send()
|
||||||
self._state.resolve_hid()
|
self._state.resolve_hid()
|
||||||
@ -211,8 +278,7 @@ class Firmware:
|
|||||||
if not isinstance(k, tuple):
|
if not isinstance(k, tuple):
|
||||||
del self.leader_dictionary[k]
|
del self.leader_dictionary[k]
|
||||||
|
|
||||||
if self.debug_enabled:
|
self._print_debug_cycle(init=True)
|
||||||
print("Firin' lazers. Keyboard is booted.")
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
state_changed = False
|
state_changed = False
|
||||||
@ -246,5 +312,5 @@ class Firmware:
|
|||||||
if self._state.hid_pending:
|
if self._state.hid_pending:
|
||||||
self._send_hid()
|
self._send_hid()
|
||||||
|
|
||||||
if self.debug_enabled and state_changed:
|
if state_changed:
|
||||||
print('New State: {}'.format(self._state._to_dict()))
|
self._print_debug_cycle()
|
||||||
|
@ -38,9 +38,9 @@ def bootloader(*args, **kwargs):
|
|||||||
|
|
||||||
def debug_pressed(key, state, KC, *args, **kwargs):
|
def debug_pressed(key, state, KC, *args, **kwargs):
|
||||||
if state.config.debug_enabled:
|
if state.config.debug_enabled:
|
||||||
print('Disabling debug mode, bye!')
|
print('DebugDisable()')
|
||||||
else:
|
else:
|
||||||
print('Enabling debug mode. Welcome to the jungle.')
|
print('DebugEnable()')
|
||||||
|
|
||||||
state.config.debug_enabled = not state.config.debug_enabled
|
state.config.debug_enabled = not state.config.debug_enabled
|
||||||
|
|
||||||
|
@ -21,6 +21,12 @@ class USB_HID:
|
|||||||
|
|
||||||
self.post_init()
|
self.post_init()
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return '{}(REPORT_BYTES={})'.format(
|
||||||
|
self.__class__.__name__,
|
||||||
|
self.REPORT_BYTES,
|
||||||
|
)
|
||||||
|
|
||||||
def post_init(self):
|
def post_init(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -30,21 +30,37 @@ class InternalState:
|
|||||||
self.config = config
|
self.config = config
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return 'InternalState({})'.format(self._to_dict())
|
return (
|
||||||
|
'InternalState('
|
||||||
def _to_dict(self):
|
'keys_pressed={} '
|
||||||
ret = {
|
'coord_keys_pressed={} '
|
||||||
'keys_pressed': self.keys_pressed,
|
'leader_pending={} '
|
||||||
'active_layers': self.active_layers,
|
'leader_last_len={} '
|
||||||
'leader_mode_history': self.leader_mode_history,
|
'hid_pending={} '
|
||||||
'leader_mode': self.config.leader_mode,
|
'leader_mode_history={} '
|
||||||
'start_time': self.start_time,
|
'active_layers={} '
|
||||||
'tapping': self.tapping,
|
'reversed_active_layers={} '
|
||||||
'tap_dance_counts': self.tap_dance_counts,
|
'start_time={} '
|
||||||
'timeouts': self.timeouts,
|
'timeouts={} '
|
||||||
}
|
'tapping={} '
|
||||||
|
'tap_dance_counts={} '
|
||||||
return ret
|
'tap_side_effects={}'
|
||||||
|
')'
|
||||||
|
).format(
|
||||||
|
self.keys_pressed,
|
||||||
|
self.coord_keys_pressed,
|
||||||
|
self.leader_pending,
|
||||||
|
self.leader_last_len,
|
||||||
|
self.hid_pending,
|
||||||
|
self.leader_mode_history,
|
||||||
|
self.active_layers,
|
||||||
|
self.reversed_active_layers,
|
||||||
|
self.start_time,
|
||||||
|
self.timeouts,
|
||||||
|
self.tapping,
|
||||||
|
self.tap_dance_counts,
|
||||||
|
self.tap_side_effects,
|
||||||
|
)
|
||||||
|
|
||||||
def _find_key_in_map(self, row, col):
|
def _find_key_in_map(self, row, col):
|
||||||
ic = intify_coordinate(row, col)
|
ic = intify_coordinate(row, col)
|
||||||
@ -54,7 +70,7 @@ class InternalState:
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
if self.config.debug_enabled:
|
if self.config.debug_enabled:
|
||||||
print(
|
print(
|
||||||
'No coord_mapping index for value {}, row={} col={}'.format(
|
'CoordMappingNotFound(ic={}, row={}, col={})'.format(
|
||||||
ic,
|
ic,
|
||||||
row,
|
row,
|
||||||
col,
|
col,
|
||||||
@ -72,7 +88,7 @@ class InternalState:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
if self.config.debug_enabled:
|
if self.config.debug_enabled:
|
||||||
print('Resolved key: {}'.format(layer_key))
|
print('KeyResolution(key={})'.format(layer_key))
|
||||||
|
|
||||||
return layer_key
|
return layer_key
|
||||||
|
|
||||||
@ -112,20 +128,23 @@ class InternalState:
|
|||||||
|
|
||||||
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('MatrixChange(col={} row={} pressed={})'.format(
|
||||||
col, row, is_pressed,
|
col,
|
||||||
|
row,
|
||||||
|
is_pressed,
|
||||||
))
|
))
|
||||||
|
|
||||||
int_coord = intify_coordinate(row, col)
|
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:
|
||||||
print('No key accessible for col, row: {}, {}'.format(row, col))
|
print('MatrixUndefinedCoordinate(col={} row={})'.format(col, row))
|
||||||
return self
|
return self
|
||||||
|
|
||||||
return self.process_key(kc_changed, is_pressed, int_coord, (row, col))
|
return self.process_key(kc_changed, is_pressed, int_coord, (row, col))
|
||||||
|
|
||||||
def process_key(self, key, is_pressed, coord_int=None, coord_raw=None):
|
def process_key(self, key, is_pressed, coord_int=None, coord_raw=None):
|
||||||
|
|
||||||
if self.tapping and not isinstance(key.meta, TapDanceKeyMeta):
|
if self.tapping and not isinstance(key.meta, TapDanceKeyMeta):
|
||||||
self._process_tap_dance(key, is_pressed)
|
self._process_tap_dance(key, is_pressed)
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user