Skip to content
Snippets Groups Projects
Commit 08f65e56 authored by Daniel Hoffend's avatar Daniel Hoffend
Browse files

make led modes iterable in the python way

parent 5bcdb8a6
No related branches found
No related tags found
No related merge requests found
Pipeline #3852 passed
......@@ -6,6 +6,7 @@ import buttons
import max30001
import math
import struct
import itertools
WIDTH = 160
HEIGHT = 80
......@@ -24,11 +25,17 @@ COLOR_MODE_FINGER = [0, 255, 0]
COLOR_MODE_USB = [0, 0, 255]
COLOR_WRITE_FG = [255, 255, 255]
COLOR_WRITE_BG = [255, 0, 0]
LED_FLAG_BAR = 1
LED_FLAG_PULSE = 2
current_mode = MODE_FINGER
led_mode = LED_FLAG_BAR + LED_FLAG_PULSE
modes = itertools.cycle(
[
({"bar", "pulse"}, {"text": "Top + Pulse", "posx": 0}),
({}, {"text": "off", "posx": 55}),
({"bar"}, {"text": "Top Only", "posx": 25}),
({"pulse"}, {"text": "Pulse Only", "posx": 5}),
]
)
led_mode = next(modes)[0]
history = []
filebuffer = bytearray()
write = 0
......@@ -240,21 +247,13 @@ def toggle_pause():
def toggle_leds():
global led_mode, disp, pause_screen, leds
led_mode = (led_mode + 1) % 4
global led_mode, disp, pause_screen, leds, modes
led_mode, display_args = next(modes)
pause_screen = utime.time_ms() + 250
disp.clear(COLOR_BACKGROUND)
disp.print("LEDs", posx=50, posy=20, fg=COLOR_TEXT)
if not led_mode:
disp.print("off", posx=55, posy=40, fg=COLOR_TEXT)
elif led_mode == LED_FLAG_BAR:
disp.print("Top only", posx=25, posy=40, fg=COLOR_TEXT)
elif led_mode == LED_FLAG_PULSE:
disp.print("Pulse only", posx=5, posy=40, fg=COLOR_TEXT)
elif led_mode == LED_FLAG_BAR + LED_FLAG_PULSE:
disp.print("Top + Pulse", posx=0, posy=40, fg=COLOR_TEXT)
disp.print(**display_args, posy=40, fg=COLOR_TEXT)
disp.update()
leds.clear()
......@@ -265,11 +264,11 @@ def draw_leds(vmin, vmax):
global pulse, samples_since_last_pulse, last_pulse_blink
# stop blinking
if not led_mode:
if not bool(led_mode):
return
# update led bar
if led_mode & LED_FLAG_BAR:
if "bar" in led_mode:
for i in reversed(range(6)):
leds.prep_hsv(
5 + i, COLORS[5 + i] if vmin <= 0 and i <= vmin * -6 else (0, 0, 0)
......@@ -281,13 +280,13 @@ def draw_leds(vmin, vmax):
# blink red on pulse
if (
led_mode & LED_FLAG_PULSE
"pulse" in led_mode
and pulse > 0
and samples_since_last_pulse < last_pulse_blink
):
for i in range(4):
leds.prep(11 + i, (255, 0, 0))
elif led_mode & LED_FLAG_PULSE:
elif "pulse" in led_mode:
for i in range(4):
leds.prep(11 + i, (0, 0, 0))
last_pulse_blink = samples_since_last_pulse
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment