read initial value of live steps data when enabling notification

live-activity-data
Daniele Gobbetti 2015-09-02 16:36:20 +02:00
parent ab8982e7f2
commit b6cbb5d6be
1 changed files with 16 additions and 8 deletions

View File

@ -524,6 +524,10 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
public void onEnableRealtimeSteps(boolean enable) {
try {
BluetoothGattCharacteristic controlPoint = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT);
if (enable) {
TransactionBuilder builder = performInitialized("Read realtime steps");
builder.read(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_REALTIME_STEPS)).queue(getQueue());
}
performInitialized(enable ? "Enabling realtime steps notifications" : "Disabling realtime steps notifications")
.write(controlPoint, enable ? startRealTimeStepsNotifications : stopRealTimeStepsNotifications).queue(getQueue());
} catch (IOException e) {
@ -613,14 +617,6 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
}
}
private void handleRealtimeSteps(byte[] value) {
int steps = 0xff & value[0] | (0xff & value[1]) << 8;
LOG.debug("realtime steps: " + steps);
Intent intent = new Intent(DeviceService.ACTION_REALTIME_STEPS)
.putExtra(DeviceService.EXTRA_REALTIME_STEPS, steps);
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
}
@Override
public void onCharacteristicRead(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic, int status) {
@ -633,6 +629,8 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
handleDeviceName(characteristic.getValue(), status);
} else if (MiBandService.UUID_CHARACTERISTIC_BATTERY.equals(characteristicUUID)) {
handleBatteryInfo(characteristic.getValue(), status);
} else if (MiBandService.UUID_CHARACTERISTIC_REALTIME_STEPS.equals(characteristicUUID)) {
handleRealtimeSteps(characteristic.getValue());
}
}
@ -661,6 +659,16 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
}
}
private void handleRealtimeSteps(byte[] value) {
int steps = 0xff & value[0] | (0xff & value[1]) << 8;
LOG.debug("realtime steps: " + steps);
Intent intent = new Intent(DeviceService.ACTION_REALTIME_STEPS)
.putExtra(DeviceService.EXTRA_REALTIME_STEPS, steps);
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
}
/**
* React to unsolicited messages sent by the Mi Band to the MiBandService.UUID_CHARACTERISTIC_NOTIFICATION
* characteristic,