feat(patterns): merge pattern styles and add mode support
Consolidate legacy pattern ids into meteor, particles, sparkle, chase, and colour_cycle with n6/mode style selection; add pattern_modes helper, self-contained tests/all.py, and preset mode alias on wire. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
159
tests/all.py
159
tests/all.py
@@ -1,14 +1,50 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Self-contained led-driver test runner for MicroPython/mpremote."""
|
||||
"""Self-contained led-driver test runner for MicroPython/mpremote.
|
||||
|
||||
Run on device (from led-driver repo root)::
|
||||
|
||||
mpremote connect <port> run tests/all.py
|
||||
|
||||
Or via dev helper::
|
||||
|
||||
python dev.py <port> test
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import utime
|
||||
from machine import WDT
|
||||
|
||||
from settings import Settings
|
||||
from presets import Presets, run_tick
|
||||
from utils import convert_and_reorder_colors
|
||||
|
||||
def _bootstrap_import_path():
|
||||
"""Find ``settings`` / ``presets`` whether this file lives in ``tests/`` or ``:/``."""
|
||||
try:
|
||||
import uos as os
|
||||
except ImportError:
|
||||
import os
|
||||
|
||||
candidates = []
|
||||
try:
|
||||
here = __file__.rsplit("/", 1)[0]
|
||||
if here:
|
||||
candidates.append(here)
|
||||
parent = here.rsplit("/", 1)[0]
|
||||
if parent:
|
||||
candidates.append(parent)
|
||||
except NameError:
|
||||
pass
|
||||
candidates.extend([".", "..", "/"])
|
||||
for p in candidates:
|
||||
if p and p not in sys.path:
|
||||
sys.path.insert(0, p)
|
||||
|
||||
|
||||
_bootstrap_import_path()
|
||||
|
||||
from settings import Settings # noqa: E402
|
||||
from presets import Presets, run_tick # noqa: E402
|
||||
from preset import Preset # noqa: E402
|
||||
from utils import convert_and_reorder_colors # noqa: E402
|
||||
|
||||
|
||||
class _TestContext:
|
||||
@@ -27,6 +63,20 @@ class _TestContext:
|
||||
utime.sleep_ms(sleep_ms)
|
||||
|
||||
|
||||
def _pattern_loaded(ctx, pattern_id):
|
||||
return pattern_id in ctx.presets.patterns
|
||||
|
||||
|
||||
def _smoke_preset(ctx, name, data, ms=80):
|
||||
pattern_id = data.get("p") or data.get("pattern")
|
||||
if not _pattern_loaded(ctx, pattern_id):
|
||||
raise AssertionError("pattern not loaded: %s" % pattern_id)
|
||||
ctx.presets.edit(name, data)
|
||||
if not ctx.presets.select(name):
|
||||
raise AssertionError("select failed: %s" % name)
|
||||
ctx.tick_for_ms(ms)
|
||||
|
||||
|
||||
def _process_message(ctx, payload):
|
||||
"""Small test helper that mirrors the main message handling logic."""
|
||||
try:
|
||||
@@ -93,8 +143,7 @@ def _process_message(ctx, payload):
|
||||
should_apply_default = this_device_name_norm in normalized_targets
|
||||
if (
|
||||
should_apply_default
|
||||
and
|
||||
isinstance(default_name, str)
|
||||
and isinstance(default_name, str)
|
||||
and default_name
|
||||
and default_name in ctx.presets.presets
|
||||
):
|
||||
@@ -145,6 +194,40 @@ def test_preset_edit_sanitization():
|
||||
assert not hasattr(p, "unknown_field")
|
||||
|
||||
|
||||
def test_preset_mode_alias_maps_to_n6():
|
||||
ctx = _TestContext()
|
||||
ctx.presets.edit(
|
||||
"rainbow_mode",
|
||||
{"pattern": "colour_cycle", "mode": 1, "d": 50, "n1": 2, "a": True},
|
||||
)
|
||||
p = ctx.presets.presets["rainbow_mode"]
|
||||
assert p.p == "colour_cycle"
|
||||
assert p.n6 == 1
|
||||
|
||||
|
||||
def test_style_mode_and_legacy_aliases():
|
||||
from patterns.pattern_modes import style_mode
|
||||
|
||||
p = Preset({"p": "colour_cycle", "mode": 0, "d": 50, "c": [(255, 0, 0)]})
|
||||
assert style_mode(p, 0, {"rainbow": 1}) == 0
|
||||
|
||||
legacy = Preset({"p": "rainbow", "d": 50, "c": [(255, 0, 0)]})
|
||||
assert style_mode(legacy, 0, {"rainbow": 1}) == 1
|
||||
|
||||
ctx = _TestContext()
|
||||
legacy_ids = (
|
||||
"rainbow",
|
||||
"meteor_rain",
|
||||
"snowfall",
|
||||
"sparkle_trail",
|
||||
"marquee",
|
||||
"northern_wave",
|
||||
)
|
||||
for lid in legacy_ids:
|
||||
if not _pattern_loaded(ctx, lid):
|
||||
raise AssertionError("legacy alias not registered: %s" % lid)
|
||||
|
||||
|
||||
def test_colour_conversion_and_transition():
|
||||
ctx = _TestContext()
|
||||
msg = {
|
||||
@@ -162,7 +245,6 @@ def test_colour_conversion_and_transition():
|
||||
result = _process_message(ctx, msg)
|
||||
assert result == "ok"
|
||||
assert ctx.presets.selected == "fade"
|
||||
# Smoke-run the generator to ensure math runs without type errors.
|
||||
ctx.tick_for_ms(250)
|
||||
|
||||
|
||||
@@ -172,19 +254,54 @@ def test_pattern_smoke():
|
||||
"t_on": {"p": "on", "c": [(16, 8, 4)]},
|
||||
"t_off": {"p": "off"},
|
||||
"t_blink": {"p": "blink", "c": [(255, 0, 0)], "d": 20},
|
||||
"t_rainbow": {"p": "rainbow", "d": 5, "n1": 2},
|
||||
"t_pulse": {"p": "pulse", "c": [(255, 0, 0)], "n1": 20, "n2": 10, "n3": 20, "d": 10},
|
||||
"t_transition": {"p": "transition", "c": [(255, 0, 0), (0, 0, 255)], "d": 30},
|
||||
"t_colour_cycle": {"p": "colour_cycle", "n6": 0, "d": 5, "n1": 2, "c": [(255, 0, 0), (0, 255, 0)]},
|
||||
"t_chase": {"p": "chase", "c": [(255, 0, 0), (0, 0, 255)], "n1": 3, "n2": 2, "n3": 1, "n4": 1, "d": 20},
|
||||
"t_circle": {"p": "circle", "c": [(255, 255, 0), (0, 0, 8)], "n1": 5, "n2": 10, "n3": 5, "n4": 2},
|
||||
}
|
||||
for name, data in cases.items():
|
||||
ctx.presets.edit(name, data)
|
||||
assert ctx.presets.select(name), "select failed: %s" % name
|
||||
ctx.tick_for_ms(120)
|
||||
_smoke_preset(ctx, name, data, ms=100)
|
||||
|
||||
|
||||
def test_merged_pattern_modes():
|
||||
"""Smoke each style (``n6`` / ``mode``) for merged multi-mode patterns."""
|
||||
ctx = _TestContext()
|
||||
colors = [(200, 220, 255), (255, 180, 80)]
|
||||
cases = (
|
||||
("mc_grad", "colour_cycle", {"p": "colour_cycle", "n6": 0, "n1": 2, "d": 8, "c": colors}),
|
||||
("mc_wheel", "colour_cycle", {"p": "colour_cycle", "mode": 1, "n1": 2, "d": 8}),
|
||||
("chase_std", "chase", {"p": "chase", "n6": 0, "n1": 2, "n2": 2, "n3": 1, "n4": 1, "d": 15, "c": colors}),
|
||||
("chase_marq", "chase", {"p": "chase", "n6": 1, "n1": 3, "n2": 2, "n3": 1, "d": 15, "c": colors}),
|
||||
("meteor_0", "meteor", {"p": "meteor", "n6": 0, "n1": 4, "n2": 2, "n3": 8, "d": 10, "c": colors}),
|
||||
("meteor_1", "meteor", {"p": "meteor", "n6": 1, "n1": 3, "n2": 2, "n3": 4, "d": 10, "c": colors}),
|
||||
("part_0", "particles", {"p": "particles", "n6": 0, "n1": 4, "n2": 1, "d": 10, "c": colors}),
|
||||
("part_1", "particles", {"p": "particles", "mode": 1, "n1": 3, "n2": 1, "n3": 4, "d": 10, "c": colors}),
|
||||
("spark_0", "sparkle", {"p": "sparkle", "n6": 0, "n1": 4, "n2": 6, "d": 10, "c": colors}),
|
||||
("spark_1", "sparkle", {"p": "sparkle", "n6": 1, "n1": 3, "n2": 4, "n3": 2, "d": 10, "c": colors}),
|
||||
("aurora_0", "aurora", {"p": "aurora", "n6": 0, "n1": 3, "n2": 2, "n3": 0, "d": 12, "c": colors}),
|
||||
("aurora_1", "aurora", {"p": "aurora", "mode": 1, "n1": 8, "n2": 2, "n3": 1, "d": 12, "c": colors}),
|
||||
)
|
||||
for name, pattern_id, data in cases:
|
||||
if not _pattern_loaded(ctx, pattern_id):
|
||||
continue
|
||||
_smoke_preset(ctx, name, data, ms=60)
|
||||
|
||||
legacy_smoke = (
|
||||
("leg_rainbow", "rainbow", {"p": "rainbow", "d": 8, "n1": 2}),
|
||||
("leg_ice", "ice_sparkle", {"p": "ice_sparkle", "n1": 3, "n2": 2, "n3": 2, "d": 10, "c": colors}),
|
||||
("leg_wave", "northern_wave", {"p": "northern_wave", "n1": 6, "n2": 2, "n3": 1, "d": 12, "c": colors}),
|
||||
("leg_star", "starfall", {"p": "starfall", "n1": 3, "n2": 1, "n3": 3, "d": 10, "c": colors}),
|
||||
)
|
||||
for name, pattern_id, data in legacy_smoke:
|
||||
if not _pattern_loaded(ctx, pattern_id):
|
||||
continue
|
||||
_smoke_preset(ctx, name, data, ms=60)
|
||||
|
||||
|
||||
def test_patterns_do_not_use_blocking_sleep():
|
||||
try:
|
||||
import uos as os
|
||||
except ImportError:
|
||||
import os
|
||||
|
||||
pattern_dir = "patterns"
|
||||
offenders = []
|
||||
try:
|
||||
@@ -192,8 +309,9 @@ def test_patterns_do_not_use_blocking_sleep():
|
||||
except OSError:
|
||||
raise AssertionError("patterns directory is missing")
|
||||
|
||||
skip = frozenset(("__init__.py", "main.py", "pattern_modes.py"))
|
||||
for filename in files:
|
||||
if not filename.endswith(".py") or filename in ("__init__.py", "main.py"):
|
||||
if not filename.endswith(".py") or filename in skip:
|
||||
continue
|
||||
path = pattern_dir + "/" + filename
|
||||
try:
|
||||
@@ -223,6 +341,7 @@ def test_default_requires_existing_preset():
|
||||
_process_message(ctx, {"v": "1", "default": "exists"})
|
||||
assert ctx.settings.get("default") == "exists"
|
||||
|
||||
|
||||
def test_default_targets_gate_by_device_name():
|
||||
ctx = _TestContext()
|
||||
ctx.settings["name"] = "a"
|
||||
@@ -243,6 +362,11 @@ def test_default_targets_gate_by_device_name():
|
||||
|
||||
|
||||
def test_save_and_load_roundtrip():
|
||||
try:
|
||||
import uos as os
|
||||
except ImportError:
|
||||
import os
|
||||
|
||||
ctx = _TestContext()
|
||||
ctx.presets.edit(
|
||||
"persist",
|
||||
@@ -270,8 +394,11 @@ def run_all():
|
||||
tests = [
|
||||
test_invalid_messages_do_not_crash,
|
||||
test_preset_edit_sanitization,
|
||||
test_preset_mode_alias_maps_to_n6,
|
||||
test_style_mode_and_legacy_aliases,
|
||||
test_colour_conversion_and_transition,
|
||||
test_pattern_smoke,
|
||||
test_merged_pattern_modes,
|
||||
test_patterns_do_not_use_blocking_sleep,
|
||||
test_default_requires_existing_preset,
|
||||
test_default_targets_gate_by_device_name,
|
||||
|
||||
@@ -1,190 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
import utime
|
||||
from machine import WDT
|
||||
from settings import Settings
|
||||
from presets import Presets, run_tick
|
||||
|
||||
|
||||
def run_for(p, wdt, duration_ms):
|
||||
"""Run pattern for specified duration."""
|
||||
start = utime.ticks_ms()
|
||||
while utime.ticks_diff(utime.ticks_ms(), start) < duration_ms:
|
||||
wdt.feed()
|
||||
run_tick(p)
|
||||
utime.sleep_ms(10)
|
||||
|
||||
|
||||
def main():
|
||||
s = Settings()
|
||||
pin = s.get("led_pin", 10)
|
||||
num = s.get("num_leds", 30)
|
||||
|
||||
p = Presets(pin=pin, num_leds=num)
|
||||
wdt = WDT(timeout=10000)
|
||||
|
||||
print("=" * 50)
|
||||
print("Testing Auto and Manual Modes")
|
||||
print("=" * 50)
|
||||
|
||||
# Test 1: Rainbow in AUTO mode (continuous)
|
||||
print("\nTest 1: Rainbow pattern in AUTO mode (should run continuously)")
|
||||
p.edit("rainbow_auto", {
|
||||
"p": "rainbow",
|
||||
"b": 128,
|
||||
"d": 50,
|
||||
"n1": 2,
|
||||
"a": True,
|
||||
})
|
||||
p.select("rainbow_auto")
|
||||
print("Running rainbow_auto for 3 seconds...")
|
||||
run_for(p, wdt, 3000)
|
||||
print("✓ Auto mode: Pattern ran continuously")
|
||||
|
||||
# Test 2: Rainbow in MANUAL mode (one step per tick)
|
||||
print("\nTest 2: Rainbow pattern in MANUAL mode (one step per tick)")
|
||||
p.edit("rainbow_manual", {
|
||||
"p": "rainbow",
|
||||
"b": 128,
|
||||
"d": 50,
|
||||
"n1": 2,
|
||||
"a": False,
|
||||
})
|
||||
p.select("rainbow_manual")
|
||||
print("Calling tick() 5 times (should advance 5 steps)...")
|
||||
for i in range(5):
|
||||
run_tick(p)
|
||||
utime.sleep_ms(100) # Small delay to see changes
|
||||
print(f" Tick {i+1}: generator={'active' if p.generator is not None else 'stopped'}")
|
||||
|
||||
# Check if generator stopped after one cycle
|
||||
if p.generator is None:
|
||||
print("✓ Manual mode: Generator stopped after one step (as expected)")
|
||||
else:
|
||||
print("⚠ Manual mode: Generator still active (may need multiple ticks)")
|
||||
|
||||
# Test 3: Pulse in AUTO mode (continuous cycles)
|
||||
print("\nTest 3: Pulse pattern in AUTO mode (should pulse continuously)")
|
||||
p.edit("pulse_auto", {
|
||||
"p": "pulse",
|
||||
"b": 128,
|
||||
"d": 100,
|
||||
"n1": 500, # Attack
|
||||
"n2": 200, # Hold
|
||||
"n3": 500, # Decay
|
||||
"c": [(255, 0, 0)],
|
||||
"a": True,
|
||||
})
|
||||
p.select("pulse_auto")
|
||||
print("Running pulse_auto for 3 seconds...")
|
||||
run_for(p, wdt, 3000)
|
||||
print("✓ Auto mode: Pulse ran continuously")
|
||||
|
||||
# Test 4: Pulse in MANUAL mode (one cycle then stop)
|
||||
print("\nTest 4: Pulse pattern in MANUAL mode (one cycle then stop)")
|
||||
p.edit("pulse_manual", {
|
||||
"p": "pulse",
|
||||
"b": 128,
|
||||
"d": 100,
|
||||
"n1": 300, # Attack
|
||||
"n2": 200, # Hold
|
||||
"n3": 300, # Decay
|
||||
"c": [(0, 255, 0)],
|
||||
"a": False,
|
||||
})
|
||||
p.select("pulse_manual")
|
||||
print("Running pulse_manual until generator stops...")
|
||||
tick_count = 0
|
||||
max_ticks = 200 # Safety limit
|
||||
while p.generator is not None and tick_count < max_ticks:
|
||||
run_tick(p)
|
||||
tick_count += 1
|
||||
utime.sleep_ms(10)
|
||||
|
||||
if p.generator is None:
|
||||
print(f"✓ Manual mode: Pulse completed one cycle after {tick_count} ticks")
|
||||
else:
|
||||
print(f"⚠ Manual mode: Pulse still running after {tick_count} ticks")
|
||||
|
||||
# Test 5: Transition in AUTO mode (continuous transitions)
|
||||
print("\nTest 5: Transition pattern in AUTO mode (continuous transitions)")
|
||||
p.edit("transition_auto", {
|
||||
"p": "transition",
|
||||
"b": 128,
|
||||
"d": 500,
|
||||
"c": [(255, 0, 0), (0, 255, 0), (0, 0, 255)],
|
||||
"a": True,
|
||||
})
|
||||
p.select("transition_auto")
|
||||
print("Running transition_auto for 3 seconds...")
|
||||
run_for(p, wdt, 3000)
|
||||
print("✓ Auto mode: Transition ran continuously")
|
||||
|
||||
# Test 6: Transition in MANUAL mode (one transition then stop)
|
||||
print("\nTest 6: Transition pattern in MANUAL mode (one transition then stop)")
|
||||
p.edit("transition_manual", {
|
||||
"p": "transition",
|
||||
"b": 128,
|
||||
"d": 500,
|
||||
"c": [(255, 0, 0), (0, 255, 0)],
|
||||
"a": False,
|
||||
})
|
||||
p.select("transition_manual")
|
||||
print("Running transition_manual until generator stops...")
|
||||
tick_count = 0
|
||||
max_ticks = 200
|
||||
while p.generator is not None and tick_count < max_ticks:
|
||||
run_tick(p)
|
||||
tick_count += 1
|
||||
utime.sleep_ms(10)
|
||||
|
||||
if p.generator is None:
|
||||
print(f"✓ Manual mode: Transition completed after {tick_count} ticks")
|
||||
else:
|
||||
print(f"⚠ Manual mode: Transition still running after {tick_count} ticks")
|
||||
|
||||
# Test 7: Switching between auto and manual modes
|
||||
print("\nTest 7: Switching between auto and manual modes")
|
||||
p.edit("switch_test", {
|
||||
"p": "rainbow",
|
||||
"b": 128,
|
||||
"d": 50,
|
||||
"n1": 2,
|
||||
"a": True,
|
||||
})
|
||||
p.select("switch_test")
|
||||
print("Running in auto mode for 1 second...")
|
||||
run_for(p, wdt, 1000)
|
||||
|
||||
# Switch to manual mode by editing the preset
|
||||
print("Switching to manual mode...")
|
||||
p.edit("switch_test", {"a": False})
|
||||
p.select("switch_test") # Re-select to apply changes
|
||||
|
||||
print("Calling tick() 3 times in manual mode...")
|
||||
for i in range(3):
|
||||
run_tick(p)
|
||||
utime.sleep_ms(100)
|
||||
print(f" Tick {i+1}: generator={'active' if p.generator is not None else 'stopped'}")
|
||||
|
||||
# Switch back to auto mode
|
||||
print("Switching back to auto mode...")
|
||||
p.edit("switch_test", {"a": True})
|
||||
p.select("switch_test")
|
||||
print("Running in auto mode for 1 second...")
|
||||
run_for(p, wdt, 1000)
|
||||
print("✓ Successfully switched between auto and manual modes")
|
||||
|
||||
# Cleanup
|
||||
print("\nCleaning up...")
|
||||
p.edit("cleanup_off", {"p": "off"})
|
||||
p.select("cleanup_off")
|
||||
run_tick(p)
|
||||
utime.sleep_ms(100)
|
||||
|
||||
print("\n" + "=" * 50)
|
||||
print("All tests completed!")
|
||||
print("=" * 50)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,43 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
import utime
|
||||
from machine import WDT
|
||||
from settings import Settings
|
||||
from presets import Presets
|
||||
|
||||
|
||||
def run_for(p, wdt, ms):
|
||||
start = utime.ticks_ms()
|
||||
while utime.ticks_diff(utime.ticks_ms(), start) < ms:
|
||||
wdt.feed()
|
||||
p.tick()
|
||||
utime.sleep_ms(10)
|
||||
|
||||
|
||||
def main():
|
||||
s = Settings()
|
||||
p = Presets(pin=s.get("led_pin", 10), num_leds=s.get("num_leds", 48))
|
||||
wdt = WDT(timeout=10000)
|
||||
|
||||
p.edit(
|
||||
"test_blizzard",
|
||||
{
|
||||
"p": "blizzard",
|
||||
"b": 220,
|
||||
"d": 40,
|
||||
"c": [(255, 255, 255), (200, 220, 255)],
|
||||
"n1": 100,
|
||||
"n2": 2,
|
||||
"n3": 150,
|
||||
"a": True,
|
||||
},
|
||||
)
|
||||
p.select("test_blizzard")
|
||||
run_for(p, wdt, 2500)
|
||||
|
||||
p.edit("cleanup_off", {"p": "off"})
|
||||
p.select("cleanup_off")
|
||||
run_for(p, wdt, 80)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,40 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
import utime
|
||||
from machine import WDT
|
||||
from settings import Settings
|
||||
from presets import Presets, run_tick
|
||||
|
||||
|
||||
def run_for(p, wdt, ms):
|
||||
start = utime.ticks_ms()
|
||||
while utime.ticks_diff(utime.ticks_ms(), start) < ms:
|
||||
wdt.feed()
|
||||
run_tick(p)
|
||||
utime.sleep_ms(10)
|
||||
|
||||
|
||||
def main():
|
||||
s = Settings()
|
||||
p = Presets(pin=s.get("led_pin", 10), num_leds=s.get("num_leds", 30))
|
||||
wdt = WDT(timeout=10000)
|
||||
|
||||
p.edit("test_candle_glow", {
|
||||
"p": "candle_glow",
|
||||
"b": 200,
|
||||
"d": 60,
|
||||
"c": [(255, 0, 0), (0, 0, 255), (0, 255, 0)],
|
||||
"n1": 4,
|
||||
"n2": 2,
|
||||
"n3": 120,
|
||||
"a": True,
|
||||
})
|
||||
p.select("test_candle_glow")
|
||||
run_for(p, wdt, 3000)
|
||||
|
||||
p.edit("cleanup_off", {"p": "off"})
|
||||
p.select("cleanup_off")
|
||||
run_for(p, wdt, 100)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,40 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
import utime
|
||||
from machine import WDT
|
||||
from settings import Settings
|
||||
from presets import Presets, run_tick
|
||||
|
||||
|
||||
def run_for(p, wdt, ms):
|
||||
start = utime.ticks_ms()
|
||||
while utime.ticks_diff(utime.ticks_ms(), start) < ms:
|
||||
wdt.feed()
|
||||
run_tick(p)
|
||||
utime.sleep_ms(10)
|
||||
|
||||
|
||||
def main():
|
||||
s = Settings()
|
||||
p = Presets(pin=s.get("led_pin", 10), num_leds=s.get("num_leds", 30))
|
||||
wdt = WDT(timeout=10000)
|
||||
|
||||
p.edit("test_ice_sparkle", {
|
||||
"p": "ice_sparkle",
|
||||
"b": 200,
|
||||
"d": 60,
|
||||
"c": [(255, 0, 0), (0, 0, 255), (0, 255, 0)],
|
||||
"n1": 4,
|
||||
"n2": 2,
|
||||
"n3": 120,
|
||||
"a": True,
|
||||
})
|
||||
p.select("test_ice_sparkle")
|
||||
run_for(p, wdt, 3000)
|
||||
|
||||
p.edit("cleanup_off", {"p": "off"})
|
||||
p.select("cleanup_off")
|
||||
run_for(p, wdt, 100)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,43 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
import utime
|
||||
from machine import WDT
|
||||
from settings import Settings
|
||||
from presets import Presets
|
||||
|
||||
|
||||
def run_for(p, wdt, ms):
|
||||
start = utime.ticks_ms()
|
||||
while utime.ticks_diff(utime.ticks_ms(), start) < ms:
|
||||
wdt.feed()
|
||||
p.tick()
|
||||
utime.sleep_ms(10)
|
||||
|
||||
|
||||
def main():
|
||||
s = Settings()
|
||||
p = Presets(pin=s.get("led_pin", 10), num_leds=s.get("num_leds", 40))
|
||||
wdt = WDT(timeout=10000)
|
||||
|
||||
p.edit(
|
||||
"test_icicles",
|
||||
{
|
||||
"p": "icicles",
|
||||
"b": 220,
|
||||
"d": 50,
|
||||
"c": [(200, 230, 255), (255, 255, 255)],
|
||||
"n1": 10,
|
||||
"n2": 8,
|
||||
"n3": 1,
|
||||
"a": True,
|
||||
},
|
||||
)
|
||||
p.select("test_icicles")
|
||||
run_for(p, wdt, 2500)
|
||||
|
||||
p.edit("cleanup_off", {"p": "off"})
|
||||
p.select("cleanup_off")
|
||||
run_for(p, wdt, 80)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,40 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
import utime
|
||||
from machine import WDT
|
||||
from settings import Settings
|
||||
from presets import Presets, run_tick
|
||||
|
||||
|
||||
def run_for(p, wdt, ms):
|
||||
start = utime.ticks_ms()
|
||||
while utime.ticks_diff(utime.ticks_ms(), start) < ms:
|
||||
wdt.feed()
|
||||
run_tick(p)
|
||||
utime.sleep_ms(10)
|
||||
|
||||
|
||||
def main():
|
||||
s = Settings()
|
||||
p = Presets(pin=s.get("led_pin", 10), num_leds=s.get("num_leds", 30))
|
||||
wdt = WDT(timeout=10000)
|
||||
|
||||
p.edit("test_northern_wave", {
|
||||
"p": "northern_wave",
|
||||
"b": 200,
|
||||
"d": 60,
|
||||
"c": [(255, 0, 0), (0, 0, 255), (0, 255, 0)],
|
||||
"n1": 4,
|
||||
"n2": 2,
|
||||
"n3": 120,
|
||||
"a": True,
|
||||
})
|
||||
p.select("test_northern_wave")
|
||||
run_for(p, wdt, 3000)
|
||||
|
||||
p.edit("cleanup_off", {"p": "off"})
|
||||
p.select("cleanup_off")
|
||||
run_for(p, wdt, 100)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,52 +0,0 @@
|
||||
#!/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()
|
||||
@@ -1,151 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
import utime
|
||||
from machine import WDT
|
||||
from settings import Settings
|
||||
from presets import Presets, run_tick
|
||||
|
||||
|
||||
def run_for(p, wdt, ms):
|
||||
"""Helper: run current pattern for given ms using tick()."""
|
||||
start = utime.ticks_ms()
|
||||
while utime.ticks_diff(utime.ticks_ms(), start) < ms:
|
||||
wdt.feed()
|
||||
run_tick(p)
|
||||
utime.sleep_ms(10)
|
||||
|
||||
|
||||
def main():
|
||||
s = Settings()
|
||||
pin = s.get("led_pin", 10)
|
||||
num = s.get("num_leds", 30)
|
||||
|
||||
p = Presets(pin=pin, num_leds=num)
|
||||
wdt = WDT(timeout=10000)
|
||||
|
||||
# Test 1: Basic rainbow with auto=True (continuous)
|
||||
print("Test 1: Basic rainbow (auto=True, n1=1)")
|
||||
p.edit("rainbow1", {
|
||||
"p": "rainbow",
|
||||
"b": 255,
|
||||
"d": 100,
|
||||
"n1": 1,
|
||||
"a": True,
|
||||
})
|
||||
p.select("rainbow1")
|
||||
run_for(p, wdt, 3000)
|
||||
|
||||
# Test 2: Fast rainbow
|
||||
print("Test 2: Fast rainbow (low delay, n1=1)")
|
||||
p.edit("rainbow2", {
|
||||
"p": "rainbow",
|
||||
"d": 50,
|
||||
"n1": 1,
|
||||
"a": True,
|
||||
})
|
||||
p.select("rainbow2")
|
||||
run_for(p, wdt, 2000)
|
||||
|
||||
# Test 3: Slow rainbow
|
||||
print("Test 3: Slow rainbow (high delay, n1=1)")
|
||||
p.edit("rainbow3", {
|
||||
"p": "rainbow",
|
||||
"d": 500,
|
||||
"n1": 1,
|
||||
"a": True,
|
||||
})
|
||||
p.select("rainbow3")
|
||||
run_for(p, wdt, 3000)
|
||||
|
||||
# Test 4: Low brightness rainbow
|
||||
print("Test 4: Low brightness rainbow (n1=1)")
|
||||
p.edit("rainbow4", {
|
||||
"p": "rainbow",
|
||||
"b": 64,
|
||||
"d": 100,
|
||||
"n1": 1,
|
||||
"a": True,
|
||||
})
|
||||
p.select("rainbow4")
|
||||
run_for(p, wdt, 2000)
|
||||
|
||||
# Test 5: Single-step rainbow (auto=False)
|
||||
print("Test 5: Single-step rainbow (auto=False, n1=1)")
|
||||
p.edit("rainbow5", {
|
||||
"p": "rainbow",
|
||||
"b": 255,
|
||||
"d": 100,
|
||||
"n1": 1,
|
||||
"a": False,
|
||||
})
|
||||
p.step = 0
|
||||
for i in range(10):
|
||||
p.select("rainbow5")
|
||||
# One tick advances the generator one frame when auto=False
|
||||
run_tick(p)
|
||||
utime.sleep_ms(100)
|
||||
wdt.feed()
|
||||
|
||||
# Test 6: Verify step updates correctly
|
||||
print("Test 6: Verify step updates (auto=False, n1=1)")
|
||||
p.edit("rainbow6", {
|
||||
"p": "rainbow",
|
||||
"n1": 1,
|
||||
"a": False,
|
||||
})
|
||||
initial_step = p.step
|
||||
p.select("rainbow6")
|
||||
run_tick(p)
|
||||
final_step = p.step
|
||||
print(f"Step updated from {initial_step} to {final_step} (expected increment: 1)")
|
||||
|
||||
# Test 7: Fast step increment (n1=5)
|
||||
print("Test 7: Fast rainbow (n1=5, auto=True)")
|
||||
p.edit("rainbow7", {
|
||||
"p": "rainbow",
|
||||
"b": 255,
|
||||
"d": 100,
|
||||
"n1": 5,
|
||||
"a": True,
|
||||
})
|
||||
p.select("rainbow7")
|
||||
run_for(p, wdt, 2000)
|
||||
|
||||
# Test 8: Very fast step increment (n1=10)
|
||||
print("Test 8: Very fast rainbow (n1=10, auto=True)")
|
||||
p.edit("rainbow8", {
|
||||
"p": "rainbow",
|
||||
"n1": 10,
|
||||
"a": True,
|
||||
})
|
||||
p.select("rainbow8")
|
||||
run_for(p, wdt, 2000)
|
||||
|
||||
# Test 9: Verify n1 controls step increment (auto=False)
|
||||
print("Test 9: Verify n1 step increment (auto=False, n1=5)")
|
||||
p.edit("rainbow9", {
|
||||
"p": "rainbow",
|
||||
"n1": 5,
|
||||
"a": False,
|
||||
})
|
||||
p.step = 0
|
||||
initial_step = p.step
|
||||
p.select("rainbow9")
|
||||
run_tick(p)
|
||||
final_step = p.step
|
||||
expected_step = (initial_step + 5) % 256
|
||||
print(f"Step updated from {initial_step} to {final_step} (expected: {expected_step})")
|
||||
if final_step == expected_step:
|
||||
print("✓ n1 step increment working correctly")
|
||||
else:
|
||||
print(f"✗ Step increment mismatch! Expected {expected_step}, got {final_step}")
|
||||
|
||||
# Cleanup
|
||||
print("Test complete, turning off")
|
||||
p.edit("cleanup_off", {"p": "off"})
|
||||
p.select("cleanup_off")
|
||||
run_for(p, wdt, 100)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
import utime
|
||||
from machine import WDT
|
||||
from settings import Settings
|
||||
from presets import Presets
|
||||
|
||||
|
||||
def run_for(p, wdt, ms):
|
||||
start = utime.ticks_ms()
|
||||
while utime.ticks_diff(utime.ticks_ms(), start) < ms:
|
||||
wdt.feed()
|
||||
p.tick()
|
||||
utime.sleep_ms(10)
|
||||
|
||||
|
||||
def main():
|
||||
s = Settings()
|
||||
p = Presets(pin=s.get("led_pin", 10), num_leds=s.get("num_leds", 40))
|
||||
wdt = WDT(timeout=10000)
|
||||
|
||||
p.edit(
|
||||
"test_rime",
|
||||
{
|
||||
"p": "rime",
|
||||
"b": 200,
|
||||
"d": 80,
|
||||
"c": [(240, 248, 255), (255, 255, 255)],
|
||||
"n1": 48,
|
||||
"n2": 14,
|
||||
"n3": 4,
|
||||
"a": True,
|
||||
},
|
||||
)
|
||||
p.select("test_rime")
|
||||
run_for(p, wdt, 2800)
|
||||
|
||||
p.edit("cleanup_off", {"p": "off"})
|
||||
p.select("cleanup_off")
|
||||
run_for(p, wdt, 80)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,40 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
import utime
|
||||
from machine import WDT
|
||||
from settings import Settings
|
||||
from presets import Presets, run_tick
|
||||
|
||||
|
||||
def run_for(p, wdt, ms):
|
||||
start = utime.ticks_ms()
|
||||
while utime.ticks_diff(utime.ticks_ms(), start) < ms:
|
||||
wdt.feed()
|
||||
run_tick(p)
|
||||
utime.sleep_ms(10)
|
||||
|
||||
|
||||
def main():
|
||||
s = Settings()
|
||||
p = Presets(pin=s.get("led_pin", 10), num_leds=s.get("num_leds", 30))
|
||||
wdt = WDT(timeout=10000)
|
||||
|
||||
p.edit("test_starfall", {
|
||||
"p": "starfall",
|
||||
"b": 200,
|
||||
"d": 60,
|
||||
"c": [(255, 0, 0), (0, 0, 255), (0, 255, 0)],
|
||||
"n1": 4,
|
||||
"n2": 2,
|
||||
"n3": 120,
|
||||
"a": True,
|
||||
})
|
||||
p.select("test_starfall")
|
||||
run_for(p, wdt, 3000)
|
||||
|
||||
p.edit("cleanup_off", {"p": "off"})
|
||||
p.select("cleanup_off")
|
||||
run_for(p, wdt, 100)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user