brainaccess.core package#
Submodules#
brainaccess.core.annotation module#
- class brainaccess.core.annotation.Annotation[source]#
Bases:
StructureRepresents a single annotation with a timestamp and text.
This class is used to mark specific points in time with a descriptive label, which is useful for synchronizing EEG data with external events.
- timestamp#
The sample number corresponding to the time the annotation was recorded. This allows for precise alignment with the EEG data stream.
- Type:
int
- annotation[source]#
The text of the annotation, decoded from ASCII. This provides a human-readable description of the event that occurred at the given timestamp.
- Type:
str
- timestamp#
Structure/Union member
brainaccess.core.battery_info module#
- class brainaccess.core.battery_info.BatteryInfo[source]#
Bases:
StructureProvides essential information about the device’s battery status.
This class includes the current charge level, whether a charger is connected, and if the battery is actively charging. This is useful for monitoring the device’s power state and ensuring it remains operational during data acquisition.
- level#
The battery charge percentage, ranging from 0 to 100.
- Type:
int
- is_charger_connected#
True if a charger is connected to the device, False otherwise.
- Type:
bool
- is_charging#
True if the battery is currently charging, False otherwise.
- Type:
bool
- is_charger_connected#
Structure/Union member
- is_charging#
Structure/Union member
- level#
Structure/Union member
brainaccess.core.device_features module#
- class brainaccess.core.device_features.DeviceFeatures(device_info)[source]#
Bases:
objectProvides an interface to query the supported features of a device.
This class allows you to check for the presence of sensors like gyroscopes and accelerometers, determine the electrode configuration, and get the total number of electrodes available on the device.
- Parameters:
device_info (DeviceInfo) – An object containing the device’s information, used to identify the specific model and its capabilities.
- Raises:
BrainAccessException – If the device is not recognized or its features cannot be retrieved.
- electrode_count()[source]#
Gets the total number of EEG/EMG electrodes on the device.
- Returns:
The number of electrodes available for data acquisition.
- Return type:
int
- has_accel()[source]#
Checks if the device is equipped with an accelerometer.
- Returns:
True if the device has an accelerometer, False otherwise.
- Return type:
bool
brainaccess.core.device_info module#
- class brainaccess.core.device_info.DeviceInfo[source]#
Bases:
StructureContains detailed information about a BrainAccess device.
This class holds static information about the device, such as its model, hardware and firmware versions, and serial number. This is useful for identifying the device and understanding its capabilities.
- serial_number#
The unique serial number of the device.
- Type:
int
- sample_per_packet#
The number of data samples contained in each packet sent by the device.
- Type:
int
- firmware_version#
Structure/Union member
- hardware_version#
Structure/Union member
- sample_per_packet#
Structure/Union member
- serial_number#
Structure/Union member
brainaccess.core.device_model module#
- class brainaccess.core.device_model.DeviceModel(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
Bases:
EnumEnumeration of the different BrainAccess device models.
This enum provides a clear and standardized way to identify the specific model of a BrainAccess device.
brainaccess.core.eeg_channel module#
Defines the starting addresses of data channels within a data chunk.
This module provides constants that represent the starting indices for different types of data within a single data chunk. This allows for easy and reliable access to specific data points, such as EEG measurements, accelerometer values, and digital input states.
- brainaccess.core.eeg_channel.SAMPLE_NUMBER[source]#
The index of the sample number, which starts at 0 at the beginning of a stream.
- Type:
int
- brainaccess.core.eeg_channel.ELECTRODE_MEASUREMENT[source]#
The starting index for EEG electrode measurement values (in microvolts).
- Type:
int
- brainaccess.core.eeg_channel.ELECTRODE_CONTACT[source]#
The starting index for the contact status of the electrodes.
- Type:
int
- brainaccess.core.eeg_channel.DIGITAL_INPUT[source]#
The starting index for the state of the digital I/O pins.
- Type:
int
- brainaccess.core.eeg_channel.ACCELEROMETER[source]#
The starting index for accelerometer data.
- Type:
int
- brainaccess.core.eeg_channel.STREAMING[source]#
The index for the streaming status of the device.
- Type:
int
- brainaccess.core.eeg_channel.ELECTRODE_CONTACT_P[source]#
The starting index for the contact status of the positive (P) electrodes.
- Type:
int
- brainaccess.core.eeg_channel.ELECTRODE_CONTACT_N[source]#
The starting index for the contact status of the negative (N) electrodes.
- Type:
int
Examples
To get the x, y, and z indices for the accelerometer data within a chunk:
x: get_channel_index(ACCELEROMETER + 0)
y: get_channel_index(ACCELEROMETER + 1)
z: get_channel_index(ACCELEROMETER + 2)
brainaccess.core.eeg_manager module#
- class brainaccess.core.eeg_manager.EEGManager[source]#
Bases:
objectManages all communication with a BrainAccess device.
The EEGManager is the primary interface for connecting to, configuring, and streaming data from a BrainAccess device. It handles the low-level details of Bluetooth communication and provides a high-level API for controlling the device.
Initializes a new EEGManager instance.
Warning
The BrainAccess Core library must be initialized with init() before creating an EEGManager.
- annotate(annotation)[source]#
Adds a timestamped annotation to the data stream.
Warning
Annotations are cleared when the device is disconnected.
- Parameters:
annotation (str) – The text of the annotation.
- Raises:
BrainAccessException – If the annotation is None or empty.
- Return type:
None
- connect(bt_device_name)[source]#
Connects to a BrainAccess device.
- Parameters:
bt_device_name (str) – The name of the device to connect to (e.g., “HALO 001”, “MINI 001”).
- Returns:
0: Connection successful.
1: Connection failed.
- 2: Connection successful, but the data stream is incompatible.
A firmware update is recommended.
- Return type:
int
- destroy()[source]#
Releases all resources associated with the EEG manager.
This method should be called when the manager is no longer needed to ensure a clean shutdown.
Warning
This method must be called exactly once.
- Return type:
None
- get_annotations()[source]#
Retrieves all accumulated annotations.
Warning
Annotations are cleared when the device is disconnected.
- Returns:
A dictionary with two keys: - “annotations”: A list of annotation strings. - “timestamps”: A list of corresponding timestamps.
- Return type:
dict
- get_battery_info()[source]#
Retrieves the current battery status from the device.
- Returns:
An object containing battery level and charging status.
- Return type:
- get_channel_index(channel)[source]#
Gets the index of a specific channel within the data chunk.
This allows you to locate the data for a particular channel within the array provided by the chunk callback.
- Parameters:
channel (int) – The ID of the channel.
- Returns:
The index of the channel’s data in the chunk array.
- Return type:
int
- Raises:
BrainAccessException – If the channel does not exist or is not currently being streamed.
- get_device_features()[source]#
Retrieves the features and capabilities of the connected device.
- Returns:
An object with methods to query for features like gyroscope, accelerometer, bipolar electrodes, and electrode count.
- Return type:
- get_device_info()[source]#
Retrieves static information about the connected device.
Warning
This method should only be called after a successful connection has been established.
- Returns:
An object containing the device model, hardware/firmware versions, and other static information.
- Return type:
- get_sample_frequency()[source]#
Gets the sampling frequency of the device.
- Returns:
The sampling frequency.
- Return type:
int
- is_connected()[source]#
Checks if a connection to a device is currently active.
- Returns:
True if connected, False otherwise.
- Return type:
bool
- is_streaming()[source]#
Checks if the device is currently streaming data.
- Returns:
True if the stream is active, False otherwise.
- Return type:
bool
- load_config(callback=None)[source]#
Applies the current channel and other settings to the device.
- Parameters:
callback (callable, optional) – A function to be called when the configuration has been successfully loaded onto the device.
- Return type:
None
- set_callback_battery(callback=None)[source]#
Sets a callback function to be executed when the battery status is updated.
Warning
The callback may be executed in a different thread. Ensure that any shared data is properly synchronized and that the callback executes quickly to avoid blocking communication with the device.
- Parameters:
callback (callable, optional) – The function to be called. It should accept a BatteryInfo object as an argument. Set to None to disable.
- Raises:
BrainAccessException – If the callback is None.
- Return type:
None
- set_callback_chunk(f)[source]#
Sets a callback function to be executed when a new data chunk is available.
Warning
The callback may be executed in a different thread. Ensure that any shared data is properly synchronized and that the callback executes quickly to avoid blocking communication with the device.
- Parameters:
f (callable) – The function to be called. It should accept a list of NumPy arrays (one for each channel) and the chunk size as arguments. Set to None to disable the callback.
- Return type:
None
- set_callback_disconnect(callback=None)[source]#
Sets a callback function to be executed when the device disconnects.
Warning
The callback may be executed in a different thread. Ensure that any shared data is properly synchronized and that the callback executes quickly.
- Parameters:
callback (callable, optional) – The function to be called on disconnect. Set to None to disable.
- Return type:
None
- set_channel_bias(self, channel: int, bias: bool) None[source]#
DEPRECATED: Use the version with Polarity instead.
Configures an electrode channel for bias feedback. The signals from bias channels are inverted and fed back into the bias electrode to reduce common-mode noise (e.g., from power lines).
This setting takes effect on stream start and is reset on stream stop. Only select channels with good skin contact for bias feedback.
- channelint
The ID of the channel to use for bias feedback.
- biasbool
True to enable bias feedback for this channel, False to disable.
- BrainAccessException
If the device is currently streaming.
- set_channel_bias(self, channel: int, p: brainaccess.core.polarity.Polarity) -> None
Configures an electrode channel for bias feedback.
The signals from bias channels are inverted and fed back into the bias electrode to reduce common-mode noise (e.g., from power lines).
This setting takes effect on stream start and is reset on stream stop. Only select channels with good skin contact for bias feedback.
- channelint
The ID of the channel to use for bias feedback.
- pPolarity
The polarity to use for the bias signal. If the device is not bipolar, use Polarity.BOTH.
- BrainAccessException
If the device is currently streaming.
- Parameters:
channel (int)
bias (bool)
- Return type:
None
- set_channel_enabled(channel, state)[source]#
Enables or disables a specific data channel.
Warning
Channel settings are reset when the stream is stopped. This method must be called before each stream start to configure the desired channels.
- Parameters:
channel (int) – The ID of the channel to enable or disable (see brainaccess.core.eeg_channel).
state (bool) – True to enable the channel, False to disable it.
- Raises:
BrainAccessException – If the device is currently streaming.
- Return type:
None
- set_channel_gain(channel, gain)[source]#
Sets the gain mode for a specific channel.
Lower gain values increase the measurable voltage range at the cost of reduced amplitude resolution. A gain of X12 is optimal for most use cases.
Warning
This setting takes effect on stream start and is reset on stream stop. It only affects channels that support gain control, such as electrode measurement channels.
- Parameters:
channel (int) – The ID of the channel to configure.
gain (GainMode) – The desired gain mode.
- Raises:
BrainAccessException – If the device is streaming or the channel number is invalid.
- Return type:
None
- set_impedance_mode(mode)[source]#
Configures the device for impedance measurement.
This mode injects a small, known current through the bias electrodes and measures the resulting voltage at each electrode. The impedance can then be calculated using Ohm’s law (Impedance = Voltage / Current).
Warning
This setting takes effect on stream start and is reset on stream stop.
- Parameters:
mode (ImpedanceMeasurementMode) – The impedance measurement mode to set.
- Raises:
BrainAccessException – If the device is currently streaming.
- set_sample_rate(sample_rate)[source]#
Sets the data stream sample rate for the device.
The available sample rates may depend on the device model and firmware version. Refer to the brainaccess.core.stream_rate.StreamRate enum for available options.
Warning
This setting takes effect on stream start and is reset on stream stop.
- Parameters:
sample_rate (int) – The desired data stream sample rate.
- Raises:
BrainAccessException – If the device is currently streaming. If the device sample rate is not possible
- Return type:
bool
- start_stream(callback=None)[source]#
Starts streaming data from the device.
- Parameters:
callback (callable, optional) – A function to be called when the stream has successfully started.
- Returns:
True if the stream was started successfully.
- Return type:
bool
- Raises:
BrainAccessException – If the stream is already running or could not be started.
- start_update(callback=None)[source]#
Starts a firmware update for the device.
- Parameters:
callback (callable, optional) – A function to be called with the progress of the update. It should accept two arguments: the number of bytes sent and the total number of bytes.
- Raises:
BrainAccessException – If the update cannot be started.
- Return type:
None
- stop_stream(callback=None)[source]#
Stops the data stream from the device.
- Parameters:
callback (callable, optional) – A function to be called when the stream has successfully stopped.
- Returns:
True if the stream was stopped successfully.
- Return type:
bool
- Raises:
BrainAccessException – If the stream is not currently running or could not be stopped.
brainaccess.core.full_battery_info module#
- class brainaccess.core.full_battery_info.EBaChargeLevel(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
Bases:
EnumEnumeration of the battery charge levels.
- class brainaccess.core.full_battery_info.EBaChargeStates(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
Bases:
EnumEnumeration of the possible battery charging states.
- class brainaccess.core.full_battery_info.FullBatteryInfo[source]#
Bases:
StructureProvides comprehensive information about the device’s battery.
This class extends the basic battery info with more detailed metrics such as health, voltage, and current, providing a complete picture of the battery’s status.
- is_charger_connected#
True if a charger is connected to the device.
- Type:
bool
- level#
The battery charge percentage (0-100).
- Type:
int
- health#
The battery health percentage (0-100).
- Type:
float
- voltage#
The battery voltage in volts.
- Type:
float
- current#
The current flow in amps (negative for discharge, positive for charge).
- Type:
float
- current#
Structure/Union member
- health#
Structure/Union member
- is_charger_connected#
Structure/Union member
- level#
Structure/Union member
- voltage#
Structure/Union member
brainaccess.core.gain_mode module#
- class brainaccess.core.gain_mode.GainMode(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
Bases:
EnumEnumeration of the available gain modes for the device’s amplifiers.
The gain mode determines the amplification factor applied to the analog signal before it is digitized. Higher gain values are suitable for measuring low-amplitude signals, while lower gain values are better for signals with a larger dynamic range.
- brainaccess.core.gain_mode.gain_mode_to_multiplier(gain_mode)[source]#
Converts a GainMode enum member to its integer multiplier.
- Parameters:
gain_mode (GainMode) – The gain mode to convert.
- Returns:
The integer multiplier corresponding to the gain mode (e.g., GainMode.X12 returns 12).
- Return type:
int
brainaccess.core.impedance_measurement_mode module#
Defines the modes for impedance measurement.
- class brainaccess.core.impedance_measurement_mode.ImpedanceMeasurementMode(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
Bases:
EnumEnumeration of the available impedance measurement modes.
Impedance measurement is used to assess the quality of the electrode-skin contact. Different modes use different frequencies for the measurement.
brainaccess.core.polarity module#
- class brainaccess.core.polarity.Polarity(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
Bases:
EnumEnumeration of the possible polarities for bipolar electrodes.
For devices with bipolar electrodes, this enum allows for the selection of which contact to use for a given measurement.
brainaccess.core.version module#
- class brainaccess.core.version.Version(major, minor, patch)[source]#
Bases:
StructureRepresents a version number with major, minor, and patch components.
This class is used to represent software and hardware versions in a structured way, following the principles of semantic versioning.
- major#
The major version number, incremented for incompatible API changes.
- Type:
int
- minor#
The minor version number, incremented for new, backward-compatible functionality.
- Type:
int
- patch#
The patch version number, incremented for backward-compatible bug fixes.
- Type:
int
- major#
Structure/Union member
- minor#
Structure/Union member
- patch#
Structure/Union member
Module contents#
Main entry point for the BrainAccess Core Python API.
This module provides a high-level interface to the BrainAccess Core library, allowing for device discovery, connection, and data streaming.
- brainaccess.core.close()[source]#
Closes the library and releases all underlying resources.
This function should be called when the application is finished with the BrainAccess Core library to ensure a clean shutdown.
Warning
Must be called after all other BrainAccess Core library functions.
Only call this function once.
Do not call this function if init() failed.
- Return type:
None
- brainaccess.core.config_enable_logging(enable)[source]#
Enables or disables the core library’s internal logging.
- Parameters:
enable (bool) – Set to True to enable logging, False to disable it.
- Returns:
True if the logging state was changed successfully.
- Return type:
bool
- Raises:
BrainAccessException – If the logging state cannot be changed.
- brainaccess.core.config_set_adapter_index(adapter_index)[source]#
Selects the Bluetooth adapter to be used for scanning and connections.
- Parameters:
adapter_index (int) – The zero-based index of the Bluetooth adapter to use.
- Returns:
True if the adapter was selected successfully.
- Return type:
bool
- Raises:
BrainAccessException – If the adapter_index is out of bounds for the number of available adapters.
- brainaccess.core.config_set_chunk_size(chunk_size)[source]#
Configures the size of data chunks for EEG streaming.
This setting affects how much data is buffered before being made available for processing. Larger chunks can improve efficiency but increase latency.
- Parameters:
chunk_size (int) – The desired number of data samples per chunk.
- Returns:
True if the chunk size was set successfully.
- Return type:
bool
- Raises:
BrainAccessException – If the provided chunk_size is invalid (e.g., zero, negative, or outside an acceptable range).
- brainaccess.core.config_set_log_level(log_level)[source]#
Sets the logging level for the core library.
This controls the verbosity of the log output.
- Parameters:
log_level (LogLevel) – The desired logging level from the LogLevel enum.
- Returns:
True if the log level was set successfully.
- Return type:
bool
- Raises:
BrainAccessException – If the provided log_level is not a valid LogLevel member.
- brainaccess.core.get_config()[source]#
Return current config as a Python dict
- Return type:
Dict[str, Any]
- brainaccess.core.get_config_ctypes()[source]#
Return the current configuration as a BacoreConfig ctypes struct.
- Return type:
- brainaccess.core.get_version()[source]#
Retrieves the version of the installed BrainAccess Core library.
- Returns:
An object containing the major, minor, and patch version numbers.
- Return type:
- brainaccess.core.init()[source]#
Initializes the BrainAccess Core library.
This function sets up the necessary resources for the library to function, including reading the configuration file and initializing the logging system.
- Returns:
Returns True on successful initialization.
- Return type:
bool
- Raises:
BrainAccessException – If the library fails to initialize. This can happen if the configuration is invalid or if system resources cannot be allocated.
Warning
This function must be called once before any other function in the BrainAccess Core library. Calling it more than once or failing to call it will result in undefined behavior.
- brainaccess.core.scan()[source]#
Performs a Bluetooth scan to discover nearby BrainAccess devices.
The scan duration is fixed. This function will block until the scan is
complete.
- Returns:
A list of BaBleDevice objects, each representing a discovered device. Returns an empty list if no devices are found.
- Return type:
list[BaBleDevice]
- Raises:
BrainAccessException – If the scan fails to start, which can happen if Bluetooth is disabled or if there are issues with the Bluetooth adapter.
- brainaccess.core.set_config_autoflush(enable=True)[source]#
Enables or disables automatic flushing of the log buffer.
When autoflush is enabled, log messages are written to disk immediately. Disabling it can improve performance by buffering writes, but may result in lost log messages if the application crashes.
- Parameters:
enable (bool, optional) – True to enable autoflush (default), False to disable it.
- Returns:
True if the setting was applied successfully.
- Return type:
bool
- Raises:
BrainAccessException – If the autoflush configuration fails.
- brainaccess.core.set_config_fields(**fields)[source]#
Update one or more core configuration settings in a single call.
This function provides a flexible way to modify the behavior of the BrainAccess core library. You can pass any combination of keyword arguments to change multiple settings at once. Fields not provided remain unchanged.
- Parameters:
**fields (dict) –
Supported keys and expected value types:
- log_buffer_sizeint
Size of the log buffer in bytes (must be ≥ 0).
- log_pathstr
Path to the log file (max 199 UTF-8 bytes).
- log_levelint or LogLevel
Logging verbosity level (e.g., Error, Warning, Info, Debug).
- append_logsbool
Whether to append to an existing log file (True) or overwrite (False).
- timestamps_enabledbool
Include timestamps in log entries if True.
- autoflushbool
Flush logs to disk immediately if True; may reduce performance.
- thread_ids_enabledbool
Include thread IDs in log entries if True.
- chunk_sizeint
Number of data samples per EEG streaming chunk (must be > 0).
- enable_logsbool
Master switch for logging; disables all logging if False.
- update_pathstr
Path to the firmware update file. Must exist and be ≤199 UTF-8 bytes.
- adapter_indexint
Index of the Bluetooth adapter to use (0–255).
- Returns:
True if the configuration was updated successfully.
- Return type:
bool
- Raises:
BrainAccessException – If an unknown field is passed, a value has the wrong type or range, a string is too long, or the firmware update file does not exist.
Examples
Enable detailed logging and set a custom log file:
>>> set_config_fields( ... log_level=LogLevel.DEBUG, ... log_path="logs/session.log", ... append_logs=False ... )
- brainaccess.core.set_config_path(file_path, append=True, buffer_size=512)[source]#
Sets the file path for the core library’s log output.
By default, logs may be disabled or go to a standard location. Use this function to specify a custom file for logging.
- Parameters:
file_path (str) – The absolute or relative path to the desired log file.
append (bool, optional) – If True (default), new logs will be appended to the file if it already exists. If False, the file will be overwritten.
buffer_size (int, optional) – The size of the log buffer in bytes. A larger buffer can improve performance by reducing the frequency of disk writes. Defaults to 512.
- Returns:
True if the log file path was configured successfully.
- Return type:
bool
- Raises:
BrainAccessException – If the path is invalid or not writable.
- brainaccess.core.set_config_thread_id(enable=True)[source]#
Enables or disables the inclusion of thread IDs in log entries.
This can be useful for debugging multi-threaded applications.
- Parameters:
enable (bool, optional) – True to include the thread ID (default), False to omit it.
- Returns:
True if the setting was applied successfully.
- Return type:
bool
- Raises:
BrainAccessException – If the thread ID configuration fails.
- brainaccess.core.set_config_timestamp(enable=True)[source]#
Enables or disables timestamps in the log file entries.
- Parameters:
enable (bool, optional) – True to include timestamps (default), False to omit them.
- Returns:
True if the setting was applied successfully.
- Return type:
bool
- Raises:
BrainAccessException – If the timestamp configuration fails.
- brainaccess.core.set_config_update_path(file_path)[source]#
Sets the file path for firmware update files.
- Parameters:
file_path (str) – The path to the firmware update file.
- Returns:
True if the path was set successfully.
- Return type:
bool
- Raises:
BrainAccessException – If the path is invalid or the file does not exist.