feat(patterns): align manual and auto behaviour

Unify manual/auto timing semantics for key patterns, add preset background support, and improve runtime observability while keeping the driver responsive under beat-triggered selects.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-05-09 20:07:58 +12:00
parent 4879fcfe90
commit 170a0e05ab
15 changed files with 301 additions and 197 deletions

52
tests/patterns/twinkle.py Normal file
View File

@@ -0,0 +1,52 @@
#!/usr/bin/env python3
import utime
from machine import WDT
from settings import Settings
from presets import Presets
def main():
print("[test] twinkle: start")
s = Settings()
p = Presets(pin=s.get("led_pin", 10), num_leds=s.get("num_leds", 30))
p.debug = True
wdt = WDT(timeout=10000)
print("[test] twinkle: auto phase begin")
p.edit("test_pattern", {"p": "twinkle", "b": 64, "a": True, "d": 3000, "c": [(255, 0, 0), (0, 0, 255)]})
if not p.select("test_pattern"):
raise Exception("twinkle select failed in auto phase")
auto_start = utime.ticks_ms()
while utime.ticks_diff(utime.ticks_ms(), auto_start) < 2500:
wdt.feed()
p.run_step()
utime.sleep_ms(20)
remaining_ms = utime.ticks_diff(p.next_tick_ms, utime.ticks_ms())
if p.next_tick_ms == 0 or remaining_ms <= 0:
raise Exception("twinkle delay scheduling invalid")
print("[test] twinkle: auto phase end")
print("[test] twinkle: manual phase begin")
p.edit("test_pattern", {"p": "twinkle", "b": 64, "a": False, "d": 3000, "c": [(255, 0, 0), (0, 0, 255)]})
if not p.select("test_pattern", step=0):
raise Exception("twinkle select failed in manual phase")
for _ in range(6):
current_step = int(p.step)
if not p.select("test_pattern", step=current_step):
raise Exception("twinkle external select failed")
p.run_step()
wdt.feed()
if int(p.step) == current_step:
raise Exception("twinkle external step did not advance")
if p.generator is not None:
raise Exception("twinkle manual mode rescheduled generator")
hold_start = utime.ticks_ms()
while utime.ticks_diff(utime.ticks_ms(), hold_start) < 700:
wdt.feed()
utime.sleep_ms(20)
print("[test] twinkle: manual phase end")
print("[test] twinkle: pass")
if __name__ == "__main__":
main()