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