mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-28 12:56:49 +01:00
Request battery info in initialize()
This commit is contained in:
parent
3e85efa898
commit
50034e0bfe
@ -204,7 +204,7 @@ public class GBDevice implements Parcelable {
|
||||
}
|
||||
|
||||
public void setBatteryLevel(short batteryLevel) {
|
||||
if (mBatteryLevel >= 0 && mBatteryLevel <= 100) {
|
||||
if (batteryLevel >= 0 && batteryLevel <= 100) {
|
||||
mBatteryLevel = batteryLevel;
|
||||
} else {
|
||||
Log.e(TAG, "Battery level musts be within range 0-100: " + batteryLevel);
|
||||
|
@ -23,7 +23,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
@Override
|
||||
protected TransactionBuilder initializeDevice(TransactionBuilder builder) {
|
||||
pair(builder).sendUserInfo(builder).setCurrentTime(builder);
|
||||
pair(builder).sendUserInfo(builder).setCurrentTime(builder).requestBatteryInfo(builder);
|
||||
return builder;
|
||||
}
|
||||
|
||||
@ -95,6 +95,13 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
return this;
|
||||
}
|
||||
|
||||
private MiBandSupport requestBatteryInfo(TransactionBuilder builder) {
|
||||
Log.d(TAG, "Requesting Battery Info!");
|
||||
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_BATTERY);
|
||||
builder.read(characteristic);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Part of device initialization process. Do not call manually.
|
||||
*
|
||||
@ -200,8 +207,8 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
public void onBatteryInfoReq() {
|
||||
try {
|
||||
TransactionBuilder builder = performInitialized("Get MI Band battery info");
|
||||
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_BATTERY);
|
||||
builder.read(characteristic).queue(getQueue());
|
||||
requestBatteryInfo(builder);
|
||||
builder.queue(getQueue());
|
||||
} catch (IOException ex) {
|
||||
Log.e(TAG, "Unable to read battery info from MI", ex);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user