mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-29 05:16:51 +01:00
Mijia LYWSD02: Fix battery drain on Mijia
This commit is contained in:
parent
59b83b92c7
commit
e6a0350197
@ -60,6 +60,7 @@ public class MijiaLywsd02Support extends AbstractBTLEDeviceSupport {
|
||||
private static final UUID UUID_TIME = UUID.fromString("ebe0ccb7-7a0a-4b0c-8a1a-6ff2997da3a6");
|
||||
private static final UUID UUID_BATTERY = UUID.fromString("ebe0ccc4-7a0a-4b0c-8a1a-6ff2997da3a6");
|
||||
private static final UUID UUID_SCALE = UUID.fromString("ebe0ccbe-7a0a-4b0c-8a1a-6ff2997da3a6");
|
||||
private static final UUID UUID_CONN_INTERVAL = UUID.fromString("ebe0ccd8-7a0a-4b0c-8a1a-6ff2997da3a6");
|
||||
private final DeviceInfoProfile<MijiaLywsd02Support> deviceInfoProfile;
|
||||
private final GBDeviceEventVersionInfo versionCmd = new GBDeviceEventVersionInfo();
|
||||
private final GBDeviceEventBatteryInfo batteryCmd = new GBDeviceEventBatteryInfo();
|
||||
@ -94,6 +95,7 @@ public class MijiaLywsd02Support extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
|
||||
getBatteryInfo(builder);
|
||||
setConnectionInterval(builder);
|
||||
setInitialized(builder);
|
||||
return builder;
|
||||
}
|
||||
@ -102,7 +104,7 @@ public class MijiaLywsd02Support extends AbstractBTLEDeviceSupport {
|
||||
BluetoothGattCharacteristic timeCharacteristc = getCharacteristic(MijiaLywsd02Support.UUID_TIME);
|
||||
long ts = System.currentTimeMillis();
|
||||
byte offsetHours = (byte) (SimpleTimeZone.getDefault().getOffset(ts) / (1000 * 60 * 60));
|
||||
ts /= 1000;
|
||||
ts = ( ts + 250 + 500 ) / 1000; // round to seconds with +250 ms to compensate for BLE connection interval
|
||||
builder.write(timeCharacteristc, new byte[]{
|
||||
(byte) (ts & 0xff),
|
||||
(byte) ((ts >> 8) & 0xff),
|
||||
@ -111,6 +113,11 @@ public class MijiaLywsd02Support extends AbstractBTLEDeviceSupport {
|
||||
offsetHours});
|
||||
}
|
||||
|
||||
private void setConnectionInterval(TransactionBuilder builder) {
|
||||
BluetoothGattCharacteristic intervalCharacteristc = getCharacteristic(MijiaLywsd02Support.UUID_CONN_INTERVAL);
|
||||
builder.write(intervalCharacteristc, new byte[]{ (byte) 0xf4, (byte) 0x01 }); // maximum interval of 500 ms
|
||||
}
|
||||
|
||||
private void getBatteryInfo(TransactionBuilder builder) {
|
||||
BluetoothGattCharacteristic batteryCharacteristc = getCharacteristic(MijiaLywsd02Support.UUID_BATTERY);
|
||||
builder.read(batteryCharacteristc);
|
||||
|
Loading…
Reference in New Issue
Block a user