Illumination Things for sangaboard and simulator
This commit is contained in:
parent
8435f6ae98
commit
5682b4d28d
3 changed files with 65 additions and 27 deletions
|
|
@ -3,19 +3,12 @@ from typing import Literal
|
|||
|
||||
import labthings_fastapi as lt
|
||||
|
||||
from .stage import BaseStage
|
||||
from .camera import BaseCam
|
||||
|
||||
class Illumination(lt.Thing):
|
||||
"""Abstract illumination controller."""
|
||||
|
||||
brightness: float = lt.property(
|
||||
default=0.0,
|
||||
description="Illumination brightness (0-1)",
|
||||
)
|
||||
|
||||
@lt.action
|
||||
def set_brightness(self, brightness: float) -> None:
|
||||
self.brightness = brightness
|
||||
|
||||
@lt.action
|
||||
def flash(
|
||||
self,
|
||||
|
|
@ -23,22 +16,14 @@ class Illumination(lt.Thing):
|
|||
dt: float = 0.5,
|
||||
) -> None:
|
||||
"""Flash the illumination source."""
|
||||
for _ in range(number_of_flashes):
|
||||
self.set_brightness(1.0)
|
||||
time.sleep(dt)
|
||||
self.set_brightness(0.0)
|
||||
time.sleep(dt)
|
||||
|
||||
raise NotImplementedError(
|
||||
'Flashing the LED can only be done from the simulator or sangaboard'
|
||||
)
|
||||
|
||||
class SangaIllumination(Illumination):
|
||||
"""Illumination driven by a Sangaboard."""
|
||||
|
||||
sangaboard = lt.thing_slot(description="Sangaboard providing LED control")
|
||||
|
||||
@lt.action
|
||||
def set_brightness(self, brightness: float) -> None:
|
||||
self.sangaboard.set_led_brightness(brightness)
|
||||
self.brightness = brightness
|
||||
_stage: BaseStage = lt.thing_slot()
|
||||
|
||||
@lt.action
|
||||
def flash(
|
||||
|
|
@ -48,7 +33,25 @@ class SangaIllumination(Illumination):
|
|||
led_channel: Literal["cc"] = "cc",
|
||||
) -> None:
|
||||
for _ in range(number_of_flashes):
|
||||
self.sangaboard.set_led(True, led_channel)
|
||||
self._stage.set_led(False, led_channel)
|
||||
time.sleep(dt)
|
||||
self.sangaboard.set_led(False, led_channel)
|
||||
self._stage.set_led(True, led_channel)
|
||||
time.sleep(dt)
|
||||
|
||||
class SimulatorIllumination(Illumination):
|
||||
"""Illumination control in the simulator."""
|
||||
|
||||
_cam: BaseCam = lt.thing_slot()
|
||||
|
||||
@lt.action
|
||||
def flash(
|
||||
self,
|
||||
number_of_flashes: int = 10,
|
||||
dt: float = 0.5,
|
||||
led_channel: Literal["cc"] = "cc",
|
||||
) -> None:
|
||||
for _ in range(number_of_flashes):
|
||||
self._cam.set_led(False, led_channel)
|
||||
time.sleep(dt)
|
||||
self._cam.set_led(True, led_channel)
|
||||
time.sleep(dt)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue