From ea18655a210592f04af2c8070f980936b1e22907 Mon Sep 17 00:00:00 2001 From: Josh Klar Date: Mon, 3 Sep 2018 15:20:27 -0700 Subject: [PATCH] On unhandled exceptions, blink the feather LED repeatedly --- entrypoints/feather_nrf52832.py | 10 +++++++++- kmk/circuitpython/util.py | 12 +++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/entrypoints/feather_nrf52832.py b/entrypoints/feather_nrf52832.py index c07d83c..a21b146 100644 --- a/entrypoints/feather_nrf52832.py +++ b/entrypoints/feather_nrf52832.py @@ -1,4 +1,12 @@ +import sys + +from kmk.circuitpython.util import feather_red_led_flash from kmk_keyboard_user import main if __name__ == '__main__': - main() + try: + main() + except Exception as e: + sys.print_exception(e) + feather_red_led_flash(duration=10, rate=0.5) + sys.exit(1) diff --git a/kmk/circuitpython/util.py b/kmk/circuitpython/util.py index 0b822b1..a0575f7 100644 --- a/kmk/circuitpython/util.py +++ b/kmk/circuitpython/util.py @@ -1,23 +1,17 @@ -import sys import time import board import digitalio -def feather_signal_error_with_led_flash(rate=0.5): +def feather_red_led_flash(duration=10, rate=0.5): ''' - Flash the red LED for 10 seconds, alternating every $rate - Could be useful as an uncaught exception handler later on, - but is for now unused + Flash the red LED for $duration seconds, alternating every $rate ''' rled = digitalio.DigitalInOut(board.LED1) rled.direction = digitalio.Direction.OUTPUT - # blink for 5 seconds and exit - for cycle in range(10): + for cycle in range(duration / rate): rled.value = cycle % 2 time.sleep(rate) - - sys.exit(1)