summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArseniy-Movshev <dodoradio@outlook.com>2023-05-30 23:54:35 +0100
committerArseniy-Movshev <dodoradio@outlook.com>2023-05-30 23:54:35 +0100
commit9b604475a0c55b59f6932d960a02241eece3c768 (patch)
tree3dca321bdbb7e4e1b2c547e3d147b1e24ecd8923
parentb6fbad69c827f26ae1f133236360a1285e8aa6c4 (diff)
Move overnight steps compensation code to the place where it's recorded
Diffstat (limited to '')
-rw-r--r--daemon/sensorPlugins/stepCounter.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/daemon/sensorPlugins/stepCounter.cpp b/daemon/sensorPlugins/stepCounter.cpp
index 35618f2..4db6662 100644
--- a/daemon/sensorPlugins/stepCounter.cpp
+++ b/daemon/sensorPlugins/stepCounter.cpp
@@ -51,23 +51,23 @@ StepCounterPlugin::StepCounterPlugin(QObject *parent, int initInterval) :
void StepCounterPlugin::timeUpdate() {
QDateTime currDateTime = QDateTime::currentDateTime();
- 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.
- }
uint elapsed = currDateTime.toMSecsSinceEpoch() - lastRecordTime.toMSecsSinceEpoch();
qDebug() << "time until next steps recording" << recordIntervalTimer->remainingTime() << " elapsed = " << elapsed << " lastRecordTime " << lastRecordTime.toMSecsSinceEpoch();
if (elapsed > interval) { //if too much time has passed, reset the timer and record
triggerRecording();
- lastRecordTime = QDateTime::currentDateTime();
} else { //otherwise, restart the timer and compensate for time spent in suspend
recordIntervalTimer->start(interval - elapsed);
}
}
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));
+ lastRecordTime = QDateTime::currentDateTime();
}