From 640efc352c6540db9e00f4124b9eac611cfce2fe Mon Sep 17 00:00:00 2001 From: Arseniy-Movshev Date: Wed, 12 Jul 2023 12:31:33 +0100 Subject: Make sure we return a sane value even if sensor isn't warmed up it seems that the sensor takes a while to warm up, and until it does, it will return 0. This fixes a check that previously already existed, but was checking the wrong value - if the step offset causes step count to increase, we will be returning erroneous values. --- qmlplugin/stepsDataLoader.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'qmlplugin') diff --git a/qmlplugin/stepsDataLoader.cpp b/qmlplugin/stepsDataLoader.cpp index 50a0101..0dcc6ba 100644 --- a/qmlplugin/stepsDataLoader.cpp +++ b/qmlplugin/stepsDataLoader.cpp @@ -36,11 +36,11 @@ StepsDataLoader::StepsDataLoader() : QObject() int StepsDataLoader::getTodayTotal() { QSettings settings("asteroid", "sensorlogd"); - int total = m_stepcounterSensor->reading()->steps() - settings.value("StepCounterPrivate/stepsOffset", 0).toInt(); - if (total < 0) { + int steps = m_stepcounterSensor->reading()->steps(); + if (steps < 1) { return getTotalForDate(QDate::currentDate()); } - return total; + return steps - settings.value("StepCounterPrivate/stepsOffset", 0).toInt(); } int StepsDataLoader::getTotalForDate(QDate date) { // This is obvious garbage. This should really be abstracted and cached, so that every page doesn't have to reload the file from scratch. -- cgit v1.2.3-70-g09d2