mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-18 14:31:23 +02:00
Inlife: clamp values to valid range
This commit is contained in:
@@ -372,6 +372,16 @@ public abstract class BluetoothCommunication {
|
|||||||
return stringBuilder.substring(0, stringBuilder.length() - 1);
|
return stringBuilder.substring(0, stringBuilder.length() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected float clamp(double value, double min, double max) {
|
||||||
|
if (value < min) {
|
||||||
|
return (float)min;
|
||||||
|
}
|
||||||
|
if (value > max) {
|
||||||
|
return (float)max;
|
||||||
|
}
|
||||||
|
return (float)value;
|
||||||
|
}
|
||||||
|
|
||||||
protected byte xorChecksum(byte[] data, int offset, int length) {
|
protected byte xorChecksum(byte[] data, int offset, int length) {
|
||||||
byte checksum = 0;
|
byte checksum = 0;
|
||||||
for (int i = offset; i < offset + length; ++i) {
|
for (int i = offset; i < offset + length; ++i) {
|
||||||
|
@@ -221,12 +221,12 @@ public class BluetoothInlife extends BluetoothCommunication {
|
|||||||
|
|
||||||
ScaleMeasurement measurement = new ScaleMeasurement();
|
ScaleMeasurement measurement = new ScaleMeasurement();
|
||||||
measurement.setWeight(weight);
|
measurement.setWeight(weight);
|
||||||
measurement.setFat((float) fat);
|
measurement.setFat(clamp(fat, 5, 80));
|
||||||
measurement.setWater((float) water);
|
measurement.setWater(clamp(water, 5, 80));
|
||||||
measurement.setMuscle((float) muscle);
|
measurement.setMuscle(clamp(muscle, 5, 80));
|
||||||
measurement.setBone((float) bone);
|
measurement.setBone(clamp(bone, 0.5, 8));
|
||||||
measurement.setLbm(lbm);
|
measurement.setLbm(lbm);
|
||||||
measurement.setVisceralFat((float) visceral);
|
measurement.setVisceralFat(clamp(visceral, 1, 50));
|
||||||
|
|
||||||
addScaleData(measurement);
|
addScaleData(measurement);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user