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 @@ -124,13 +124,15 @@ public void onClick(View v) {

// If there are paired devices, add each one to the ArrayAdapter
if (pairedDevices.size() > 0) {
pairedListView.setEnabled(true);
findViewById(R.id.title_paired_devices).setVisibility(View.VISIBLE);
for (BluetoothDevice device : pairedDevices) {
mPairedDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
}
} else {
String noDevices = getResources().getText(R.string.none_paired).toString();
mPairedDevicesArrayAdapter.add(noDevices);
pairedListView.setEnabled(false);
}
}

Expand Down Expand Up @@ -187,7 +189,7 @@ public void onItemClick(AdapterView<?> av, View v, int arg2, long arg3) {
Toast.makeText(getApplicationContext(),"Device Selected " + "-> "+ address, Toast.LENGTH_SHORT).show();
setResult(Activity.RESULT_OK, intent); // Set result and finish this Activity

finish();
finish();
}

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.shimmerresearch.driver.Configuration;
import com.shimmerresearch.driver.ObjectCluster;
import com.shimmerresearch.driver.ShimmerDevice;
import com.shimmerresearch.driver.ShimmerObject;
import com.shimmerresearch.driver.shimmer4sdk.Shimmer4sdk;
import com.shimmerresearch.driverUtilities.BluetoothDeviceDetails;
import com.shimmerresearch.driverUtilities.ChannelDetails;
Expand All @@ -35,7 +34,6 @@

import com.shimmerresearch.exceptions.ConnectionExceptionListener;
import com.shimmerresearch.exceptions.ShimmerException;
import com.shimmerresearch.exgConfig.ExGConfigOptionDetails;
import com.shimmerresearch.managers.bluetoothManager.ShimmerBluetoothManager;

import java.util.ArrayList;
Expand All @@ -46,8 +44,6 @@
import java.util.Set;
import java.util.TreeMap;

import static android.R.id.list;

/**
* Created by ASaez on 10-Aug-16.
*/
Expand Down Expand Up @@ -89,8 +85,19 @@ public void connectBluetoothDevice(BluetoothDevice device){
}

/**
* @param bluetoothAddress
* When true, will attempt to pair the device if the device is not paired. User will have to manually key in the pairing key.
* @param enable
*/
public void enablePairingOnConnect(boolean enable){
AllowAutoPairing = enable;
}

/**
* See also {@link #connectShimmerThroughBTAddress(String)}.
* @param bluetoothAddress in the form of XX:XX:XX:XX:XX:XX
* @param context if the context is set, a progress dialog will show, otherwise a toast msg will show
* @exception IllegalArgumentException if bluetoothAddress is invalid, note this will only occur when {@link #enablePairingOnConnect(boolean)} is enabled
* @exception DeviceNotPairedException if the device is not paired
*/
public void connectShimmerThroughBTAddress(final String bluetoothAddress,Context context) {

Expand Down Expand Up @@ -143,12 +150,23 @@ public void onConnectStartException(String connectionHandle) {
}
}

/**
* See also {@link #connectShimmerThroughBTAddress(String,Context)}.
* @param bluetoothAddress in the form of XX:XX:XX:XX:XX:XX
* @exception IllegalArgumentException if bluetoothAddress is invalid, note this will only occur when {@link #enablePairingOnConnect(boolean)} is enabled
* @exception DeviceNotPairedException if the device is not paired
*/
@Override
public void connectShimmerThroughBTAddress(final String bluetoothAddress) {
connectShimmerThroughBTAddress(bluetoothAddress,null);
}

private boolean isDevicePaired(String bluetoothAddress){
/**
* Using the specified bluetooth address in the form of XX:XX:XX:XX:XX:XX check if the device is currently paired to the android device
* @param bluetoothAddress
* @return true if the device is paired
*/
public boolean isDevicePaired(String bluetoothAddress){
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
for(BluetoothDevice device: pairedDevices){
if(device.getAddress().equals(bluetoothAddress)){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@
</activity>

</application>
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>


</manifest>
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package shimmerresearch.com.shimmerbasicexample;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.ActivityCompat;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
Expand Down Expand Up @@ -36,7 +38,9 @@ public class MainActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION,Manifest.permission.ACCESS_COARSE_LOCATION},
0);
shimmer = new Shimmer(mHandler);
}

Expand Down
27 changes: 7 additions & 20 deletions ShimmerAndroidInstrumentDriver/shimmerConnectionTest/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
# Shimmer Basic Example
This example is only applicable for Shimmer3 devices onwards. For Shimmer2 devices, please see the Legacy Example
# Shimmer Connection Test Example
This example is only applicable for Shimmer3 devices onwards.

- This example demonstrates connecting and streaming data from a Shimmer directly, without the use of the Bluetooth Manager
- The build.gradle file shows how to retrieve the library from bintray. Take note of the following:-

```
compile 'ShimmerAndroidInstrumentDriver:ShimmerAndroidInstrumentDriver:3.0.65Beta'
```

- Note you will need to specify the url for the shimmer bintray repository, this is done in the build.gradle file (root projects folder)
This shows how to implement the retry logic for a successful connection on the first try. Note the important part are that a new shimmer instance be created everytime an attempt to connect is made (_this also applies if you aren't using the Bluetooth Manager_). Also note that the method setMacIdFromUart is called in order to maintain functionality of the BluetoothManager (_e.g. public void startStreaming(String bluetoothAddress)_)
```
allprojects {
repositories {
google()
jcenter()
maven {
url "http://dl.bintray.com/shimmerengineering/Shimmer"
}
}
}
```
Shimmer shimmer = new Shimmer(mHandler);
shimmer.setMacIdFromUart(macAdd);
btManager.removeShimmerDeviceBtConnected(macAdd);
btManager.putShimmerGlobalMap(macAdd, shimmer);