OptoGrid
- class OptoGrid(sessions_directory: str = '', filename: str = '', device_name: str = 'OptoGrid 1', command_timeout: float = 5.0, scan_timeout: float = 4.0, device_log: bool = False, save_accel_gyro: bool = True, save_orientation: bool = True, save_magnetometer: bool = False, imu_logging: bool = True, sham: bool = False)[source]
Bases:
objectSynchronous, thread-safe BLE driver for the OptoGrid, with optional IMU logging. BLE work happens on a private background thread; public methods block the calling thread for the BLE round-trip but never block the loop.
- __init__(sessions_directory: str = '', filename: str = '', device_name: str = 'OptoGrid 1', command_timeout: float = 5.0, scan_timeout: float = 4.0, device_log: bool = False, save_accel_gyro: bool = True, save_orientation: bool = True, save_magnetometer: bool = False, imu_logging: bool = True, sham: bool = False)[source]
Methods
Attributes
- imu_raw_history: deque
- start() None[source]
- stop() None[source]
- property is_connected: bool
- property is_connecting: bool
- property address: str | None
- status() str[source]
Human-readable connection status, e.g. for a GUI label.
- connect(identifier: str | None = None, timeout: float = 10.0) bool[source]
- connect_async(identifier: str | None = None, timeout: float = 10.0) None[source]
Connect in a background thread. Returns immediately. Check is_connected / is_connecting for status.
- disconnect() bool[source]
- scan() list[str][source]
- trigger() bool[source]
- program(settings: OptoSetting) bool[source]
- start_imu_logging() str | None[source]
Enable the IMU on the device and start logging to a CSV file. Returns the file path, or None on failure.
- sync(value: int = 1) bool[source]
Manually mark a sync value in the IMU stream, independent of trigger().
Useful to mark task events (e.g. trial onset) in the IMU log. If IMU logging is not active, returns False without doing anything.
- stop_imu_logging() str | None[source]
Disable the IMU on the device and close the CSV file. Returns the file path that was written.
- property imu_logging: bool
- toggle_status_led(on: bool) bool[source]
- toggle_sham_led(on: bool) bool[source]
- read_battery_mv() int | None[source]
- read_last_stim_ms() int | None[source]
- read_uled_check() int | None[source]
- read_device_id() str | None[source]
- read_params() dict[str, str] | None[source]
Read all opto parameters and device info from the connected device.