From cdc60cec5106513666402c4775607fa090cd218b Mon Sep 17 00:00:00 2001 From: Daniel Dakhno Date: Tue, 20 Sep 2022 15:55:36 +0200 Subject: [PATCH] Flipper Zero: fetch firmware version from flipper --- .../flipper/zero/support/FlipperZeroSupport.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/flipper/zero/support/FlipperZeroSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/flipper/zero/support/FlipperZeroSupport.java index 0cbfd8456..cff651c3c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/flipper/zero/support/FlipperZeroSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/flipper/zero/support/FlipperZeroSupport.java @@ -1,5 +1,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.flipper.zero.support; +import android.bluetooth.BluetoothGatt; +import android.bluetooth.BluetoothGattCharacteristic; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -11,9 +13,11 @@ import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.util.UUID; +import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInfo; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.BatteryState; +import nodomain.freeyourgadget.gadgetbridge.service.btle.GattCharacteristic; import nodomain.freeyourgadget.gadgetbridge.service.btle.GattService; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction; @@ -98,6 +102,7 @@ public class FlipperZeroSupport extends FlipperZeroBaseSupport{ } }); addSupportedService(GattService.UUID_SERVICE_BATTERY_SERVICE); + addSupportedService(GattService.UUID_SERVICE_DEVICE_INFORMATION); addSupportedProfile(batteryInfoProfile); addSupportedService(UUID.fromString(UUID_SERIAL_SERVICE)); @@ -111,6 +116,7 @@ public class FlipperZeroSupport extends FlipperZeroBaseSupport{ } builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZING, getContext())); + builder.read(getCharacteristic(GattCharacteristic.UUID_CHARACTERISTIC_FIRMWARE_REVISION_STRING)); batteryInfoProfile.requestBatteryInfo(builder); batteryInfoProfile.enableNotify(builder, true); @@ -121,6 +127,16 @@ public class FlipperZeroSupport extends FlipperZeroBaseSupport{ .add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZED, getContext())); } + @Override + public boolean onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { + if(characteristic.getUuid().equals(GattCharacteristic.UUID_CHARACTERISTIC_FIRMWARE_REVISION_STRING)){ + String revision = characteristic.getStringValue(0); + getDevice().setFirmwareVersion(revision); + getDevice().sendDeviceUpdateIntent(getContext()); + } + return super.onCharacteristicRead(gatt, characteristic, status); + } + @Override public void dispose() { super.dispose();