Skip to content

Commit

Permalink
fixed bug with enabling ble notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
bayosip committed Nov 16, 2021
1 parent 341d4b3 commit 1eae98c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void disableNotificationsFor(String serviceUuid, String attrId,
}

@Override
public void connectToDeviceWithDeviceInfoFrom(Intent intent) {
public void connectToDeviceWithDeviceInfoFrom(@NonNull Intent intent) {
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -781,21 +781,22 @@ public void writeToDescriptorToEnableIndicator(String serviceUUID, String charxU
if (setCharacteristicNotification(gatt, charx, false)) {
BluetoothGattDescriptor descriptor = charx.getDescriptor(
UUID.fromString(CCC_DESCRIPTOR_UUID));
descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);

Queue<Object> BleWriteQueue = writeQueueMap.get(deviceAddress);
Objects.requireNonNull(BleWriteQueue).add(descriptor);
writeQueueMap.put(deviceAddress, BleWriteQueue);
if(BleWriteQueue.size()==1)
Log.d(TAG, "writeToDescriptorToEnableNotifications: ->"
+gatt.writeDescriptor(descriptor));
if(descriptor!=null) {
descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);

Queue<Object> BleWriteQueue = writeQueueMap.get(deviceAddress);
Objects.requireNonNull(BleWriteQueue).add(descriptor);
writeQueueMap.put(deviceAddress, BleWriteQueue);
if (BleWriteQueue.size() == 1)
Log.d(TAG, "writeToDescriptorToEnableNotifications: ->"
+ gatt.writeDescriptor(descriptor));
}
}
}

private void writeToDescriptorToEnableNotifications(BluetoothGattCharacteristic characteristic, BluetoothGatt gatt){
if (setCharacteristicNotification(gatt, characteristic, true)) {
UUID descUuid = UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG);
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(descUuid);
BluetoothGattDescriptor descriptor = characteristic.getDescriptors().get(0);
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);

String deviceAddress = gatt.getDevice().getAddress();
Expand All @@ -810,8 +811,7 @@ private void writeToDescriptorToEnableNotifications(BluetoothGattCharacteristic
private void writeToDescriptorToEnableIndicator(BluetoothGattCharacteristic characteristic,
BluetoothGatt gatt){
if (setCharacteristicNotification(gatt, characteristic, true)) {
UUID descUuid = UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG);
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(descUuid);
BluetoothGattDescriptor descriptor = characteristic.getDescriptors().get(0);
descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);

String deviceAddress = gatt.getDevice().getAddress();
Expand All @@ -835,13 +835,15 @@ public void writeToDescriptorToDisableNotifications(String serviceUUID, String c

BluetoothGattDescriptor descriptor = charx.getDescriptor(
UUID.fromString(CCC_DESCRIPTOR_UUID));
descriptor.setValue(BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE);
Queue<Object> BleWriteQueue = writeQueueMap.get(deviceAddress);
Objects.requireNonNull(BleWriteQueue).add(descriptor);
writeQueueMap.put(deviceAddress, BleWriteQueue);
if(BleWriteQueue.size()==1)
Log.d(TAG, "writeToDescriptorToDisableNotifications: "
+gatt.writeDescriptor(descriptor));
if(descriptor!=null) {
descriptor.setValue(BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE);
Queue<Object> BleWriteQueue = writeQueueMap.get(deviceAddress);
Objects.requireNonNull(BleWriteQueue).add(descriptor);
writeQueueMap.put(deviceAddress, BleWriteQueue);
if (BleWriteQueue.size() == 1)
Log.d(TAG, "writeToDescriptorToDisableNotifications: "
+ gatt.writeDescriptor(descriptor));
}
}
}

Expand Down

0 comments on commit 1eae98c

Please sign in to comment.