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:
@@ -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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user