Bugfix: Cycling Cadence and Distance sensor allow for repeated data.

Fixes #1790.
This commit is contained in:
Dennis Guse
2024-01-01 14:38:59 +01:00
parent 8c9e3882c7
commit 0584f05ddc
2 changed files with 11 additions and 3 deletions
@@ -23,7 +23,11 @@ public class AggregatorCyclingCadence extends Aggregator<BluetoothHandlerCycling
if (previous != null) {
float timeDiff_ms = UintUtils.diff(current.value().crankRevolutionsTime(), previous.value().crankRevolutionsTime(), UintUtils.UINT16_MAX) / 1024f * 1000;
Duration timeDiff = Duration.ofMillis((long) timeDiff_ms);
if (timeDiff.isZero() || timeDiff.isNegative()) {
if (timeDiff.isZero()) {
return;
}
if (timeDiff.isNegative()) {
Log.e(TAG, "Timestamps difference is invalid: cannot compute cadence.");
value = null;
return;
@@ -26,8 +26,12 @@ public class AggregatorCyclingDistanceSpeed extends Aggregator<BluetoothHandlerC
if (previous != null) {
float timeDiff_ms = UintUtils.diff(current.value().wheelRevolutionsTime(), previous.value().wheelRevolutionsTime(), UintUtils.UINT16_MAX) / 1024f * 1000;
Duration timeDiff = Duration.ofMillis((long) timeDiff_ms);
if (timeDiff.isZero() || timeDiff.isNegative()) {
Log.e(TAG, "Timestamps difference is invalid: cannot compute speed.");
if (timeDiff.isZero()) {
return;
}
if (timeDiff.isNegative()) {
Log.e(TAG, "Timestamps difference is invalid: cannot compute cadence.");
value = null;
return;
}