From d33fa791871bd93124308510200915f63151524e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Tue, 17 Sep 2024 22:30:44 +0100 Subject: [PATCH] Mi Band 8 Pro: Fix outdoor walking and cycling parsing --- .../activity/impl/WorkoutSummaryParser.java | 30 +++++++++++++++++++ .../impl/XiaomiSimpleActivityParser.java | 3 ++ 2 files changed, 33 insertions(+) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/activity/impl/WorkoutSummaryParser.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/activity/impl/WorkoutSummaryParser.java index c797db033..8dc9eefb4 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/activity/impl/WorkoutSummaryParser.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/activity/impl/WorkoutSummaryParser.java @@ -17,9 +17,14 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.activity.impl; import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.ACTIVE_SECONDS; +import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.ALTITUDE_AVG; +import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.ALTITUDE_MAX; +import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.ALTITUDE_MIN; import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.CADENCE_AVG; import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.CALORIES_BURNT; import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.DISTANCE_METERS; +import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.ELEVATION_GAIN; +import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.ELEVATION_LOSS; import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.HR_AVG; import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.HR_MAX; import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.HR_MIN; @@ -30,6 +35,7 @@ import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries. import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.HR_ZONE_WARM_UP; import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.LAPS; import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.LAP_PACE_AVERAGE; +import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.MAXIMUM_OXYGEN_UPTAKE; import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.PACE_AVG_SECONDS_KM; import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.PACE_MAX; import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.PACE_MIN; @@ -51,6 +57,7 @@ import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries. import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.UNIT_KMPH; import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.UNIT_LAPS; import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.UNIT_METERS; +import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.UNIT_ML_KG_MIN; import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.UNIT_NONE; import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.UNIT_SECONDS; import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.UNIT_SECONDS_PER_KM; @@ -441,6 +448,7 @@ public class WorkoutSummaryParser extends XiaomiActivityParser implements Activi final int headerSize; switch (version) { case 4: + case 5: headerSize = 6; break; default: @@ -460,10 +468,32 @@ public class WorkoutSummaryParser extends XiaomiActivityParser implements Activi builder.addShort(CALORIES_BURNT, UNIT_KCAL); builder.addUnknown(4); builder.addUnknown(4); + if (version >= 5) { + builder.addFloat(SPEED_AVG, UNIT_KMPH); + } builder.addFloat(SPEED_MAX, UNIT_KMPH); builder.addByte(HR_AVG, UNIT_BPM); builder.addByte(HR_MAX, UNIT_BPM); builder.addByte(HR_MIN, UNIT_BPM); + builder.addFloat(ELEVATION_GAIN, UNIT_METERS); + builder.addFloat(ELEVATION_LOSS, UNIT_METERS); + builder.addFloat(ALTITUDE_AVG, UNIT_METERS); + builder.addFloat(ALTITUDE_MAX, UNIT_METERS); + builder.addFloat(ALTITUDE_MIN, UNIT_METERS); + builder.addFloat(TRAINING_EFFECT_AEROBIC, UNIT_NONE); + builder.addUnknown(1); + builder.addFloat(TRAINING_EFFECT_ANAEROBIC, UNIT_NONE); + builder.addUnknown(1); + builder.addByte(MAXIMUM_OXYGEN_UPTAKE, UNIT_ML_KG_MIN); + builder.addUnknown(1); + builder.addUnknown(1); + builder.addShort(RECOVERY_TIME, UNIT_HOURS); + builder.addUnknown(1); + builder.addInt(HR_ZONE_EXTREME, UNIT_SECONDS); + builder.addInt(HR_ZONE_ANAEROBIC, UNIT_SECONDS); + builder.addInt(HR_ZONE_AEROBIC, UNIT_SECONDS); + builder.addInt(HR_ZONE_FAT_BURN, UNIT_SECONDS); + builder.addInt(HR_ZONE_WARM_UP, UNIT_SECONDS); return builder.build(); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/activity/impl/XiaomiSimpleActivityParser.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/activity/impl/XiaomiSimpleActivityParser.java index a37b01d42..b6b4a3f5f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/activity/impl/XiaomiSimpleActivityParser.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/activity/impl/XiaomiSimpleActivityParser.java @@ -101,6 +101,9 @@ public class XiaomiSimpleActivityParser { } else if (dataEntry.getKey().equals(XIAOMI_WORKOUT_TYPE)) { // TODO use XiaomiWorkoutType switch (value.intValue()) { + case 1: + summary.setActivityKind(ActivityKind.OUTDOOR_WALKING.getCode()); + break; case 2: summary.setActivityKind(ActivityKind.WALKING.getCode()); break;