Add global brightness support to driver
Handle per-device global brightness via ESPNow messages and apply it alongside per-preset brightness in all patterns.
This commit is contained in:
10
src/main.py
10
src/main.py
@@ -28,9 +28,16 @@ while True:
|
||||
if e.any():
|
||||
host, msg = e.recv()
|
||||
data = json.loads(msg)
|
||||
if data["v"] != "1":
|
||||
# Only handle messages with the expected version.
|
||||
if data.get("v") != "1":
|
||||
continue
|
||||
print(data)
|
||||
# Global brightness (0–255) for this device
|
||||
if "b" in data:
|
||||
try:
|
||||
patterns.b = max(0, min(255, int(data["b"])))
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
if "presets" in data:
|
||||
for name, preset_data in data["presets"].items():
|
||||
# Convert hex color strings to RGB tuples and reorder based on device color order
|
||||
@@ -44,4 +51,3 @@ while True:
|
||||
preset_name = select_list[0]
|
||||
step = select_list[1] if len(select_list) > 1 else None
|
||||
patterns.select(preset_name, step=step)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user