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, imu_config: IMUConfig | None = None)[source]

Bases: object

Synchronous, 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, imu_config: IMUConfig | None = None)[source]

Methods

Attributes

configure_imu(imu_config: IMUConfig) None[source]

Replace the IMU logging configuration. Cannot change mid-session.

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, imu_logging: bool = False) 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 Parquet 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 Parquet 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.