Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Only do heart rate stuff when supported #178
Browse files Browse the repository at this point in the history
  • Loading branch information
cpfeiffer committed Feb 27, 2016
1 parent de6f898 commit ac8d7be
Showing 1 changed file with 19 additions and 10 deletions.
Expand Up @@ -107,8 +107,6 @@ protected TransactionBuilder initializeDevice(TransactionBuilder builder) {
.setCurrentTime(builder)
.requestBatteryInfo(builder)
.setInitialized(builder);
// heartrate(builder)
// .requestHRInfo(builder);
return builder;
}

Expand Down Expand Up @@ -138,8 +136,10 @@ private MiBandSupport enableFurtherNotifications(TransactionBuilder builder, boo
builder.notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_REALTIME_STEPS), enable)
.notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_ACTIVITY_DATA), enable)
.notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_BATTERY), enable)
.notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_SENSOR_DATA), enable)
.notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT), enable);
.notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_SENSOR_DATA), enable);
if (supportsHeartRate()) {
builder.notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT), enable);
}

return this;
}
Expand Down Expand Up @@ -530,14 +530,23 @@ public void onReboot() {
}
@Override
public void onHearRateTest() {
try {
TransactionBuilder builder = performInitialized("HeartRateTest");
builder.write(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_HEART_RATE_CONTROL_POINT), startHeartMeasurementManual);
builder.queue(getQueue());
} catch (IOException ex) {
LOG.error("Unable to read HearRate in MI1S", ex);
if (supportsHeartRate()) {
try {
TransactionBuilder builder = performInitialized("HeartRateTest");
builder.write(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_HEART_RATE_CONTROL_POINT), startHeartMeasurementManual);
builder.queue(getQueue());
} catch (IOException 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
public void onFindDevice(boolean start) {
isLocatingDevice = start;
Expand Down

0 comments on commit ac8d7be

Please sign in to comment.