mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-18 14:31:23 +02:00
Use real values in scale set up #352
This commit is contained in:
@@ -34,6 +34,23 @@ public class BluetoothInlife extends BluetoothCommunication {
|
|||||||
private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0xfff1);
|
private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0xfff1);
|
||||||
private final UUID WEIGHT_CMD_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0xfff2);
|
private final UUID WEIGHT_CMD_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0xfff2);
|
||||||
|
|
||||||
|
private final byte START_BYTE = 0x02;
|
||||||
|
private final byte END_BYTE = (byte)0xaa;
|
||||||
|
|
||||||
|
private int getActivityLevel(ScaleUser scaleUser) {
|
||||||
|
switch (scaleUser.getActivityLevel()) {
|
||||||
|
case SEDENTARY:
|
||||||
|
case MILD:
|
||||||
|
break;
|
||||||
|
case MODERATE:
|
||||||
|
case HEAVY:
|
||||||
|
return 1;
|
||||||
|
case EXTREME:
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
public BluetoothInlife(Context context) {
|
public BluetoothInlife(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
@@ -51,14 +68,15 @@ public class BluetoothInlife extends BluetoothCommunication {
|
|||||||
BluetoothGattUuid.DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION);
|
BluetoothGattUuid.DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
byte level = 1;
|
ScaleUser scaleUser = OpenScale.getInstance().getSelectedScaleUser();
|
||||||
byte sex = 0; // Male, 1 = female
|
byte level = (byte)(getActivityLevel(scaleUser) + 1);
|
||||||
byte userId = 0;
|
byte sex = (byte)scaleUser.getGender().toInt();
|
||||||
byte age = 30;
|
byte userId = (byte)scaleUser.getId();
|
||||||
byte height = (byte)156;
|
byte age = (byte)scaleUser.getAge();
|
||||||
byte[] data = {(byte)0x02, (byte)0xd2, level, sex, userId, age, height,
|
byte height = (byte)scaleUser.getBodyHeight();
|
||||||
0, 0, 0, 0, 0, 0, (byte)0xaa};
|
byte[] data = {START_BYTE, (byte)0xd2, level, sex, userId, age, height,
|
||||||
data[data.length - 2] = xorChecksum(data, 1, 6);
|
0, 0, 0, 0, 0, 0, END_BYTE};
|
||||||
|
data[data.length - 2] = xorChecksum(data, 1, data.length - 3);
|
||||||
|
|
||||||
writeBytes(WEIGHT_SERVICE, WEIGHT_CMD_CHARACTERISTIC, data);
|
writeBytes(WEIGHT_SERVICE, WEIGHT_CMD_CHARACTERISTIC, data);
|
||||||
break;
|
break;
|
||||||
@@ -87,29 +105,38 @@ public class BluetoothInlife extends BluetoothCommunication {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data[0] != (byte)0x02 || data[data.length - 1] != (byte)0xaa) {
|
if (data[0] != START_BYTE || data[data.length - 1] != END_BYTE) {
|
||||||
Timber.d("Wrong start or end byte");
|
Timber.d("Wrong start or end byte");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data[1] != (byte)0xdd) {
|
if (xorChecksum(data, 1, data.length - 2) != 0) {
|
||||||
Timber.d("Measurement not done yet");
|
Timber.d("Invalid checksum");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
float weight = Converters.fromUnsignedInt16Be(data, 2) / 10.0f;
|
float weight = Converters.fromUnsignedInt16Be(data, 2) / 10.0f;
|
||||||
|
|
||||||
|
if (data[1] == (byte)0xd8) {
|
||||||
|
Timber.d("Current weight %.2f kg", weight);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data[1] != (byte)0xdd) {
|
||||||
|
Timber.d("Unknown command 0x%02x", data[1]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
float lbm = Converters.fromUnsignedInt24Be(data, 4) / 1000.0f;
|
float lbm = Converters.fromUnsignedInt24Be(data, 4) / 1000.0f;
|
||||||
|
|
||||||
final ScaleUser selectedUser = OpenScale.getInstance().getSelectedScaleUser();
|
final ScaleUser selectedUser = OpenScale.getInstance().getSelectedScaleUser();
|
||||||
switch (selectedUser.getActivityLevel()) {
|
switch (getActivityLevel(selectedUser)) {
|
||||||
case SEDENTARY:
|
case 0:
|
||||||
case MILD:
|
|
||||||
break;
|
break;
|
||||||
case MODERATE:
|
case 1:
|
||||||
lbm *= 1.0427f;
|
lbm *= 1.0427f;
|
||||||
break;
|
break;
|
||||||
case HEAVY:
|
case 2:
|
||||||
case EXTREME:
|
|
||||||
lbm *= 1.0958f;
|
lbm *= 1.0958f;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -128,5 +155,9 @@ public class BluetoothInlife extends BluetoothCommunication {
|
|||||||
measurement.setBone(bone);
|
measurement.setBone(bone);
|
||||||
|
|
||||||
addScaleData(measurement);
|
addScaleData(measurement);
|
||||||
|
|
||||||
|
byte[] done = {START_BYTE, (byte)0xd4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, END_BYTE};
|
||||||
|
done[done.length - 2] = xorChecksum(done, 1, done.length - 3);
|
||||||
|
writeBytes(WEIGHT_SERVICE, WEIGHT_CMD_CHARACTERISTIC, done);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user