1
0
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:
cpfeiffer 2015-05-05 23:25:54 +02:00
parent 3e85efa898
commit 50034e0bfe
2 changed files with 11 additions and 4 deletions

View File

@ -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);

View File

@ -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);
}