unit tests for execution in desktop dev environment

This commit is contained in:
Christian Tu
2021-12-05 15:24:51 +01:00
committed by Josh Klar
parent e70ce5f431
commit b6201d43d4
9 changed files with 285 additions and 34 deletions

View File

@@ -53,6 +53,7 @@ class AbstractHID:
REPORT_BYTES = 8
def __init__(self, **kwargs):
self._prev_evt = bytearray(self.REPORT_BYTES)
self._evt = bytearray(self.REPORT_BYTES)
self.report_device = memoryview(self._evt)[0:1]
self.report_device[0] = HIDReportTypes.KEYBOARD
@@ -125,7 +126,10 @@ class AbstractHID:
pass
def send(self):
self.hid_send(self._evt)
changed = not self._evt.startswith(self._prev_evt)
if changed:
self._prev_evt[:] = self._evt
self.hid_send(self._evt)
return self

View File

@@ -373,6 +373,11 @@ class KMKKeyboard:
print('Failed to run post hid function in extension: ', err, ext)
def go(self, hid_type=HIDModes.USB, secondary_hid_type=None, **kwargs):
self._init(hid_type=hid_type, secondary_hid_type=secondary_hid_type, **kwargs)
while True:
self._main_loop()
def _init(self, hid_type=HIDModes.USB, secondary_hid_type=None, **kwargs):
self._go_args = kwargs
self.hid_type = hid_type
self.secondary_hid_type = secondary_hid_type
@@ -398,46 +403,44 @@ class KMKKeyboard:
self._print_debug_cycle(init=True)
while True:
self.current_key = None
self.state_changed = False
self.sandbox.active_layers = self.active_layers.copy()
def _main_loop(self):
self.current_key = None
self.state_changed = False
self.sandbox.active_layers = self.active_layers.copy()
self.before_matrix_scan()
self.before_matrix_scan()
self.matrix_update = (
self.sandbox.matrix_update
) = self.matrix.scan_for_changes()
self.sandbox.secondary_matrix_update = self.secondary_matrix_update
self.matrix_update = self.sandbox.matrix_update = self.matrix.scan_for_changes()
self.sandbox.secondary_matrix_update = self.secondary_matrix_update
self.after_matrix_scan()
self.after_matrix_scan()
self._handle_matrix_report(self.secondary_matrix_update)
self.secondary_matrix_update = None
self._handle_matrix_report(self.matrix_update)
self.matrix_update = None
self._handle_matrix_report(self.secondary_matrix_update)
self.secondary_matrix_update = None
self._handle_matrix_report(self.matrix_update)
self.matrix_update = None
self.before_hid_send()
self.before_hid_send()
if self.hid_pending:
self._send_hid()
self._old_timeouts_len = len(self._timeouts)
self._process_timeouts()
self._new_timeouts_len = len(self._timeouts)
if self._old_timeouts_len != self._new_timeouts_len:
self.state_changed = True
if self.hid_pending:
self._send_hid()
self._old_timeouts_len = len(self._timeouts)
self._process_timeouts()
self._new_timeouts_len = len(self._timeouts)
self.after_hid_send()
if self._old_timeouts_len != self._new_timeouts_len:
self.state_changed = True
if self.hid_pending:
self._send_hid()
if self._trigger_powersave_enable:
self.powersave_enable()
self.after_hid_send()
if self._trigger_powersave_disable:
self.powersave_disable()
if self._trigger_powersave_enable:
self.powersave_enable()
if self._trigger_powersave_disable:
self.powersave_disable()
if self.state_changed:
self._print_debug_cycle()
if self.state_changed:
self._print_debug_cycle()

View File

@@ -44,8 +44,7 @@ class HoldTap(Module):
self.ht_activate_on_interrupt(
key, keyboard, *state.args, **state.kwargs
)
if keyboard.hid_pending:
keyboard._send_hid()
keyboard._send_hid()
return current_key
def before_hid_send(self, keyboard):