mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-27 02:05:26 +02:00
BluetoothStandardWeightProfile: avoid hang if battery service is not implemented by connected device;
This commit is contained in:
@@ -61,6 +61,7 @@ public class BluetoothStandardWeightProfile extends BluetoothCommunication {
|
|||||||
protected boolean registerNewUser;
|
protected boolean registerNewUser;
|
||||||
ScaleUser selectedUser;
|
ScaleUser selectedUser;
|
||||||
ScaleMeasurement previousMeasurement;
|
ScaleMeasurement previousMeasurement;
|
||||||
|
protected boolean haveBatteryService;
|
||||||
|
|
||||||
public BluetoothStandardWeightProfile(Context context) {
|
public BluetoothStandardWeightProfile(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
@@ -68,6 +69,7 @@ public class BluetoothStandardWeightProfile extends BluetoothCommunication {
|
|||||||
this.selectedUser = OpenScale.getInstance().getSelectedScaleUser();
|
this.selectedUser = OpenScale.getInstance().getSelectedScaleUser();
|
||||||
this.registerNewUser = false;
|
this.registerNewUser = false;
|
||||||
previousMeasurement = null;
|
previousMeasurement = null;
|
||||||
|
haveBatteryService = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -135,13 +137,20 @@ public class BluetoothStandardWeightProfile extends BluetoothCommunication {
|
|||||||
// Turn on notification for User Control Point
|
// Turn on notification for User Control Point
|
||||||
setIndicationOn(BluetoothGattUuid.SERVICE_USER_DATA, BluetoothGattUuid.CHARACTERISTIC_USER_CONTROL_POINT);
|
setIndicationOn(BluetoothGattUuid.SERVICE_USER_DATA, BluetoothGattUuid.CHARACTERISTIC_USER_CONTROL_POINT);
|
||||||
break;
|
break;
|
||||||
case READ_BATTERY_LEVEL:
|
|
||||||
// read Battery Service
|
|
||||||
readBytes(BluetoothGattUuid.SERVICE_BATTERY_LEVEL, BluetoothGattUuid.CHARACTERISTIC_BATTERY_LEVEL);
|
|
||||||
break;
|
|
||||||
case SET_NOTIFY_BATTERY_LEVEL:
|
case SET_NOTIFY_BATTERY_LEVEL:
|
||||||
// Turn on notifications for Battery Service
|
// 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;
|
break;
|
||||||
case SET_NOTIFY_VENDOR_SPECIFIC_USER_LIST:
|
case SET_NOTIFY_VENDOR_SPECIFIC_USER_LIST:
|
||||||
setNotifyVendorSpecificUserList();
|
setNotifyVendorSpecificUserList();
|
||||||
|
Reference in New Issue
Block a user