summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--daemon/sensorPlugins/stepCounter.cpp17
-rw-r--r--daemon/sensorPlugins/stepCounter.h1
2 files changed, 5 insertions, 13 deletions
diff --git a/daemon/sensorPlugins/stepCounter.cpp b/daemon/sensorPlugins/stepCounter.cpp
index 7d4a86f..3df23c7 100644
--- a/daemon/sensorPlugins/stepCounter.cpp
+++ b/daemon/sensorPlugins/stepCounter.cpp
@@ -15,6 +15,7 @@
#include <QtSensors/QStepCounterSensor>
#include <QDebug>
#include <QString>
+#include <time.h>
#include "../logger.h"
@@ -36,18 +37,11 @@ StepCounterPlugin::StepCounterPlugin(QObject *parent, int initInterval) :
QDateTime currDateTime = QDateTime::currentDateTime();
setupFilePath(sensorPathPrefix);
+ while (!stepcounterSensor->isActive()) {}
if (dayFileExists(sensorPathPrefix)) {
QStringList lastLineData = fileGetPrevRecord(sensorPathPrefix);
- lastRecordTime = QDateTime::fromSecsSinceEpoch(lastLineData[0].toInt());
- if (stepcounterSensor->reading()->steps() == 0) {
- stepsOffset = -(lastLineData[1].toInt());
- } else {
- stepsOffset = - stepcounterSensor->reading()->steps() + (lastLineData[1].toInt());
- }
- } else {
- //if it's a new day, we 'reset' the counter. this is crude - we should really check for a boot here, since certain machines have capability of counting steps when powered down.
- stepsOffset = stepcounterSensor->reading()->steps();
+ stepcounterSensor->reading()->setSteps(lastLineData[1].toInt() + stepcounterSensor->reading()->steps()); // we add the last recorded value from today to the current value. This 'recovers' the steps from between reboots. I'm not sure how this will work on catfish or medaka.
}
}
@@ -66,15 +60,14 @@ void StepCounterPlugin::triggerRecording() {
qDebug() << "stepcounter interval recording";
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
+ fileAddRecord(sensorPathPrefix,QString::number(steps),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));
+ fileAddRecord(sensorPathPrefix,QString::number(steps));
}
lastRecordTime = QDateTime::currentDateTime();
}
diff --git a/daemon/sensorPlugins/stepCounter.h b/daemon/sensorPlugins/stepCounter.h
index a221561..27dc01e 100644
--- a/daemon/sensorPlugins/stepCounter.h
+++ b/daemon/sensorPlugins/stepCounter.h
@@ -35,7 +35,6 @@ private:
int interval;
QTimer *recordIntervalTimer;
QStepCounterSensor *stepcounterSensor;
- int stepsOffset; //this is subtracted from the raw sensor value to compensate for daily step resets and boot offsets.
const QString sensorPathPrefix = "stepCounter";
};