Skip to content

Commit

Permalink
Ability to switch to indications for command output.
Browse files Browse the repository at this point in the history
  • Loading branch information
jayalfredprufrock committed Jul 3, 2018
1 parent 09fd3a8 commit 87b24d8
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 15 deletions.
24 changes: 15 additions & 9 deletions app/src/main/java/com/aurorasdk/app/SDKExampleActivity.java
Expand Up @@ -130,13 +130,6 @@ public void onSyncTimeClick(View v){
public void onOsInfoClick(View v){

queueCommand("os-info");
/* queueCommand("os-info");
queueCommand("os-info");
queueCommand("os-info");
queueCommand("os-info");
queueCommand("os-info");
queueCommand("os-info");
queueCommand("led-demo");*/
}

public void onWriteFileClick(View v) {
Expand Down Expand Up @@ -187,8 +180,8 @@ public void onWriteFileClick(View v) {

public void onReadFileClick(View v)
{
//queueCommand(new CommandSdFileRead("test.txt", null));
queueCommand(new CommandSdFileRead("sessions/2018-05-22@215852/session.txt"));
//queueCommand(new CommandSdFileRead("test.txt"));
queueCommand(new CommandSdFileRead("sessions/2018-05-22@2158/session.txt"));
}

public void onLoadProfileClick(View v) {
Expand Down Expand Up @@ -244,6 +237,19 @@ public void onDisableEventsClick(View v) {
}
}

public void onUseIndicationsClick(View v) {

if (aurora.isConnected()){

showMsg("Now using indications for command output.");
aurora.useIndicationsForCommandOutput();
}
else {

showMsg("Aurora must first be connected before switching to indications.");
}
}


/* Helper methods
------------------------------------------------------------------------------------------------
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/layout/activity_sdkexample.xml
Expand Up @@ -16,6 +16,17 @@
tools:context="com.aurorasdk.SDKExampleActivity">


<Button
android:id="@+id/button16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:onClick="onUseIndicationsClick"
android:text="Use Indications"
app:layout_constraintStart_toEndOf="@+id/button7"
app:layout_constraintTop_toBottomOf="@+id/button4" />

<Button
android:id="@+id/button11"
android:layout_width="63dp"
Expand Down
7 changes: 7 additions & 0 deletions aurorasdk/src/main/java/com/aurorasdk/Aurora.java
Expand Up @@ -251,6 +251,13 @@ public Command disableEvents(EnumSet<Event.EventType> eventTypes){
}


//TODO: remove this when firmware 2.X is deprecated
public void useIndicationsForCommandOutput(){

connectionManager.useIndicationsForCommandOutput();
}


/* Helper methods
------------------------------------------------------------------------------------------------
*/
Expand Down
Expand Up @@ -19,7 +19,7 @@

public class AuroraBleConnectionManager extends BleManager<AuroraBleCallbacks> {

private BluetoothGattCharacteristic commandStatusChar, commandDataChar, commandOutputChar, eventChar;
private BluetoothGattCharacteristic commandStatusChar, commandDataChar, commandOutputCharNotified, commandOutputCharIndicated, eventChar;

private Queue<ByteBuffer> readBuffers;

Expand Down Expand Up @@ -49,8 +49,8 @@ protected Deque<Request> initGatt(final BluetoothGatt gatt) {

final LinkedList<Request> requests = new LinkedList<>();
requests.push(Request.newEnableIndicationsRequest(commandStatusChar));
//requests.push(Request.newEnableNotificationsRequest(commandOutputChar));
requests.push(Request.newEnableIndicationsRequest(commandOutputChar));
requests.push(Request.newEnableNotificationsRequest(commandOutputCharNotified));
//requests.push(Request.newEnableIndicationsRequest(commandOutputCharIndicated));
requests.push(Request.newEnableNotificationsRequest(eventChar));

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
Expand All @@ -70,8 +70,8 @@ public boolean isRequiredServiceSupported(final BluetoothGatt gatt) {

commandStatusChar = service.getCharacteristic(Constants.COMMAND_STATUS_UUID.getUuid());
commandDataChar = service.getCharacteristic(Constants.COMMAND_DATA_UUID.getUuid());
//commandOutputChar = service.getCharacteristic(Constants.COMMAND_OUTPUT_NOTIFIED_UUID.getUuid());
commandOutputChar = service.getCharacteristic(Constants.COMMAND_OUTPUT_INDICATED_UUID.getUuid());
commandOutputCharNotified = service.getCharacteristic(Constants.COMMAND_OUTPUT_NOTIFIED_UUID.getUuid());
commandOutputCharIndicated = service.getCharacteristic(Constants.COMMAND_OUTPUT_INDICATED_UUID.getUuid());
eventChar = service.getCharacteristic(Constants.EVENT_NOTIFIED_UUID.getUuid());

return commandStatusChar != null && commandDataChar != null;
Expand Down Expand Up @@ -144,7 +144,7 @@ private void onCharacteristic(final BluetoothGatt gatt, final BluetoothGattChara

byte[] charValue = characteristic.getValue();

if (characteristic == commandOutputChar){
if (characteristic == commandOutputCharNotified || characteristic == commandOutputCharIndicated){

mCallbacks.onCommandOutput(charValue);
}
Expand Down Expand Up @@ -195,4 +195,13 @@ private void clearReadBuffers(){
}
}

public void useIndicationsForCommandOutput(){

if (isConnected()){

disableNotifications(commandOutputCharNotified);
enableIndications(commandOutputCharIndicated);
}
}

}

0 comments on commit 87b24d8

Please sign in to comment.