Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ captures/

# IntelliJ
*.iml
.idea/
misc.xml
deploymentTargetDropDown.xml
render.experimental.xml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
Expand Down Expand Up @@ -92,3 +96,4 @@ lint/tmp/
# Android Profiling
*.hprof
gradle.properties

4 changes: 4 additions & 0 deletions ShimmerAndroidInstrumentDriver/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ captures/

# IntelliJ
*.iml
.idea/
misc.xml
deploymentTargetDropDown.xml
render.experimental.xml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
Expand Down
6 changes: 0 additions & 6 deletions ShimmerAndroidInstrumentDriver/.idea/compiler.xml

This file was deleted.

31 changes: 0 additions & 31 deletions ShimmerAndroidInstrumentDriver/.idea/gradle.xml

This file was deleted.

4 changes: 0 additions & 4 deletions ShimmerAndroidInstrumentDriver/.idea/misc.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ apply plugin: 'maven-publish'
version = '3.0.72Beta'

android {
compileSdkVersion 25
compileSdkVersion 26

lintOptions {
abortOnError false
Expand All @@ -18,7 +18,7 @@ android {
// Enabling multidex support.
multiDexEnabled true
minSdkVersion 14
targetSdkVersion 14
targetSdkVersion 26
}

buildTypes {
Expand Down Expand Up @@ -104,13 +104,13 @@ dependencies {
compile files('libs/ShimmerBiophysicalProcessingLibrary_Rev_0_11.jar')
compile files('libs/AndroidBluetoothLibrary.jar')
compile files('libs/androidplot-core-0.5.0-release.jar')
implementation (group: 'com.shimmerresearch', name: 'shimmerbluetoothmanager', version:'0.10.0_alpha'){
implementation (group: 'com.shimmerresearch', name: 'shimmerbluetoothmanagerdev', version:'JA-90_v0.4'){
// excluding org.json which is provided by Android
exclude group: 'io.netty'
exclude group: 'com.google.protobuf'
exclude group: 'org.apache.commons.math'
}
implementation (group: 'com.shimmerresearch', name: 'shimmerdriver', version:'0.10.0_alpha'){
implementation (group: 'com.shimmerresearch', name: 'shimmerdriverdev', version:'JA-90_v0.4'){
// excluding org.json which is provided by Android
exclude group: 'io.netty'
exclude group: 'com.google.protobuf'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.shimmerresearch.android.manager.ShimmerBluetoothManagerAndroid;
import com.shimmerresearch.android.shimmerService.ShimmerService;
import com.shimmerresearch.androidinstrumentdriver.R;
import com.shimmerresearch.androidradiodriver.Shimmer3BLEAndroid;
import com.shimmerresearch.bluetooth.ShimmerBluetooth;
import com.shimmerresearch.driver.Configuration;
import com.shimmerresearch.driver.ShimmerDevice;
Expand Down Expand Up @@ -224,6 +225,8 @@ public void onClick(DialogInterface dialog, int id) {

if (shimmerDeviceClone instanceof Shimmer) {
bluetoothManager.configureShimmer(shimmerDeviceClone);
}else if(shimmerDeviceClone instanceof Shimmer3BLEAndroid) {
bluetoothManager.configureShimmer(shimmerDeviceClone);
}
}
})
Expand Down Expand Up @@ -329,6 +332,8 @@ public void onClick(DialogInterface dialog, int which) {
((Shimmer)shimmerDevice).writeConfigBytes(shimmerDeviceClone.getShimmerConfigBytes());
} else if (shimmerDevice instanceof Shimmer4Android){
((Shimmer4Android)shimmerDevice).writeConfigBytes(shimmerDeviceClone.getShimmerConfigBytes());
}else if(shimmerDeviceClone instanceof Shimmer3BLEAndroid) {
((Shimmer3BLEAndroid)shimmerDevice).writeBytes(shimmerDeviceClone.getShimmerConfigBytes());
}
}
});
Expand Down Expand Up @@ -363,6 +368,8 @@ public void onClick(DialogInterface dialog, int which) {
((Shimmer)shimmerDevice).writeConfigBytes(shimmerDeviceClone.getShimmerConfigBytes());
} else if (shimmerDevice instanceof Shimmer4Android){
((Shimmer4Android)shimmerDevice).writeConfigBytes(shimmerDeviceClone.getShimmerConfigBytes());
}else if(shimmerDeviceClone instanceof Shimmer3BLEAndroid) {
((Shimmer3BLEAndroid)shimmerDevice).writeBytes(shimmerDeviceClone.getShimmerConfigBytes());
}
}
});
Expand Down Expand Up @@ -415,6 +422,8 @@ public void onClick(DialogInterface dialog, int which) {
//((Shimmer)shimmerDevice).configureShimmer(shimmerDeviceClone);
} else if (shimmerDevice instanceof Shimmer4Android){
bluetoothManager.configureShimmer(shimmerDeviceClone);
}else if(shimmerDevice instanceof Shimmer3BLEAndroid) {
bluetoothManager.configureShimmer(shimmerDeviceClone);
}
}
});
Expand Down Expand Up @@ -532,6 +541,8 @@ public void writeConfigToShimmer(ShimmerDevice clone, ShimmerBluetoothManagerAnd
bluetoothManager.configureShimmer(clone);
} else if (clone instanceof Shimmer4Android){
bluetoothManager.configureShimmer(clone);
} else if (clone instanceof Shimmer3BLEAndroid){
bluetoothManager.configureShimmer(clone);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@
import android.app.ProgressDialog;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.le.BluetoothLeScanner;
import android.bluetooth.le.ScanCallback;
import android.bluetooth.le.ScanFilter;
import android.bluetooth.le.ScanResult;
import android.bluetooth.le.ScanSettings;
import android.content.Context;
import android.os.Handler;
import android.os.ParcelUuid;
import android.util.Log;
import android.widget.Toast;

import com.shimmerresearch.android.Shimmer;
import com.shimmerresearch.android.Shimmer4Android;
import com.shimmerresearch.android.VerisenseDeviceAndroid;
import com.shimmerresearch.androidradiodriver.AndroidBleRadioByteCommunication;
import com.shimmerresearch.androidradiodriver.Shimmer3BLEAndroid;
import com.shimmerresearch.androidradiodriver.ShimmerRadioInitializerAndroid;
import com.shimmerresearch.androidradiodriver.ShimmerSerialPortAndroid;
import com.shimmerresearch.bluetooth.ShimmerBluetooth;
Expand Down Expand Up @@ -62,6 +69,11 @@ public class ShimmerBluetoothManagerAndroid extends ShimmerBluetoothManager {
protected Handler mHandler;
private boolean AllowAutoPairing = true;

public enum BT_TYPE{
BT_CLASSIC,
BLE
}

public ShimmerBluetoothManagerAndroid(Context context, Handler handler) throws Exception {
super();
ShimmerRadioInitializer.useLegacyDelayBeforeBtRead(true);
Expand Down Expand Up @@ -167,11 +179,107 @@ public void run(){
thread.start();
}

public void connectShimmerThroughBTAddress(final String bluetoothAddress, BT_TYPE btType) {
if(btType.equals(BT_TYPE.BT_CLASSIC)){
connectShimmerThroughBTAddress(bluetoothAddress);
}else{
connectShimmer3BLEThroughBTAddress(bluetoothAddress,"",null);
}
}
@Override
public void connectShimmerThroughBTAddress(final String bluetoothAddress) {

//scanLeDevice(bluetoothAddress);
//doDiscovery();
connectShimmerThroughBTAddress(bluetoothAddress,"",null);
}

public void connectShimmer3BLEThroughBTAddress(final String bluetoothAddress, final String deviceName, Context context){
final Shimmer3BLEAndroid shimmer3BLE = new Shimmer3BLEAndroid(bluetoothAddress, mHandler);
shimmer3BLE.setMacIdFromUart(bluetoothAddress);
initializeNewShimmerCommon(shimmer3BLE);
Thread thread = new Thread(){
public void run(){
shimmer3BLE.connect(bluetoothAddress, "default");
}
};
thread.start();
}

//BT Classic Scan
private void doDiscovery() {

// If we're already discovering, stop it
if (mBluetoothAdapter.isDiscovering()) {
mBluetoothAdapter.cancelDiscovery();
}

// Request discover from BluetoothAdapter
mBluetoothAdapter.startDiscovery();
}

private BluetoothLeScanner bluetoothLeScanner;
private boolean scanning;
private Handler handler = new Handler();
// Stops scanning after 10 seconds.
private static final long SCAN_PERIOD = 10000;
List<BluetoothDevice> listScanBleDevice = new ArrayList<BluetoothDevice>();

//BLE Scan
private void scanLeDevice(String deviceMacAddress) {
getScannedBleDevices();
bluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner();
if (!scanning) {
// Stops scanning after a predefined scan period.
handler.postDelayed(new Runnable() {
@Override
public void run() {
scanning = false;
bluetoothLeScanner.stopScan(leScanCallback);
}
}, SCAN_PERIOD);

scanning = true;
scanForAllBleDevices();
//scanForSpecificBleDevices(deviceMacAddress);

} else {
scanning = false;
bluetoothLeScanner.stopScan(leScanCallback);
}
}
private void scanForAllBleDevices() {
bluetoothLeScanner.startScan(leScanCallback);
}
private void scanForSpecificBleDevices(String deviceMacAddress) {
List<ScanFilter> scanFilters = new ArrayList<>();
ScanFilter filter = new ScanFilter.Builder().setDeviceAddress(deviceMacAddress).build();
scanFilters.add(filter);
ScanSettings scanSettings = new ScanSettings.Builder().build();
bluetoothLeScanner.startScan(scanFilters, scanSettings, leScanCallback);
}

// Device scan callback.
private ScanCallback leScanCallback =
new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
super.onScanResult(callbackType, result);
BluetoothDevice bledevice = result.getDevice();
if(!listScanBleDevice.contains(result.getDevice())){
listScanBleDevice.add(result.getDevice());
}
}
};

private void getScannedBleDevices(){
for(BluetoothDevice dev : listScanBleDevice)
{
System.out.println(dev.getAddress());
}

}

private boolean isDevicePaired(String bluetoothAddress){
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
for(BluetoothDevice device: pairedDevices){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.shimmerresearch.androidradiodriver;

import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattService;
Expand Down Expand Up @@ -94,13 +95,19 @@ public void onMtuChanged(int mtu) {
} catch (InterruptedException e) {
e.printStackTrace();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
gatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH);
}

if (mByteCommunicationListener != null) {
mByteCommunicationListener.eventConnected();
}
mBleDevice = bleDevice;
startServiceS(bleDevice);
System.out.println(bleDevice.getMac() + " Connected");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
gatt.setPreferredPhy(BluetoothDevice.PHY_LE_2M_MASK, BluetoothDevice.PHY_LE_2M_MASK, BluetoothDevice.PHY_OPTION_NO_PREFERRED);
}
mTaskConnect.setResult("Connected");
}

Expand Down Expand Up @@ -181,7 +188,11 @@ public void onNotifyFailure(BleException exception) {
@Override
public void onCharacteristicChanged(byte[] data) {
if (mByteCommunicationListener != null) {
mByteCommunicationListener.eventNewBytesReceived(data);
try{
mByteCommunicationListener.eventNewBytesReceived(data);
}catch (Exception e){
e.printStackTrace();
}
}
}
});
Expand Down
Loading