From 6d0e2d18556ef6a8b3cf37eefbbee0968d8ab410 Mon Sep 17 00:00:00 2001 From: Sunguk Lee Date: Wed, 4 Dec 2019 23:35:49 +0900 Subject: [PATCH] Add YUNMAI LBM & visceral fat value. (#522) * Add YUNMAI LBM value this scale machine just use `weight - fat` formula * Initial implement YunmaiLib.getVisceralFat a return value range is 1 to 30 an original app use `floor` calculation to last value and return the integer value. it's a different part. --- .../bluetooth/BluetoothYunmaiSE_Mini.java | 2 + .../core/bluetooth/lib/YunmaiLib.java | 44 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothYunmaiSE_Mini.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothYunmaiSE_Mini.java index 6c7be176..343ad5cd 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothYunmaiSE_Mini.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothYunmaiSE_Mini.java @@ -145,6 +145,8 @@ public class BluetoothYunmaiSE_Mini extends BluetoothCommunication { scaleBtData.setMuscle(yunmaiLib.getMuscle(bodyFat)); scaleBtData.setWater(yunmaiLib.getWater(bodyFat)); scaleBtData.setBone(yunmaiLib.getBoneMass(scaleBtData.getMuscle(), weight)); + scaleBtData.setLbm(yunmaiLib.getLeanBodyMass(weight, bodyFat)); + scaleBtData.setVisceralFat(yunmaiLib.getVisceralFat(bodyFat, scaleUser.getAge())); } else { Timber.e("body fat is zero"); } diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/lib/YunmaiLib.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/lib/YunmaiLib.java index 01db2117..c21eb99c 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/lib/YunmaiLib.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/lib/YunmaiLib.java @@ -79,4 +79,48 @@ public class YunmaiLib { return boneMass; } + + public float getLeanBodyMass(float weight, float bodyFat) { + if (bodyFat < 5.0f || bodyFat > 75.0f) { + return 0.0f; + } + return weight * (100.0f - bodyFat) / 100.0f; + } + + public float getVisceralFat(float bodyFat, int age) { + float f = (bodyFat < 5.0f || bodyFat > 75.0f) ? 0.0f : bodyFat; + int a = (age < 18 || age > 120) ? 18 : age; + + if (sex == 1) { + if (a < 40) { + f -= 21.0f; + } else if (a < 60) { + f -= 22.0f; + } else { + f -= 24.0f; + } + } else { + if (a < 40) { + f -= 34.0f; + } else if (a < 60) { + f -= 35.0f; + } else { + f -= 36.0f; + } + } + + float d = sex == 1 ? 1.4f : 1.8f; + if (f > 0.0f) { + d = 1.1f; + } + + float vf = (f / d) + 9.5f; + if (vf < 1.0f) { + return 1.0f; + } + if (vf > 30.0f) { + return 30.0f; + } + return vf; + } }