Skip to content
Snippets Groups Projects
Commit 02de39bc 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
...@@ -6,6 +6,7 @@ import buttons ...@@ -6,6 +6,7 @@ import buttons
import max30001 import max30001
import math import math
import struct import struct
import itertools
WIDTH = 160 WIDTH = 160
HEIGHT = 80 HEIGHT = 80
...@@ -24,11 +25,15 @@ COLOR_MODE_FINGER = [0, 255, 0] ...@@ -24,11 +25,15 @@ COLOR_MODE_FINGER = [0, 255, 0]
COLOR_MODE_USB = [0, 0, 255] COLOR_MODE_USB = [0, 0, 255]
COLOR_WRITE_FG = [255, 255, 255] COLOR_WRITE_FG = [255, 255, 255]
COLOR_WRITE_BG = [255, 0, 0] COLOR_WRITE_BG = [255, 0, 0]
LED_FLAG_BAR = 1
LED_FLAG_PULSE = 2
current_mode = MODE_FINGER 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 = [] history = []
filebuffer = bytearray() filebuffer = bytearray()
write = 0 write = 0
...@@ -240,21 +245,13 @@ def toggle_pause(): ...@@ -240,21 +245,13 @@ def toggle_pause():
def toggle_leds(): def toggle_leds():
global led_mode, disp, pause_screen, leds global led_mode, disp, pause_screen, leds, modes
led_mode = (led_mode + 1) % 4 led_mode, display_args = next(modes)
pause_screen = utime.time_ms() + 250 pause_screen = utime.time_ms() + 250
disp.clear(COLOR_BACKGROUND) disp.clear(COLOR_BACKGROUND)
disp.print("LEDs", posx=50, posy=20, fg=COLOR_TEXT) disp.print("LEDs", posx=50, posy=20, fg=COLOR_TEXT)
if not led_mode: disp.print(**display_args, posy=40, fg=COLOR_TEXT)
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.update() disp.update()
leds.clear() leds.clear()
...@@ -265,11 +262,11 @@ def draw_leds(vmin, vmax): ...@@ -265,11 +262,11 @@ def draw_leds(vmin, vmax):
global pulse, samples_since_last_pulse, last_pulse_blink global pulse, samples_since_last_pulse, last_pulse_blink
# stop blinking # stop blinking
if not led_mode: if not bool(led_mode):
return return
# update led bar # update led bar
if led_mode & LED_FLAG_BAR: if "bar" in led_mode:
for i in reversed(range(6)): for i in reversed(range(6)):
leds.prep_hsv( leds.prep_hsv(
5 + i, COLORS[5 + i] if vmin <= 0 and i <= vmin * -6 else (0, 0, 0) 5 + i, COLORS[5 + i] if vmin <= 0 and i <= vmin * -6 else (0, 0, 0)
...@@ -281,13 +278,13 @@ def draw_leds(vmin, vmax): ...@@ -281,13 +278,13 @@ def draw_leds(vmin, vmax):
# blink red on pulse # blink red on pulse
if ( if (
led_mode & LED_FLAG_PULSE "pulse" in led_mode
and pulse > 0 and pulse > 0
and samples_since_last_pulse < last_pulse_blink and samples_since_last_pulse < last_pulse_blink
): ):
for i in range(4): for i in range(4):
leds.prep(11 + i, (255, 0, 0)) leds.prep(11 + i, (255, 0, 0))
elif led_mode & LED_FLAG_PULSE: elif "pulse" in led_mode:
for i in range(4): for i in range(4):
leds.prep(11 + i, (0, 0, 0)) leds.prep(11 + i, (0, 0, 0))
last_pulse_blink = samples_since_last_pulse 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