use of com.health.openscale.core.bluetooth.lib.YunmaiLib in project openScale by oliexdev.
the class BluetoothYunmaiSE_Mini method parseBytes.
private void parseBytes(byte[] weightBytes) {
final ScaleUser scaleUser = OpenScale.getInstance().getSelectedScaleUser();
ScaleMeasurement scaleBtData = new ScaleMeasurement();
long timestamp = Converters.fromUnsignedInt32Be(weightBytes, 5) * 1000;
scaleBtData.setDateTime(new Date(timestamp));
float weight = Converters.fromUnsignedInt16Be(weightBytes, 13) / 100.0f;
scaleBtData.setWeight(weight);
if (isMini) {
int sex;
if (scaleUser.getGender() == Converters.Gender.MALE) {
sex = 1;
} else {
sex = 0;
}
YunmaiLib yunmaiLib = new YunmaiLib(sex, scaleUser.getBodyHeight(), scaleUser.getActivityLevel());
float bodyFat;
int resistance = Converters.fromUnsignedInt16Be(weightBytes, 15);
if (weightBytes[1] >= (byte) 0x1E) {
Timber.d("Extract the fat value from received bytes");
bodyFat = Converters.fromUnsignedInt16Be(weightBytes, 17) / 100.0f;
} else {
Timber.d("Calculate the fat value using the Yunmai lib");
bodyFat = yunmaiLib.getFat(scaleUser.getAge(), weight, resistance);
}
if (bodyFat != 0) {
scaleBtData.setFat(bodyFat);
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");
}
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);
}
addScaleMeasurement(scaleBtData);
}
Aggregations