77from labthings_fastapi .thing import Thing
88from labthings_fastapi .decorators import thing_action , thing_property
99from labthings_fastapi .dependencies .invocation import CancelHook , InvocationCancelledError
10- from typing import Iterator
10+ from typing import Iterator , Literal
1111from contextlib import contextmanager
1212from collections .abc import Sequence , Mapping
1313import sangaboard
1414import threading
15+ import time
1516import numpy as np
1617
1718class 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