EEG manager#

Connecting to one device, configuring it, streaming and updating its firmware. See Using the library for the order of calls and the threading rules.

eeg_manager.h#

EEG device manager.

Author

Neurotechnology (brainaccess@neurotechnology.com)

Copyright

Copyright (c) 2022 Neurotechnology

Typedefs

typedef void ba_eeg_manager#

EEG manager typedef.

The EEG manager is not thread-safe: call its functions from one thread at a time. The three callback setters are the exception - ba_eeg_manager_set_callback_chunk, ba_eeg_manager_set_callback_battery and ba_eeg_manager_set_callback_disconnect may be called from any thread, also while the library is calling those callbacks on a thread of its own.

Functions

ba_eeg_manager *ba_eeg_manager_new()#

Creates a new instance of an EEG manager.

Returns:

A pointer to a new instance of the EEG manager. Returns nullptr if the allocation fails.

void ba_eeg_manager_free(ba_eeg_manager *instance)#

Frees the memory associated with the specified EEG manager instance.

This function deallocates the resources used by the provided EEG manager. Ensure that the instance is no longer in use on any other thread before calling this function.

It may be called from inside any of the manager’s callbacks. The manager is then released as soon as the library returns from that callback, and once this function has returned none of the manager’s callbacks is called again, so the data registered with them may be freed too.

Every manager must be freed before ba_core_close(); otherwise ba_core_close() returns BA_INIT_ERROR_NOT_ALL_MANAGERS_CLOSED.

Parameters:

instance – A pointer to the EEG manager instance to be freed. The pointer must point to an instance created earlier, and it should not be accessed after this function is called.

ba_error ba_eeg_manager_connect(ba_eeg_manager *instance, const char *device_name, ba_callback_future_bool callback, void *data)#

Connects to a device and attempts to initialize it.

You must wait for the callback to complete before doing anything else with the EEG manager. The boolean parameter of the callback is true if the connection is successful, false otherwise.

Parameters:
  • instance – Handle of the EEG manager instance to connect to the port

  • device_name – Brainaccess device name

  • callback – Function to be called after the connection succeeds

  • data – Data to be passed to the callback

Returns:

A ba_error indicating the result:

  • BA_ERROR_OK: Connected and the device was initialized.

  • BA_ERROR_CORE_NOT_INITIALIZED: Call ba_core_init() before connecting.

  • BA_ERROR_WRONG_VALUE: device_name is NULL, or this manager is already connected (disconnect it first). Nothing was changed.

  • BA_ERROR_NO_DEVICES_FOUND: Discovery ran on the configured adapter but nothing was advertising under device_name.

  • BA_ERROR_UNSUPPORTED_DEVICE: The device answered but is not a supported model.

  • BA_ERROR_CONNECTION: The device was found but the connection or its device-info handshake failed.

  • BA_ERROR_ADAPTER_OUT_OF_INDEX: Linux only. The host has Bluetooth controllers, but not the one sBACORE_Config_t::adapter_index names. Checked on every connect, not only during ba_core_scan(); no discovery ran.

  • BA_ERROR_BLUETOOTH_ADAPTER_NOT_FOUND: The Bluetooth service answered and reported no controller at all. No discovery ran.

  • BA_ERROR_BLUETOOTH_SERVICE_UNAVAILABLE: The Bluetooth service could not be reached, or did not answer in time. No discovery ran.

void ba_eeg_manager_disconnect(ba_eeg_manager *instance)#

Disconnects the EEG manager instance, terminating any active connection.

Parameters:

instance – A pointer to the EEG manager instance to disconnect.

bool ba_eeg_manager_is_connected(ba_eeg_manager *instance)#

Checks if the EEG manager instance is currently connected.

Parameters:

instance – A pointer to the EEG manager instance to check. Must not be null.

Returns:

True if the EEG manager is connected, false otherwise.

ba_error ba_eeg_manager_start_stream(ba_eeg_manager *instance, ba_callback_future_void callback, void *data)#

Starts streaming EEG data using the given EEG manager instance.

Initiates data streaming using the current in-memory configuration (enabled channels, gains, bias, impedance mode, and data stream rate). If not explicitly configured since the last stop or disconnect, defaults are used where applicable (e.g., impedance measurement off; default data stream rate is 250 Hz).

Requirements:

  • The manager must be connected.

  • Do not call if a stream is already running.

  • Wait for the callback to complete before issuing further streaming calls.

Possible return values:

Parameters:
  • instance – A pointer to the EEG manager instance.

  • callback – The callback function invoked after the stream start completes.

  • data – User-defined data passed to the callback.

