- Fix initialization order: initialize self.presets before calling self.select() - Separate add() and edit() methods: add() creates new presets, edit() updates existing ones - Update all test files to use add() instead of edit() for creating presets - Add comprehensive auto/manual mode test - Remove tool.py (moved to led-tool project)
152 lines
3.8 KiB
Python
152 lines
3.8 KiB
Python
#!/usr/bin/env python3
|
|
import utime
|
|
from machine import WDT
|
|
from settings import Settings
|
|
from patterns import Patterns
|
|
|
|
|
|
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()
|
|
p.tick()
|
|
utime.sleep_ms(10)
|
|
|
|
|
|
def main():
|
|
s = Settings()
|
|
pin = s.get("led_pin", 10)
|
|
num = s.get("num_leds", 30)
|
|
|
|
p = Patterns(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.add("rainbow1", {
|
|
"pattern": "rainbow",
|
|
"brightness": 255,
|
|
"delay": 100,
|
|
"n1": 1,
|
|
"auto": True
|
|
})
|
|
p.select("rainbow1")
|
|
run_for(p, wdt, 3000)
|
|
|
|
# Test 2: Fast rainbow
|
|
print("Test 2: Fast rainbow (low delay, n1=1)")
|
|
p.add("rainbow2", {
|
|
"pattern": "rainbow",
|
|
"delay": 50,
|
|
"n1": 1,
|
|
"auto": True
|
|
})
|
|
p.select("rainbow2")
|
|
run_for(p, wdt, 2000)
|
|
|
|
# Test 3: Slow rainbow
|
|
print("Test 3: Slow rainbow (high delay, n1=1)")
|
|
p.add("rainbow3", {
|
|
"pattern": "rainbow",
|
|
"delay": 500,
|
|
"n1": 1,
|
|
"auto": True
|
|
})
|
|
p.select("rainbow3")
|
|
run_for(p, wdt, 3000)
|
|
|
|
# Test 4: Low brightness rainbow
|
|
print("Test 4: Low brightness rainbow (n1=1)")
|
|
p.add("rainbow4", {
|
|
"pattern": "rainbow",
|
|
"brightness": 64,
|
|
"delay": 100,
|
|
"n1": 1,
|
|
"auto": 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.add("rainbow5", {
|
|
"pattern": "rainbow",
|
|
"brightness": 255,
|
|
"delay": 100,
|
|
"n1": 1,
|
|
"auto": False
|
|
})
|
|
p.step = 0
|
|
for i in range(10):
|
|
p.select("rainbow5")
|
|
# One tick advances the generator one frame when auto=False
|
|
p.tick()
|
|
utime.sleep_ms(100)
|
|
wdt.feed()
|
|
|
|
# Test 6: Verify step updates correctly
|
|
print("Test 6: Verify step updates (auto=False, n1=1)")
|
|
p.add("rainbow6", {
|
|
"pattern": "rainbow",
|
|
"n1": 1,
|
|
"auto": False
|
|
})
|
|
initial_step = p.step
|
|
p.select("rainbow6")
|
|
p.tick()
|
|
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.add("rainbow7", {
|
|
"pattern": "rainbow",
|
|
"brightness": 255,
|
|
"delay": 100,
|
|
"n1": 5,
|
|
"auto": 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.add("rainbow8", {
|
|
"pattern": "rainbow",
|
|
"n1": 10,
|
|
"auto": 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.add("rainbow9", {
|
|
"pattern": "rainbow",
|
|
"n1": 5,
|
|
"auto": False
|
|
})
|
|
p.step = 0
|
|
initial_step = p.step
|
|
p.select("rainbow9")
|
|
p.tick()
|
|
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.add("cleanup_off", {"pattern": "off"})
|
|
p.select("cleanup_off")
|
|
run_for(p, wdt, 100)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|