Android
SDK Integretion
Flow Diagram
Environment
- Android 5.0 or above
- Need apply dbay account,in order to perform authentication.
Integration Steps
- Download alg-android-v1.0.aar
- Copy file
alg-android-v1.0.aar
to project folderlibs
Append the following content to build.gradle
under app module
repositories {
flatDir {
dirs 'libs'
}
}
implementation(name:'alglibrary', ext:'aar')
Permissions
Apply for Bluetooth permission as required
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Init Method
AlgSdk.init(context, accountId, token, algSdkInitCallback)
Parameter | Type | Description |
---|---|---|
context | Activity | Current activity context |
accountId | String | Unique accountId, provided by deepbay team |
token | String | Unique token, provided by deepbay team |
algSdkInitCallback | AlgSdkInitCallback | 2 callback parameters: 1. onSdkInitSuccess call SDK after success 2. onSdkInitFail return error message when init unsuccessfully |
Add Device Method
AlgSdk.addDevice(String deviceName)
Parameter | Type | Description |
---|---|---|
deviceName | String | Headband device name |
Result | Type | Description |
---|---|---|
deviceIndex | int | Device SN Number |
Example:
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
super.onConnectionStateChange(gatt, status, newState);
if (newState == STATE_CONNECTED) {
deviceIndex = algSdk.addDevice(gatt.getDevice().getName());
// To use mBluetoothGatt.discoverServices(),we can get all BLE devices services。
gatt.discoverServices();
} else if (newState == STATE_DISCONNECTED) {
algSdk.deleteDevice(gatt.getDevice().getName());
}
}
Delete Device Method
AlgSdk.deleteDevice(String deviceName)
Note: delete target device need add before, or the algorithm will be caculted error
Parameter | Type | Description |
---|---|---|
deviceName | String | Headband Device Name |
Result | Type | Description |
---|---|---|
deviceIndex | int | Device SN Number |
Call Algorithm Method(s)
AlgSdk.warpAlgorithm(double[] data, int deviceIndex, boolean onEEG)
Parameter | Type | Description |
---|---|---|
data | double[] | Input BLE original data array |
deviceIndex | int | Device SN Number |
onEEG | boolean | if return original data (If not, return false ) |
Result | Type | Description |
---|---|---|
algorithm | JSONObject | Result from algorithm |
algData stands for all indicators and original data
signal description: 0 stands for good signal quality,1 stands for poor signal quality
{
"algData":{
"mindfulness":-0.441,
"stress":41,
"fatigue":100,
"relaxation":100,
"emotion":0.3051,
"focus":32,
"energy":{
"alpha":1.2708,
"beta":1.931,
"theta":11.6847,
"delta":84.8496,
"gamma":0.2639
},
"signal":0
}
}
Include original JSON data. AF7Data is from channel AF7,AF8Data is from channel AF8
{
"AF7Data":Array[29],
"AF8Data":Array[29],
"algData":{
"mindfulness":0.3408,
"stress":65,
"fatigue":77,
"relaxation":77,
"emotion":-0.1953,
"focus":42,
"energy":{
"alpha":4.3394,
"beta":13.9877,
"theta":20.8158,
"delta":58.8296,
"gamma":2.0275
},
"signal":0
}
}
If you want to know more about indicators detail, please refer to:Data Specification
Example:
byte[] data = characteristic.getValue();
if (characteristic.getUuid().toString().equals(UUID_CHARACTER_NOTIFY1)) {
JSONObject object = algSdk.warpAlgorithm(data, deviceIndex);
if (object != null) {
Log.d(TAG, "onCharacteristicChanged: " + object.toString());
}
}
Mindfulness Indicators Radar Map Scores
AlgSdk.getMindfulness(double[] data,int len)
Parameter | Type | Description |
---|---|---|
data | double[] | Data array from algorithm |
len | int | Data array length (512) |
Result | Type | Description |
---|---|---|
mindful | double | Coherence Value |
AlgSdk.getMindfulnessScore(double[] data,int len)
Parameter | Type | Description |
---|---|---|
data | double[] | Coherence Value Array from algorithm |
len | int | Array length |
Result | Type | Description |
---|---|---|
mind | MindScore | Scores from algorithm |
public class MindScore {
public int stability; // Mindfulness Stability
public double potential; // Mindfulness Potential
public double percent; // Mindfulness Percentage
public int score; // Mindfulness Score
Please refer to:Data Specification