Return values:
  • BA_ERROR_OK – Streaming started successfully.

  • BA_ERROR_STREAM_START_FAILED – The device could not configure its EEG converter, or refused the start after a configuration it rejected, and is not streaming. Firmware that predates this report never returns it.

  • BA_ERROR_CONNECTION – The device is not connected, or a connection error occurred while starting the stream.

  • BA_ERROR_WRONG_VALUE – A stream is already running; or the settings changed since the last ba_eeg_manager_load_config are invalid (an impedance mode above BA_IMPEDANCE_MEASUREMENT_MODE_DR_DIV4) or were rejected by the device, which keeps the configuration it had. Nothing is started and the callback is not called.

  • BA_ERROR_CORE_NOT_INITIALIZED – Core isn’t initialized.

  • BA_ERROR_BLUETOOTH_DISABLED – Bluetooth is disabled on the host.

  • BA_ERROR_BLUETOOTH_ADAPTER_NOT_FOUND – No Bluetooth adapter found.

  • BA_ERROR_ADAPTER_OUT_OF_INDEX – Selected adapter index is invalid.

  • BA_ERROR_UNKNOWN – An unspecified error occurred.

Returns:

A ba_error indicating the outcome of the operation.

ba_error ba_eeg_manager_stop_stream(ba_eeg_manager *instance, ba_callback_future_void callback, void *data)#

Stops streaming EEG data using the given EEG manager instance.

Requests the device to stop data streaming. Before it returns, the samples parsed since the last full chunk reach the chunk callback in one last, shorter call (see ba_eeg_manager_set_callback_chunk). After a successful stop, volatile per-stream configuration is cleared. To start streaming again, re-apply channel enables, gains, bias selection, impedance mode, and data stream rate as needed.

Requirements:

  • The manager must be connected.

  • A stream must be currently running.

  • Do not call repeatedly without a new start in between.

  • Wait for the callback to complete before issuing further streaming calls.

Possible return values:

Parameters:
  • instance – A pointer to the EEG manager instance.

  • callback – The callback function invoked after the stream stop completes.

  • data – User-defined data passed to the callback.

Return values:
  • BA_ERROR_OK – Streaming stopped successfully.

  • BA_ERROR_CONNECTION – The device is not connected, or a connection error occurred while stopping the stream.

  • BA_ERROR_WRONG_VALUE – The operation is invalid in the current state (e.g., stream not running).

  • BA_ERROR_CORE_NOT_INITIALIZED – Core isn’t initialized.

  • BA_ERROR_BLUETOOTH_DISABLED – Bluetooth is disabled on the host.

  • BA_ERROR_BLUETOOTH_ADAPTER_NOT_FOUND – No Bluetooth adapter found.

  • BA_ERROR_ADAPTER_OUT_OF_INDEX – Selected adapter index is invalid.

  • BA_ERROR_UNKNOWN – An unspecified error occurred.

Returns:

A ba_error indicating the outcome of the operation.

bool ba_eeg_manager_is_streaming(const ba_eeg_manager *instance)#

Checks whether EEG data streaming is currently active.

Provides a non-blocking snapshot of the streaming state. During start/stop transitions, the state may not reflect the final result until the corresponding callback has completed.

Usage notes:

  • Safe to call after the manager is created.

  • For definitive state after a start/stop request, wait for the associated callback and then query this function if needed.

Parameters:

instance – A pointer to the EEG manager instance.

Returns:

true if the device is currently streaming, false otherwise.

ba_error ba_eeg_manager_read_battery_info(ba_eeg_manager *instance, ba_battery_info *info)#

Retrieves the latest battery status reported by the device.

Returns the most recently cached battery information. The device periodically reports its battery status, which the manager stores internally. This call is synchronous and does not request an update from the device; it only returns the last known values.

Defaults and freshness:

  • If no battery report has been received yet for this session, the returned structure may contain default-initialized values (e.g., zeros or unspecified fields depending on the platform).

  • To receive updates as they arrive, register a battery update callback with ba_eeg_manager_set_callback_battery (pass NULL to unregister), and call this function after the callback has been triggered.

Parameters:
  • instance – Handle of the EEG manager to get the battery info of.

  • info – A valid pointer to ba_battery_info structure that will be filled with the cached battery information. Zeroed before any failure return, so it is never left indeterminate.

Returns:

BA_ERROR_OK on success; BA_ERROR_WRONG_VALUE if instance or info is NULL; BA_ERROR_CONNECTION if the device is not connected.

ba_battery_info ba_eeg_manager_get_battery_info(ba_eeg_manager *instance)#

Deprecated:

Cannot report failure: a zeroed struct is also a valid reading (0%, unplugged, not charging). Use ba_eeg_manager_read_battery_info instead.

ba_error ba_eeg_manager_read_full_battery_info(ba_eeg_manager *instance, ba_full_battery_info *info)#

Returns the full battery information of the device.

Fetches complete information about the status of the device battery. Could be useful for debugging purposes, use it sparingly.

Note

BA_ERROR_OK does not yet mean every field was read. This call makes three characteristic reads and does not check them individually, so a partial result is still reported as success.

Parameters:
  • instance – Handle of the EEG manager to get the battery info of.

  • info – Valid pointer to a ba_full_battery_info structure. Zeroed before any failure return, so it is never left indeterminate.

Returns:

BA_ERROR_OK on success; BA_ERROR_WRONG_VALUE if instance or info is NULL; BA_ERROR_CONNECTION if the device is not connected.

ba_full_battery_info ba_eeg_manager_get_full_battery_info(ba_eeg_manager *instance)#

Deprecated:

