Mi2: support for current battery status #449
so far we understand - last charge date - current level - state normal - state charging and we are notified on changes.
This commit is contained in:
parent
dd48869fa5
commit
caaa38ed04
|
@ -26,7 +26,7 @@ public class MiBand2Service {
|
||||||
public static final UUID UUID_CHARACTERISTIC_3_CONFIGURATION = UUID.fromString("00000003-0000-3512-2118-0009af100700");
|
public static final UUID UUID_CHARACTERISTIC_3_CONFIGURATION = UUID.fromString("00000003-0000-3512-2118-0009af100700");
|
||||||
public static final UUID UUID_UNKNOWN_CHARACTERISTIC4 = UUID.fromString("00000004-0000-3512-2118-0009af100700");
|
public static final UUID UUID_UNKNOWN_CHARACTERISTIC4 = UUID.fromString("00000004-0000-3512-2118-0009af100700");
|
||||||
public static final UUID UUID_CHARACTERISTIC_5_ACTIVITY_DATA = UUID.fromString("00000005-0000-3512-2118-0009af100700");
|
public static final UUID UUID_CHARACTERISTIC_5_ACTIVITY_DATA = UUID.fromString("00000005-0000-3512-2118-0009af100700");
|
||||||
public static final UUID UUID_UNKNOWN_CHARACTERISTIC6 = UUID.fromString("00000006-0000-3512-2118-0009af100700");
|
public static final UUID UUID_CHARACTERISTIC_6_BATTERY_INFO = UUID.fromString("00000006-0000-3512-2118-0009af100700");
|
||||||
public static final UUID UUID_UNKNOWN_CHARACTERISTIC7 = UUID.fromString("00000007-0000-3512-2118-0009af100700");
|
public static final UUID UUID_UNKNOWN_CHARACTERISTIC7 = UUID.fromString("00000007-0000-3512-2118-0009af100700");
|
||||||
public static final UUID UUID_UNKNOWN_CHARACTERISTIC8 = UUID.fromString("00000008-0000-3512-2118-0009af100700");
|
public static final UUID UUID_UNKNOWN_CHARACTERISTIC8 = UUID.fromString("00000008-0000-3512-2118-0009af100700");
|
||||||
// service uuid fee1
|
// service uuid fee1
|
||||||
|
|
|
@ -0,0 +1,95 @@
|
||||||
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.miband2;
|
||||||
|
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandDateConverter;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.AbstractInfo;
|
||||||
|
|
||||||
|
//00000006-0000-3512-2118-0009af100700
|
||||||
|
//
|
||||||
|
// f = ?
|
||||||
|
// 30 = 48%
|
||||||
|
// 00 = 00 = STATUS_NORMAL, 01 = STATUS_CHARGING
|
||||||
|
// e0 07 = 2016
|
||||||
|
// 0b = 11
|
||||||
|
// 1a = 26
|
||||||
|
// 12 = 18
|
||||||
|
// 23 = 35
|
||||||
|
// 2c = 44
|
||||||
|
// 04 = 4 // num charges??
|
||||||
|
//
|
||||||
|
// e0 07 = 2016 // last charge time
|
||||||
|
// 0b = 11
|
||||||
|
// 1a = 26
|
||||||
|
// 17 = 23
|
||||||
|
// 2b = 43
|
||||||
|
// 3b = 59
|
||||||
|
// 04 = 4 // num charges??
|
||||||
|
// 64 = 100 // how much was charged
|
||||||
|
|
||||||
|
public class BatteryInfo extends AbstractInfo {
|
||||||
|
public static final byte DEVICE_BATTERY_NORMAL = 0;
|
||||||
|
public static final byte DEVICE_BATTERY_CHARGING = 1;
|
||||||
|
// public static final byte DEVICE_BATTERY_LOW = 1;
|
||||||
|
// public static final byte DEVICE_BATTERY_CHARGING_FULL = 3;
|
||||||
|
// public static final byte DEVICE_BATTERY_CHARGE_OFF = 4;
|
||||||
|
|
||||||
|
public BatteryInfo(byte[] data) {
|
||||||
|
super(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLevelInPercent() {
|
||||||
|
if (mData.length >= 2) {
|
||||||
|
return mData[1];
|
||||||
|
}
|
||||||
|
return 50; // actually unknown
|
||||||
|
}
|
||||||
|
|
||||||
|
public BatteryState getState() {
|
||||||
|
if (mData.length >= 3) {
|
||||||
|
int value = mData[2];
|
||||||
|
switch (value) {
|
||||||
|
case DEVICE_BATTERY_NORMAL:
|
||||||
|
return BatteryState.BATTERY_NORMAL;
|
||||||
|
case DEVICE_BATTERY_CHARGING:
|
||||||
|
return BatteryState.BATTERY_CHARGING;
|
||||||
|
// case DEVICE_BATTERY_CHARGING:
|
||||||
|
// return BatteryState.BATTERY_CHARGING;
|
||||||
|
// case DEVICE_BATTERY_CHARGING_FULL:
|
||||||
|
// return BatteryState.BATTERY_CHARGING_FULL;
|
||||||
|
// case DEVICE_BATTERY_CHARGE_OFF:
|
||||||
|
// return BatteryState.BATTERY_NOT_CHARGING_FULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return BatteryState.UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLastChargeLevelInParcent() {
|
||||||
|
if (mData.length >= 20) {
|
||||||
|
return mData[19];
|
||||||
|
}
|
||||||
|
return 50; // actually unknown
|
||||||
|
}
|
||||||
|
|
||||||
|
public GregorianCalendar getLastChargeTime() {
|
||||||
|
GregorianCalendar lastCharge = MiBandDateConverter.createCalendar();
|
||||||
|
|
||||||
|
if (mData.length >= 18) {
|
||||||
|
lastCharge = BLETypeConversions.rawBytesToCalendar(new byte[]{
|
||||||
|
mData[10], mData[11], mData[12], mData[13], mData[14], mData[15], mData[16], mData[17]
|
||||||
|
}, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return lastCharge;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNumCharges() {
|
||||||
|
// if (mData.length >= 10) {
|
||||||
|
// return ((0xff & mData[7]) | ((0xff & mData[8]) << 8));
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
|
@ -68,9 +68,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateA
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.WriteAction;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.WriteAction;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.DeviceInfoProfile;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.DeviceInfoProfile;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.heartrate.HeartRateProfile;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.heartrate.HeartRateProfile;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.BatteryInfo;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.CheckAuthenticationNeededAction;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.CheckAuthenticationNeededAction;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.DeviceInfo;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.DeviceInfo;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.MiBandSupport;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.NotificationStrategy;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.NotificationStrategy;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.RealtimeSamplesSupport;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.RealtimeSamplesSupport;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.operations.FetchActivityOperation;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.operations.FetchActivityOperation;
|
||||||
|
@ -268,9 +268,9 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
||||||
public MiBand2Support enableFurtherNotifications(TransactionBuilder builder, boolean enable) {
|
public MiBand2Support enableFurtherNotifications(TransactionBuilder builder, boolean enable) {
|
||||||
// builder.notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_REALTIME_STEPS), enable)
|
// builder.notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_REALTIME_STEPS), enable)
|
||||||
// .notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_ACTIVITY_DATA), 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_SENSOR_DATA), enable);
|
||||||
builder.notify(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_3_CONFIGURATION), enable);
|
builder.notify(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_3_CONFIGURATION), enable);
|
||||||
|
builder.notify(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_6_BATTERY_INFO), enable);
|
||||||
BluetoothGattCharacteristic heartrateCharacteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT);
|
BluetoothGattCharacteristic heartrateCharacteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT);
|
||||||
if (heartrateCharacteristic != null) {
|
if (heartrateCharacteristic != null) {
|
||||||
builder.notify(heartrateCharacteristic, enable);
|
builder.notify(heartrateCharacteristic, enable);
|
||||||
|
@ -367,6 +367,13 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private MiBand2Support requestBatteryInfo(TransactionBuilder builder) {
|
||||||
|
LOG.debug("Requesting Battery Info!");
|
||||||
|
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_6_BATTERY_INFO);
|
||||||
|
builder.read(characteristic);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public MiBand2Support requestDeviceInfo(TransactionBuilder builder) {
|
public MiBand2Support requestDeviceInfo(TransactionBuilder builder) {
|
||||||
LOG.debug("Requesting Device Info!");
|
LOG.debug("Requesting Device Info!");
|
||||||
deviceInfoProfile.requestDeviceInfo(builder);
|
deviceInfoProfile.requestDeviceInfo(builder);
|
||||||
|
@ -817,7 +824,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
||||||
super.onCharacteristicChanged(gatt, characteristic);
|
super.onCharacteristicChanged(gatt, characteristic);
|
||||||
|
|
||||||
UUID characteristicUUID = characteristic.getUuid();
|
UUID characteristicUUID = characteristic.getUuid();
|
||||||
if (MiBandService.UUID_CHARACTERISTIC_BATTERY.equals(characteristicUUID)) {
|
if (MiBand2Service.UUID_CHARACTERISTIC_6_BATTERY_INFO.equals(characteristicUUID)) {
|
||||||
handleBatteryInfo(characteristic.getValue(), BluetoothGatt.GATT_SUCCESS);
|
handleBatteryInfo(characteristic.getValue(), BluetoothGatt.GATT_SUCCESS);
|
||||||
return true;
|
return true;
|
||||||
} else if (MiBandService.UUID_CHARACTERISTIC_NOTIFICATION.equals(characteristicUUID)) {
|
} else if (MiBandService.UUID_CHARACTERISTIC_NOTIFICATION.equals(characteristicUUID)) {
|
||||||
|
@ -856,7 +863,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
||||||
if (GattCharacteristic.UUID_CHARACTERISTIC_GAP_DEVICE_NAME.equals(characteristicUUID)) {
|
if (GattCharacteristic.UUID_CHARACTERISTIC_GAP_DEVICE_NAME.equals(characteristicUUID)) {
|
||||||
handleDeviceName(characteristic.getValue(), status);
|
handleDeviceName(characteristic.getValue(), status);
|
||||||
return true;
|
return true;
|
||||||
} else if (MiBandService.UUID_CHARACTERISTIC_BATTERY.equals(characteristicUUID)) {
|
} else if (MiBand2Service.UUID_CHARACTERISTIC_6_BATTERY_INFO.equals(characteristicUUID)) {
|
||||||
handleBatteryInfo(characteristic.getValue(), status);
|
handleBatteryInfo(characteristic.getValue(), status);
|
||||||
return true;
|
return true;
|
||||||
} else if (MiBandService.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT.equals(characteristicUUID)) {
|
} else if (MiBandService.UUID_CHARACTERISTIC_HEART_RATE_MEASUREMENT.equals(characteristicUUID)) {
|
||||||
|
@ -1272,11 +1279,11 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
||||||
public void phase2Initialize(TransactionBuilder builder) {
|
public void phase2Initialize(TransactionBuilder builder) {
|
||||||
LOG.info("phase2Initialize...");
|
LOG.info("phase2Initialize...");
|
||||||
enableFurtherNotifications(builder, true);
|
enableFurtherNotifications(builder, true);
|
||||||
|
requestBatteryInfo(builder);
|
||||||
setDateDisplay(builder);
|
setDateDisplay(builder);
|
||||||
setWearLocation(builder);
|
setWearLocation(builder);
|
||||||
setFitnessGoal(builder);
|
setFitnessGoal(builder);
|
||||||
setActivateDisplayOnLiftWrist(builder);
|
setActivateDisplayOnLiftWrist(builder);
|
||||||
setHeartrateSleepSupport(builder);
|
setHeartrateSleepSupport(builder);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue