From 641eb1bee7923a8378299fd1a2202981b4169e32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Sun, 25 Feb 2024 00:02:52 +0000 Subject: [PATCH] Xiaomi: Fix steps and stress parsing for some devices --- .../xiaomi/activity/impl/DailyDetailsParser.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/activity/impl/DailyDetailsParser.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/activity/impl/DailyDetailsParser.java index 624368676..94e5d4a72 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/activity/impl/DailyDetailsParser.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/activity/impl/DailyDetailsParser.java @@ -88,7 +88,12 @@ public class DailyDetailsParser extends XiaomiActivityParser { final XiaomiActivitySample sample = new XiaomiActivitySample(); sample.setTimestamp((int) (timestamp.getTimeInMillis() / 1000)); - sample.setSteps(buf.getShort()); + // we only need the first 14 bits of the 2 bytes + // FIXME we should parse the header + final byte[] steps = new byte[2]; + buf.get(steps); + final int stepsNum = (steps[0] & 0xff) | (((steps[1] >> 2) & 0xff) << 8); + sample.setSteps(stepsNum); final int calories = buf.get() & 0xff; final int unk2 = buf.get() & 0xff; @@ -105,7 +110,10 @@ public class DailyDetailsParser extends XiaomiActivityParser { if (version == 3) { // TODO gadgets with versions 2 also should have stress, but the values don't make sense sample.setSpo2(buf.get() & 0xff); - sample.setStress(buf.get() & 0xff); + int stress = buf.get() & 0xff; + if (stress != 0xff) { + sample.setStress(buf.get() & 0xff); + } } }