The Brainiac library handles connections and data transfer between Braniac (alpha title) accessory and Android device.
#Requirements
Android 4.3+
0.1
- Import library module to your android project.
- Initialize BrainiacManager.
- Set OnReceiveDataCallback.
- Set OnFftDataCallback.
- Connect to accessory
- Download source from GitHub.
- Open your project.
- Use File->New->Import Module and choose brainiac library.
BrainiacManager brainiacManager = BrainiacManager.getBrainiacManager(this); // this - reference to instance of Context
brainiacManager.setOnReceiveDataCallback(new OnReceiveDataCallback() {
@Override
public void onReceiveData(Value value) {
//Do something with recived data
}
});
brainiacManager.setOnReceiveFftDataCallback(new OnReceiveFftDataCallback() {
@Override
public void onReceiveData(FftValue[] fftValues) {
//Do something with transformed data.
}
});
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter.isEnabled()) {
if (brainiacManager.isConnected()) {
brainiacManager.release();
...
} else {
brainiacManager.startScan(onConnectCallback);
...
}
}
Value - class which represents raw values received from Braniac accessory. It contains a few fields:
- channel1 - brain activity measure for channel 1 (T3) - double
- channel2 - brain activity measure for channel 2 (O1) - double
- channel3 - brain activity measure for channel 3 (T4) - double
- channel4 - brain activity measure for channel 4 (O2) - double
##FftValue FftValue - class which represents transformed values. It contains a few fields:
- data1 - dominant frequency value for current time range and frequencies range 3-7 Hz - int
- data2 - dominant frequency value for current time range and frequencies range 7-13 Hz - int
- data3 - dominant frequency value for current time range and frequencies range 14-24 Hz - int
##OnConnectCallback OnConnectCallback is used for handling connection state.
###onConnectSuccess Callback is called after successful connection to Brainiac accessory.
void onConnectSuccess()
###onConnectFailed Callback is called after failed connection to Brainiac accessory.
void onConnectFailed()
##OnReceiveDataCallback OnReceiveDataCallback is used for handling a new bundle of raw data.
###onReceiveData Callback is called once raw data received.
void onReceiveData(Value value)
Parameter
- value - contains raw data of every channel
##OnReceiveFftDataCallback OnReceiveFftDataCallback is used for handling dominant frequencies.
###onReceiveData Callback is called once transformed data received.
void onReceiveData(FftValue[] fftValues)
Parameter
- fftValues - is array of 4 FftValue instances which represent dominant frequencies for every channel
##BrainiacManager The BrainiacManager class handles connections and data transfer between Braniac (alpha title) accessory and Android device.
###setOnReceiveFftDataCallback Register a callback to be invoked when fft data received.
public void setOnReceiveFftDataCallback(OnReceiveFftDataCallback onReceiveFftDataCallback)
Parameter
- onReceiveFftDataCallback - An implementation of OnReceiveFftDataCallback
###getBrainiacManager Returns BrainiacManager singleton.
public static BrainiacManager getBrainiacManager(Context context)
Parameter
- context - application context
###setOnReceiveDataCallback Register a callback to be invoked when raw data received.
public void setOnReceiveDataCallback(OnReceiveDataCallback onReceiveDataCallback)
Parameter
- onReceiveDataCallback - An implementation of OnReceiveDataCallback
###startScan Starts a scan for Brainiac devices.
public void startScan(final OnConnectCallback onConnectCallback)
Parameter
- onConnectCallback - These callbacks may get called at any time, when connected to a brainiac device.
###isConnected Indicates whether BrainiacManager connected to device. Return true if instance connected to device, false otherwise
public boolean isConnected()
###stopScan Stops an ongoing Bluetooth LE device scan.
public void stopScan()
###release Release all using resources
public void release()