From fd718937e22c22e716a951e2bb58ac1bc624f70e Mon Sep 17 00:00:00 2001 From: Arseniy-Movshev Date: Mon, 29 May 2023 16:30:31 +0100 Subject: Add a method for daemon recordings to be triggered from qml This allows the app to always show an up-to-date value --- daemon/logger.cpp | 10 ++++++++++ daemon/logger.h | 1 + qmlplugin/stepsDataLoader.cpp | 12 ++++++++++++ qmlplugin/stepsDataLoader.h | 4 ++++ 4 files changed, 27 insertions(+) diff --git a/daemon/logger.cpp b/daemon/logger.cpp index 984ae33..4488a03 100644 --- a/daemon/logger.cpp +++ b/daemon/logger.cpp @@ -78,6 +78,16 @@ void Logger::displayOn(QString displayState) { } } +void Logger::triggerRecording() { + if (heartrateSensorEnabled) { + m_heartrateSensor->triggerRecording(); + } + + if (stepCounterEnabled) { + m_stepCounter->triggerRecording(); + } +} + void fileAddRecord(QString sensorPrefix, QString logdata, QDateTime recordTime) { //adds a record to today's log file for the given sensor qDebug() << fileNameForDate(recordTime.date(), sensorPrefix); QFile file(fileNameForDate(recordTime.date(), sensorPrefix)); diff --git a/daemon/logger.h b/daemon/logger.h index 7bfe06b..515adb2 100644 --- a/daemon/logger.h +++ b/daemon/logger.h @@ -32,6 +32,7 @@ public: public slots: void setup(); void resetup(); + void triggerRecording(); private slots: void displayOn(QString displayState); diff --git a/qmlplugin/stepsDataLoader.cpp b/qmlplugin/stepsDataLoader.cpp index 0c084ea..199b324 100644 --- a/qmlplugin/stepsDataLoader.cpp +++ b/qmlplugin/stepsDataLoader.cpp @@ -14,11 +14,18 @@ #include #include #include +#include #include "stepsDataLoader.h" StepsDataLoader::StepsDataLoader() : QObject() { + m_iface = new QDBusInterface("org.asteroid.sensorlogd.logger","/org/asteroid/sensorlogd/logger","", QDBusConnection::sessionBus(), this); + if (!m_iface->isValid()) { + qDebug()<<"interface is not valid"; + } else { + qDebug()<<"interface is valid"; + } } int StepsDataLoader::getTodayData() { @@ -45,6 +52,11 @@ int StepsDataLoader::getDataForDate(QDate date) { // This is obvious garbage. Th return line.split(":")[1].toInt(); } +void StepsDataLoader::triggerDaemonRecording() { + m_iface->call("triggerRecording"); +} + + QString fileNameForDate(QDate date, QString prefix) { QSettings settings("asteroid","sensorlogd"); //this should be moved out of here at some point TODO return settings.value("loggerRootPath",QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.asteroid-sensorlogd/").toString() + prefix + "/" + date.toString("yyyy-MM-dd.log"); diff --git a/qmlplugin/stepsDataLoader.h b/qmlplugin/stepsDataLoader.h index 4937ee9..869b434 100644 --- a/qmlplugin/stepsDataLoader.h +++ b/qmlplugin/stepsDataLoader.h @@ -12,6 +12,7 @@ #define STEPSDATALOADER_H #include +#include class StepsDataLoader : public QObject { @@ -21,6 +22,9 @@ public: explicit StepsDataLoader(); Q_INVOKABLE int getDataForDate(QDate date); Q_INVOKABLE int getTodayData(); + Q_INVOKABLE void triggerDaemonRecording(); +private: + QDBusInterface *m_iface; }; QString fileNameForDate(QDate date, QString prefix); -- cgit v1.2.3-54-g00ecf