feat: Visual feedback on LEDs during startup

Set the LEDs to a fixed color during bootup to show the different modes:
- Orange when the device is booting
- Red when button 0 is held and the device goes to a shell
- Blue when button 1 is held and the device goes to AP mode instead of
  joining the configured WiFi network
- Red blinking when the run() method throws an exception for any reason

Signed-off-by: Matthias Blankertz <matthias@blankertz.org>
This commit is contained in:
2025-12-23 11:49:28 +01:00
parent 58f8526d7e
commit 02954cd87c

View File

@@ -10,6 +10,7 @@ import network
import os
import time
import ubinascii
import sys
# Own modules
import app
@@ -73,13 +74,18 @@ DB_PATH = '/sd/tonberry.db'
config = Configuration()
# Setup LEDs
np = NeoPixel(hwconfig.LED_DIN, config.get_led_count(), sm=1)
np.fill((32, 32, 0))
np.write()
def run():
asyncio.new_event_loop()
# Setup LEDs
np = NeoPixel(hwconfig.LED_DIN, config.get_led_count(), sm=1)
if machine.Pin(hwconfig.BUTTONS[1], machine.Pin.IN, machine.Pin.PULL_UP).value() == 0:
np.fill((0, 0, 32))
np.write()
# Force default access point
setup_wifi('', '')
else:
@@ -141,7 +147,24 @@ def builddb():
os.sync()
def error_blink():
while True:
np.fill((32, 0, 0))
np.write()
time.sleep_ms(500)
np.fill((0, 0, 0))
np.write()
time.sleep_ms(500)
if __name__ == '__main__':
time.sleep(1)
if machine.Pin(hwconfig.BUTTONS[0], machine.Pin.IN, machine.Pin.PULL_UP).value() != 0:
run()
try:
run()
except Exception as ex:
sys.print_exception(ex)
error_blink()
else:
np.fill((32, 0, 0))
np.write()