Only do heart rate stuff when supported #178

This commit is contained in:
cpfeiffer 2016-02-27 11:23:55 +01:00
parent de6f898fef
commit ac8d7bee5f
1 changed files with 19 additions and 10 deletions

View File

@ -107,8 +107,6 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
.setCurrentTime(builder) .setCurrentTime(builder)
.requestBatteryInfo(builder) .requestBatteryInfo(builder)
.setInitialized(builder); .setInitialized(builder);
// heartrate(builder)
// .requestHRInfo(builder);
return builder; return builder;
} }
@ -138,8 +136,10 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
builder.notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_REALTIME_STEPS), enable) builder.notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_REALTIME_STEPS), enable)
.notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_ACTIVITY_DATA), enable) .notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_ACTIVITY_DATA), enable)
.notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_BATTERY), enable) .notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_BATTERY), enable)
.notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_SENSOR_DATA), enable) .notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_SENSOR_DATA), enable);
.notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT), enable); if (supportsHeartRate()) {
builder.notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT), enable);
}
return this; return this;
} }
@ -530,6 +530,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
} }
@Override @Override
public void onHearRateTest() { public void onHearRateTest() {
if (supportsHeartRate()) {
try { try {
TransactionBuilder builder = performInitialized("HeartRateTest"); TransactionBuilder builder = performInitialized("HeartRateTest");
builder.write(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_HEART_RATE_CONTROL_POINT), startHeartMeasurementManual); builder.write(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_HEART_RATE_CONTROL_POINT), startHeartMeasurementManual);
@ -537,7 +538,15 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
} catch (IOException ex) { } catch (IOException ex) {
LOG.error("Unable to read HearRate in MI1S", ex); LOG.error("Unable to read HearRate in MI1S", ex);
} }
} else {
GB.toast(getContext(), "Heart rate is not supported on this device", Toast.LENGTH_LONG, GB.ERROR);
} }
}
public boolean supportsHeartRate() {
return getDeviceInfo() != null && getDeviceInfo().isMilli1S();
}
@Override @Override
public void onFindDevice(boolean start) { public void onFindDevice(boolean start) {
isLocatingDevice = start; isLocatingDevice = start;