Add support for all RGB color order permutations (RGB, RBG, GRB, GBR, BRG, BGR)
This commit is contained in:
@@ -9,8 +9,7 @@ class Settings(dict):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.load() # Load settings from file during initialization
|
self.load() # Load settings from file during initialization
|
||||||
if self["color_order"] == "rbg": self.color_order = (1, 5, 3)
|
self.color_order = self.get_color_order(self["color_order"])
|
||||||
else: self.color_order = (1, 3, 5)
|
|
||||||
|
|
||||||
def set_defaults(self):
|
def set_defaults(self):
|
||||||
self["led_pin"] = 10
|
self["led_pin"] = 10
|
||||||
@@ -24,6 +23,7 @@ class Settings(dict):
|
|||||||
self["name"] = f"led-{ubinascii.hexlify(wifi.get_mac()).decode()}"
|
self["name"] = f"led-{ubinascii.hexlify(wifi.get_mac()).decode()}"
|
||||||
self["ap_password"] = ""
|
self["ap_password"] = ""
|
||||||
self["id"] = 0
|
self["id"] = 0
|
||||||
|
self["debug"] = False
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
try:
|
try:
|
||||||
@@ -84,8 +84,8 @@ class Settings(dict):
|
|||||||
self.save()
|
self.save()
|
||||||
machine.reset()
|
machine.reset()
|
||||||
elif key == "color_order":
|
elif key == "color_order":
|
||||||
if value == "rbg": self.color_order = (1, 5, 3)
|
self["color_order"] = value
|
||||||
else: self.color_order = (1, 3, 5)
|
self.color_order = self.get_color_order(value)
|
||||||
pass
|
pass
|
||||||
elif key == "id":
|
elif key == "id":
|
||||||
pass
|
pass
|
||||||
@@ -102,6 +102,18 @@ class Settings(dict):
|
|||||||
except (KeyError, ValueError):
|
except (KeyError, ValueError):
|
||||||
return "Bad request", 400
|
return "Bad request", 400
|
||||||
|
|
||||||
|
def get_color_order(self, color_order):
|
||||||
|
"""Convert color order string to tuple of hex string indices."""
|
||||||
|
color_orders = {
|
||||||
|
"rgb": (1, 3, 5),
|
||||||
|
"rbg": (1, 5, 3),
|
||||||
|
"grb": (3, 1, 5),
|
||||||
|
"gbr": (3, 5, 1),
|
||||||
|
"brg": (5, 1, 3),
|
||||||
|
"bgr": (5, 3, 1)
|
||||||
|
}
|
||||||
|
return color_orders.get(color_order.lower(), (1, 3, 5)) # Default to RGB
|
||||||
|
|
||||||
# Example usage
|
# Example usage
|
||||||
def main():
|
def main():
|
||||||
settings = Settings()
|
settings = Settings()
|
||||||
|
|||||||
Reference in New Issue
Block a user