summaryrefslogtreecommitdiff
path: root/daemon/sensorPlugins
diff options
context:
space:
mode:
authorArseniy-Movshev <dodoradio@outlook.com>2023-06-07 14:06:18 +0100
committerArseniy-Movshev <dodoradio@outlook.com>2023-06-11 10:17:45 +0100
commit2a1363a223cd8a59f08609c18022d09bda5d66df (patch)
tree0ae16615b214c443e81e552df5f76c99f9aeb481 /daemon/sensorPlugins
parent6e92b73b935fced594ffe5dc7545639225c99b06 (diff)
StepCounter: revert to an offsets model
It seems that the step counter doesn't actually allow setting the steps value. While setSteps() will cause the reading to change, the step counter may reset back to the previous step count when more steps are taken.
Diffstat (limited to 'daemon/sensorPlugins')
-rw-r--r--daemon/sensorPlugins/stepCounter.cpp15
-rw-r--r--daemon/sensorPlugins/stepCounter.h8
2 files changed, 14 insertions, 9 deletions
diff --git a/daemon/sensorPlugins/stepCounter.cpp b/daemon/sensorPlugins/stepCounter.cpp
index a01c0b9..00d7066 100644
--- a/daemon/sensorPlugins/stepCounter.cpp
+++ b/daemon/sensorPlugins/stepCounter.cpp
@@ -15,6 +15,7 @@
#include <QTime>
#include <QTimer>
#include <QtSensors/QStepCounterSensor>
+#include <QSettings>
#include <time.h>
#include "../logger.h"
@@ -38,14 +39,15 @@ StepCounterPlugin::StepCounterPlugin(QObject* parent, int initInterval, bool dae
setupFilePath(sensorPathPrefix);
while (!stepcounterSensor->isActive()) { }
+ m_settings = new QSettings("asteroid", "sensorlogd");
if (dayFileExists(sensorPathPrefix) && daemonFresh) {
QStringList lastLineData = fileGetPrevRecord(sensorPathPrefix);
lastRecordTime = QDateTime::currentDateTime();
- 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.
-
+ m_stepsOffset = -lastLineData[1].toInt(); // 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.
} else if (dayFileExists) {
lastRecordTime = QDateTime::currentDateTime();
+ m_stepsOffset = m_settings->value("StepCounterPrivate/stepsOffset", 0).toInt();
}
}
@@ -65,12 +67,13 @@ void StepCounterPlugin::triggerRecording()
{
qDebug() << "stepcounter interval recording";
if (lastRecordTime.date() < QDate::currentDate()) {
- int steps = stepcounterSensor->reading()->steps();
+ int steps = stepcounterSensor->reading()->steps() - m_stepsOffset;
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
- qDebug() << "date change detected; recorded " << steps << " to previous day and reset step counter hw. Step counter now holds " << stepcounterSensor->reading()->steps() << " steps";
+ m_stepsOffset = stepcounterSensor->reading()->steps(); // and then we reset the step counter
+ m_settings->setValue("StepCounterPrivate/stepsOffset", m_stepsOffset);
+ qDebug() << "date change detected; recorded " << steps << " to previous day and reset step counter hw.";
} else {
- int steps = stepcounterSensor->reading()->steps();
+ int steps = stepcounterSensor->reading()->steps() - m_stepsOffset;
qDebug() << QDateTime::currentDateTime().toString("hh:mm:ss") << " : " << steps << stepcounterSensor->isActive();
// we probably ought to do some error checking here
fileAddRecord(sensorPathPrefix, QString::number(steps));
diff --git a/daemon/sensorPlugins/stepCounter.h b/daemon/sensorPlugins/stepCounter.h
index a6475f5..cb6a7e4 100644
--- a/daemon/sensorPlugins/stepCounter.h
+++ b/daemon/sensorPlugins/stepCounter.h
@@ -15,14 +15,14 @@
#include <QDateTime>
#include <QDBusInterface>
#include <QTimer>
+#include <QSettings>
#include <QtSensors/QStepCounterSensor>
-class StepCounterPlugin : public QObject
-{
+class StepCounterPlugin : public QObject {
Q_OBJECT
public:
- explicit StepCounterPlugin(QObject *parent = 0, int initInterval = 600000, bool daemonFresh = false);
+ explicit StepCounterPlugin(QObject* parent = 0, int initInterval = 600000, bool daemonFresh = false);
virtual ~StepCounterPlugin() {};
void timeUpdate();
@@ -35,6 +35,8 @@ private:
int interval;
QTimer *recordIntervalTimer;
QStepCounterSensor *stepcounterSensor;
+ int m_stepsOffset;
+ QSettings *m_settings;
const QString sensorPathPrefix = "stepCounter";
};