mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-02-04 14:07:32 +01:00
read initial value of live steps data when enabling notification
This commit is contained in:
parent
ab8982e7f2
commit
b6cbb5d6be
@ -524,6 +524,10 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
|||||||
public void onEnableRealtimeSteps(boolean enable) {
|
public void onEnableRealtimeSteps(boolean enable) {
|
||||||
try {
|
try {
|
||||||
BluetoothGattCharacteristic controlPoint = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT);
|
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")
|
performInitialized(enable ? "Enabling realtime steps notifications" : "Disabling realtime steps notifications")
|
||||||
.write(controlPoint, enable ? startRealTimeStepsNotifications : stopRealTimeStepsNotifications).queue(getQueue());
|
.write(controlPoint, enable ? startRealTimeStepsNotifications : stopRealTimeStepsNotifications).queue(getQueue());
|
||||||
} catch (IOException e) {
|
} 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
|
@Override
|
||||||
public void onCharacteristicRead(BluetoothGatt gatt,
|
public void onCharacteristicRead(BluetoothGatt gatt,
|
||||||
BluetoothGattCharacteristic characteristic, int status) {
|
BluetoothGattCharacteristic characteristic, int status) {
|
||||||
@ -633,6 +629,8 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
|||||||
handleDeviceName(characteristic.getValue(), status);
|
handleDeviceName(characteristic.getValue(), status);
|
||||||
} else if (MiBandService.UUID_CHARACTERISTIC_BATTERY.equals(characteristicUUID)) {
|
} else if (MiBandService.UUID_CHARACTERISTIC_BATTERY.equals(characteristicUUID)) {
|
||||||
handleBatteryInfo(characteristic.getValue(), status);
|
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
|
* React to unsolicited messages sent by the Mi Band to the MiBandService.UUID_CHARACTERISTIC_NOTIFICATION
|
||||||
* characteristic,
|
* characteristic,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user