diff options
author | Arseniy-Movshev <dodoradio@outlook.com> | 2022-11-12 21:24:52 +0000 |
---|---|---|
committer | Arseniy-Movshev <dodoradio@outlook.com> | 2022-11-12 22:14:34 +0000 |
commit | ba534a200056c44fca6ec129867cec27fccc6f7e (patch) | |
tree | 7e86e4ca9bb5564ea467ab3c42733fd44bdbd47b | |
parent | 287b52dd0e339574e11b05a5f6cbcf99e4d1dc93 (diff) |
Add a connection between sensor start and recording
Diffstat (limited to '')
-rw-r--r-- | sensors.cpp | 38 | ||||
-rw-r--r-- | sensors.h | 9 |
2 files changed, 35 insertions, 12 deletions
diff --git a/sensors.cpp b/sensors.cpp index d670ad7..df87122 100644 --- a/sensors.cpp +++ b/sensors.cpp @@ -17,9 +17,13 @@ Logger::Logger(QObject *parent) : QSettings settings; if (true) { //add check for HRM hrmInterval = settings.value("hrmInterval",60000).toInt(); + + heartrateSensor = new QHrmSensor(this); + connect(heartrateSensor,SIGNAL(readingChanged()),this,SLOT(recordHeartrate())); + qDebug() << "heartrate sensor is enabled. interval is (ms) " << hrmInterval; hrmTimer = new QTimer(this); - connect(hrmTimer,SIGNAL(timeout()),this,SLOT(recordHeartrate())); + connect(hrmTimer,SIGNAL(timeout()),this,SLOT(setupRecordHeartrate())); hrmTimer->setSingleShot(true); hrmTimer->start(hrmInterval); hrmLastTime = QDateTime::currentDateTime(); @@ -70,27 +74,32 @@ void Logger::displayOn(QString displayState) { } } -void Logger::recordHeartrate() { +void Logger::setupRecordHeartrate() { qDebug() << "heartrate interval recording"; hrmTimer->start(hrmInterval); - QHrmSensor* heartrateSensor = new QHrmSensor(this); + heartrateSensor->start(); +} + +void Logger::recordHeartrate() { + int bpm = heartrateSensor->reading()->bpm(); + qDebug() << QDateTime::currentDateTime().toString("hh:mm:ss") << " : " << bpm << heartrateSensor->status() << heartrateSensor->isActive(); + if ((bpm == 0) || (heartrateSensor->status() < 3)) { + return; + } QFile file("out.txt"); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { qDebug() << "failed to open file"; return; } - heartrateSensor->start(); QTextStream out(&file); - while(heartrateSensor->reading()->bpm() == 0) { - qDebug() << "waiting for reading, currently " << heartrateSensor->reading()->bpm() << heartrateSensor->status() << heartrateSensor->isActive(); - } - qDebug() << QDateTime::currentDateTime().toString("hh:mm:ss") << " : " << heartrateSensor->reading()->bpm() << heartrateSensor->status() << heartrateSensor->isActive(); - out << QDateTime::currentSecsSinceEpoch() << " : " << heartrateSensor->reading(); //reading() like this doesn't do anything useful. We need to wait for sensor to initialise and feed us back a reading + while(!out.atEnd()){} + out << QDateTime::currentSecsSinceEpoch() << " : " << bpm; + qDebug() << "wrote to file"; heartrateSensor->stop(); file.close(); } -void Logger::recordGPS() { +void Logger::setupRecordGPS() { QTimer::singleShot(hrmInterval, this, SLOT(recordHeartrate())); QHrmSensor* heartrateSensor = new QHrmSensor(this); //ok GPS doesn't work like this, this gonna need a custom solution. QtLocation to the rescue, or something :/ QFile file("out.txt"); @@ -108,10 +117,12 @@ void Logger::recordGPS() { //save to file } -void Logger::recordStepcounter() { +void Logger::recordGPS() { +} + +void Logger::setupRecordStepcounter() { qDebug() << "stepcounter interval recording"; hrmTimer->start(hrmInterval); - QStepCounterSensor* stepcounterSensor = new QStepCounterSensor(this); QFile file("out.txt"); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { qDebug() << "failed to open file"; @@ -127,3 +138,6 @@ void Logger::recordStepcounter() { stepcounterSensor->stop(); file.close(); } + +void Logger::recordStepcounter() { +} @@ -6,6 +6,9 @@ #include <QDBusInterface> #include <QTimer> +#include <QtSensors/QStepCounterSensor> +#include <QtSensors/QHrmSensor> + class Logger : public QObject { Q_OBJECT @@ -17,6 +20,10 @@ private slots: void recordHeartrate(); void recordGPS(); void recordStepcounter(); + + void setupRecordHeartrate(); + void setupRecordGPS(); + void setupRecordStepcounter(); private: QDateTime hrmLastTime; QDateTime stepsLastTime; @@ -27,6 +34,8 @@ private: QTimer *hrmTimer; QTimer *gpsTimer; QTimer *stepsTimer; + QHrmSensor *heartrateSensor ; + QStepCounterSensor *stepcounterSensor; }; #endif // LOGGER_H |