js-neurosdk2
v1.0.30
Published
Web SDK for Headband, BrainBit2, Flex4 and Flex8 devices
Readme
Documentation
Overview
Neurosdk is a powerful tool for working with neuro-sensors BrainBit, Headband, Flex, Flex Pro. All these devices work with BLE 4.0+ technology. SDK allows you to connect, read the parameters of devices, as well as receive signals of various types from the selected device.
Usage
SDK can be conditionally divided into two parts: device search and the device itself.
The scanner allows you to find devices nearby, it is also responsible for the first creation of the device.
If an error occurs while working with the library, you will receive an exception for any of the methods.
Connection to device functions
A list of functions that connects to specific device:
startScannerBrainBit() - function that connects BrainBit, return device object and uuid of device;
startScannerHeadband() - function that connects HeadBand, return device object and uuid of device; IMPORTANT! You must go into pairing mode with your pc and then connect device
connectFlex() - function that connects Flex device, return device object and uuid of device;;
connectFlexPro() - function that connects Flex Pro device, return device object and uuid of device;
device object has name of device and BluetoothDevice, {name: "Brainbit", device: BluetoothDevice}
Manage connection state
You can connect and disconnect from device manually by methods connect() and disconnect()
connect(device: BluetoothDevice, uuidService: string) => return {batteryLevel: batteryLevel, cmdError: cmdError, status: status, service: service};disconnectDevice(device: BluetoothDevice, service: BluetoothRemoteGATTService, uuidService: string) - disconnect device and set your device to powerDown state
Manage device parameters
Battery
BatteryLevel is power value from your device.
Name
Name of device. String value.
State
Information about the connection status of a device. Status return number 0 - 4
{
0: NSS_STATUS_INVALID, // Module status unknown
1: NSS_STATUS_POWERDOWN, // Module disabled
2: NSS_STATUS_IDLE, // Standby mode
3: NSS_STATUS_SIGNAL, // Signal registration
4: NSS_STATUS_RESIST, // Resistance registration
}A module here refers to a chip that converts data from an analog signal to a digital one.
Information about the command errors(cmdError) of a device. Status return number 0 - 2
{
0: NSS_ERROR_NOERROR, // No error
1: NSS_ERROR_LEN, // Command size error
2: NSS_ERROR_NOCOMMAND // Command number error (no such command)
}Commands
Functions that control state of device:
getDeviceStatus(service: BluetoothDevice, uuidService: string) - get current device status => return {batteryLevel: batteryLevel, cmdError: cmdError, status: status}
goIdle(service: BluetoothDevice, uuidService: string) - set device to idle state;
- Turning on the analog-to-digital power supply
goPowerDown(service: BluetoothDevice, uuidService: string) - set device to powerdown state;
- Switching to low power mode
goSignal(service: BluetoothDevice, uuidService: string) - set device to signal state and get values from device;
To receive signal data, you need to subscribe to the corresponding callback. The values will be received as a packet from four channels at once, which will avoid desynchronization between them.
You should connect to notifications from device to your project.
goResist(service: BluetoothDevice, uuidService: string) - set device to resist state and get values from device;
- You should connect to notifications from device to your project.
Transition from any state to any state is allowed, but it is recommended to use a sequence to start the measurement PowerDown→Idle→Signal(or Resist). When the measurement is stopped for a short time, it is recommended to switch to Idle, and when the session is terminated, to PowerDown. The transition from PowerDown to Idle takes about 1 second, further transitions from Idle to Signal and back, as well as to PowerDown from any state, take about 20 ms.
Handlers to subscribe on events from device
You get signal values as a list of samples, each containing:
- PackNum - number for each packet
- Marker - marker of sample, if it was sent and this feature is supported by the device
- O1 - value of O1 channel in V
- O2 - value of O2 channel in V
- T3 - value of T3 channel in V
- T4 - value of T4 channel in V
In resistance state marker wouldnt come to host
- handleSignalNotification(event) - (signal)return object with 8 channels, packet_numer, marker
{
marker: number,
packet_number: number,
ot0_ch0: number, // ch0 - O2
ot0_ch1: number, // ch1 - T3
ot0_ch2: number, // ch3 - T4
ot0_ch3: number, // ch4 - O1
...
ot7_ch2: number,
ot7_ch3: number,
}- handleResistNotification(event) - (resist)return object with 4 channels and packet_number
{
packet_number: number,
ch0: number, // ch0 - O2
ch1: number, // ch1 - T3
ch2: number, // ch3 - T4
ch3: number, // ch4 - O1
}- handleResistProNotification(event) - You should use this handler when you have FLEX PRO device (resist)return object with 8 channels and packet_number
{
packet_number: number,
ch0: number, // ch0 - O1
ch1: number, // ch1 - PZ
ch2: number, // ch3 - FZ
ch3: number, // ch4 - CZ
ch4: number, // ch5 - O2
ch5: number, // ch6 - T4
ch6: number, // ch7 - T3
ch7: number // ch8 - not named
}