feat(driver): add HTTP routes, startup split, and binary envelope support
Wire controller messages through new modules (background tasks, runtime state, startup) and add binary envelope handling. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import json
|
||||
import socket
|
||||
|
||||
from binary_envelope import parse_binary_envelope
|
||||
from utils import convert_and_reorder_colors
|
||||
|
||||
try:
|
||||
@@ -12,13 +13,22 @@ except ImportError:
|
||||
|
||||
|
||||
def process_data(payload, settings, presets, controller_ip=None):
|
||||
"""Read one controller message; json.loads (bytes or str), then apply fields."""
|
||||
try:
|
||||
data = json.loads(payload)
|
||||
print(payload)
|
||||
if data.get("v", "") != "1":
|
||||
"""Read one controller message; binary v1 envelope or JSON v1, then apply fields."""
|
||||
data = None
|
||||
if isinstance(payload, (bytes, bytearray)):
|
||||
data = parse_binary_envelope(payload)
|
||||
if data is None:
|
||||
try:
|
||||
data = json.loads(payload)
|
||||
except (ValueError, TypeError):
|
||||
return
|
||||
else:
|
||||
try:
|
||||
data = json.loads(payload)
|
||||
except (ValueError, TypeError):
|
||||
return
|
||||
except (ValueError, TypeError):
|
||||
print(payload)
|
||||
if data.get("v", "") != "1":
|
||||
return
|
||||
if "b" in data:
|
||||
apply_brightness(data, settings, presets)
|
||||
|
||||
Reference in New Issue
Block a user