From a2543afe0214b1594028f4cac8d4ed203aecf30c Mon Sep 17 00:00:00 2001 From: Erik Johansson Date: Wed, 4 Jul 2018 00:56:46 +0200 Subject: [PATCH] Ignore duplicate weight measurements (1byone) As reported in #159. --- .../openscale/core/bluetooth/BluetoothOneByone.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothOneByone.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothOneByone.java index bf85e6c2..55215fae 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothOneByone.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothOneByone.java @@ -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); + } } }