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,20 +19,20 @@ 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 chase (n1=5, n2=5, n3=1, n4=1)
print("Test 1: Basic chase (n1=5, n2=5, n3=1, n4=1)")
p.edit("chase1", {
"pattern": "chase",
"brightness": 255,
"delay": 200,
"p": "chase",
"b": 255,
"d": 200,
"n1": 5,
"n2": 5,
"n3": 1,
"n4": 1,
"colors": [(255, 0, 0), (0, 255, 0)]
"c": [(255, 0, 0), (0, 255, 0)],
})
p.select("chase1")
run_for(p, wdt, 3000)
@@ -40,13 +40,13 @@ def main():
# Test 2: Forward and backward (n3=2, n4=-1)
print("Test 2: Forward and backward (n3=2, n4=-1)")
p.edit("chase2", {
"pattern": "chase",
"p": "chase",
"n1": 3,
"n2": 3,
"n3": 2,
"n4": -1,
"delay": 150,
"colors": [(0, 0, 255), (255, 255, 0)]
"d": 150,
"c": [(0, 0, 255), (255, 255, 0)],
})
p.select("chase2")
run_for(p, wdt, 3000)
@@ -54,13 +54,13 @@ def main():
# Test 3: Large segments (n1=10, n2=5)
print("Test 3: Large segments (n1=10, n2=5, n3=3, n4=3)")
p.edit("chase3", {
"pattern": "chase",
"p": "chase",
"n1": 10,
"n2": 5,
"n3": 3,
"n4": 3,
"delay": 200,
"colors": [(255, 128, 0), (128, 0, 255)]
"d": 200,
"c": [(255, 128, 0), (128, 0, 255)],
})
p.select("chase3")
run_for(p, wdt, 3000)
@@ -68,13 +68,13 @@ def main():
# Test 4: Fast movement (n3=5, n4=5)
print("Test 4: Fast movement (n3=5, n4=5)")
p.edit("chase4", {
"pattern": "chase",
"p": "chase",
"n1": 4,
"n2": 4,
"n3": 5,
"n4": 5,
"delay": 100,
"colors": [(255, 0, 255), (0, 255, 255)]
"d": 100,
"c": [(255, 0, 255), (0, 255, 255)],
})
p.select("chase4")
run_for(p, wdt, 2000)
@@ -82,13 +82,13 @@ def main():
# Test 5: Backward movement (n3=-2, n4=-2)
print("Test 5: Backward movement (n3=-2, n4=-2)")
p.edit("chase5", {
"pattern": "chase",
"p": "chase",
"n1": 6,
"n2": 4,
"n3": -2,
"n4": -2,
"delay": 200,
"colors": [(255, 255, 255), (0, 0, 0)]
"d": 200,
"c": [(255, 255, 255), (0, 0, 0)],
})
p.select("chase5")
run_for(p, wdt, 3000)
@@ -96,13 +96,13 @@ def main():
# Test 6: Alternating forward/backward (n3=3, n4=-2)
print("Test 6: Alternating forward/backward (n3=3, n4=-2)")
p.edit("chase6", {
"pattern": "chase",
"p": "chase",
"n1": 5,
"n2": 5,
"n3": 3,
"n4": -2,
"delay": 250,
"colors": [(255, 0, 0), (0, 255, 0)]
"d": 250,
"c": [(255, 0, 0), (0, 255, 0)],
})
p.select("chase6")
run_for(p, wdt, 4000)
@@ -110,14 +110,14 @@ def main():
# Test 7: Manual mode - advance one step per beat
print("Test 7: Manual mode chase (auto=False, n3=2, n4=1)")
p.edit("chase_manual", {
"pattern": "chase",
"p": "chase",
"n1": 4,
"n2": 4,
"n3": 2,
"n4": 1,
"delay": 200,
"colors": [(255, 255, 0), (0, 255, 255)],
"auto": False
"d": 200,
"c": [(255, 255, 0), (0, 255, 255)],
"a": False,
})
p.step = 0 # Reset step counter
print(" Advancing pattern with 10 beats (select + tick)...")
@@ -131,12 +131,12 @@ def main():
# Test 8: Verify step increments correctly in manual mode
print("Test 8: Verify step increments (auto=False)")
p.edit("chase_manual2", {
"pattern": "chase",
"p": "chase",
"n1": 3,
"n2": 3,
"n3": 1,
"n4": 1,
"auto": False
"a": False,
})
p.step = 0
initial_step = p.step
@@ -151,7 +151,7 @@ def main():
# 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)