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:
52
tests/patterns/radiate.py
Normal file
52
tests/patterns/radiate.py
Normal 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] radiate: 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] radiate: auto phase begin")
|
||||
p.edit("test_pattern", {"p": "radiate", "b": 64, "a": True, "d": 3000, "c": [(255, 0, 0), (0, 0, 255)]})
|
||||
if not p.select("test_pattern"):
|
||||
raise Exception("radiate 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("radiate delay scheduling invalid")
|
||||
print("[test] radiate: auto phase end")
|
||||
|
||||
print("[test] radiate: manual phase begin")
|
||||
p.edit("test_pattern", {"p": "radiate", "b": 64, "a": False, "d": 3000, "c": [(255, 0, 0), (0, 0, 255)]})
|
||||
if not p.select("test_pattern", step=0):
|
||||
raise Exception("radiate 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("radiate external select failed")
|
||||
p.run_step()
|
||||
wdt.feed()
|
||||
if int(p.step) == current_step:
|
||||
raise Exception("radiate external step did not advance")
|
||||
if p.generator is not None:
|
||||
raise Exception("radiate 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] radiate: manual phase end")
|
||||
print("[test] radiate: pass")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user