test if heartrate is supported before writing preferences

here
Christian Fischer 2016-04-02 16:11:51 +02:00
parent 20aa7d9ad9
commit f2de21a664
1 changed files with 17 additions and 13 deletions

View File

@ -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;
}