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:
2026-02-07 11:40:04 +13:00
parent f35d8f7084
commit 43957adb28
14 changed files with 253 additions and 225 deletions

View File

@@ -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, ms):
@@ -19,19 +19,19 @@ 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)
# 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.edit("circle1", {
"pattern": "circle",
"brightness": 255,
"p": "circle",
"b": 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
"c": [(255, 0, 0)], # Red
})
p.select("circle1")
run_for(p, wdt, 5000)
@@ -39,12 +39,12 @@ def main():
# 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.edit("circle2", {
"pattern": "circle",
"p": "circle",
"n1": 20,
"n2": 50,
"n3": 100,
"n4": 0,
"colors": [(0, 255, 0)] # Green
"c": [(0, 255, 0)], # Green
})
p.select("circle2")
run_for(p, wdt, 5000)
@@ -52,12 +52,12 @@ def main():
# 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.edit("circle3", {
"pattern": "circle",
"p": "circle",
"n1": 100,
"n2": 30,
"n3": 20,
"n4": 0,
"colors": [(0, 0, 255)] # Blue
"c": [(0, 0, 255)], # Blue
})
p.select("circle3")
run_for(p, wdt, 5000)
@@ -65,12 +65,12 @@ def main():
# 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.edit("circle4", {
"pattern": "circle",
"p": "circle",
"n1": 50,
"n2": 40,
"n3": 100,
"n4": 10,
"colors": [(255, 255, 0)] # Yellow
"c": [(255, 255, 0)], # Yellow
})
p.select("circle4")
run_for(p, wdt, 5000)
@@ -78,12 +78,12 @@ def main():
# 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.edit("circle5", {
"pattern": "circle",
"p": "circle",
"n1": 200,
"n2": 20,
"n3": 200,
"n4": 0,
"colors": [(255, 0, 255)] # Magenta
"c": [(255, 0, 255)], # Magenta
})
p.select("circle5")
run_for(p, wdt, 3000)
@@ -91,19 +91,19 @@ def main():
# 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.edit("circle6", {
"pattern": "circle",
"p": "circle",
"n1": 10,
"n2": 25,
"n3": 10,
"n4": 0,
"colors": [(0, 255, 255)] # Cyan
"c": [(0, 255, 255)], # Cyan
})
p.select("circle6")
run_for(p, wdt, 5000)
# Cleanup
print("Test complete, turning off")
p.edit("cleanup_off", {"pattern": "off"})
p.edit("cleanup_off", {"p": "off"})
p.select("cleanup_off")
run_for(p, wdt, 100)