Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/trcc/core/commands/led.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ def execute(self, app: App) -> LedColorsResult:
# device (LCD carries a surface; LED carries the colors).
app.events.publish(FrameSent(
key=self.key, bytes_sent=len(colors), display_colors=colors,
mask=list(mask),
))
return LedColorsResult(
ok=ok, key=self.key, colors=colors,
Expand Down
4 changes: 4 additions & 0 deletions src/trcc/core/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ class FrameSent(Event):
# LCD (one render → FrameSent → handle_frame → preview), not a parallel
# one. Empty for LCD / pure-bytes sends.
display_colors: list = field(default_factory=list)
# LED segment mask (list of bool) — determines which LEDs are
# lit vs off. Carried alongside display_colors so the GUI preview
# accurately mirrors the physical hardware for segment-display styles.
mask: list = field(default_factory=list)


@dataclass(frozen=True, slots=True)
Expand Down
3 changes: 2 additions & 1 deletion src/trcc/ui/gui/led_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,10 @@ def _on_test_mode_changed(self, on: bool) -> None:
def handle_frame(self, image: Any) -> None:
"""Receive tick result — update LED color display on the panel."""
display_colors = image.get('display_colors') if isinstance(image, dict) else None
display_mask = image.get('mask') if isinstance(image, dict) else None
log.debug("handle_frame: active=%s colors=%s",
self._active, len(display_colors) if display_colors else None)
if not self._active:
return
if display_colors is not None:
self._panel.set_led_colors(display_colors)
self._panel.set_led_colors(display_colors, display_mask)
3 changes: 2 additions & 1 deletion src/trcc/ui/gui/trcc_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,11 @@ def _on_bus_frame_sent(self, event: Any) -> None:
# FrameSent → handle_frame seam (the device's render IS the preview).
surface = getattr(event, "surface", None)
colors = getattr(event, "display_colors", None)
mask = getattr(event, "mask", None)
if surface is not None:
handler.handle_frame(surface)
elif colors:
handler.handle_frame({"display_colors": list(colors)})
handler.handle_frame({"display_colors": list(colors), "mask": list(mask) if mask else None})
else:
handler.rebuild_preview()

Expand Down
4 changes: 3 additions & 1 deletion src/trcc/ui/gui/uc_led_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,9 +859,11 @@ def initialize(self, style_id: int, segment_count: int,
elif is_lf11:
self._populate_disk_identity()

def set_led_colors(self, colors: list[tuple[int, int, int]]) -> None:
def set_led_colors(self, colors: list[tuple[int, int, int]], mask: list[bool] | None = None) -> None:
"""Update LED preview from controller tick."""
self._preview.set_colors(colors)
if mask is not None:
self._preview.set_mask(mask)

def set_status(self, text: str) -> None:
"""Update status text."""
Expand Down
9 changes: 9 additions & 0 deletions src/trcc/ui/gui/uc_screen_led.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,13 @@ def set_colors(self, colors: list[tuple[int, int, int]]) -> None:
self._colors.append((0, 0, 0))
self.update()

def set_mask(self, mask: list[bool]) -> None:
"""Update LED on/off mask from controller tick."""
self._is_on = list(mask[:len(self._is_on)])
while len(self._is_on) < len(self._positions):
self._is_on.append(False)
self.update()

def set_segment_on(self, index: int, on: bool) -> None:
"""Toggle an individual segment."""
if 0 <= index < len(self._is_on):
Expand Down Expand Up @@ -637,6 +644,8 @@ def _paint_led_rects(self, painter: QPainter) -> None:
for i, pos in enumerate(self._positions):
if i >= len(self._colors):
break
if i < len(self._is_on) and not self._is_on[i]:
continue
r, g, b = self._colors[i]
if r == 0 and g == 0 and b == 0:
continue
Expand Down