Cannot report failure. Use ba_eeg_manager_read_full_battery_info instead.

ba_error ba_eeg_manager_load_config(ba_eeg_manager *instance, ba_callback_future_void callback, void *data)#

Loads the current in-memory configuration to the EEG device.

Sends the manager’s current configuration to the device, including enabled channels, channel gains, bias selection, impedance measurement mode, and data stream rate. The operation is asynchronous; wait for the provided callback to complete before issuing additional configuration or streaming requests.

How to set values:

  • Enable or disable channels with ba_eeg_manager_set_channel_enabled(instance, ch, state).

  • Set channel gains with ba_eeg_manager_set_channel_gain(instance, ch,

    gain).

  • Select the bias electrode with ba_eeg_manager_set_channel_bias_feedback(instance, ch).

  • Configure impedance measurement with ba_eeg_manager_set_impedance_mode(instance, mode).

  • Set the data stream rate with ba_eeg_manager_set_data_stream_rate(instance, rate).

  • Then call ba_eeg_manager_load_config(instance, callback, data) and wait for the callback.

Defaults:

  • If a setting has not been explicitly configured since the last stop or disconnect, device defaults are applied:

    • Impedance measurement: off by default.

    • Data stream rate: 250 Hz by default.

    • Channels: all electrodes enabled, every other channel disabled.

    • Bias: all disabled.

    • Gains: all set to 8.

Requirements:

  • The manager must be connected.

  • Recommended to call when streaming is stopped. If called while a stream is running, the device may defer or reject the request; rely on the callback result.

Possible return values:

Parameters:
  • instance – A pointer to the EEG manager instance.

  • callback – The callback invoked once the device has accepted the configuration; not called when it is refused.

  • data – User-defined data passed to the callback.

Return values:
  • BA_ERROR_OK – The device accepted the configuration. Firmware that does not report a rejection, 3.6.0 among them, is taken at its word.

  • BA_ERROR_CONNECTION – The device is not connected, or a connection error occurred while applying the configuration.

  • BA_ERROR_WRONG_VALUE – The configuration is invalid (an impedance mode above BA_IMPEDANCE_MEASUREMENT_MODE_DR_DIV4), and was not sent; or the device rejected it, and keeps the configuration it had. The callback is not called, and the next ba_eeg_manager_start_stream sends the settings again.

  • BA_ERROR_CORE_NOT_INITIALIZED – Core isn’t initialized.

  • BA_ERROR_BLUETOOTH_DISABLED – Bluetooth is disabled on the host.

  • BA_ERROR_BLUETOOTH_ADAPTER_NOT_FOUND – No Bluetooth adapter found.

  • BA_ERROR_ADAPTER_OUT_OF_INDEX – Selected adapter index is invalid.

  • BA_ERROR_UNKNOWN – An unspecified error occurred.

Returns:

A ba_error indicating the outcome of the operation.

ba_error ba_eeg_manager_read_charging_settings(ba_eeg_manager *instance, ba_charging_settings *settings)#

Retrieves the charging settings of the EEG device.

Returns the current charging behavior of the device, including whether the device is allowed to be enabled while charging and the sleep timeout (in minutes) while charging.

Defaults and persistence:

  • After the device powers off, charging settings revert to defaults:

    • enabled = false

    • timeout = 20 minutes

  • If a timeout value of 0 is provided, it is automatically treated as 1 minute.

How to set values:

  • Prepare a ba_charging_settings structure:

    • settings.enabled_on_while_charging = true or false

    • settings.sleep_timeout = desired timeout in minutes (0 becomes 1)

  • Apply it with ba_eeg_manager_set_charging_settings(instance, settings).

Parameters:
  • instance – Handle of the EEG Manager instance to retrieve the charging settings from.

  • settings – Valid pointer to a structure that will be filled with the current charging settings on the device. Zeroed before any failure return, so it is never left indeterminate.

Returns:

BA_ERROR_OK on success, both settings read from the device; BA_ERROR_WRONG_VALUE if instance or settings is NULL; BA_ERROR_CONNECTION if the device is not connected, or either read failed. Nothing is partly filled in: settings is then zeroed.

ba_charging_settings ba_eeg_manager_get_charging_settings(ba_eeg_manager *instance)#

Deprecated:

Cannot report failure, and its failure value is one the device cannot hold: a zeroed struct means sleep_timeout = 0, which ba_eeg_manager_set_charging_settings itself rejects and replaces with 1. Use ba_eeg_manager_read_charging_settings instead.

bool ba_eeg_manager_set_charging_settings(ba_eeg_manager *instance, ba_charging_settings settings)#

Updates the charging settings of the EEG device.

Applies new charging behavior to the device:

  • Whether the device is allowed to remain enabled while charging (settings.enabled_on_while_charging).

  • The sleep timeout in minutes while charging (settings.sleep_timeout).

Defaults and constraints:

  • After the device powers off, settings revert to defaults:

    • enabled_on_while_charging = false

    • sleep_timeout = 20 minutes

  • If settings.sleep_timeout is set to 0, it is automatically treated as 1 minute.

