Bugfix: running sensor's data should be null if not connected.

Fixes #950.
This commit is contained in:
Dennis Guse
2021-09-30 22:38:53 +02:00
parent 847be686ea
commit d76d5673a8
@@ -57,22 +57,24 @@ public final class SensorDataRunning extends SensorData<SensorDataRunning.Data>
@Override @Override
protected Data getNoneValue() { protected Data getNoneValue() {
if (value != null) { if (value != null) {
return new Data(Speed.zero(), 0f, ((Data) value).distance); return new Data(Speed.zero(), 0f, value.distance);
} else { } else {
return new Data(Speed.zero(), 0f, Distance.of(0)); return new Data(Speed.zero(), 0f, Distance.of(0));
} }
} }
public void compute(SensorDataRunning previous) { public void compute(SensorDataRunning previous) {
Distance overallDistance = null; if (speed != null && hasTotalDistance()) {
if (hasTotalDistance() && previous != null && previous.hasTotalDistance()) { Distance overallDistance = null;
overallDistance = this.totalDistance.minus(previous.totalDistance); if (previous != null && previous.hasTotalDistance()) {
if (previous.hasValue() && previous.getValue().getDistance() != null) { overallDistance = this.totalDistance.minus(previous.totalDistance);
overallDistance = overallDistance.plus(previous.getValue().getDistance()); if (previous.hasValue() && previous.getValue().getDistance() != null) {
overallDistance = overallDistance.plus(previous.getValue().getDistance());
}
} }
}
value = new Data(speed, cadence, overallDistance); value = new Data(speed, cadence, overallDistance);
}
} }
@Override @Override