From 113f9b87c61322cda321c0651a79b0741e94ad8b Mon Sep 17 00:00:00 2001 From: Me7c7 Date: Fri, 20 Sep 2024 16:56:01 +0300 Subject: [PATCH] Huawei: SetMediumToStrengthThresholdRequest v2 implemented --- .../devices/huawei/HuaweiCoordinator.java | 2 ++ .../devices/huawei/packets/FitnessData.java | 11 +++++-- .../SetMediumToStrengthThresholdRequest.java | 31 ++++++++++++++----- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiCoordinator.java index 71f3a5fb4..3fb7b053b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiCoordinator.java @@ -396,12 +396,14 @@ public class HuaweiCoordinator { public boolean supportsFitnessThresholdValue() { return supportsCommandForService(0x07, 0x29); } + public boolean supportsFitnessThresholdValueV2() { return supportsExpandCapability(0x9a) || supportsExpandCapability(0x9c); } // 0x1d - SupportTemperature // 0xba - SupportTemperatureClassification // 0x43 - SupportTemperatureStudy public boolean supportsTemperature() { return supportsExpandCapability(0x1d); } + public boolean supportsEventAlarm() { return supportsCommandForService(0x08, 0x01); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/FitnessData.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/FitnessData.java index 806718164..39a02be04 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/FitnessData.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/packets/FitnessData.java @@ -550,7 +550,9 @@ public class FitnessData { byte heartRate, byte cycleSpeed, byte sample, - byte countLength) { + byte countLength, + int walkRunSpeed, + int walkRunWithHeartRate) { super(paramsProvider); this.serviceId = FitnessData.id; @@ -571,7 +573,12 @@ public class FitnessData { .put(0x04, cycleSpeed) .put(0x05, sample) .put(0x06, countLength); - + if(walkRunSpeed != -1) { + this.tlv.put(0x07, (byte)walkRunSpeed); + } + if(walkRunWithHeartRate != -1) { + this.tlv.put(0x08, (byte)walkRunWithHeartRate); + } this.complete = true; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/SetMediumToStrengthThresholdRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/SetMediumToStrengthThresholdRequest.java index 3166b691a..a35bc4738 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/SetMediumToStrengthThresholdRequest.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/SetMediumToStrengthThresholdRequest.java @@ -44,14 +44,29 @@ public class SetMediumToStrengthThresholdRequest extends Request { protected List createRequest() throws RequestCreationException { try { //Hardcoded value till interface enable threshold values - return new MediumToStrengthThreshold.Request(paramsProvider, - (byte)0x6E, - (byte)0x3C, - (byte)0x05, - (byte)0x40, - (byte)0x50, - (byte)0x03 - ).serialize(); + if(supportProvider.getHuaweiCoordinator().supportsFitnessThresholdValueV2()) { + return new MediumToStrengthThreshold.Request(paramsProvider, + (byte) 0x6E, + (byte) 0x3C, + (byte) 0x19, + (byte) 0x58, + (byte) 0x01, + (byte) 0x01, + 0x28, + 0x28 + ).serialize(); + } else { + return new MediumToStrengthThreshold.Request(paramsProvider, + (byte) 0x6E, + (byte) 0x3C, + (byte) 0x05, + (byte) 0x40, + (byte) 0x50, + (byte) 0x03, + -1, + -1 + ).serialize(); + } } catch (HuaweiPacket.CryptoException e) { throw new RequestCreationException(e); }