Skip to content

Commit

Permalink
Update hardware.py
Browse files Browse the repository at this point in the history
  • Loading branch information
bimac committed Oct 31, 2023
1 parent f13ea04 commit 606316d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions iblrig/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Bpod(BpodIO):
_instances = {}
_lock = threading.Lock()
_is_initialized = False
_can_control_led = True

def __new__(cls, *args, **kwargs):
serial_port = args[0] if len(args) > 0 else ''
Expand Down Expand Up @@ -64,6 +65,7 @@ def __init__(self, *args, **kwargs):
"Please unplug the Bpod USB cable from the computer and plug it back in to start the task. ") from e
self.default_message_idx = 0
self.actions = Bunch({})
self._can_control_led = self.set_status_led(True)
self._is_initialized = True

def close(self) -> None:
Expand Down Expand Up @@ -180,17 +182,17 @@ def toggle_valve(self, duration=None):

@static_vars(supported=True)
def set_status_led(self, state: bool) -> bool:
if self._arcom.serial_object and self.set_status_led.supported:
if self._can_control_led and self._arcom.serial_object:
try:
log.info(f'{"en" if state else "dis"}abling Bpod Status LED')
command = struct.pack("cB", b":", state)
self._arcom.serial_object.write(command)
if self._arcom.read_uint8() == 1:
return True
except serial.SerialException:
self._arcom.serial_object.flush()
log.error('Bpod device does not support control of the status LED. Please update firmware.')
self.set_status_led.supported = False
pass
self._arcom.serial_object.flush()
log.error('Bpod device does not support control of the status LED. Please update firmware.')
return False

def valve(self, valve_id: int, state: bool):
Expand Down

0 comments on commit 606316d

Please sign in to comment.