summaryrefslogtreecommitdiff
path: root/sensorPlugins/heartrateSensor.cpp
diff options
context:
space:
mode:
authorArseniy-Movshev <dodoradio@outlook.com>2023-03-19 11:14:04 +0000
committerArseniy-Movshev <dodoradio@outlook.com>2023-05-26 00:32:20 +0100
commitec42177b24b47ba68b3ae49634c942c76a9f92d4 (patch)
treeb0b85601ef46f4e0bd8bb94f81eb89faaf8da5f1 /sensorPlugins/heartrateSensor.cpp
parentbfe0c3f7a03c53cff7a4050a42f14eaa210364f8 (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/heartrateSensor.cpp')
-rw-r--r--sensorPlugins/heartrateSensor.cpp53
1 files changed, 0 insertions, 53 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();
-}