This page describes simple steps to consume SDK for the Android operating system in your application.
If you found some erroneous information on this or any other page or you have any questions about the device or SDK, don't hesitate to ask your questions via e-mail or file a bug on our public issue tracker.
Email: support@brainbit.com
Issue tracker link: gitlab.com/brainbit-inc/brainbit-sdk/issues
We also have a chat on Gitter.
OS: Android 5.1 API 21 or higher
Hardware: Bluetooth v4.2
Software: Android Studio 2.3.3 or higher, Download link
Used the standard Android project dependency loading mechanism of Gradle.
implementation 'com.neuromd.neurosdk:neuro-sdk:1.7.6'
Git : gitlab.com/brainbit-inc/brainbit-examples/tree/master/android/Brainbit
Step-by-step
To use the device class Device from the SDK, you need to search for the device and connect to it. To do this, you need to implement the following steps:
DeviceEnumerator deviceEnum = new DeviceEnumerator(context, DeviceType.Brainbit);
deviceEnum.deviceListChanged.subscribe(...);
In event handlers, it is possible to request a list with information about found devices from DeviceEnumerator:
List<DeviceInfo> deviceInfoList = deviceEnum.devices();
Device battery channel:
Channel creation:
BatteryChannel batteryChannel = new BatteryChannel(device);
Subscribe to the event of receiving new data in the channel and their processing:
batteryChannel.dataLengthChanged.subscribe(new INotificationCallback<Integer>() {
@Override
public void onNotify(Object o, Integer integer) {
int[] batVal = batteryChannel.readData(batteryChannel.totalLength() - 1, 1);
if (batVal != null && batVal.length > 0)
invokeBatteryChanged(batVal[0]);
}
});
Device signal channel:
Channel creation:
SignalChannel signalChannel = new SignalChannel(device, channelInfo);
Subscribing to an event of receiving new data in a channel and processing it is similar to a battery channel. The second parameter of the constructor is required in order to establish from which lead to remove the signal (T3, T4, O1, O2). The indicated signal channels can be obtained from the device class:
ChannelInfo[] channelInfos = device.channels();
For data channels other than the battery channel, you must execute the command to start receiving data, for example, for the signal channel and its derivatives:
device.execute(Command.StartSignal);
If you do not need to receive data from the device, then it is recommended to stop the process of transferring this data (to save battery power of the device and the phone), for the signal channel and its derivatives it is:
device.execute(Command.StopSignal);
After finishing work with the device, you need to disconnect from it and free up resources, for this you need to execute blocking methods:
device.disconnect();
device.close();