forked from upstream-mirrors/OpenTracks
Heartrate: ignore "0" if sent from sensor as this is an invalid value.
On import "0" is ignored.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package de.dennisguse.opentracks.sensors.driver;
|
||||
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
@@ -13,6 +14,8 @@ import de.dennisguse.opentracks.sensors.ServiceMeasurementUUID;
|
||||
|
||||
public class HeartRateBluetooth implements BluetoothDriver.BluetoothParser<HeartRate> {
|
||||
|
||||
private static final String TAG = BluetoothHandlerManagerHeartRate.class.getSimpleName();
|
||||
|
||||
public static final ServiceMeasurementUUID HEARTRATE = new ServiceMeasurementUUID(
|
||||
new UUID(0x180D00001000L, 0x800000805f9b34fbL),
|
||||
new UUID(0x2A3700001000L, 0x800000805f9b34fbL)
|
||||
@@ -35,7 +38,16 @@ public class HeartRateBluetooth implements BluetoothDriver.BluetoothParser<Heart
|
||||
|
||||
@Override
|
||||
public HeartRate parsePayload(@NonNull ServiceMeasurementUUID serviceMeasurementUUID, String sensorName, BluetoothGattCharacteristic characteristic) {
|
||||
return parseHeartRate(characteristic);
|
||||
HeartRate heartRate = parseHeartRate(characteristic);
|
||||
|
||||
if (heartRate == null) return null;
|
||||
|
||||
if (heartRate.value() == 0.0) {
|
||||
Log.d(TAG, "Invalid heartrate received. Ignoring.");
|
||||
return null;
|
||||
}
|
||||
|
||||
return heartRate;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
||||
@@ -10,8 +10,6 @@ public class AggregatorHeartRate extends Aggregator<HeartRate, HeartRate> {
|
||||
|
||||
@Override
|
||||
protected void computeValue(Raw<HeartRate> current) {
|
||||
if (current.value().isValid()) {
|
||||
this.output = current.value();
|
||||
}
|
||||
this.output = current.value();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user