Rename patterns module to presets
Rename the driver module and update imports so tests and main entry use the new presets naming, while moving Preset to its own file. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
import utime
|
||||
from machine import WDT
|
||||
from settings import Settings
|
||||
from patterns import Patterns
|
||||
from presets import Presets
|
||||
|
||||
|
||||
def run_for(p, wdt, duration_ms):
|
||||
@@ -19,7 +19,7 @@ def main():
|
||||
pin = s.get("led_pin", 10)
|
||||
num = s.get("num_leds", 30)
|
||||
|
||||
p = Patterns(pin=pin, num_leds=num)
|
||||
p = Presets(pin=pin, num_leds=num)
|
||||
wdt = WDT(timeout=10000)
|
||||
|
||||
print("=" * 50)
|
||||
@@ -29,11 +29,11 @@ def main():
|
||||
# Test 1: Rainbow in AUTO mode (continuous)
|
||||
print("\nTest 1: Rainbow pattern in AUTO mode (should run continuously)")
|
||||
p.edit("rainbow_auto", {
|
||||
"pattern": "rainbow",
|
||||
"brightness": 128,
|
||||
"delay": 50,
|
||||
"p": "rainbow",
|
||||
"b": 128,
|
||||
"d": 50,
|
||||
"n1": 2,
|
||||
"auto": True
|
||||
"a": True,
|
||||
})
|
||||
p.select("rainbow_auto")
|
||||
print("Running rainbow_auto for 3 seconds...")
|
||||
@@ -43,11 +43,11 @@ def main():
|
||||
# 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", {
|
||||
"pattern": "rainbow",
|
||||
"brightness": 128,
|
||||
"delay": 50,
|
||||
"p": "rainbow",
|
||||
"b": 128,
|
||||
"d": 50,
|
||||
"n1": 2,
|
||||
"auto": False
|
||||
"a": False,
|
||||
})
|
||||
p.select("rainbow_manual")
|
||||
print("Calling tick() 5 times (should advance 5 steps)...")
|
||||
@@ -65,14 +65,14 @@ def main():
|
||||
# Test 3: Pulse in AUTO mode (continuous cycles)
|
||||
print("\nTest 3: Pulse pattern in AUTO mode (should pulse continuously)")
|
||||
p.edit("pulse_auto", {
|
||||
"pattern": "pulse",
|
||||
"brightness": 128,
|
||||
"delay": 100,
|
||||
"p": "pulse",
|
||||
"b": 128,
|
||||
"d": 100,
|
||||
"n1": 500, # Attack
|
||||
"n2": 200, # Hold
|
||||
"n3": 500, # Decay
|
||||
"colors": [(255, 0, 0)],
|
||||
"auto": True
|
||||
"c": [(255, 0, 0)],
|
||||
"a": True,
|
||||
})
|
||||
p.select("pulse_auto")
|
||||
print("Running pulse_auto for 3 seconds...")
|
||||
@@ -82,14 +82,14 @@ def main():
|
||||
# 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", {
|
||||
"pattern": "pulse",
|
||||
"brightness": 128,
|
||||
"delay": 100,
|
||||
"p": "pulse",
|
||||
"b": 128,
|
||||
"d": 100,
|
||||
"n1": 300, # Attack
|
||||
"n2": 200, # Hold
|
||||
"n3": 300, # Decay
|
||||
"colors": [(0, 255, 0)],
|
||||
"auto": False
|
||||
"c": [(0, 255, 0)],
|
||||
"a": False,
|
||||
})
|
||||
p.select("pulse_manual")
|
||||
print("Running pulse_manual until generator stops...")
|
||||
@@ -108,11 +108,11 @@ def main():
|
||||
# Test 5: Transition in AUTO mode (continuous transitions)
|
||||
print("\nTest 5: Transition pattern in AUTO mode (continuous transitions)")
|
||||
p.edit("transition_auto", {
|
||||
"pattern": "transition",
|
||||
"brightness": 128,
|
||||
"delay": 500,
|
||||
"colors": [(255, 0, 0), (0, 255, 0), (0, 0, 255)],
|
||||
"auto": True
|
||||
"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...")
|
||||
@@ -122,11 +122,11 @@ def main():
|
||||
# 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", {
|
||||
"pattern": "transition",
|
||||
"brightness": 128,
|
||||
"delay": 500,
|
||||
"colors": [(255, 0, 0), (0, 255, 0)],
|
||||
"auto": False
|
||||
"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...")
|
||||
@@ -145,11 +145,11 @@ def main():
|
||||
# Test 7: Switching between auto and manual modes
|
||||
print("\nTest 7: Switching between auto and manual modes")
|
||||
p.edit("switch_test", {
|
||||
"pattern": "rainbow",
|
||||
"brightness": 128,
|
||||
"delay": 50,
|
||||
"p": "rainbow",
|
||||
"b": 128,
|
||||
"d": 50,
|
||||
"n1": 2,
|
||||
"auto": True
|
||||
"a": True,
|
||||
})
|
||||
p.select("switch_test")
|
||||
print("Running in auto mode for 1 second...")
|
||||
@@ -157,7 +157,7 @@ def main():
|
||||
|
||||
# Switch to manual mode by editing the preset
|
||||
print("Switching to manual mode...")
|
||||
p.edit("switch_test", {"auto": False})
|
||||
p.edit("switch_test", {"a": False})
|
||||
p.select("switch_test") # Re-select to apply changes
|
||||
|
||||
print("Calling tick() 3 times in manual mode...")
|
||||
@@ -168,7 +168,7 @@ def main():
|
||||
|
||||
# Switch back to auto mode
|
||||
print("Switching back to auto mode...")
|
||||
p.edit("switch_test", {"auto": True})
|
||||
p.edit("switch_test", {"a": True})
|
||||
p.select("switch_test")
|
||||
print("Running in auto mode for 1 second...")
|
||||
run_for(p, wdt, 1000)
|
||||
@@ -176,7 +176,7 @@ def main():
|
||||
|
||||
# Cleanup
|
||||
print("\nCleaning up...")
|
||||
p.edit("cleanup_off", {"pattern": "off"})
|
||||
p.edit("cleanup_off", {"p": "off"})
|
||||
p.select("cleanup_off")
|
||||
p.tick()
|
||||
utime.sleep_ms(100)
|
||||
|
||||
Reference in New Issue
Block a user