How to set values:

  • Construct a ba_charging_settings value:

  • Call ba_eeg_manager_set_charging_settings(instance, s).

  • Optionally call ba_eeg_manager_read_charging_settings afterward to confirm what the device accepted.

Requirements:

  • The manager must be connected.

Warning

This performs two independent characteristic writes and returns false if the second fails, having already committed the first. A false return therefore does not tell you whether nothing, the timeout only, or both were applied.

Parameters:
  • instance – Handle of the EEG Manager instance to configure.

  • settings – A ba_charging_settings structure with desired values.

Returns:

true if the settings were successfully applied, false otherwise.

void ba_eeg_manager_set_channel_enabled(ba_eeg_manager *instance, ba_eeg_channel ch, bool state)#

Enables the channel on the device and adds the data to the stream chunks.

This function takes effect on stream start, and its effects are reset by stream stop. Therefore, it must be called with the appropriate arguments before every stream starts.

Note

An electrode’s BA_EEG_CHANNEL_ID_ELECTRODE_CONTACT channel on its own makes the device measure the electrode, as its BA_EEG_CHANNEL_ID_ELECTRODE_MEASUREMENT channel would: the device detects contact only on an electrode it measures. The electrode’s readings then cost the same bandwidth as a measured electrode’s but are left out of the chunks, and in impedance mode the electrode is part of every sweep. Turning MEASUREMENT off while CONTACT stays on saves nothing; turn both off to leave an electrode out.

Parameters:
  • instance – Handle of the EEG Manager instance for which to enable/disable the channel

  • ch – Channel ID of the channel to enable/disable

  • state – True for enabling, false for disable

void ba_eeg_manager_set_channel_gain(ba_eeg_manager *instance, ba_eeg_channel ch, ba_gain_mode g)#

Sets the gain mode for a specific channel.

Configures the amplification applied to the selected channel. This setting is applied on the next stream start and is reset when the stream stops.

Notes:

  • The returned channel data is already scaled by the configured gain during streaming.

  • If not explicitly configured before the stream starts, the device uses its default gain for that channel. The default value is 8.

How to set values:

  • Choose the target channel (BA_EEG_CHANNEL_ID_ELECTRODE_MEASUREMENT + ch) and a supported gain mode (g).

  • Call ba_eeg_manager_set_channel_gain(instance, BA_EEG_CHANNEL_ID_ELECTRODE_MEASUREMENT + ch, g) for each channel you wish to configure.

  • Call ba_eeg_manager_load_config(instance, callback, data) and wait for the callback, then start the stream.

Requirements:

  • Call before starting the stream (changes take effect on stream start).

  • The manager must be connected for the configuration to be applied to the device via load_config.

Parameters:
  • instance – Handle of the EEG Manager instance to configure.

  • ch – Channel ID to modify.

  • g – Gain mode to set for the specified channel.

void ba_eeg_manager_set_channel_bias_feedback(ba_eeg_manager *instance, ba_eeg_channel ch)#

Sets an electrode channel to be used as the bias reference.

This setting takes effect on the next stream start and is reset when the stream stops.

Channel selection:

  • Use BA_EEG_CHANNEL_ID_ELECTRODE_MEASUREMENT + ch to target an electrode measurement channel, where ch is the zero-based electrode index. This ensures the bias is applied to a valid electrode channel.

How to set values:

  • Compute the target channel as BA_EEG_CHANNEL_ID_ELECTRODE_MEASUREMENT + ch.

  • Call ba_eeg_manager_set_channel_bias_feedback(instance, computed_channel).

  • Apply settings with ba_eeg_manager_load_config(instance, callback,

    data) and wait for the callback, then start streaming.

Requirements:

  • Call before starting the stream (changes take effect on stream start).

  • The manager must be connected for the configuration to be pushed using load_config.

Parameters:
  • instance – Handle of the EEG Manager instance to configure.

  • ch – Channel ID of the electrode to set as bias (use BA_EEG_CHANNEL_ID_ELECTRODE_MEASUREMENT + index).

void ba_eeg_manager_set_channel_bias(ba_eeg_manager *instance, ba_eeg_channel ch)#

Deprecated:

Bad, misleading function name

void ba_eeg_manager_set_impedance_mode(ba_eeg_manager *instance, ba_impedance_measurement_mode mode)#

Sets electrode impedance measurement mode.

Prepares the device for electrode impedance measurement by injecting a small AC current (6 nA at a fixed frequency) through the bias electrodes to the measurement electrodes. The device measures one electrode at a time and computes the impedance itself, so in this mode each BA_EEG_CHANNEL_ID_ELECTRODE_MEASUREMENT channel carries the electrode’s impedance in kOhm, not a voltage in uV:

Impedance = Vpp / (2 * 6 nA) - 4.7 kOhm

where Vpp is the peak-to-peak voltage over the electrode’s measurement window - the test current is a square wave of +/-6 nA, 12 nA peak to peak - and 4.7 kOhm is the device’s own series resistor. The value is in whole kOhm and never below 0. A row of the stream is one sweep of the measured electrodes, not one ADC sample.

