1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-28 18:49:56 +02:00

Ignore duplicate weight measurements (1byone)

As reported in #159.
This commit is contained in:
Erik Johansson
2018-07-04 00:56:46 +02:00
parent e0331c54c0
commit a2543afe02

View File

@@ -37,6 +37,8 @@ public class BluetoothOneByone extends BluetoothCommunication {
private final UUID CMD_MEASUREMENT_CHARACTERISTIC = UUID.fromString("0000fff1-0000-1000-8000-00805f9b34fb"); // write only
private final UUID WEIGHT_MEASUREMENT_CONFIG = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
private float lastWeight;
public BluetoothOneByone(Context context) {
super(context);
}
@@ -50,6 +52,7 @@ public class BluetoothOneByone extends BluetoothCommunication {
protected boolean nextInitCmd(int stateNr) {
switch (stateNr) {
case 0:
lastWeight = 0;
setIndicationOn(WEIGHT_MEASUREMENT_SERVICE_BODY_COMPOSITION, WEIGHT_MEASUREMENT_CHARACTERISTIC_BODY_COMPOSITION, WEIGHT_MEASUREMENT_CONFIG);
break;
case 1:
@@ -104,10 +107,14 @@ public class BluetoothOneByone extends BluetoothCommunication {
Timber.d("weight: %.2f, impedance: %d", weight, impedance);
ScaleMeasurement scaleBtData = new ScaleMeasurement();
// This check should be a bit more elaborate, but it works for now...
if (weight != lastWeight) {
lastWeight = weight;
scaleBtData.setWeight(weight);
ScaleMeasurement scaleBtData = new ScaleMeasurement();
scaleBtData.setWeight(weight);
addScaleData(scaleBtData);
addScaleData(scaleBtData);
}
}
}