From 09b5e8d4333090a898f04f5976dce6e9e83cff88 Mon Sep 17 00:00:00 2001 From: Arseniy-Movshev Date: Tue, 30 May 2023 23:56:00 +0100 Subject: Clear the step counter in hardware after midnight The midnight detection code is basic, it just checks if the date has changed between days. So that the user doesn't lose steps on their midnight outings, we write the current value to the previous day's log file before wiping the counter. This will always be the previous day, even if recordings have been missing for a few days. --- daemon/sensorPlugins/stepCounter.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/daemon/sensorPlugins/stepCounter.cpp b/daemon/sensorPlugins/stepCounter.cpp index 4db6662..7d4a86f 100644 --- a/daemon/sensorPlugins/stepCounter.cpp +++ b/daemon/sensorPlugins/stepCounter.cpp @@ -9,6 +9,8 @@ */ #include +#include +#include #include #include #include @@ -61,13 +63,18 @@ void StepCounterPlugin::timeUpdate() { } void StepCounterPlugin::triggerRecording() { - if (lastRecordTime.date() < currDateTime.date()) { - stepsOffset = stepcounterSensor->reading()->steps(); //this 'resets' the reading whenever the screen is first turned on after midnight. this means that, in the morning, the step count will always be zero, but steps taken just before midnight are still counted and not discarded. - } qDebug() << "stepcounter interval recording"; - int steps = stepcounterSensor->reading()->steps(); - qDebug() << QDateTime::currentDateTime().toString("hh:mm:ss") << " : " << steps << stepcounterSensor->isActive(); - //we probably ought to do some error checking here - fileAddRecord(sensorPathPrefix,QString::number(steps - stepsOffset)); + if (lastRecordTime.date() < QDate::currentDate()) { + int steps = stepcounterSensor->reading()->steps(); + fileAddRecord(sensorPathPrefix,QString::number(steps - stepsOffset),QDateTime(QDate::currentDate().addDays(-1),QTime(23,59,59))); // this writes the current step count to the last second of the previous day + stepcounterSensor->reading()->setSteps(0); // and then we reset the step counter + stepsOffset = 0; // and, since the step counter has been reset, there's no need for an offset any more + qDebug() << "date change detected; recorded " << steps << " to previous day and reset step counter hw"; + } else { + int steps = stepcounterSensor->reading()->steps(); + qDebug() << QDateTime::currentDateTime().toString("hh:mm:ss") << " : " << steps << stepcounterSensor->isActive(); + //we probably ought to do some error checking here + fileAddRecord(sensorPathPrefix,QString::number(steps - stepsOffset)); + } lastRecordTime = QDateTime::currentDateTime(); } -- cgit v1.2.3-54-g00ecf