Pebble 2 Duo: Fix getting inital battery level (for the rest still rely on datalog

This commit is contained in:
Andreas Shimokawa
2025-11-02 13:06:36 +01:00
parent 876f5c8050
commit fd2627caee
3 changed files with 13 additions and 5 deletions
@@ -481,6 +481,9 @@ class PebbleIoThread extends GBDeviceIoThread {
write(mPebbleProtocol.encodeEnableAppLogs(devicePrefs.getBoolean("pebble_enable_applogs", false)));
write(mPebbleProtocol.encodeReportDataLogSessions());
gbDevice.setState(GBDevice.State.INITIALIZED);
if (mPebbleLESupport != null) {
mPebbleLESupport.readBatteryCharacteristic();
}
return false;
} else if (deviceEvent instanceof GBDeviceEventAppManagement) {
GBDeviceEventAppManagement appMgmt = (GBDeviceEventAppManagement) deviceEvent;
@@ -245,12 +245,13 @@ class PebbleGATTClient extends BluetoothGattCallback {
if (status == BluetoothGatt.GATT_SUCCESS) {
LOG.info("MTU changed to {}", mtu);
mPebbleLESupport.setMTU(mtu);
}
}
// read battery
BluetoothGattCharacteristic characteristic = gatt.getService(GattService.UUID_SERVICE_BATTERY_SERVICE).getCharacteristic(GattCharacteristic.UUID_CHARACTERISTIC_BATTERY_LEVEL);
if (characteristic != null) {
gatt.readCharacteristic(characteristic);
}
public void readBatteryCharacteristic() {
BluetoothGattCharacteristic characteristic = mBluetoothGatt.getService(GattService.UUID_SERVICE_BATTERY_SERVICE).getCharacteristic(GattCharacteristic.UUID_CHARACTERISTIC_BATTERY_LEVEL);
if (characteristic != null) {
mBluetoothGatt.readCharacteristic(characteristic);
}
}
@@ -154,6 +154,10 @@ public class PebbleLESupport {
mMTU = Math.min(mtu, mMTULimit);
}
public void readBatteryCharacteristic() {
mPebbleGATTClient.readBatteryCharacteristic();
}
public void handlePPoGATTPacket(byte[] value) {
if (!mIsConnected) {
mIsConnected = true;