From cb0848673182344c1a541a93a81f5f683f637689 Mon Sep 17 00:00:00 2001 From: Krisjans Blukis Date: Tue, 27 Jul 2021 19:28:04 +0300 Subject: [PATCH] BluetoothStandardWeightProfile: Calculate lean body mass and bone mass; Thanks to Adam Serbinski for providing formulas! --- .../BluetoothStandardWeightProfile.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothStandardWeightProfile.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothStandardWeightProfile.java index 5d588d2b..0b4ca1b9 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothStandardWeightProfile.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothStandardWeightProfile.java @@ -434,8 +434,9 @@ public class BluetoothStandardWeightProfile extends BluetoothCommunication { } // Read softleanMass if present + float softLeanMass = 0.0f; if (softLeanMassPresent) { - float softLeanMass = parser.getIntValue(BluetoothBytesParser.FORMAT_UINT16) * massMultiplier; + softLeanMass = parser.getIntValue(BluetoothBytesParser.FORMAT_UINT16) * massMultiplier; Timber.d(prefix + "softLeanMass: " + softLeanMass); } @@ -453,11 +454,29 @@ public class BluetoothStandardWeightProfile extends BluetoothCommunication { } // Read weight if present + float weightValue = 0.0f; if (weightPresent) { - float weightValue = parser.getIntValue(BluetoothBytesParser.FORMAT_UINT16) * massMultiplier; + weightValue = parser.getIntValue(BluetoothBytesParser.FORMAT_UINT16) * massMultiplier; Timber.d(prefix + "weightValue: " + weightValue); scaleMeasurement.setWeight(weightValue); } + else { + if (previousMeasurement != null) { + weightValue = previousMeasurement.getWeight(); + if (weightValue > 0) { + weightPresent = true; + } + } + } + + // calculate lean body mass and bone mass + if (weightPresent && softLeanMassPresent) { + float fatMass = weightValue * bodyFatPercentage / 100.0f; + float leanBodyMass = weightValue - fatMass; + float boneMass = leanBodyMass - softLeanMass; + scaleMeasurement.setLbm(leanBodyMass); + scaleMeasurement.setBone(boneMass); + } // Read height if present if (heightPresent) {