diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothExingtechY1.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothExingtechY1.java index d463e234..efe1aff5 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothExingtechY1.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothExingtechY1.java @@ -23,6 +23,7 @@ import android.content.Context; import com.health.openscale.core.OpenScale; import com.health.openscale.core.datatypes.ScaleMeasurement; import com.health.openscale.core.datatypes.ScaleUser; +import com.health.openscale.core.utils.Converters; import java.util.Date; import java.util.UUID; @@ -92,17 +93,17 @@ public class BluetoothExingtechY1 extends BluetoothCommunication { private void parseBytes(byte[] weightBytes) { int userId = weightBytes[0] & 0x0F; - int gender = (int)(weightBytes[1]); // 0x00 male; 0x01 female - int age = (int)(weightBytes[2]); // 10 ~ 99 - int height = (int)(weightBytes[3]); // 0 ~ 255 - float weight = (float) (((weightBytes[4] & 0xFF) << 8) | (weightBytes[5] & 0xFF)) / 10.0f; // kg - float fat = (float)(((weightBytes[6] & 0xFF) << 8) | (weightBytes[7] & 0xFF)) / 10.0f; // % - float water = (float)(((weightBytes[8] & 0xFF) << 8) | (weightBytes[9] & 0xFF)) / 10.0f; // % - float bone = (float)(((weightBytes[10] & 0xFF) << 8) | (weightBytes[11] & 0xFF)) / 10.0f; // kg - float muscle = (float)(((weightBytes[12] & 0xFF) << 8) | (weightBytes[13] & 0xFF)) / 10.0f; // % - float visc_muscle = (float)(weightBytes[14] & 0xFF); // % - float calorie = (float)(((weightBytes[15] & 0xFF) << 8) | (weightBytes[16] & 0xFF)); - float bmi = (float)(((weightBytes[17] & 0xFF) << 8) | (weightBytes[18] & 0xFF)) / 10.0f; + int gender = weightBytes[1] & 0xFF; // 0x00 male; 0x01 female + int age = weightBytes[2] & 0xFF; // 10 ~ 99 + int height = weightBytes[3] & 0xFF; // 0 ~ 255 + float weight = Converters.fromUnsignedInt16Be(weightBytes, 4) / 10.0f; // kg + float fat = Converters.fromUnsignedInt16Be(weightBytes, 6) / 10.0f; // % + float water = Converters.fromUnsignedInt16Be(weightBytes, 8) / 10.0f; // % + float bone = Converters.fromUnsignedInt16Be(weightBytes, 10) / 10.0f; // kg + float muscle = Converters.fromUnsignedInt16Be(weightBytes, 12) / 10.0f; // % + float visc_muscle = weightBytes[14] & 0xFF; // % + float calorie = Converters.fromUnsignedInt16Be(weightBytes, 15); + float bmi = Converters.fromUnsignedInt16Be(weightBytes, 17) / 10.0f; ScaleMeasurement scaleBtData = new ScaleMeasurement();