fixing leds

This commit is contained in:
Alex
2026-04-11 15:58:56 -05:00
parent 10e39dd0f1
commit 2f7b45fa45

View File

@@ -32,12 +32,13 @@ CTRL_REQUEST_TYPE_IN = usb.util.CTRL_IN | usb.util.CTRL_TYPE_VENDOR | usb.util
GPO_RESID = 20 GPO_RESID = 20
# Command IDs (wValue in USB control transfer) # Command IDs (wValue in USB control transfer)
# Verified against official xvf_host.py WriteCMD output
DOA_VALUE_CMD = 18 # returns (angle 0-359, vad 0/1) DOA_VALUE_CMD = 18 # returns (angle 0-359, vad 0/1)
LED_EFFECT_CMD = 12 # 0=off, 1=breath, 2=rainbow, 3=solid, 4=doa, 5=ring LED_EFFECT_CMD = 12 # 0=off, 1=breath, 2=rainbow, 3=solid, 4=doa, 5=ring
LED_BRIGHTNESS_CMD = 13 LED_BRIGHTNESS_CMD = 14
LED_COLOR_CMD = 15 # single uint32 color LED_COLOR_CMD = 16 # single uint32 color (confirmed: xvf_host LED_COLOR cmdid=16)
LED_DOA_COLOR_CMD = 16 # two uint32 values: base + indicator LED_DOA_COLOR_CMD = 17 # two uint32 values: base + indicator
LED_RING_COLOR_CMD = 17 # 12 × uint32 LED_RING_COLOR_CMD = 18 # 12 × uint32
class XVF3800: class XVF3800:
@@ -94,20 +95,28 @@ class XVF3800:
def led_off(self): def led_off(self):
self._write(GPO_RESID, LED_EFFECT_CMD, struct.pack("<I", 0)) self._write(GPO_RESID, LED_EFFECT_CMD, struct.pack("<I", 0))
@staticmethod
def _color_bytes(color: int) -> bytes:
"""Convert 0xRRGGBB to [R, G, B, 0] payload."""
r = (color >> 16) & 0xFF
g = (color >> 8) & 0xFF
b = color & 0xFF
return bytes([r, g, b, 0])
def led_solid(self, color: int): def led_solid(self, color: int):
"""Solid color on all LEDs. color is 0xRRGGBB.""" """Solid color on all LEDs. color is 0xRRGGBB."""
self._write(GPO_RESID, LED_COLOR_CMD, struct.pack("<I", color)) self._write(GPO_RESID, LED_COLOR_CMD, self._color_bytes(color))
self._write(GPO_RESID, LED_EFFECT_CMD, struct.pack("<I", 3)) self._write(GPO_RESID, LED_EFFECT_CMD, struct.pack("<I", 3))
def led_breath(self, color: int, brightness: int = 128): def led_breath(self, color: int, brightness: int = 128):
"""Breathing effect.""" """Breathing effect."""
self._write(GPO_RESID, LED_COLOR_CMD, struct.pack("<I", color)) self._write(GPO_RESID, LED_COLOR_CMD, self._color_bytes(color))
self._write(GPO_RESID, LED_BRIGHTNESS_CMD, struct.pack("<I", brightness)) self._write(GPO_RESID, LED_BRIGHTNESS_CMD, struct.pack("<I", brightness))
self._write(GPO_RESID, LED_EFFECT_CMD, struct.pack("<I", 1)) self._write(GPO_RESID, LED_EFFECT_CMD, struct.pack("<I", 1))
def led_doa(self, base_color: int = 0x003333, doa_color: int = 0x00FFFF): def led_doa(self, base_color: int = 0x003333, doa_color: int = 0x00FFFF):
"""DoA indicator mode — shows beam direction on LED ring.""" """DoA indicator mode — shows beam direction on LED ring."""
data = struct.pack("<II", base_color, doa_color) data = self._color_bytes(base_color) + self._color_bytes(doa_color)
self._write(GPO_RESID, LED_DOA_COLOR_CMD, data) self._write(GPO_RESID, LED_DOA_COLOR_CMD, data)
self._write(GPO_RESID, LED_EFFECT_CMD, struct.pack("<I", 4)) self._write(GPO_RESID, LED_EFFECT_CMD, struct.pack("<I", 4))