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
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@

import android.Manifest;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.clj.fastble.BleManager;
import com.shimmerresearch.android.Shimmer;
import com.shimmerresearch.android.guiUtilities.FileListActivity;
import com.shimmerresearch.android.guiUtilities.ShimmerBluetoothDialog;
Expand All @@ -22,6 +27,7 @@
import com.shimmerresearch.driver.Configuration;
import com.shimmerresearch.driver.ObjectCluster;
import com.shimmerresearch.driverUtilities.ChannelDetails;
import com.shimmerresearch.driverUtilities.HwDriverShimmerDeviceDetails;
import com.shimmerresearch.exceptions.ShimmerException;
import com.shimmerresearch.tools.FileUtils;
import com.shimmerresearch.verisense.VerisenseDevice;
Expand All @@ -39,6 +45,7 @@
import java.util.concurrent.Executors;

import static com.shimmerresearch.android.guiUtilities.ShimmerBluetoothDialog.EXTRA_DEVICE_ADDRESS;
import static com.shimmerresearch.android.guiUtilities.ShimmerBluetoothDialog.EXTRA_DEVICE_NAME;
import static com.shimmerresearch.android.guiUtilities.ShimmerBluetoothDialog.REQUEST_CONNECT_SHIMMER;

import androidx.core.app.ActivityCompat;
Expand Down Expand Up @@ -73,6 +80,10 @@ public class MainActivity extends Activity {
private File file;
boolean firstTimeWrite = true;
Uri mTreeUri;

ShimmerBluetoothManagerAndroid.BT_TYPE preferredBtType;
Looper looper = Looper.myLooper();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -120,6 +131,7 @@ protected void onCreate(Bundle savedInstanceState) {


try {
BleManager.getInstance().init(getApplication());
btManager = new ShimmerBluetoothManagerAndroid(this, mHandler);


Expand All @@ -135,8 +147,12 @@ public void connectDevice(View v) {
startActivityForResult(intent, REQUEST_CONNECT_SHIMMER);
}

public void disconnectDevice(View v){
btManager.disconnectAllDevices();
}

public void startStreaming(View v) {
Shimmer shimmer = (Shimmer) btManager.getShimmer(bluetoothAdd);
ShimmerBluetooth shimmer = (ShimmerBluetooth) btManager.getShimmer(bluetoothAdd);
if(shimmer != null) { //this is null if Shimmer device is not connected
setupCSV();
//Disable PC timestamps for better performance. Disabling this takes the timestamps on every full packet received instead of on every byte received.
Expand All @@ -158,7 +174,7 @@ public void startStreaming(View v) {
public void stopStreaming(View v) {
if(btManager.getShimmer(bluetoothAdd) != null) {
try {
Shimmer shimmer = (Shimmer) btManager.getShimmer(bluetoothAdd);
ShimmerBluetooth shimmer = (ShimmerBluetooth) btManager.getShimmer(bluetoothAdd);
btManager.stopStreaming(bluetoothAdd);
} catch (ShimmerException e) {
e.printStackTrace();
Expand All @@ -182,7 +198,12 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
//Get the Bluetooth mac address of the selected device:
bluetoothAdd = data.getStringExtra(EXTRA_DEVICE_ADDRESS);
btManager.connectShimmerThroughBTAddress(bluetoothAdd); //Connect to the selected device
String deviceName = data.getStringExtra(EXTRA_DEVICE_NAME);
preferredBtType = ShimmerBluetoothManagerAndroid.BT_TYPE.BT_CLASSIC;
if (deviceName.contains(HwDriverShimmerDeviceDetails.DEVICE_TYPE.SHIMMER3R.toString())){
showBtTypeConnectionOption();
}
btManager.connectShimmerThroughBTAddress(bluetoothAdd,deviceName,preferredBtType); //Connect to the selected device
}

}
Expand All @@ -198,6 +219,26 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}

public void showBtTypeConnectionOption(){
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setCancelable(false);
alertDialog.setMessage("Choose preferred Bluetooth type");
alertDialog.setButton( Dialog.BUTTON_POSITIVE, "BT CLASSIC", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
preferredBtType = ShimmerBluetoothManagerAndroid.BT_TYPE.BT_CLASSIC;
looper.quit();
};
});
alertDialog.setButton( Dialog.BUTTON_NEGATIVE, "BLE", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
preferredBtType = ShimmerBluetoothManagerAndroid.BT_TYPE.BLE;
looper.quit();
};
});
alertDialog.show();
try{ looper.loop(); }
catch(RuntimeException e){}
}
private final ExecutorService executor = Executors.newSingleThreadExecutor();

private int countNonNulls(String[] dataArray){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@
android:onClick="connectDevice"
android:text="Connect" />

<Button
android:id="@+id/buttonDisconnect"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:onClick="disconnectDevice"
android:text="Disconnect" />

<Button
android:id="@+id/button"
android:layout_width="200dp"
Expand Down