Refactor patterns to use preset-based API and fix initialization order
- 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)
This commit is contained in:
190
test/patterns/auto_manual.py
Normal file
190
test/patterns/auto_manual.py
Normal file
@@ -0,0 +1,190 @@
|
||||
#!/usr/bin/env python3
|
||||
import utime
|
||||
from machine import WDT
|
||||
from settings import Settings
|
||||
from patterns import Patterns
|
||||
|
||||
|
||||
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()
|
||||
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)
|
||||
|
||||
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.add("rainbow_auto", {
|
||||
"pattern": "rainbow",
|
||||
"brightness": 128,
|
||||
"delay": 50,
|
||||
"n1": 2,
|
||||
"auto": 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.add("rainbow_manual", {
|
||||
"pattern": "rainbow",
|
||||
"brightness": 128,
|
||||
"delay": 50,
|
||||
"n1": 2,
|
||||
"auto": False
|
||||
})
|
||||
p.select("rainbow_manual")
|
||||
print("Calling tick() 5 times (should advance 5 steps)...")
|
||||
for i in range(5):
|
||||
p.tick()
|
||||
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.add("pulse_auto", {
|
||||
"pattern": "pulse",
|
||||
"brightness": 128,
|
||||
"delay": 100,
|
||||
"n1": 500, # Attack
|
||||
"n2": 200, # Hold
|
||||
"n3": 500, # Decay
|
||||
"colors": [(255, 0, 0)],
|
||||
"auto": 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.add("pulse_manual", {
|
||||
"pattern": "pulse",
|
||||
"brightness": 128,
|
||||
"delay": 100,
|
||||
"n1": 300, # Attack
|
||||
"n2": 200, # Hold
|
||||
"n3": 300, # Decay
|
||||
"colors": [(0, 255, 0)],
|
||||
"auto": 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:
|
||||
p.tick()
|
||||
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.add("transition_auto", {
|
||||
"pattern": "transition",
|
||||
"brightness": 128,
|
||||
"delay": 500,
|
||||
"colors": [(255, 0, 0), (0, 255, 0), (0, 0, 255)],
|
||||
"auto": 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.add("transition_manual", {
|
||||
"pattern": "transition",
|
||||
"brightness": 128,
|
||||
"delay": 500,
|
||||
"colors": [(255, 0, 0), (0, 255, 0)],
|
||||
"auto": 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:
|
||||
p.tick()
|
||||
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.add("switch_test", {
|
||||
"pattern": "rainbow",
|
||||
"brightness": 128,
|
||||
"delay": 50,
|
||||
"n1": 2,
|
||||
"auto": 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", {"auto": False})
|
||||
p.select("switch_test") # Re-select to apply changes
|
||||
|
||||
print("Calling tick() 3 times in manual mode...")
|
||||
for i in range(3):
|
||||
p.tick()
|
||||
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", {"auto": 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.add("cleanup_off", {"pattern": "off"})
|
||||
p.select("cleanup_off")
|
||||
p.tick()
|
||||
utime.sleep_ms(100)
|
||||
|
||||
print("\n" + "=" * 50)
|
||||
print("All tests completed!")
|
||||
print("=" * 50)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -12,10 +12,15 @@ def main():
|
||||
|
||||
p = Patterns(pin=pin, num_leds=num)
|
||||
wdt = WDT(timeout=10000)
|
||||
p.set_param("br", 64)
|
||||
p.set_param("dl", 200)
|
||||
p.set_param("cl", [(255, 0, 0), (0, 0, 255)])
|
||||
p.select("blink")
|
||||
|
||||
# Create blink preset
|
||||
p.add("test_blink", {
|
||||
"pattern": "blink",
|
||||
"brightness": 64,
|
||||
"delay": 200,
|
||||
"colors": [(255, 0, 0), (0, 0, 255)]
|
||||
})
|
||||
p.select("test_blink")
|
||||
|
||||
start = utime.ticks_ms()
|
||||
while utime.ticks_diff(utime.ticks_ms(), start) < 1500:
|
||||
|
||||
@@ -24,74 +24,93 @@ def main():
|
||||
|
||||
# Test 1: Basic chase (n1=5, n2=5, n3=1, n4=1)
|
||||
print("Test 1: Basic chase (n1=5, n2=5, n3=1, n4=1)")
|
||||
p.set_param("br", 255)
|
||||
p.set_param("dl", 200)
|
||||
p.set_param("n1", 5)
|
||||
p.set_param("n2", 5)
|
||||
p.set_param("n3", 1)
|
||||
p.set_param("n4", 1)
|
||||
p.set_param("cl", [(255, 0, 0), (0, 255, 0)])
|
||||
p.select("chase")
|
||||
p.add("chase1", {
|
||||
"pattern": "chase",
|
||||
"brightness": 255,
|
||||
"delay": 200,
|
||||
"n1": 5,
|
||||
"n2": 5,
|
||||
"n3": 1,
|
||||
"n4": 1,
|
||||
"colors": [(255, 0, 0), (0, 255, 0)]
|
||||
})
|
||||
p.select("chase1")
|
||||
run_for(p, wdt, 3000)
|
||||
|
||||
# Test 2: Forward and backward (n3=2, n4=-1)
|
||||
print("Test 2: Forward and backward (n3=2, n4=-1)")
|
||||
p.set_param("n1", 3)
|
||||
p.set_param("n2", 3)
|
||||
p.set_param("n3", 2)
|
||||
p.set_param("n4", -1)
|
||||
p.set_param("dl", 150)
|
||||
p.set_param("cl", [(0, 0, 255), (255, 255, 0)])
|
||||
p.select("chase")
|
||||
p.add("chase2", {
|
||||
"pattern": "chase",
|
||||
"n1": 3,
|
||||
"n2": 3,
|
||||
"n3": 2,
|
||||
"n4": -1,
|
||||
"delay": 150,
|
||||
"colors": [(0, 0, 255), (255, 255, 0)]
|
||||
})
|
||||
p.select("chase2")
|
||||
run_for(p, wdt, 3000)
|
||||
|
||||
# Test 3: Large segments (n1=10, n2=5)
|
||||
print("Test 3: Large segments (n1=10, n2=5, n3=3, n4=3)")
|
||||
p.set_param("n1", 10)
|
||||
p.set_param("n2", 5)
|
||||
p.set_param("n3", 3)
|
||||
p.set_param("n4", 3)
|
||||
p.set_param("dl", 200)
|
||||
p.set_param("cl", [(255, 128, 0), (128, 0, 255)])
|
||||
p.select("chase")
|
||||
p.add("chase3", {
|
||||
"pattern": "chase",
|
||||
"n1": 10,
|
||||
"n2": 5,
|
||||
"n3": 3,
|
||||
"n4": 3,
|
||||
"delay": 200,
|
||||
"colors": [(255, 128, 0), (128, 0, 255)]
|
||||
})
|
||||
p.select("chase3")
|
||||
run_for(p, wdt, 3000)
|
||||
|
||||
# Test 4: Fast movement (n3=5, n4=5)
|
||||
print("Test 4: Fast movement (n3=5, n4=5)")
|
||||
p.set_param("n1", 4)
|
||||
p.set_param("n2", 4)
|
||||
p.set_param("n3", 5)
|
||||
p.set_param("n4", 5)
|
||||
p.set_param("dl", 100)
|
||||
p.set_param("cl", [(255, 0, 255), (0, 255, 255)])
|
||||
p.select("chase")
|
||||
p.add("chase4", {
|
||||
"pattern": "chase",
|
||||
"n1": 4,
|
||||
"n2": 4,
|
||||
"n3": 5,
|
||||
"n4": 5,
|
||||
"delay": 100,
|
||||
"colors": [(255, 0, 255), (0, 255, 255)]
|
||||
})
|
||||
p.select("chase4")
|
||||
run_for(p, wdt, 2000)
|
||||
|
||||
# Test 5: Backward movement (n3=-2, n4=-2)
|
||||
print("Test 5: Backward movement (n3=-2, n4=-2)")
|
||||
p.set_param("n1", 6)
|
||||
p.set_param("n2", 4)
|
||||
p.set_param("n3", -2)
|
||||
p.set_param("n4", -2)
|
||||
p.set_param("dl", 200)
|
||||
p.set_param("cl", [(255, 255, 255), (0, 0, 0)])
|
||||
p.select("chase")
|
||||
p.add("chase5", {
|
||||
"pattern": "chase",
|
||||
"n1": 6,
|
||||
"n2": 4,
|
||||
"n3": -2,
|
||||
"n4": -2,
|
||||
"delay": 200,
|
||||
"colors": [(255, 255, 255), (0, 0, 0)]
|
||||
})
|
||||
p.select("chase5")
|
||||
run_for(p, wdt, 3000)
|
||||
|
||||
# Test 6: Alternating forward/backward (n3=3, n4=-2)
|
||||
print("Test 6: Alternating forward/backward (n3=3, n4=-2)")
|
||||
p.set_param("n1", 5)
|
||||
p.set_param("n2", 5)
|
||||
p.set_param("n3", 3)
|
||||
p.set_param("n4", -2)
|
||||
p.set_param("dl", 250)
|
||||
p.set_param("cl", [(255, 0, 0), (0, 255, 0)])
|
||||
p.select("chase")
|
||||
p.add("chase6", {
|
||||
"pattern": "chase",
|
||||
"n1": 5,
|
||||
"n2": 5,
|
||||
"n3": 3,
|
||||
"n4": -2,
|
||||
"delay": 250,
|
||||
"colors": [(255, 0, 0), (0, 255, 0)]
|
||||
})
|
||||
p.select("chase6")
|
||||
run_for(p, wdt, 4000)
|
||||
|
||||
# Cleanup
|
||||
print("Test complete, turning off")
|
||||
p.select("off")
|
||||
p.add("cleanup_off", {"pattern": "off"})
|
||||
p.select("cleanup_off")
|
||||
run_for(p, wdt, 100)
|
||||
|
||||
|
||||
|
||||
@@ -24,68 +24,87 @@ def main():
|
||||
|
||||
# Test 1: Basic circle (n1=50, n2=100, n3=200, n4=0)
|
||||
print("Test 1: Basic circle (n1=50, n2=100, n3=200, n4=0)")
|
||||
p.set_param("br", 255)
|
||||
p.set_param("n1", 50) # Head moves 50 LEDs/second
|
||||
p.set_param("n2", 100) # Max length 100 LEDs
|
||||
p.set_param("n3", 200) # Tail moves 200 LEDs/second
|
||||
p.set_param("n4", 0) # Min length 0 LEDs
|
||||
p.set_param("cl", [(255, 0, 0)]) # Red
|
||||
p.select("circle")
|
||||
p.add("circle1", {
|
||||
"pattern": "circle",
|
||||
"brightness": 255,
|
||||
"n1": 50, # Head moves 50 LEDs/second
|
||||
"n2": 100, # Max length 100 LEDs
|
||||
"n3": 200, # Tail moves 200 LEDs/second
|
||||
"n4": 0, # Min length 0 LEDs
|
||||
"colors": [(255, 0, 0)] # Red
|
||||
})
|
||||
p.select("circle1")
|
||||
run_for(p, wdt, 5000)
|
||||
|
||||
# Test 2: Slow growth, fast shrink (n1=20, n2=50, n3=100, n4=0)
|
||||
print("Test 2: Slow growth, fast shrink (n1=20, n2=50, n3=100, n4=0)")
|
||||
p.set_param("n1", 20)
|
||||
p.set_param("n2", 50)
|
||||
p.set_param("n3", 100)
|
||||
p.set_param("n4", 0)
|
||||
p.set_param("cl", [(0, 255, 0)]) # Green
|
||||
p.select("circle")
|
||||
p.add("circle2", {
|
||||
"pattern": "circle",
|
||||
"n1": 20,
|
||||
"n2": 50,
|
||||
"n3": 100,
|
||||
"n4": 0,
|
||||
"colors": [(0, 255, 0)] # Green
|
||||
})
|
||||
p.select("circle2")
|
||||
run_for(p, wdt, 5000)
|
||||
|
||||
# Test 3: Fast growth, slow shrink (n1=100, n2=30, n3=20, n4=0)
|
||||
print("Test 3: Fast growth, slow shrink (n1=100, n2=30, n3=20, n4=0)")
|
||||
p.set_param("n1", 100)
|
||||
p.set_param("n2", 30)
|
||||
p.set_param("n3", 20)
|
||||
p.set_param("n4", 0)
|
||||
p.set_param("cl", [(0, 0, 255)]) # Blue
|
||||
p.select("circle")
|
||||
p.add("circle3", {
|
||||
"pattern": "circle",
|
||||
"n1": 100,
|
||||
"n2": 30,
|
||||
"n3": 20,
|
||||
"n4": 0,
|
||||
"colors": [(0, 0, 255)] # Blue
|
||||
})
|
||||
p.select("circle3")
|
||||
run_for(p, wdt, 5000)
|
||||
|
||||
# Test 4: With minimum length (n1=50, n2=40, n3=100, n4=10)
|
||||
print("Test 4: With minimum length (n1=50, n2=40, n3=100, n4=10)")
|
||||
p.set_param("n1", 50)
|
||||
p.set_param("n2", 40)
|
||||
p.set_param("n3", 100)
|
||||
p.set_param("n4", 10)
|
||||
p.set_param("cl", [(255, 255, 0)]) # Yellow
|
||||
p.select("circle")
|
||||
p.add("circle4", {
|
||||
"pattern": "circle",
|
||||
"n1": 50,
|
||||
"n2": 40,
|
||||
"n3": 100,
|
||||
"n4": 10,
|
||||
"colors": [(255, 255, 0)] # Yellow
|
||||
})
|
||||
p.select("circle4")
|
||||
run_for(p, wdt, 5000)
|
||||
|
||||
# Test 5: Very fast (n1=200, n2=20, n3=200, n4=0)
|
||||
print("Test 5: Very fast (n1=200, n2=20, n3=200, n4=0)")
|
||||
p.set_param("n1", 200)
|
||||
p.set_param("n2", 20)
|
||||
p.set_param("n3", 200)
|
||||
p.set_param("n4", 0)
|
||||
p.set_param("cl", [(255, 0, 255)]) # Magenta
|
||||
p.select("circle")
|
||||
p.add("circle5", {
|
||||
"pattern": "circle",
|
||||
"n1": 200,
|
||||
"n2": 20,
|
||||
"n3": 200,
|
||||
"n4": 0,
|
||||
"colors": [(255, 0, 255)] # Magenta
|
||||
})
|
||||
p.select("circle5")
|
||||
run_for(p, wdt, 3000)
|
||||
|
||||
# Test 6: Very slow (n1=10, n2=25, n3=10, n4=0)
|
||||
print("Test 6: Very slow (n1=10, n2=25, n3=10, n4=0)")
|
||||
p.set_param("n1", 10)
|
||||
p.set_param("n2", 25)
|
||||
p.set_param("n3", 10)
|
||||
p.set_param("n4", 0)
|
||||
p.set_param("cl", [(0, 255, 255)]) # Cyan
|
||||
p.select("circle")
|
||||
p.add("circle6", {
|
||||
"pattern": "circle",
|
||||
"n1": 10,
|
||||
"n2": 25,
|
||||
"n3": 10,
|
||||
"n4": 0,
|
||||
"colors": [(0, 255, 255)] # Cyan
|
||||
})
|
||||
p.select("circle6")
|
||||
run_for(p, wdt, 5000)
|
||||
|
||||
# Cleanup
|
||||
print("Test complete, turning off")
|
||||
p.select("off")
|
||||
p.add("cleanup_off", {"pattern": "off"})
|
||||
p.select("cleanup_off")
|
||||
run_for(p, wdt, 100)
|
||||
|
||||
|
||||
|
||||
@@ -12,7 +12,10 @@ def main():
|
||||
|
||||
p = Patterns(pin=pin, num_leds=num)
|
||||
wdt = WDT(timeout=10000)
|
||||
p.select("off")
|
||||
|
||||
# Create an "off" preset
|
||||
p.add("test_off", {"pattern": "off"})
|
||||
p.select("test_off")
|
||||
|
||||
start = utime.ticks_ms()
|
||||
while utime.ticks_diff(utime.ticks_ms(), start) < 200:
|
||||
|
||||
@@ -12,12 +12,18 @@ def main():
|
||||
|
||||
p = Patterns(pin=pin, num_leds=num)
|
||||
wdt = WDT(timeout=10000)
|
||||
p.set_param("br", 64)
|
||||
p.set_param("dl", 120)
|
||||
p.set_param("cl", [(255, 0, 0), (0, 0, 255)])
|
||||
|
||||
# Create presets for on and off
|
||||
p.add("test_on", {
|
||||
"pattern": "on",
|
||||
"brightness": 64,
|
||||
"delay": 120,
|
||||
"colors": [(255, 0, 0), (0, 0, 255)]
|
||||
})
|
||||
p.add("test_off", {"pattern": "off"})
|
||||
|
||||
# ON phase
|
||||
p.select("on")
|
||||
p.select("test_on")
|
||||
start = utime.ticks_ms()
|
||||
while utime.ticks_diff(utime.ticks_ms(), start) < 800:
|
||||
wdt.feed()
|
||||
@@ -25,7 +31,7 @@ def main():
|
||||
utime.sleep_ms(10)
|
||||
|
||||
# OFF phase
|
||||
p.select("off")
|
||||
p.select("test_off")
|
||||
start = utime.ticks_ms()
|
||||
while utime.ticks_diff(utime.ticks_ms(), start) < 100:
|
||||
wdt.feed()
|
||||
|
||||
@@ -24,52 +24,65 @@ def main():
|
||||
|
||||
# Test 1: Simple single-color pulse
|
||||
print("Test 1: Single-color pulse (attack=500, hold=500, decay=500, delay=500)")
|
||||
p.set_param("br", 255)
|
||||
p.set_param("cl", [(255, 0, 0)]) # Red
|
||||
p.set_param("n1", 500) # attack ms
|
||||
p.set_param("n2", 500) # hold ms
|
||||
p.set_param("n3", 500) # decay ms
|
||||
p.set_param("dl", 500) # delay ms between pulses
|
||||
p.set_param("auto", True)
|
||||
p.select("pulse")
|
||||
p.add("pulse1", {
|
||||
"pattern": "pulse",
|
||||
"brightness": 255,
|
||||
"colors": [(255, 0, 0)],
|
||||
"n1": 500, # attack ms
|
||||
"n2": 500, # hold ms
|
||||
"n3": 500, # decay ms
|
||||
"delay": 500, # delay ms between pulses
|
||||
"auto": True
|
||||
})
|
||||
p.select("pulse1")
|
||||
run_for(p, wdt, 5000)
|
||||
|
||||
# Test 2: Faster pulse
|
||||
print("Test 2: Fast pulse (attack=100, hold=100, decay=100, delay=100)")
|
||||
p.set_param("n1", 100)
|
||||
p.set_param("n2", 100)
|
||||
p.set_param("n3", 100)
|
||||
p.set_param("dl", 100)
|
||||
p.set_param("cl", [(0, 255, 0)]) # Green
|
||||
p.select("pulse")
|
||||
p.add("pulse2", {
|
||||
"pattern": "pulse",
|
||||
"n1": 100,
|
||||
"n2": 100,
|
||||
"n3": 100,
|
||||
"delay": 100,
|
||||
"colors": [(0, 255, 0)]
|
||||
})
|
||||
p.select("pulse2")
|
||||
run_for(p, wdt, 4000)
|
||||
|
||||
# Test 3: Multi-color pulse cycle
|
||||
print("Test 3: Multi-color pulse (red -> green -> blue)")
|
||||
p.set_param("n1", 300)
|
||||
p.set_param("n2", 300)
|
||||
p.set_param("n3", 300)
|
||||
p.set_param("dl", 200)
|
||||
p.set_param("cl", [(255, 0, 0), (0, 255, 0), (0, 0, 255)])
|
||||
p.set_param("auto", True)
|
||||
p.select("pulse")
|
||||
p.add("pulse3", {
|
||||
"pattern": "pulse",
|
||||
"n1": 300,
|
||||
"n2": 300,
|
||||
"n3": 300,
|
||||
"delay": 200,
|
||||
"colors": [(255, 0, 0), (0, 255, 0), (0, 0, 255)],
|
||||
"auto": True
|
||||
})
|
||||
p.select("pulse3")
|
||||
run_for(p, wdt, 6000)
|
||||
|
||||
# Test 4: One-shot pulse (auto=False)
|
||||
print("Test 4: Single pulse, auto=False")
|
||||
p.set_param("n1", 400)
|
||||
p.set_param("n2", 0)
|
||||
p.set_param("n3", 400)
|
||||
p.set_param("dl", 0)
|
||||
p.set_param("cl", [(255, 255, 255)])
|
||||
p.set_param("auto", False)
|
||||
p.select("pulse")
|
||||
p.add("pulse4", {
|
||||
"pattern": "pulse",
|
||||
"n1": 400,
|
||||
"n2": 0,
|
||||
"n3": 400,
|
||||
"delay": 0,
|
||||
"colors": [(255, 255, 255)],
|
||||
"auto": False
|
||||
})
|
||||
p.select("pulse4")
|
||||
# Run long enough to allow one full pulse cycle
|
||||
run_for(p, wdt, 1500)
|
||||
|
||||
# Cleanup
|
||||
print("Test complete, turning off")
|
||||
p.select("off")
|
||||
p.add("cleanup_off", {"pattern": "off"})
|
||||
p.select("cleanup_off")
|
||||
run_for(p, wdt, 200)
|
||||
|
||||
|
||||
|
||||
@@ -24,47 +24,62 @@ def main():
|
||||
|
||||
# Test 1: Basic rainbow with auto=True (continuous)
|
||||
print("Test 1: Basic rainbow (auto=True, n1=1)")
|
||||
p.set_param("br", 255)
|
||||
p.set_param("dl", 100) # Delay affects animation speed
|
||||
p.set_param("n1", 1) # Step increment of 1
|
||||
p.set_param("auto", True)
|
||||
p.select("rainbow")
|
||||
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.set_param("dl", 50)
|
||||
p.set_param("n1", 1)
|
||||
p.set_param("auto", True)
|
||||
p.select("rainbow")
|
||||
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.set_param("dl", 500)
|
||||
p.set_param("n1", 1)
|
||||
p.set_param("auto", True)
|
||||
p.select("rainbow")
|
||||
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.set_param("br", 64)
|
||||
p.set_param("dl", 100)
|
||||
p.set_param("n1", 1)
|
||||
p.set_param("auto", True)
|
||||
p.select("rainbow")
|
||||
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.set_param("br", 255)
|
||||
p.set_param("dl", 100)
|
||||
p.set_param("n1", 1)
|
||||
p.set_param("auto", False)
|
||||
p.add("rainbow5", {
|
||||
"pattern": "rainbow",
|
||||
"brightness": 255,
|
||||
"delay": 100,
|
||||
"n1": 1,
|
||||
"auto": False
|
||||
})
|
||||
p.step = 0
|
||||
for i in range(10):
|
||||
p.select("rainbow")
|
||||
p.select("rainbow5")
|
||||
# One tick advances the generator one frame when auto=False
|
||||
p.tick()
|
||||
utime.sleep_ms(100)
|
||||
@@ -72,37 +87,49 @@ def main():
|
||||
|
||||
# Test 6: Verify step updates correctly
|
||||
print("Test 6: Verify step updates (auto=False, n1=1)")
|
||||
p.set_param("n1", 1)
|
||||
p.set_param("auto", False)
|
||||
p.add("rainbow6", {
|
||||
"pattern": "rainbow",
|
||||
"n1": 1,
|
||||
"auto": False
|
||||
})
|
||||
initial_step = p.step
|
||||
p.select("rainbow")
|
||||
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.set_param("br", 255)
|
||||
p.set_param("dl", 100)
|
||||
p.set_param("n1", 5)
|
||||
p.set_param("auto", True)
|
||||
p.select("rainbow")
|
||||
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.set_param("n1", 10)
|
||||
p.set_param("auto", True)
|
||||
p.select("rainbow")
|
||||
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.set_param("n1", 5)
|
||||
p.set_param("auto", False)
|
||||
p.add("rainbow9", {
|
||||
"pattern": "rainbow",
|
||||
"n1": 5,
|
||||
"auto": False
|
||||
})
|
||||
p.step = 0
|
||||
initial_step = p.step
|
||||
p.select("rainbow")
|
||||
p.select("rainbow9")
|
||||
p.tick()
|
||||
final_step = p.step
|
||||
expected_step = (initial_step + 5) % 256
|
||||
@@ -114,7 +141,8 @@ def main():
|
||||
|
||||
# Cleanup
|
||||
print("Test complete, turning off")
|
||||
p.select("off")
|
||||
p.add("cleanup_off", {"pattern": "off"})
|
||||
p.select("cleanup_off")
|
||||
run_for(p, wdt, 100)
|
||||
|
||||
|
||||
|
||||
@@ -24,41 +24,54 @@ def main():
|
||||
|
||||
# Test 1: Simple two-color transition
|
||||
print("Test 1: Two-color transition (red <-> blue, delay=1000)")
|
||||
p.set_param("br", 255)
|
||||
p.set_param("dl", 1000) # transition duration
|
||||
p.set_param("cl", [(255, 0, 0), (0, 0, 255)])
|
||||
p.set_param("auto", True)
|
||||
p.select("transition")
|
||||
p.add("transition1", {
|
||||
"pattern": "transition",
|
||||
"brightness": 255,
|
||||
"delay": 1000, # transition duration
|
||||
"colors": [(255, 0, 0), (0, 0, 255)],
|
||||
"auto": True
|
||||
})
|
||||
p.select("transition1")
|
||||
run_for(p, wdt, 6000)
|
||||
|
||||
# Test 2: Multi-color transition
|
||||
print("Test 2: Multi-color transition (red -> green -> blue -> white)")
|
||||
p.set_param("dl", 800)
|
||||
p.set_param("cl", [(255, 0, 0), (0, 255, 0), (0, 0, 255), (255, 255, 255)])
|
||||
p.set_param("auto", True)
|
||||
p.select("transition")
|
||||
p.add("transition2", {
|
||||
"pattern": "transition",
|
||||
"delay": 800,
|
||||
"colors": [(255, 0, 0), (0, 255, 0), (0, 0, 255), (255, 255, 255)],
|
||||
"auto": True
|
||||
})
|
||||
p.select("transition2")
|
||||
run_for(p, wdt, 8000)
|
||||
|
||||
# Test 3: One-shot transition (auto=False)
|
||||
print("Test 3: One-shot transition (auto=False)")
|
||||
p.set_param("dl", 1000)
|
||||
p.set_param("cl", [(255, 0, 0), (0, 255, 0)])
|
||||
p.set_param("auto", False)
|
||||
p.select("transition")
|
||||
p.add("transition3", {
|
||||
"pattern": "transition",
|
||||
"delay": 1000,
|
||||
"colors": [(255, 0, 0), (0, 255, 0)],
|
||||
"auto": False
|
||||
})
|
||||
p.select("transition3")
|
||||
# Run long enough for a single transition step
|
||||
run_for(p, wdt, 2000)
|
||||
|
||||
# Test 4: Single-color behavior (should just stay on)
|
||||
print("Test 4: Single-color transition (should hold color)")
|
||||
p.set_param("cl", [(0, 0, 255)])
|
||||
p.set_param("dl", 500)
|
||||
p.set_param("auto", True)
|
||||
p.select("transition")
|
||||
p.add("transition4", {
|
||||
"pattern": "transition",
|
||||
"colors": [(0, 0, 255)],
|
||||
"delay": 500,
|
||||
"auto": True
|
||||
})
|
||||
p.select("transition4")
|
||||
run_for(p, wdt, 3000)
|
||||
|
||||
# Cleanup
|
||||
print("Test complete, turning off")
|
||||
p.select("off")
|
||||
p.add("cleanup_off", {"pattern": "off"})
|
||||
p.select("cleanup_off")
|
||||
run_for(p, wdt, 200)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user