From f2de21a6647ea515db373484b7431c1a2c8af7fe Mon Sep 17 00:00:00 2001 From: Christian Fischer Date: Sat, 2 Apr 2016 16:11:51 +0200 Subject: [PATCH] test if heartrate is supported before writing preferences --- .../service/devices/miband/MiBandSupport.java | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java index a72e23db..a3367180 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java @@ -376,20 +376,24 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { * @return */ private MiBandSupport setHeartrateSleepSupport(TransactionBuilder transaction) { - LOG.info("Attempting to set heartrate sleep support..."); - BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_HEART_RATE_CONTROL_POINT); - if (characteristic != null) { - if(MiBandCoordinator.getHeartrateSleepSupport(getDevice().getAddress())) { - LOG.info("Enabling heartrate sleep support..."); - transaction.write(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_HEART_RATE_CONTROL_POINT), startHeartMeasurementSleep); + if (supportsHeartRate()) { + LOG.info("Attempting to set heartrate sleep support..."); + BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_HEART_RATE_CONTROL_POINT); + if (characteristic != null) { + if(MiBandCoordinator.getHeartrateSleepSupport(getDevice().getAddress())) { + LOG.info("Enabling heartrate sleep support..."); + transaction.write(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_HEART_RATE_CONTROL_POINT), startHeartMeasurementSleep); + } + else { + LOG.info("Disabling heartrate sleep support..."); + transaction.write(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_HEART_RATE_CONTROL_POINT), stopHeartMeasurementSleep); + } + } else { + LOG.info("Unable to set Heartrate sleep support"); } - else { - LOG.info("Disabling heartrate sleep support..."); - transaction.write(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_HEART_RATE_CONTROL_POINT), stopHeartMeasurementSleep); - } - } else { - LOG.info("Unable to set Wear Location"); - } + + } else + GB.toast(getContext(), "Heart rate is not supported on this device", Toast.LENGTH_LONG, GB.ERROR); return this; }