Using the library#

Lifecycle#

An application initializes the library once, creates one EEG manager per device, and releases both in reverse order:

ba_core_init()
ba_core_scan()                      optional: list nearby devices
ba_eeg_manager_new()                one per device
  ba_eeg_manager_set_callback_*()   data, battery, disconnect
  ba_eeg_manager_connect()
    configure channels, gain, sample rate
    ba_eeg_manager_start_stream()   data arrives in the chunk callback
    ba_eeg_manager_stop_stream()
  ba_eeg_manager_disconnect()
ba_eeg_manager_free()
ba_core_close()
  • Call ba_core_init() before anything else.

  • Free every manager before ba_core_close(); until then it returns BA_INIT_ERROR_NOT_ALL_MANAGERS_CLOSED.

  • The device list from ba_core_scan() belongs to the library: do not free it. A scan takes about five seconds and lists BrainAccess devices only.

  • Stream settings (channels, gain, bias, impedance mode, sample rate) apply to one stream. Set them again before every start.

Several devices#

Create one manager per device. Managers are independent: connect, stream and free each one separately, then call ba_core_close() once at the end.

Library settings#

ba_core_init() starts with default settings. Change them with ba_core_get_config() and ba_core_set_config():

sBACORE_Config_t config;
ba_core_get_config(&config);
config.chunk_size = 50;           /* samples per chunk callback, 1..100 */
config.log_level = BA_LOG_LEVEL_WARNING;
ba_core_set_config(&config);

See sBACORE_Config_t in Core library for every setting and its default.

Calls and callbacks#

ba_eeg_manager_connect(), ba_eeg_manager_start_stream() and ba_eeg_manager_stop_stream() return once the device has answered, and their return value is the result, so their optional callback can be NULL.

Data, battery and disconnect callbacks may run on a thread of the library: keep them short and protect data you share with the rest of the application. Call the functions of one manager from one thread at a time; the callback setters are the exception and may be called from any thread.

Disconnects#

The disconnect callback runs whenever the connection ends, expected or not. The manager stays usable: call ba_eeg_manager_connect() again to reconnect.