From c2f5fd32156a3b2542be29771a1b532e8b96631c Mon Sep 17 00:00:00 2001 From: NekoBox Date: Sat, 30 Jul 2022 21:37:21 +0200 Subject: [PATCH] Fix Amazfit Neo daily steps goal and notification, fixes #2773 (#2780) The notification, once enabled, can only be triggerd once per day, mind that when testing. Packet structure: ``` 00:c2:00:3a:01:00:00:00:01:88:13:00:00 00:c2:00: - chunked transfer type 2 3a: - command set goals/notificatrions 01: - 01 - set steps goal, 02 - set calories goal, 03 - both 00:00:00: - delimiter 01: - enable steps goal notification 88:13: - set steps goal (5000) 00:00 - delimiter ``` This is sent when goal notification switch is enabled in Zepp app: ``` 00:c2:00:3a:03:00:00:00:01:40:1f:00:00:01:2c:01:00:00 00:c2:00: - chunked transfer type 2 3a: - command set goals/notificatrions 03: - 01 - set steps goal, 02 - set calories goal, 03 - both 00:00:00: - delimiter 01: - enable steps goal notification 40:1f: - steps goal (8000) 00:00: - delimiter 01: - enable calories goal notification (seems to be not used in Neo) 2c:01: - set calories goal (300) 00:00 - delimiter ``` And when disabled: `00:c2:00:3a:03:00:00:00:00:40:1f:00:00:00:2c:01:00:00` Reviewed-on: https://codeberg.org/Freeyourgadget/Gadgetbridge/pulls/2780 Co-authored-by: NekoBox Co-committed-by: NekoBox --- .../service/devices/huami/HuamiSupport.java | 4 +-- .../huami/amazfitneo/AmazfitNeoSupport.java | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java index 35fcc33e9..6f9e07d66 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java @@ -528,7 +528,7 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport { * @return */ - private HuamiSupport setFitnessGoal(TransactionBuilder transaction) { + protected HuamiSupport setFitnessGoal(TransactionBuilder transaction) { LOG.info("Attempting to set Fitness Goal..."); BluetoothGattCharacteristic characteristic = getCharacteristic(HuamiService.UUID_CHARACTERISTIC_8_USER_SETTINGS); if (characteristic != null) { @@ -3161,7 +3161,7 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport { return this; } - private HuamiSupport setGoalNotification(TransactionBuilder builder) { + protected HuamiSupport setGoalNotification(TransactionBuilder builder) { boolean enable = HuamiCoordinator.getGoalNotification(gbDevice.getAddress()); LOG.info("Setting goal notification to " + enable); if (enable) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitneo/AmazfitNeoSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitneo/AmazfitNeoSupport.java index 6cc9623f4..d5dacabb0 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitneo/AmazfitNeoSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitneo/AmazfitNeoSupport.java @@ -48,6 +48,32 @@ public class AmazfitNeoSupport extends MiBand5Support { return this; } + @Override + protected AmazfitNeoSupport setFitnessGoal(TransactionBuilder builder) { + LOG.info("Attempting to set Fitness Goal..."); + setNeoFitnessGoal(builder); + return this; + } + + @Override + protected AmazfitNeoSupport setGoalNotification(TransactionBuilder builder) { + LOG.info("Attempting to set goal notification..."); + setNeoFitnessGoal(builder); + return this; + } + + private void setNeoFitnessGoal(TransactionBuilder builder) { + int fitnessGoal = GBApplication.getPrefs().getInt(ActivityUser.PREF_USER_STEPS_GOAL, ActivityUser.defaultUserStepsGoal); + boolean fitnessGoalNotification = HuamiCoordinator.getGoalNotification(gbDevice.getAddress()); + LOG.info("Setting Amazfit Neo fitness goal to: " + fitnessGoal + ", notification: " + fitnessGoalNotification); + byte[] bytes = ArrayUtils.addAll( + new byte[] { 0x3a, 1, 0, 0, 0, (byte) (fitnessGoalNotification ? 1 : 0 ) }, + BLETypeConversions.fromUint16(fitnessGoal)); + bytes = ArrayUtils.addAll(bytes, + HuamiService.COMMAND_SET_FITNESS_GOAL_END); + writeToChunked(builder, 2, bytes); + } + @Override public HuamiFWHelper createFWHelper(Uri uri, Context context) throws IOException { return new AmazfitNeoFWHelper(uri, context);