1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-29 03:55:49 +01:00

Mi/Amazfit Band 5: Support flashing watchfaces

This commit is contained in:
Andreas Shimokawa 2020-11-20 22:03:23 +01:00
parent 498bf1af1f
commit 0e88adbaf7
4 changed files with 25 additions and 8 deletions

View File

@ -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
};

View File

@ -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)) {

View File

@ -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;

View File

@ -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;