Modes:

  • BA_IMPEDANCE_MEASUREMENT_MODE_OFF: No active impedance measurement.

  • BA_IMPEDANCE_MEASUREMENT_MODE_HZ_7_8: 7.8 Hz test wave. Always streamed at 250 Hz.

  • BA_IMPEDANCE_MEASUREMENT_MODE_HZ_31_2: 31.2 Hz test wave. Streamed at 250 Hz when the rate set is above 1 kHz.

  • BA_IMPEDANCE_MEASUREMENT_MODE_DR_DIV4: Test wave at sample_rate/4. Streamed at the rate set.

Stream rate:

  • The device measures each electrode over a fixed 20 samples, which have to span a flip of the test wave. At a rate too fast for the wave’s frequency they may not, and the impedance reads close to 0 kOhm, so the two fixed-frequency modes are streamed at 250 Hz instead of such a rate, whatever ba_eeg_manager_set_data_stream_rate set. The rate set is not changed: turning impedance measurement off again before the stream starts gives it back. ba_eeg_manager_read_sample_frequency reports the rate streamed.

Any other value is stored, and makes the next ba_eeg_manager_load_config and ba_eeg_manager_start_stream return BA_ERROR_WRONG_VALUE without sending anything to the device.

Effect lifetime:

  • Takes effect on the next stream start and is reset when the stream stops. Call this before every stream where impedance measurement is desired.

How to set values:

  • Choose the desired impedance mode (mode).

  • Call ba_eeg_manager_set_impedance_mode(instance, mode).

  • Apply settings with ba_eeg_manager_load_config(instance, callback,

    data) and wait for the callback, then start streaming.

Requirements and notes:

  • Call before starting the stream (changes take effect on stream start).

  • The manager must be connected for the configuration to be pushed using load_config.

  • At least one valid bias electrode should be configured when enabling impedance measurement to ensure proper current injection.

Parameters:
  • instance – Handle of the EEG Manager instance for which to set the mode.

  • mode – Impedance measurement mode to set (see a list above).

ba_error ba_eeg_manager_set_data_stream_rate(ba_eeg_manager *instance, ba_data_stream_rate rate)#

Sets the data stream rate for the EEG device.

Configures how many samples per second are produced during streaming. The selected value is applied on the next stream start and does not change the rate of an already active stream.

How to set:

  • Choose a supported rate from ba_data_stream_rate (e.g., 250 Hz).

  • Call ba_eeg_manager_set_data_stream_rate(instance, rate).

  • Apply settings with ba_eeg_manager_load_config(instance, callback,

    data), wait for the callback to complete, then start streaming.

How to check:

  • Call ba_eeg_manager_read_sample_frequency(instance, &rate).

    • Before streaming: returns the configured rate that will be used on the next start.

    • During streaming: returns the active device sample rate.

Defaults:

  • If not explicitly configured before streaming, the default rate is 250 Hz.

Requirements and notes:

  • Call before starting the stream (changes take effect on stream start).

  • The manager must be connected for the configuration to be pushed using load_config.

  • If called while streaming, the new rate will take effect only after the next successful start_stream following load_config.

  • An impedance measurement mode may stream at 250 Hz instead of the rate set: see ba_eeg_manager_set_impedance_mode.

Device-specific supported rates:

  • MINI V2, EMG: 250 Hz, 500 Hz

  • HALO V1, HALO V2: 250 Hz, 500 Hz

  • MIDI, MAXI: 250 Hz, 500 Hz

  • HALO V3: 250 Hz, 500 Hz, 1 kHz

  • EXG8: 250 Hz, 500 Hz, 1 kHz, 2 kHz

Attempting to set a rate not supported by the connected device returns an error and leaves the previously configured rate unchanged.

Parameters:
  • instance – Handle of the EEG Manager instance to set the stream rate for.

  • rate – Desired data stream rate (see ba_data_stream_rate).

Returns:

ba_error

  • BA_ERROR_OK: rate accepted and stored; will apply on the next stream start.

  • BA_ERROR_UNSUPPORTED_DEVICE: a connected device does not support the requested rate.

  • BA_ERROR_WRONG_VALUE: rate value is invalid or out of defined range.

  • BA_ERROR_CONNECTION: not connected when attempting to push configuration via load_config.

  • Other error codes may be returned if underlying operations fail.

ba_error ba_eeg_manager_set_output_mode(ba_eeg_manager *instance, ba_output_mode mode)#

Selects the device output mode used for the next stream.

Switches what the device streams:

  • BA_OUTPUT_MODE_NORMAL: real EEG readings from the electrodes (default).

  • BA_OUTPUT_MODE_SQUARE_WAVE: the ADS1299 internally generated square-wave test signal on every channel, for verifying the signal path.

The selected mode is stored on the manager and applied on the next ba_eeg_manager_start_stream call (the device applies it at stream start); changing it while streaming takes effect after a stop/start. The value is not reset by stopping the stream.

Parameters:
  • instance – Handle of the EEG Manager instance to configure.

  • mode – Desired output mode.

Returns:

  • BA_ERROR_OK: mode accepted and stored.

  • BA_ERROR_WRONG_VALUE: mode is not a recognized ba_output_mode value.

  • BA_ERROR_CONNECTION: instance is null.

