Files
pti-ledy/rpi/mock_rpi_ws281x.py
T
cos 7d2fe96704 add mock mode, websocket display stream, and text editor
- mock_rpi_ws281x: stub for running without RPi hardware; auto-fallback
  on RuntimeError, forced via --mock flag or MOCK_LED env var
- mock mode runs web server on port 8080 instead of 80
- replace display polling with WebSocket stream (/ws/display); client
  sends start/stop messages, server pushes binary RGB frames
- force-button feedback: button shows waiting state and polls until
  the cycle clears the flag
- text editor UI: edit top and bottom texts with per-segment color
  pickers; saved to texts.json for persistence across restarts
- bottom and top texts read from server state instead of hardcoded
- bottom text switched to _add_multi_color_node to support multi-color
- fix bottom text invisible: split scroll_all_multi_color_texts into
  top (y<8) and bottom (y>=8) passes so fill_pixels does not wipe
  bottom nodes before they are drawn; this also fixes force-vehicles
  polling loop that stalled when the bottom node never expired

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-30 21:15:39 +02:00

40 lines
848 B
Python

"""
Stub replacement for rpi_ws281x that allows running without a Raspberry Pi.
Pixel data is stored in memory; hardware calls are no-ops.
"""
def Color(r, g, b):
return ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF)
class _ws:
WS2811_STRIP_GRB = 0x00081000
ws = _ws()
class PixelStrip:
def __init__(self, num, pin, freq_hz=800000, dma=5, invert=False,
brightness=255, channel=0, strip_type=None, gamma=None):
self._pixels = [0] * num
def begin(self):
pass
def show(self):
pass
def setBrightness(self, brightness):
pass
def setPixelColor(self, n, color):
if 0 <= n < len(self._pixels):
self._pixels[n] = color
def getPixelColor(self, n):
if 0 <= n < len(self._pixels):
return self._pixels[n]
return 0