1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2025-01-28 02:27:32 +01:00

InfiniTime: support notification for battery level

This commit is contained in:
Andreas Shimokawa 2021-07-08 23:46:18 +02:00
parent c5aaaec7e3
commit 603050b7cc
3 changed files with 12 additions and 2 deletions

View File

@ -108,4 +108,7 @@ public abstract class AbstractBleProfile<T extends AbstractBTLEDeviceSupport> ex
return mSupport.getQueue();
}
public void enableNotify(TransactionBuilder builder, boolean enable) {
}
}

View File

@ -53,8 +53,9 @@ public class BatteryInfoProfile<T extends AbstractBTLEDeviceSupport> extends Abs
builder.read(getCharacteristic(UUID_CHARACTERISTIC_BATTERY_LEVEL));
}
public void enableNotifiy() {
// TODO: notification
@Override
public void enableNotify(TransactionBuilder builder, boolean enable) {
builder.notify(getCharacteristic(BatteryInfoProfile.UUID_CHARACTERISTIC_BATTERY_LEVEL), enable);
}
@Override
@ -73,6 +74,11 @@ public class BatteryInfoProfile<T extends AbstractBTLEDeviceSupport> extends Abs
return false;
}
@Override
public boolean onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
return onCharacteristicRead(gatt, characteristic, BluetoothGatt.GATT_SUCCESS);
}
private void handleBatteryLevel(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
int percent = ValueDecoder.decodePercent(characteristic);
batteryInfo.setPercentCharged(percent);

View File

@ -453,6 +453,7 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport implements DfuL
}
setInitialized(builder);
batteryInfoProfile.requestBatteryInfo(builder);
batteryInfoProfile.enableNotify(builder,true);
return builder;
}