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
|
||||
# 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 gc # isort:skip
|
||||
import supervisor # isort:skip
|
||||
|
||||
# Now "light" KMK stuff with few/no external deps
|
||||
import kmk.consts # isort:skip
|
||||
import kmk.kmktime # isort:skip
|
||||
import kmk.types # 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.hid import USB_HID # isort:skip
|
||||
from kmk.internal_state import InternalState # isort:skip
|
||||
@ -100,6 +102,71 @@ class Firmware:
|
||||
|
||||
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):
|
||||
self._hid_helper_inst.create_report(self._state.keys_pressed).send()
|
||||
self._state.resolve_hid()
|
||||
@ -211,8 +278,7 @@ class Firmware:
|
||||
if not isinstance(k, tuple):
|
||||
del self.leader_dictionary[k]
|
||||
|
||||
if self.debug_enabled:
|
||||
print("Firin' lazers. Keyboard is booted.")
|
||||
self._print_debug_cycle(init=True)
|
||||
|
||||
while True:
|
||||
state_changed = False
|
||||
@ -246,5 +312,5 @@ class Firmware:
|
||||
if self._state.hid_pending:
|
||||
self._send_hid()
|
||||
|
||||
if self.debug_enabled and state_changed:
|
||||
print('New State: {}'.format(self._state._to_dict()))
|
||||
if state_changed:
|
||||
self._print_debug_cycle()
|
||||
|
@ -38,9 +38,9 @@ def bootloader(*args, **kwargs):
|
||||
|
||||
def debug_pressed(key, state, KC, *args, **kwargs):
|
||||
if state.config.debug_enabled:
|
||||
print('Disabling debug mode, bye!')
|
||||
print('DebugDisable()')
|
||||
else:
|
||||
print('Enabling debug mode. Welcome to the jungle.')
|
||||
print('DebugEnable()')
|
||||
|
||||
state.config.debug_enabled = not state.config.debug_enabled
|
||||
|
||||
|
@ -21,6 +21,12 @@ class USB_HID:
|
||||
|
||||
self.post_init()
|
||||
|
||||
def __repr__(self):
|
||||
return '{}(REPORT_BYTES={})'.format(
|
||||
self.__class__.__name__,
|
||||
self.REPORT_BYTES,
|
||||
)
|
||||
|
||||
def post_init(self):
|
||||
pass
|
||||
|
||||
|
@ -30,21 +30,37 @@ class InternalState:
|
||||
self.config = config
|
||||
|
||||
def __repr__(self):
|
||||
return 'InternalState({})'.format(self._to_dict())
|
||||
|
||||
def _to_dict(self):
|
||||
ret = {
|
||||
'keys_pressed': self.keys_pressed,
|
||||
'active_layers': self.active_layers,
|
||||
'leader_mode_history': self.leader_mode_history,
|
||||
'leader_mode': self.config.leader_mode,
|
||||
'start_time': self.start_time,
|
||||
'tapping': self.tapping,
|
||||
'tap_dance_counts': self.tap_dance_counts,
|
||||
'timeouts': self.timeouts,
|
||||
}
|
||||
|
||||
return ret
|
||||
return (
|
||||
'InternalState('
|
||||
'keys_pressed={} '
|
||||
'coord_keys_pressed={} '
|
||||
'leader_pending={} '
|
||||
'leader_last_len={} '
|
||||
'hid_pending={} '
|
||||
'leader_mode_history={} '
|
||||
'active_layers={} '
|
||||
'reversed_active_layers={} '
|
||||
'start_time={} '
|
||||
'timeouts={} '
|
||||
'tapping={} '
|
||||
'tap_dance_counts={} '
|
||||
'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):
|
||||
ic = intify_coordinate(row, col)
|
||||
@ -54,7 +70,7 @@ class InternalState:
|
||||
except ValueError:
|
||||
if self.config.debug_enabled:
|
||||
print(
|
||||
'No coord_mapping index for value {}, row={} col={}'.format(
|
||||
'CoordMappingNotFound(ic={}, row={}, col={})'.format(
|
||||
ic,
|
||||
row,
|
||||
col,
|
||||
@ -72,7 +88,7 @@ class InternalState:
|
||||
continue
|
||||
|
||||
if self.config.debug_enabled:
|
||||
print('Resolved key: {}'.format(layer_key))
|
||||
print('KeyResolution(key={})'.format(layer_key))
|
||||
|
||||
return layer_key
|
||||
|
||||
@ -112,20 +128,23 @@ class InternalState:
|
||||
|
||||
def matrix_changed(self, row, col, is_pressed):
|
||||
if self.config.debug_enabled:
|
||||
print('Matrix changed (col, row, pressed?): {}, {}, {}'.format(
|
||||
col, row, is_pressed,
|
||||
print('MatrixChange(col={} row={} pressed={})'.format(
|
||||
col,
|
||||
row,
|
||||
is_pressed,
|
||||
))
|
||||
|
||||
int_coord = intify_coordinate(row, col)
|
||||
kc_changed = self._find_key_in_map(row, col)
|
||||
|
||||
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.process_key(kc_changed, is_pressed, int_coord, (row, col))
|
||||
|
||||
def process_key(self, key, is_pressed, coord_int=None, coord_raw=None):
|
||||
|
||||
if self.tapping and not isinstance(key.meta, TapDanceKeyMeta):
|
||||
self._process_tap_dance(key, is_pressed)
|
||||
else:
|
||||
|
Loading…
x
Reference in New Issue
Block a user