diff --git a/src/settings.py b/src/settings.py index 410ed97..ba15882 100644 --- a/src/settings.py +++ b/src/settings.py @@ -9,8 +9,7 @@ class Settings(dict): def __init__(self): super().__init__() self.load() # Load settings from file during initialization - if self["color_order"] == "rbg": self.color_order = (1, 5, 3) - else: self.color_order = (1, 3, 5) + self.color_order = self.get_color_order(self["color_order"]) def set_defaults(self): self["led_pin"] = 10 @@ -24,6 +23,7 @@ class Settings(dict): self["name"] = f"led-{ubinascii.hexlify(wifi.get_mac()).decode()}" self["ap_password"] = "" self["id"] = 0 + self["debug"] = False def save(self): try: @@ -84,8 +84,8 @@ class Settings(dict): self.save() machine.reset() elif key == "color_order": - if value == "rbg": self.color_order = (1, 5, 3) - else: self.color_order = (1, 3, 5) + self["color_order"] = value + self.color_order = self.get_color_order(value) pass elif key == "id": pass @@ -102,6 +102,18 @@ class Settings(dict): except (KeyError, ValueError): 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 def main(): settings = Settings()