diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiFirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiFirmwareInfo.java index 72461bac9..d8801754f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiFirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiFirmwareInfo.java @@ -40,6 +40,10 @@ public abstract class HuamiFirmwareInfo { 0x48, 0x4d, 0x44, 0x49, 0x41, 0x4c }; + public static final byte[] WATCHFACE_HEADER_UIHH = new byte[]{ + 'U', 'I', 'H', 'H', 0x01 + }; + protected static final byte[] FT_HEADER = new byte[]{ // HMZK font file (*.ft, *.ft.xx) 0x48, 0x4d, 0x5a, 0x4b }; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitband5/AmazfitBand5FirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitband5/AmazfitBand5FirmwareInfo.java index 9e2ffc190..ed426764c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitband5/AmazfitBand5FirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitband5/AmazfitBand5FirmwareInfo.java @@ -54,7 +54,7 @@ public class AmazfitBand5FirmwareInfo extends HuamiFirmwareInfo { } return HuamiFirmwareType.INVALID; } - if (ArrayUtils.startsWith(bytes, WATCHFACE_HEADER)) { + if (ArrayUtils.startsWith(bytes, WATCHFACE_HEADER_UIHH)) { return HuamiFirmwareType.WATCHFACE; } if (ArrayUtils.startsWith(bytes, NEWFT_HEADER)) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/miband5/MiBand5FirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/miband5/MiBand5FirmwareInfo.java index d4fbf1071..0873169bd 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/miband5/MiBand5FirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/miband5/MiBand5FirmwareInfo.java @@ -69,11 +69,9 @@ public class MiBand5FirmwareInfo extends HuamiFirmwareInfo { } return HuamiFirmwareType.INVALID; } - /* - if (ArrayUtils.startsWith(bytes, new byte[] {'U','I','H','H'})) { + if (ArrayUtils.startsWith(bytes, WATCHFACE_HEADER_UIHH)) { return HuamiFirmwareType.WATCHFACE; } - */ if (ArrayUtils.startsWith(bytes, NEWFT_HEADER)) { if (bytes[10] == 0x03 || bytes[10] == 0x06) { return HuamiFirmwareType.FONT; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/UpdateFirmwareOperationNew.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/UpdateFirmwareOperationNew.java index a8a0a29ae..b7cb06b56 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/UpdateFirmwareOperationNew.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/UpdateFirmwareOperationNew.java @@ -29,7 +29,11 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceBusyAction; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareInfo; +import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareType; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSupport; +import nodomain.freeyourgadget.gadgetbridge.util.ArrayUtils; + +import static nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareInfo.WATCHFACE_HEADER_UIHH; public class UpdateFirmwareOperationNew extends UpdateFirmwareOperation { private static final Logger LOG = LoggerFactory.getLogger(UpdateFirmwareOperationNew.class); @@ -39,13 +43,13 @@ public class UpdateFirmwareOperationNew extends UpdateFirmwareOperation { super(uri, support); } - + @Override public boolean sendFwInfo() { try { TransactionBuilder builder = performInitialized("send firmware info"); builder.add(new SetDeviceBusyAction(getDevice(), getContext().getString(R.string.updating_firmware), getContext())); int fwSize = getFirmwareInfo().getSize(); - byte[] sizeBytes = BLETypeConversions.fromUint24(fwSize); + byte[] sizeBytes = BLETypeConversions.fromUint32(fwSize); byte[] bytes = new byte[10]; int i = 0; bytes[i++] = HuamiService.COMMAND_FIRMWARE_INIT; @@ -53,7 +57,7 @@ public class UpdateFirmwareOperationNew extends UpdateFirmwareOperation { bytes[i++] = sizeBytes[0]; bytes[i++] = sizeBytes[1]; bytes[i++] = sizeBytes[2]; - bytes[i++] = 0; // TODO: what is that? + bytes[i++] = sizeBytes[3]; int crc32 = firmwareInfo.getCrc32(); byte[] crcBytes = BLETypeConversions.fromUint32(crc32); bytes[i++] = crcBytes[0]; @@ -61,7 +65,18 @@ public class UpdateFirmwareOperationNew extends UpdateFirmwareOperation { bytes[i++] = crcBytes[2]; bytes[i] = crcBytes[3]; - + if (getFirmwareInfo().getFirmwareType() == HuamiFirmwareType.WATCHFACE) { + byte[] fwBytes = firmwareInfo.getBytes(); + if (ArrayUtils.startsWith(fwBytes, WATCHFACE_HEADER_UIHH)) { + builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), + new byte[]{0x39, 0x00, 0x00, (byte) 0xff, (byte) 0xff, (byte) 0xff, + fwBytes[18], + fwBytes[19], + fwBytes[20], + fwBytes[21] + }); + } + } builder.write(fwCControlChar, bytes); builder.queue(getQueue()); return true;