Add knight rider LED effect via STM32 USB companion IC
This commit is contained in:
@@ -24,8 +24,8 @@ except ImportError:
|
|||||||
_HAS_USB = False
|
_HAS_USB = False
|
||||||
|
|
||||||
# ── STM32 companion USB IDs — update after running lsusb ─────────────────────
|
# ── STM32 companion USB IDs — update after running lsusb ─────────────────────
|
||||||
_STM32_VID = None # e.g. 0x0483
|
_STM32_VID = 0x2f8f # Flowbird Axio4 Companion
|
||||||
_STM32_PID = None # e.g. 0x5740
|
_STM32_PID = 0x0003
|
||||||
|
|
||||||
# ── Force framebuffer QPA before any Qt import ────────────────────────────────
|
# ── Force framebuffer QPA before any Qt import ────────────────────────────────
|
||||||
if 'DISPLAY' not in os.environ and 'QT_QPA_PLATFORM' not in os.environ:
|
if 'DISPLAY' not in os.environ and 'QT_QPA_PLATFORM' not in os.environ:
|
||||||
@@ -336,10 +336,22 @@ class LedController:
|
|||||||
if _HAS_USB and _STM32_VID:
|
if _HAS_USB and _STM32_VID:
|
||||||
try:
|
try:
|
||||||
self._dev = usb.core.find(idVendor=_STM32_VID, idProduct=_STM32_PID)
|
self._dev = usb.core.find(idVendor=_STM32_VID, idProduct=_STM32_PID)
|
||||||
if self._dev:
|
|
||||||
self._dev.set_configuration()
|
|
||||||
except Exception:
|
except Exception:
|
||||||
self._dev = None
|
self._dev = None
|
||||||
|
if self._dev:
|
||||||
|
try:
|
||||||
|
self._dev.set_configuration()
|
||||||
|
except Exception:
|
||||||
|
pass # already configured by kernel driver
|
||||||
|
try:
|
||||||
|
if self._dev.is_kernel_driver_active(1):
|
||||||
|
self._dev.detach_kernel_driver(1)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
usb.util.claim_interface(self._dev, 1)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
# ── Public ────────────────────────────────────────────────────────────────
|
# ── Public ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
@@ -354,6 +366,10 @@ class LedController:
|
|||||||
self._running = False
|
self._running = False
|
||||||
if self._dev:
|
if self._dev:
|
||||||
self._set_brightness(self.STRING_MAIN, 0)
|
self._set_brightness(self.STRING_MAIN, 0)
|
||||||
|
try:
|
||||||
|
usb.util.release_interface(self._dev, 1)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
# ── USB helpers ───────────────────────────────────────────────────────────
|
# ── USB helpers ───────────────────────────────────────────────────────────
|
||||||
|
|
||||||
@@ -391,9 +407,10 @@ class LedController:
|
|||||||
# ── Knight rider loop ─────────────────────────────────────────────────────
|
# ── Knight rider loop ─────────────────────────────────────────────────────
|
||||||
|
|
||||||
def _knight_rider(self):
|
def _knight_rider(self):
|
||||||
STEPS = 20 # steps per half-cycle
|
STEPS = 30 # steps per half-cycle
|
||||||
STEP_MS = 0.03 # 30 ms per step → ~600 ms fade up, ~600 ms fade down
|
STEP_MS = 0.05 # 50 ms per step → ~1.5 s fade up, ~1.5 s fade down
|
||||||
|
|
||||||
|
self._set_brightness(self.STRING_MAIN, 255)
|
||||||
while self._running:
|
while self._running:
|
||||||
# Fade purple → pink
|
# Fade purple → pink
|
||||||
for i in range(STEPS):
|
for i in range(STEPS):
|
||||||
|
|||||||
Reference in New Issue
Block a user