1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-26 17:54:50 +02:00

BluetoothStandardWeightProfile: avoid hang if battery service is not implemented by connected device;

This commit is contained in:
Krisjans Blukis
2021-07-29 14:21:30 +03:00
parent 5ba6e050e1
commit 4b287a0167

View File

@@ -61,6 +61,7 @@ public class BluetoothStandardWeightProfile extends BluetoothCommunication {
protected boolean registerNewUser;
ScaleUser selectedUser;
ScaleMeasurement previousMeasurement;
protected boolean haveBatteryService;
public BluetoothStandardWeightProfile(Context context) {
super(context);
@@ -68,6 +69,7 @@ public class BluetoothStandardWeightProfile extends BluetoothCommunication {
this.selectedUser = OpenScale.getInstance().getSelectedScaleUser();
this.registerNewUser = false;
previousMeasurement = null;
haveBatteryService = false;
}
@Override
@@ -135,13 +137,20 @@ public class BluetoothStandardWeightProfile extends BluetoothCommunication {
// Turn on notification for User Control Point
setIndicationOn(BluetoothGattUuid.SERVICE_USER_DATA, BluetoothGattUuid.CHARACTERISTIC_USER_CONTROL_POINT);
break;
case READ_BATTERY_LEVEL:
// read Battery Service
readBytes(BluetoothGattUuid.SERVICE_BATTERY_LEVEL, BluetoothGattUuid.CHARACTERISTIC_BATTERY_LEVEL);
break;
case SET_NOTIFY_BATTERY_LEVEL:
// Turn on notifications for Battery Service
setNotificationOn(BluetoothGattUuid.SERVICE_BATTERY_LEVEL, BluetoothGattUuid.CHARACTERISTIC_BATTERY_LEVEL);
if (setNotificationOn(BluetoothGattUuid.SERVICE_BATTERY_LEVEL, BluetoothGattUuid.CHARACTERISTIC_BATTERY_LEVEL)) {
haveBatteryService = true;
}
else {
haveBatteryService = false;
}
break;
case READ_BATTERY_LEVEL:
// read Battery Service
if (haveBatteryService) {
readBytes(BluetoothGattUuid.SERVICE_BATTERY_LEVEL, BluetoothGattUuid.CHARACTERISTIC_BATTERY_LEVEL);
}
break;
case SET_NOTIFY_VENDOR_SPECIFIC_USER_LIST:
setNotifyVendorSpecificUserList();