1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-27 18:20:21 +02:00

BluetoothCommunication: Stop state machine only if setNotification operation was enqueued;

This commit is contained in:
Krisjans Blukis
2021-07-29 14:19:20 +03:00
parent ea579c02fe
commit 5ba6e050e1

View File

@@ -308,15 +308,21 @@ public abstract class BluetoothCommunication {
* Set notification flag on for the Bluetooth device. * Set notification flag on for the Bluetooth device.
* *
* @param characteristic the Bluetooth UUID characteristic * @param characteristic the Bluetooth UUID characteristic
* @return true if the operation was enqueued, false if the characteristic doesn't support notification or indications or
*/ */
protected void setNotificationOn(UUID service, UUID characteristic) { protected boolean setNotificationOn(UUID service, UUID characteristic) {
Timber.d("Invoke set notification on " + BluetoothGattUuid.prettyPrint(characteristic)); Timber.d("Invoke set notification on " + BluetoothGattUuid.prettyPrint(characteristic));
if(btPeripheral.getService(service) != null) { if(btPeripheral.getService(service) != null) {
stopMachineState();
BluetoothGattCharacteristic currentTimeCharacteristic = btPeripheral.getCharacteristic(service, characteristic); BluetoothGattCharacteristic currentTimeCharacteristic = btPeripheral.getCharacteristic(service, characteristic);
btPeripheral.setNotify(currentTimeCharacteristic, true); if (currentTimeCharacteristic != null) {
if (btPeripheral.setNotify(currentTimeCharacteristic, true)) {
stopMachineState();
return true;
} }
} }
}
return false;
}
/** /**
* Disconnect from a Bluetooth device * Disconnect from a Bluetooth device