Add support for all RGB color order permutations (RGB, RBG, GRB, GBR, BRG, BGR)

This commit is contained in:
2025-11-30 18:26:56 +13:00
parent 47837c00e5
commit f53c57f036
2 changed files with 28 additions and 9 deletions

View File

@@ -9,8 +9,21 @@ 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.get("color_order", "rgb"))
def _get_color_order(self, order):
"""Convert color order string to tuple of hex string indices.
Hex string format: #RRGGBB where indices are 1, 3, 5 (0-indexed).
Returns tuple (R_index, G_index, B_index) for hex string parsing."""
color_orders = {
"rgb": (1, 3, 5), # Red at 1, Green at 3, Blue at 5
"rbg": (1, 5, 3), # Red at 1, Blue at 5, Green at 3
"grb": (3, 1, 5), # Green at 3, Red at 1, Blue at 5
"gbr": (3, 5, 1), # Green at 3, Blue at 5, Red at 1
"brg": (5, 1, 3), # Blue at 5, Red at 1, Green at 3
"bgr": (5, 3, 1), # Blue at 5, Green at 3, Red at 1
}
return color_orders.get(order.lower(), (1, 3, 5)) # Default to RGB
def set_defaults(self):
self["led_pin"] = 10
@@ -84,8 +97,7 @@ 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 = self._get_color_order(value)
pass
elif key == "id":
pass