Skip to content

Commit 034990f

Browse files
committed
Add an action to flash the LED
1 parent c1c6c88 commit 034990f

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/labthings_sangaboard/__init__.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
from labthings_fastapi.thing import Thing
88
from labthings_fastapi.decorators import thing_action, thing_property
99
from labthings_fastapi.dependencies.invocation import CancelHook, InvocationCancelledError
10-
from typing import Iterator
10+
from typing import Iterator, Literal
1111
from contextlib import contextmanager
1212
from collections.abc import Sequence, Mapping
1313
import sangaboard
1414
import threading
15+
import time
1516
import numpy as np
1617

1718
class SangaboardThing(Thing):
@@ -141,3 +142,31 @@ def set_zero_position(self):
141142
with self.sangaboard() as sb:
142143
sb.zero_position()
143144
self.update_position()
145+
146+
@thing_action
147+
def flash_led(
148+
self,
149+
number_of_flashes: int = 10,
150+
dt: float = 0.5,
151+
led_channel: Literal["cc"]="cc",
152+
) -> None:
153+
"""Flash the LED to identify the board
154+
155+
This is intended to be useful in situations where there are multiple
156+
Sangaboards in use, and it is necessary to identify which one is
157+
being addressed.
158+
"""
159+
with self.sangaboard() as sb:
160+
r = sb.query("led_cc?")
161+
if not r.startswith('CC LED:'):
162+
raise IOError("The sangaboard does not support LED control")
163+
# This suffers from repeated reads and writes decreasing it, so for
164+
# now, I'll fix it at the default value.
165+
# TODO: proper LED control from python
166+
#on_brightness = float(r[7:])
167+
on_brightness = 0.32
168+
for i in range(number_of_flashes):
169+
sb.query("led_cc 0")
170+
time.sleep(dt)
171+
sb.query(f"led_cc {on_brightness}")
172+
time.sleep(dt)

0 commit comments

Comments
 (0)