mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-22 00:06:48 +02:00
Use help function for converting from bytes to int
This commit is contained in:
@@ -23,6 +23,7 @@ import android.content.Context;
|
|||||||
import com.health.openscale.core.OpenScale;
|
import com.health.openscale.core.OpenScale;
|
||||||
import com.health.openscale.core.datatypes.ScaleMeasurement;
|
import com.health.openscale.core.datatypes.ScaleMeasurement;
|
||||||
import com.health.openscale.core.datatypes.ScaleUser;
|
import com.health.openscale.core.datatypes.ScaleUser;
|
||||||
|
import com.health.openscale.core.utils.Converters;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@@ -92,17 +93,17 @@ public class BluetoothExingtechY1 extends BluetoothCommunication {
|
|||||||
|
|
||||||
private void parseBytes(byte[] weightBytes) {
|
private void parseBytes(byte[] weightBytes) {
|
||||||
int userId = weightBytes[0] & 0x0F;
|
int userId = weightBytes[0] & 0x0F;
|
||||||
int gender = (int)(weightBytes[1]); // 0x00 male; 0x01 female
|
int gender = weightBytes[1] & 0xFF; // 0x00 male; 0x01 female
|
||||||
int age = (int)(weightBytes[2]); // 10 ~ 99
|
int age = weightBytes[2] & 0xFF; // 10 ~ 99
|
||||||
int height = (int)(weightBytes[3]); // 0 ~ 255
|
int height = weightBytes[3] & 0xFF; // 0 ~ 255
|
||||||
float weight = (float) (((weightBytes[4] & 0xFF) << 8) | (weightBytes[5] & 0xFF)) / 10.0f; // kg
|
float weight = Converters.fromUnsignedInt16Be(weightBytes, 4) / 10.0f; // kg
|
||||||
float fat = (float)(((weightBytes[6] & 0xFF) << 8) | (weightBytes[7] & 0xFF)) / 10.0f; // %
|
float fat = Converters.fromUnsignedInt16Be(weightBytes, 6) / 10.0f; // %
|
||||||
float water = (float)(((weightBytes[8] & 0xFF) << 8) | (weightBytes[9] & 0xFF)) / 10.0f; // %
|
float water = Converters.fromUnsignedInt16Be(weightBytes, 8) / 10.0f; // %
|
||||||
float bone = (float)(((weightBytes[10] & 0xFF) << 8) | (weightBytes[11] & 0xFF)) / 10.0f; // kg
|
float bone = Converters.fromUnsignedInt16Be(weightBytes, 10) / 10.0f; // kg
|
||||||
float muscle = (float)(((weightBytes[12] & 0xFF) << 8) | (weightBytes[13] & 0xFF)) / 10.0f; // %
|
float muscle = Converters.fromUnsignedInt16Be(weightBytes, 12) / 10.0f; // %
|
||||||
float visc_muscle = (float)(weightBytes[14] & 0xFF); // %
|
float visc_muscle = weightBytes[14] & 0xFF; // %
|
||||||
float calorie = (float)(((weightBytes[15] & 0xFF) << 8) | (weightBytes[16] & 0xFF));
|
float calorie = Converters.fromUnsignedInt16Be(weightBytes, 15);
|
||||||
float bmi = (float)(((weightBytes[17] & 0xFF) << 8) | (weightBytes[18] & 0xFF)) / 10.0f;
|
float bmi = Converters.fromUnsignedInt16Be(weightBytes, 17) / 10.0f;
|
||||||
|
|
||||||
ScaleMeasurement scaleBtData = new ScaleMeasurement();
|
ScaleMeasurement scaleBtData = new ScaleMeasurement();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user