Flash LED endpoint in simulator for parity

This commit is contained in:
Joe Knapper 2026-02-10 15:52:06 +00:00
parent 9ab5a461c0
commit 1de4366df7
2 changed files with 23 additions and 2 deletions

View file

@ -342,7 +342,11 @@ class SimulatedCamera(BaseCamera):
def generate_frame(self) -> Image.Image:
"""Generate a frame with blobs based on the stage coordinates."""
pos = self._stage.instantaneous_position
return self.generate_image((pos["y"], pos["x"], pos["z"]))
frame = self.generate_image((pos["y"], pos["x"], pos["z"]))
# Simulate LED turning off by setting all channels to 0
if not self._stage.led_on:
frame = np.full((self.shape[0], self.shape[1], 3), 0, dtype=np.uint8)
return frame
def __enter__(self) -> Self:
"""Start the capture thread when the Thing context manager is opened."""

View file

@ -4,7 +4,7 @@ from __future__ import annotations
import time
from types import TracebackType
from typing import Any, Optional, Self
from typing import Any, Literal, Optional, Self
import labthings_fastapi as lt
@ -18,6 +18,8 @@ class DummyStage(BaseStage):
hardware attached.
"""
led_on: bool = lt.property(default=True)
def __init__(
self,
thing_server_interface: lt.ThingServerInterface,
@ -115,3 +117,18 @@ class DummyStage(BaseStage):
"""
self._hardware_position = dict.fromkeys(self.axis_names, 0)
self.instantaneous_position = self._hardware_position
# led_channel is unused in the simulation, but must exist to match the real API
@lt.action
def flash_led(
self,
number_of_flashes: int = 10,
dt: float = 0.5,
led_channel: Literal["cc"] = "cc", # noqa: ARG002
) -> None:
"""Flash the LED to identify the board (simulated)."""
for _ in range(number_of_flashes):
self.led_on = False
time.sleep(dt)
self.led_on = True
time.sleep(dt)