add short-key param mapping and set_param()
This commit is contained in:
@@ -3,6 +3,24 @@ from neopixel import NeoPixel
|
|||||||
import utime
|
import utime
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
# Short-key parameter mapping for convenience setters
|
||||||
|
param_mapping = {
|
||||||
|
"pt": "selected",
|
||||||
|
"pa": "selected",
|
||||||
|
"cl": "colors",
|
||||||
|
"br": "brightness",
|
||||||
|
"dl": "delay",
|
||||||
|
"nl": "num_leds",
|
||||||
|
"co": "color_order",
|
||||||
|
"lp": "led_pin",
|
||||||
|
"n1": "n1",
|
||||||
|
"n2": "n2",
|
||||||
|
"n3": "n3",
|
||||||
|
"n4": "n4",
|
||||||
|
"n5": "n5",
|
||||||
|
"n6": "n6",
|
||||||
|
}
|
||||||
|
|
||||||
class Patterns:
|
class Patterns:
|
||||||
def __init__(self, pin, num_leds, color1=(0,0,0), color2=(0,0,0), brightness=127, selected="rainbow_cycle", delay=100):
|
def __init__(self, pin, num_leds, color1=(0,0,0), color2=(0,0,0), brightness=127, selected="rainbow_cycle", delay=100):
|
||||||
self.n = NeoPixel(Pin(pin, Pin.OUT), num_leds)
|
self.n = NeoPixel(Pin(pin, Pin.OUT), num_leds)
|
||||||
@@ -62,6 +80,13 @@ class Patterns:
|
|||||||
if self.patterns[self.selected]:
|
if self.patterns[self.selected]:
|
||||||
self.patterns[self.selected]()
|
self.patterns[self.selected]()
|
||||||
|
|
||||||
|
def set_param(self, key, value):
|
||||||
|
if key in param_mapping:
|
||||||
|
setattr(self, param_mapping[key], value)
|
||||||
|
return True
|
||||||
|
print(f"Invalid parameter: {key}")
|
||||||
|
return False
|
||||||
|
|
||||||
def update_num_leds(self, pin, num_leds):
|
def update_num_leds(self, pin, num_leds):
|
||||||
self.n = NeoPixel(Pin(pin, Pin.OUT), num_leds)
|
self.n = NeoPixel(Pin(pin, Pin.OUT), num_leds)
|
||||||
self.num_leds = num_leds
|
self.num_leds = num_leds
|
||||||
|
|||||||
Reference in New Issue
Block a user