ba_error ba_eeg_manager_read_output_mode(const ba_eeg_manager *instance, ba_output_mode *mode)#

Returns the output mode currently selected for the manager.

This reads manager state and does no device I/O, so the only failure is a bad argument.

Parameters:
  • instance – Handle of the EEG Manager instance to query.

  • mode – Valid pointer that receives the output mode. Set to BA_OUTPUT_MODE_NORMAL before any failure return, so it is never left indeterminate.

Returns:

BA_ERROR_OK on success; BA_ERROR_WRONG_VALUE if instance or mode is NULL.

const ba_device_info *ba_eeg_manager_get_device_info(const ba_eeg_manager *instance)#

Retrieves a pointer to information about the connected EEG device.

Returns a pointer to a structure describing the currently connected device. The pointer refers to memory owned by the manager; do not free or modify the returned data. The contents are updated internally when the device is initialized or queried.

Usage and lifetime:

  • Valid only after a successful connection.

  • The returned pointer remains valid until the device is disconnected or the manager is destroyed.

  • Treat the data as read-only.

Requirements:

  • The manager must be connected.

Parameters:

instance – A pointer to the EEG manager instance.

Returns:

A read-only pointer to a ba_device_info structure describing the connected device, or nullptr if no device is connected.

size_t ba_eeg_manager_get_channel_index(const ba_eeg_manager *instance, ba_eeg_channel ch)#

Returns the row of a channel in the data a chunk callback receives.

A chunk holds one row per stream channel, ordered by channel ID; the callback’s data[row] points to that channel’s values (see ba_callback_chunk). This function finds the row of channel ch:

  • While a stream runs, or from inside the chunk callback: the row the channel has in that stream’s chunks.

  • Otherwise: the row the channel will have in the next stream, given the channels enabled now with ba_eeg_manager_set_channel_enabled.

Rows change only when a stream starts, so the index can be looked up once per stream.

Parameters:
  • instance – A pointer to the EEG manager instance.

  • ch – Channel ID, e.g. BA_EEG_CHANNEL_ID_ELECTRODE_MEASUREMENT + 2.

Returns:

The row of ch, or (size_t)-1 if instance is NULL or the channel is not enabled (not in the stream).

ba_error ba_eeg_manager_read_sample_frequency(const ba_eeg_manager *instance, ba_data_stream_rate *rate)#

Retrieves the current sample frequency setting of the device.

Returns the data stream rate that the manager/device will use:

  • Before streaming: the configured rate that will be applied on the next stream start (as last set by ba_eeg_manager_set_data_stream_rate), or 250 Hz when the impedance mode set cannot be measured at that rate (see ba_eeg_manager_set_impedance_mode).

  • During streaming: the active device sample rate.

Defaults:

  • If not explicitly configured, the default sample rate is 250 Hz.

Usage notes:

  • Use this to verify the rate you set before starting the stream or to check the active rate while streaming.

This reads manager state and does no device I/O, so the only failure is a bad argument.

Parameters:
  • instance – A pointer to the EEG manager instance.

  • rate – Valid pointer that receives the current or active sample frequency. Set to BA_DATA_STREAM_RATE_250_HZ before any failure return, so it is never left indeterminate.

Returns:

BA_ERROR_OK on success; BA_ERROR_WRONG_VALUE if instance or rate is NULL.

ba_data_stream_rate ba_eeg_manager_get_sample_frequency(const ba_eeg_manager *instance)#

Deprecated:

Cannot report failure: BA_DATA_STREAM_RATE_250_HZ is both the documented default and what a null handle returns, and every device supports it. Use ba_eeg_manager_read_sample_frequency instead.

void ba_eeg_manager_set_callback_chunk(ba_eeg_manager *instance, ba_callback_chunk callback, void *data)#

Sets a callback invoked whenever a new data chunk is available.

Registers a function that is called each time the manager assembles a complete data chunk during streaming; in impedance measurement mode it is called for every packet instead, with fewer samples. Use the size argument. A stream’s last call may have fewer samples in any mode: when the stream ends - ba_eeg_manager_stop_stream, ba_eeg_manager_disconnect, ba_eeg_manager_free or an unexpected disconnect - the samples parsed since the last full chunk are handed on before that call returns, or before the disconnect callback runs. The callback may be executed on an internal reader/worker thread; keep it short and thread-safe to avoid blocking device communication. Pass NULL as a callback to disable.

Replacing or unregistering:

  • May be called from any thread, also during a stream and from inside a callback.

  • Once this returns, the callback it replaced is not running and will not be called again, so the data registered with it may be freed. The one exception is a call on this same thread - this function called from inside that callback - which goes on until the callback returns.

  • It waits for a call under way on another thread to return, so do not call it while holding a lock the callback takes.

Chunk size:

  • Default chunk size is 25 samples.

  • To change it, call ba_core_set_config() before starting streaming and while no managers are active (requires to be initialized core).

  • Valid range is 1–100 samples. Larger chunks reduce callback frequency but increase latency; smaller chunks do the opposite.

