diff options
author | Arseniy-Movshev <dodoradio@outlook.com> | 2023-05-30 23:56:00 +0100 |
---|---|---|
committer | Arseniy-Movshev <dodoradio@outlook.com> | 2023-05-31 00:39:08 +0100 |
commit | 09b5e8d4333090a898f04f5976dce6e9e83cff88 (patch) | |
tree | 280f521d54e34966a2972f8f4f18abaaaa54f1ce | |
parent | 9b604475a0c55b59f6932d960a02241eece3c768 (diff) |
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.
-rw-r--r-- | daemon/sensorPlugins/stepCounter.cpp | 21 |
1 files 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 <QDateTime> +#include <QDate> +#include <QTime> #include <QTimer> #include <QtSensors/QStepCounterSensor> #include <QDebug> @@ -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(); } |