Skip to content

Commit

Permalink
add start_watchdog() method
Browse files Browse the repository at this point in the history
  • Loading branch information
regicidalplutophage committed Dec 18, 2024
1 parent 8e8dccf commit eaa0c03
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 14 additions & 4 deletions kmk/hid.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from storage import getmount

from kmk.keys import ConsumerKey, KeyboardKey, ModifierKey, MouseKey
from kmk.scheduler import create_task

# from kmk.scheduler import create_task
from kmk.utils import Debug, clamp
Expand Down Expand Up @@ -65,7 +66,7 @@ def __init__(self, **kwargs):
self._nkro = False
self._mouse = True
self._pan = False
self.make_device_list()
self.find_devices()

self._cc_report = bytearray(HID_REPORT_SIZES[HIDReportTypes.CONSUMER] + 1)
self._cc_report[0] = HIDReportTypes.CONSUMER
Expand All @@ -74,7 +75,7 @@ def __init__(self, **kwargs):
self.test_nkro()
self.test_mouse()

def make_device_list(self):
def find_devices(self):
self.devices = {}

for device in self.hid_devices:
Expand Down Expand Up @@ -150,6 +151,9 @@ def test_mouse(self):
def watchdog(self):
return

def start_watchdog(self):
return

def __repr__(self):
return f'{self.__class__.__name__}(REPORT_BYTES={self.REPORT_BYTES})'

Expand Down Expand Up @@ -307,10 +311,13 @@ def __init__(self, **kwargs):
def watchdog(self):
if self.usb_status != supervisor.runtime.usb_connected:
self.usb_status = supervisor.runtime.usb_connected
self.make_device_list()
self.find_devices()
self.test_nkro()
self.test_mouse()

def start_watchdog(self, period_ms=200):
return create_task(self.watchdog, period_ms=period_ms)

def hid_send(self, evt):
if not supervisor.runtime.usb_connected:
return
Expand Down Expand Up @@ -347,7 +354,10 @@ def __init__(self, ble_name=str(getmount('/').label), **kwargs):
def watchdog(self):
if self.ble_status != self.ble.connected:
self.ble_status = self.ble.connected
self.make_device_list()
self.find_devices()

def start_watchdog(self, period_ms=200):
return create_task(self.watchdog, period_ms=period_ms)

def hid_send(self, evt):
if not self.ble.connected:
Expand Down
2 changes: 1 addition & 1 deletion kmk/kmk_keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def _init_hid(self) -> None:
else:
self._hid_helper = AbstractHID
self._hid_helper = self._hid_helper(**self._go_args)
self._watchdog = create_task(self._hid_helper.watchdog, period_ms=200)
self._hid_helper.start_watchdog()
self._hid_send_enabled = True

if debug.enabled:
Expand Down

0 comments on commit eaa0c03

Please sign in to comment.