1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-26 17:54:50 +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,14 +308,20 @@ public abstract class BluetoothCommunication {
* Set notification flag on for the Bluetooth device.
*
* @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));
if(btPeripheral.getService(service) != null) {
stopMachineState();
BluetoothGattCharacteristic currentTimeCharacteristic = btPeripheral.getCharacteristic(service, characteristic);
btPeripheral.setNotify(currentTimeCharacteristic, true);
if (currentTimeCharacteristic != null) {
if (btPeripheral.setNotify(currentTimeCharacteristic, true)) {
stopMachineState();
return true;
}
}
}
return false;
}
/**