Usage notes:

  • Register the callback before starting the stream to avoid missing the first chunks.

  • The provided data pointer is forwarded to the callback on each invocation.

  • The callback will stop being invoked after the stream stops or the callback is unregistered (see Replacing or unregistering).

Threading:

  • The thread on which the callback runs is not guaranteed. Protect any shared state with synchronization primitives.

  • A stream’s last call runs on the thread that ends the stream, with ba_eeg_manager_is_streaming already false; a ba_eeg_manager_stop_stream made from it is refused.

Parameters:
  • instance – Handle of the EEG Manager to attach the callback to.

  • callback – Function to call for each available chunk (or NULL to unregister).

  • data – User-defined pointer passed through to the callback.

void ba_eeg_manager_set_callback_battery(ba_eeg_manager *instance, ba_callback_battery callback, void *data)#

Sets a callback invoked whenever the device reports a battery update.

Registers a function called when new battery information is received from the device. The callback may run on an internal reader/worker thread; keep it short and thread-safe to avoid blocking device communication. Pass NULL as callback to disable.

How it works:

  • the device event-drives Battery updates; there is no polling.

  • The manager caches the latest battery values. Inside your callback (or afterward), call ba_eeg_manager_read_battery_info(instance, &info) to read the most recent cached data.

Usage notes:

  • You can register the callback before or after connecting; updates will only arrive while connected and when the device publishes them.

  • The provided data pointer is forwarded to the callback on each invocation.

  • The callback stops when the device disconnects, streaming stops (if applicable), or when unregistered.

Replacing or unregistering: as for ba_eeg_manager_set_callback_chunk. Once this returns, the callback it replaced is not running, except on this same thread, and will not be called again, so its data may be freed. It waits for a call under way on another thread to return, so do not call it while holding a lock the callback takes.

Threading:

  • The execution thread is not guaranteed. Protect shared state with synchronization primitives.

Parameters:
  • instance – Handle of the EEG Manager to attach the callback to.

  • callback – Function to call on battery updates (or NULL to unregister).

  • data – User-defined pointer passed through to the callback.

void ba_eeg_manager_set_callback_disconnect(ba_eeg_manager *instance, ba_callback_disconnect callback, void *data)#

Sets a callback invoked when the device disconnects.

Registers a function to be called whenever the connection to the device is lost, whether due to an expected user-initiated disconnect or an unexpected drop (e.g., out of range, power off). The callback may run on an internal reader/worker thread; keep it short and thread-safe to avoid blocking device communication. Pass NULL as callback to disable.

Usage notes:

  • You may register the callback before or after connecting.

  • The callback is invoked on both graceful and unexpected disconnects.

  • The provided data pointer is forwarded to the callback on each invocation.

  • After the callback returns, the manager remains valid but is no longer connected. Reconnect if further interaction is required.

Replacing or unregistering: as for ba_eeg_manager_set_callback_chunk. Once this returns, the callback it replaced is not running, except on this same thread, and will not be called again, so its data may be freed. It waits for a call under way on another thread to return, so do not call it while holding a lock the callback takes.

Threading:

  • The execution thread is not guaranteed. Protect shared state with synchronization primitives.

Parameters:
  • instance – Handle of the EEG Manager to attach the callback to.

  • callback – Function to call on device disconnect (or NULL to unregister).

  • data – User-defined pointer passed through to the callback.

ba_error ba_eeg_manager_annotate(ba_eeg_manager *instance, const char *annotation)#

Adds an annotation at the current stream timestamp.

Records the provided text together with the current sample timestamp in the manager’s in-memory annotation list. You can later retrieve all accumulated annotations using ba_eeg_manager_get_annotations. All annotations are cleared on device disconnect.

The timestamp is the number of the sample the device was converting when this function was called, the same number the stream’s SAMPLE_NUMBER channel carries. With firmware 3.8.0 or later it comes from the device’s own clock, which the library keeps in step with the host’s by pinging the device while the stream runs (see ba_eeg_manager_get_time_sync_info). Without that - older firmware, impedance mode, or the first half second of a stream - it is extrapolated from the newest packet, and lands early, on a sample from before the call, by however long that packet took to arrive.

Calibration notes:

  • After starting the stream, wait for a short period to ensure annotation timestamps are properly calibrated.

  • Setting annotations immediately after stream start may result in inaccurate timestamps.

  • Use annotations to mark calibration events (e.g., start/end of calibration, electrode adjustment) during streaming.

  • This helps synchronize calibration steps with recorded EEG data for later analysis.

Usage notes:

  • Call only while streaming; before stream start the current timestamp is undefined and the operation may fail.

  • Keep annotation strings reasonably short to avoid unnecessary memory usage.

The annotation is timestamped against the stream and stored on the manager; retrieve them with ba_eeg_manager_get_annotations(). Recording one while no stream is running is accepted and timestamped at the last sample seen — there is no connected-or-streaming check.

Parameters:
  • instance – Handle of the EEG Manager to add an annotation to.

  • annotation – Null-terminated string to record as the annotation text.

