diff options
author | Arseniy-Movshev <dodoradio@outlook.com> | 2023-03-06 20:59:36 +0000 |
---|---|---|
committer | Arseniy-Movshev <dodoradio@outlook.com> | 2023-03-07 21:44:42 +0000 |
commit | 222f776d9f9d1f362038d26f835c96918a7af5fe (patch) | |
tree | e1c5b01753d52603bc9d8e5cb91c1cf3287a8ba9 /logger.cpp | |
parent | 31a0592f40ccbe0ed31abcd8bf39c2c00dab699a (diff) |
Refactor sensors into separate files
- this should make things a lot easier to maintain. instead of having everything in the same file, each sensor provides a constructor that sets it up correctly etc.
- this should also get the step counter running when the service starts, which is necessary, since the sensor won't count on most devices unless the service is running.
- this also temporarily removes the gps module from the service. it's not implemented right now anyway.
Diffstat (limited to '')
-rw-r--r-- | logger.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/logger.cpp b/logger.cpp new file mode 100644 index 0000000..74b3d59 --- /dev/null +++ b/logger.cpp @@ -0,0 +1,65 @@ +#include <QSettings> +#include <QDBusInterface> +#include <QDBusConnection> +#include <QDateTime> +#include <QFile> +#include <QTextStream> +#include <QTimer> +#include <QDebug> + +#include "logger.h" + +#include "sensorPlugins/stepCounter.h" +#include "sensorPlugins/heartrateSensor.h" + +Logger::Logger(QObject *parent) : + QObject(parent){ + m_iface = new QDBusInterface("com.nokia.mce","/com/nokia/mce/signal", "com.nokia.mce.signal", QDBusConnection::systemBus()); + QSettings settings; + +//intialise HRM + if (heartrateSensorEnabled) { //add check for HRM + m_heartrateSensor = new HeartrateSensorPlugin(this,settings.value("stepsInterval",600000).toInt()); + } + +//initialise step counter + if (stepCounterEnabled) { //add check for step sensor + m_stepCounter = new StepCounterPlugin(this,settings.value("stepsInterval",600000).toInt()); + } + + if(!m_iface->isValid()) { + qDebug() << "interface is not valid"; + qDebug() << m_iface->lastError(); + } + if(connect(m_iface, SIGNAL(display_status_ind(QString)), this, SLOT(displayOn(QString)))) { //this fires when the display turns on + qDebug() << "healthd connected display_status signal to slot"; + } + qDebug() << "healthd sensors logger initialised"; +} + +void Logger::displayOn(QString displayState) { + if (displayState == "off") + return; + qDebug() << "display on detected"; + uint currTime = QDateTime::currentMSecsSinceEpoch(); + + if (heartrateSensorEnabled) { + m_heartrateSensor->timeUpdate(); + } + + if (stepCounterEnabled) { + m_stepCounter->timeUpdate(); + } +} + +void writeReadingToFile(QString data, QString filename) { + QFile file(filename); + if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) { + qDebug() << "failed to open file"; + return; + } + file.seek(file.size()); + QTextStream out(&file); + out << data; + file.close(); +} |