diff options
author | Arseniy-Movshev <dodoradio@outlook.com> | 2023-03-19 11:14:04 +0000 |
---|---|---|
committer | Arseniy-Movshev <dodoradio@outlook.com> | 2023-05-26 00:32:20 +0100 |
commit | ec42177b24b47ba68b3ae49634c942c76a9f92d4 (patch) | |
tree | b0b85601ef46f4e0bd8bb94f81eb89faaf8da5f1 /sensorPlugins | |
parent | bfe0c3f7a03c53cff7a4050a42f14eaa210364f8 (diff) |
Restructure to split to daemon and qml accessor
- add separate subdirs for daemon and qml
- add some generic qml boilerplate
- add a really lazy 'last value' loader implementation
- license the project as gplv3 (add copyright notices and license text)
Diffstat (limited to 'sensorPlugins')
-rw-r--r-- | sensorPlugins/heartrateSensor.cpp | 53 | ||||
-rw-r--r-- | sensorPlugins/heartrateSensor.h | 35 | ||||
-rw-r--r-- | sensorPlugins/stepCounter.cpp | 61 | ||||
-rw-r--r-- | sensorPlugins/stepCounter.h | 33 |
4 files changed, 0 insertions, 182 deletions
diff --git a/sensorPlugins/heartrateSensor.cpp b/sensorPlugins/heartrateSensor.cpp deleted file mode 100644 index 3477e9a..0000000 --- a/sensorPlugins/heartrateSensor.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include <QDateTime> -#include <QTimer> -#include <QtSensors/QHrmSensor> -#include <QDebug> -#include <QString> - -#include "../logger.h" - -#include "heartrateSensor.h" - -HeartrateSensorPlugin::HeartrateSensorPlugin(QObject *parent, int initInterval) : - QObject(parent){ - interval = initInterval; - - hrmSensor = new QHrmSensor(this); - connect(hrmSensor,SIGNAL(readingChanged()),this,SLOT(finishRecording())); - - qDebug() << "heartrate sensor is enabled. interval is (ms) " << interval; - recordIntervalTimer = new QTimer(this); - connect(recordIntervalTimer,SIGNAL(timeout()),this,SLOT(triggerRecording())); - recordIntervalTimer->setSingleShot(true); - recordIntervalTimer->start(interval); - lastRecordTime = QDateTime::currentDateTime(); -} - -void HeartrateSensorPlugin::timeUpdate() { - uint elapsed = QDateTime::currentMSecsSinceEpoch() - 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 HeartrateSensorPlugin::triggerRecording() { - qDebug() << "heartrate interval recording"; - recordIntervalTimer->start(interval); - hrmSensor->start(); -} - -void HeartrateSensorPlugin::finishRecording() { - qDebug() << "bpm update received"; - int bpm = hrmSensor->reading()->bpm(); - qDebug() << QDateTime::currentDateTime().toString("hh:mm:ss") << " : " << bpm << hrmSensor->status() << hrmSensor->isActive(); - if ((bpm == 0) || (hrmSensor->status() < 3)) { - qDebug() << "hrm sensor accuracy insufficient. waiting."; - return; - } - fileAddRecord(sensorPathPrefix,QString::number(bpm)); - hrmSensor->stop(); -} diff --git a/sensorPlugins/heartrateSensor.h b/sensorPlugins/heartrateSensor.h deleted file mode 100644 index 13c1b9d..0000000 --- a/sensorPlugins/heartrateSensor.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef HEARTRATESENSOR_H -#define HEARTRATESENSOR_H - -#include <QObject> -#include <QDateTime> -#include <QDBusInterface> -#include <QTimer> - -#include <QtSensors/QHrmSensor> - -class HeartrateSensorPlugin : public QObject -{ - Q_OBJECT -public: - explicit HeartrateSensorPlugin(QObject *parent = 0, int initInterval = 600000); - virtual ~HeartrateSensorPlugin() {}; - - void timeUpdate(); - -public slots: - void triggerRecording(); - -private slots: - void finishRecording(); - -private: - QDateTime lastRecordTime; - int interval; - QTimer *recordIntervalTimer; - QHrmSensor *hrmSensor; - - const QString sensorPathPrefix = "heartrateMonitor"; -}; - -#endif // HEARTRATESENSOR_H diff --git a/sensorPlugins/stepCounter.cpp b/sensorPlugins/stepCounter.cpp deleted file mode 100644 index 1d1fb7a..0000000 --- a/sensorPlugins/stepCounter.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include <QDateTime> -#include <QTimer> -#include <QtSensors/QStepCounterSensor> -#include <QDebug> -#include <QString> - -#include "../logger.h" - -#include "stepCounter.h" - -StepCounterPlugin::StepCounterPlugin(QObject *parent, int initInterval) : - QObject(parent){ - interval = initInterval; - - stepcounterSensor = new QStepCounterSensor(this); - stepcounterSensor->start(); - - qDebug() << "step counter sensor is enabled. interval is (ms) " << interval; - recordIntervalTimer = new QTimer(this); - connect(recordIntervalTimer,SIGNAL(timeout()),this,SLOT(triggerRecording())); - recordIntervalTimer->setSingleShot(true); - recordIntervalTimer->start(interval); - - QDateTime currDateTime = QDateTime::currentDateTime(); - - if (dayFileExists(sensorPathPrefix)) { - QStringList lastLineData = fileGetPrevRecord(sensorPathPrefix); - lastRecordTime = QDateTime::fromSecsSinceEpoch(lastLineData[0].toInt()); - if (stepcounterSensor->reading()->steps() == 0) { - stepsOffset = -(lastLineData[1].toInt()); - } else { - - } - } 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(); - } -} - -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() { - 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)); -} diff --git a/sensorPlugins/stepCounter.h b/sensorPlugins/stepCounter.h deleted file mode 100644 index a7cb580..0000000 --- a/sensorPlugins/stepCounter.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef STEPCOUNTER_H -#define STEPCOUNTER_H - -#include <QObject> -#include <QDateTime> -#include <QDBusInterface> -#include <QTimer> - -#include <QtSensors/QStepCounterSensor> - -class StepCounterPlugin : public QObject -{ - Q_OBJECT -public: - explicit StepCounterPlugin(QObject *parent = 0, int initInterval = 600000); - virtual ~StepCounterPlugin() {}; - - void timeUpdate(); - -public slots: - void triggerRecording(); - -private: - QDateTime lastRecordTime; - 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"; -}; - -#endif // STEPCOUNTER_H |