Return values:
  • BA_ERROR_OK – Annotation recorded successfully.

  • BA_ERROR_CONNECTION – instance is NULL.

  • BA_ERROR_WRONG_VALUE – annotation is NULL, or the stream’s rate is not a ba_data_stream_rate.

Returns:

A ba_error indicating the outcome of the operation.

ba_error ba_eeg_manager_get_time_sync_info(const ba_eeg_manager *instance, ba_time_sync_info *info)#

Reports how annotations are being placed: whether the device does time sync, and how well its clock fits the host’s.

For diagnostics; nothing else depends on it. Can be called at any time, connected or not: the figures describe the current connection and its running or last stream, and are zero before there are any.

Parameters:
  • instance – Handle of an EEG Manager instance.

  • info – Receives the state. Zeroed before any failure return.

Returns:

  • BA_ERROR_OK: info holds the state.

  • BA_ERROR_WRONG_VALUE: instance or info is NULL.

ba_error ba_eeg_manager_start_update(ba_eeg_manager *instance, ba_callback_ota_update callback, void *data)#

Starts an over-the-air (OTA) update process for the EEG device.

This function initiates the OTA update process, allowing the device’s firmware to be updated. The operation is asynchronous, and the provided callback is invoked upon completion or failure of the update process.

Usage notes:

  • Ensure the device is connected before calling this function.

  • The callback function should handle both success and failure scenarios.

  • The data parameter allows passing user-defined context to the callback.

Requirements:

  • The manager must be connected to the device.

Possible return values:

  • BA_ERROR_CONNECTION: Indicates a connection issue, such as the device not being connected.

  • BA_ERROR_UPDATE_FILE_NOT_FOUND: The update file required for the operation could not be located.

  • BA_ERROR_UPDATE_FAILED_DEVICE_DISCONNECTED: The update process failed because the device was disconnected, or did not report a result within 10 seconds of the last packet.

  • BA_ERROR_UPDATE_REJECTED: The device received the whole image and refused it; it keeps running its current firmware.

  • BA_ERROR_UPDATE_INITIATED_UNSUCCESSFULLY: The update process was started but was not successful.

  • BA_ERROR_OK: The device accepted the image and is rebooting into it. Firmware that predates result reporting only says the transfer finished, which is also returned as BA_ERROR_OK.

The call blocks until the device reports the result. callback is called with (data, 0, 0) only when BA_ERROR_OK is about to be returned.

Parameters:
  • instance – A pointer to the EEG manager instance initiating the update.

  • callback – A function to be called when the update process completes. The callback should handle success and error cases.

  • data – A user-defined pointer passed to the callback for context.

Returns:

A ba_error indicating the outcome of the operation.

void ba_eeg_manager_get_annotations(const ba_eeg_manager *instance, ba_annotation **annotations, size_t *annotations_size)#

Retrieves all annotations recorded during the current streaming session.

This function provides access to the annotations added during the current streaming session. Each annotation includes a timestamp and the associated text. The annotations are cleared when the device disconnects.

Usage notes:

  • Call this function only while the manager is connected.

  • The annotations pointer will be populated with an array of annotations, and the annotations_size pointer will indicate the number of annotations.

  • The memory for the annotations array is managed by the EEG manager and should not be freed by the caller.

Requirements:

  • The manager must be connected and streaming.

  • A NULL instance, annotations or annotations_size gives an empty result: *annotations is set to NULL and *annotations_size to 0, in whichever of the two is not NULL. Both are set before anything else, so they are never left as the caller’s uninitialised variables were.

Parameters:
  • instance – A pointer to the EEG manager instance.

  • annotations – A pointer to a ba_annotation array that will be populated with the recorded annotations.

  • annotations_size – A pointer to a size_t variable that will be set to the number of annotations.

void ba_eeg_manager_clear_annotations(ba_eeg_manager *instance)#

Clears all annotations recorded during the current streaming session.

This function removes all annotations that were added during the current streaming session. It is useful for resetting the annotation list without disconnecting the device. Once cleared, the annotations cannot be retrieved.

Usage notes:

  • Call this function only while the manager is connected.

  • This operation does not affect the streaming state or other configurations.

Requirements:

  • The manager must be connected.

Parameters:

instance – A pointer to the EEG manager instance.

void ba_eeg_manager_get_stream_channel_data_types(const ba_eeg_manager *const instance, const uint8_t **const data, size_t *const data_size)#

Returns the data type of every row in the stream’s chunks.

Element i of the returned array is the type of the values that data[i] of the chunk callback points to (see ba_callback_chunk):

  • 0: float (accelerometer, gyroscope)

  • 1: uint8_t (contact, digital input, streaming flag)

  • 2: size_t (sample number)

  • 3: double (electrode measurement)

The array is filled when ba_eeg_manager_start_stream starts a stream, and describes that stream until the next one starts. It is owned by the manager; do not free it.

A NULL instance, data or data_size gives an empty result: *data is set to NULL and *data_size to 0, in whichever of the two is not NULL. Both are set before anything else, so they are never left as the caller’s uninitialised variables were.

Parameters:
  • instance – A pointer to the EEG manager instance.

  • data – Receives a pointer to the array of type codes, one per row.

  • data_size – Receives the number of elements in the array.