mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-22 00:06:48 +02:00
supported body measurements for Yunmai scale
This commit is contained in:
@@ -23,6 +23,7 @@ import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import com.health.openscale.core.OpenScale;
|
||||
import com.health.openscale.core.bluetooth.lib.YunmaiLib;
|
||||
import com.health.openscale.core.datatypes.ScaleMeasurement;
|
||||
import com.health.openscale.core.datatypes.ScaleUser;
|
||||
import com.health.openscale.core.utils.Converters;
|
||||
@@ -31,6 +32,8 @@ import java.util.Date;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
public class BluetoothYunmaiSE_Mini extends BluetoothCommunication {
|
||||
private final UUID WEIGHT_MEASUREMENT_SERVICE = UUID.fromString("0000ffe0-0000-1000-8000-00805f9b34fb");
|
||||
private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC = UUID.fromString("0000ffe4-0000-1000-8000-00805f9b34fb");
|
||||
@@ -119,7 +122,7 @@ public class BluetoothYunmaiSE_Mini extends BluetoothCommunication {
|
||||
}
|
||||
|
||||
private void parseBytes(byte[] weightBytes) {
|
||||
final ScaleUser selectedUser = OpenScale.getInstance().getSelectedScaleUser();
|
||||
final ScaleUser scaleUser = OpenScale.getInstance().getSelectedScaleUser();
|
||||
|
||||
ScaleMeasurement scaleBtData = new ScaleMeasurement();
|
||||
|
||||
@@ -130,8 +133,26 @@ public class BluetoothYunmaiSE_Mini extends BluetoothCommunication {
|
||||
scaleBtData.setWeight(weight);
|
||||
|
||||
if (isMini) {
|
||||
float fat = Converters.fromUnsignedInt16Be(weightBytes, 17) / 100.0f;
|
||||
scaleBtData.setFat(fat);
|
||||
int sex;
|
||||
|
||||
if (scaleUser.getGender() == Converters.Gender.MALE) {
|
||||
sex = 1;
|
||||
} else {
|
||||
sex = 0;
|
||||
}
|
||||
|
||||
YunmaiLib yunmaiLib = new YunmaiLib(sex, scaleUser.getBodyHeight());
|
||||
float bodyFat = Converters.fromUnsignedInt16Be(weightBytes, 17) / 100.0f;
|
||||
int resistance = Converters.fromUnsignedInt16Be(weightBytes, 15);
|
||||
scaleBtData.setFat(bodyFat);
|
||||
scaleBtData.setMuscle(yunmaiLib.getMuscle(bodyFat));
|
||||
scaleBtData.setWater(yunmaiLib.getWater(bodyFat));
|
||||
scaleBtData.setBone(yunmaiLib.getBoneMass(scaleBtData.getMuscle(), weight));
|
||||
|
||||
Timber.d("received bytes [%s]", byteInHex(weightBytes));
|
||||
Timber.d("received decrypted bytes [weight: %.2f, fat: %.2f, resistance: %d]", weight, bodyFat, resistance);
|
||||
Timber.d("user [%s]", scaleUser);
|
||||
Timber.d("scale measurement [%s]", scaleBtData);
|
||||
}
|
||||
|
||||
addScaleData(scaleBtData);
|
||||
|
@@ -0,0 +1,60 @@
|
||||
/* Copyright (C) 2018 olie.xdev <olie.xdev@googlemail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package com.health.openscale.core.bluetooth.lib;
|
||||
|
||||
public class YunmaiLib {
|
||||
private int sex; // male = 1; female = 0
|
||||
private float height;
|
||||
|
||||
public YunmaiLib(int sex, float height) {
|
||||
this.sex = sex;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public float getWater(float bodyFat) {
|
||||
return ((100.0f - bodyFat) * 0.726f * 100.0f + 0.5f) / 100.0f;
|
||||
}
|
||||
|
||||
public float getMuscle(float bodyFat) {
|
||||
float muscle;
|
||||
muscle = (100.0f - bodyFat) * 0.67f;
|
||||
|
||||
if (sex == 1) {
|
||||
muscle = (100.0f - bodyFat) * 0.7f;
|
||||
}
|
||||
|
||||
muscle = ((muscle * 100.0f) + 0.5f) / 100.0f;
|
||||
|
||||
return muscle;
|
||||
}
|
||||
|
||||
public float getBoneMass(float muscle, float weight) {
|
||||
float boneMass;
|
||||
|
||||
float h = height - 170.0f;
|
||||
|
||||
if (sex == 1) {
|
||||
boneMass = ((weight * (muscle / 100.0f) * 4.0f) / 7.0f * 0.22f * 0.6f) + (h / 100.0f);
|
||||
} else {
|
||||
boneMass = ((weight * (muscle / 100.0f) * 4.0f) / 7.0f * 0.34f * 0.45f) + (h / 100.0f);
|
||||
}
|
||||
|
||||
boneMass = ((boneMass * 10.0f) + 0.5f) / 10.0f;
|
||||
|
||||
return boneMass;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user