Skip to content

Commit

Permalink
Implement automatic firmware reload and show error stacktrace
Browse files Browse the repository at this point in the history
Trigger a supervisor reload on any exception, restarting the firmware; unless
it's a keyboard interrupt in which case we explicitly want to drop into the
REPL.
Replace the sparse debug error message with a stacktrace.
  • Loading branch information
xs5871 committed Jun 8, 2024
1 parent 05b96e0 commit e79414e
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions kmk/kmk_keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,18 +461,29 @@ def deinit(self) -> None:
debug_error(ext, 'deinit', err)

def go(self, hid_type=HIDModes.USB, secondary_hid_type=None, **kwargs) -> None:
self._init(hid_type=hid_type, secondary_hid_type=secondary_hid_type, **kwargs)
try:
self._init(
hid_type=hid_type,
secondary_hid_type=secondary_hid_type,
**kwargs,
)
while True:
self._main_loop()
except Exception as err:
debug_error(self, 'Unexpected error', err)
import traceback

traceback.print_exception(err)
finally:
debug('cleaning up...')
self._deinit_hid()
self.deinit()
debug('...done')

if not debug.enabled:
import supervisor

supervisor.reload()

def _init(
self,
hid_type: HIDModes = HIDModes.USB,
Expand Down

0 comments on commit e79414e

Please sign in to comment.