summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--daemon/CMakeLists.txt2
-rw-r--r--daemon/logger.cpp15
-rw-r--r--daemon/logger.h3
-rw-r--r--daemon/sensorPlugins/barometerSensor.cpp67
-rw-r--r--daemon/sensorPlugins/barometerSensor.h46
5 files changed, 133 insertions, 0 deletions
diff --git a/daemon/CMakeLists.txt b/daemon/CMakeLists.txt
index 996f9f8..9093b33 100644
--- a/daemon/CMakeLists.txt
+++ b/daemon/CMakeLists.txt
@@ -6,6 +6,8 @@ add_executable(sensorlogd
sensorPlugins/stepCounter.h
sensorPlugins/heartrateSensor.cpp
sensorPlugins/heartrateSensor.h
+ sensorPlugins/barometerSensor.cpp
+ sensorPlugins/barometerSensor.h
../common.cpp
../common.h
)
diff --git a/daemon/logger.cpp b/daemon/logger.cpp
index 3cadf2c..e9fefdb 100644
--- a/daemon/logger.cpp
+++ b/daemon/logger.cpp
@@ -24,6 +24,7 @@
#include "sensorPlugins/stepCounter.h"
#include "sensorPlugins/heartrateSensor.h"
+#include "sensorPlugins/barometerSensor.h"
Logger::Logger(QObject *parent) :
QObject(parent){
@@ -39,6 +40,7 @@ void Logger::setup() {
heartrateSensorEnabled = this->settings->value("heartrateSensor/enabled",true).toBool();
stepCounterEnabled = this->settings->value("stepCounter/enabled",true).toBool();
+ barometerEnabled = this->settings->value("barometer/enabled",true).toBool();
//intialise HRM
if (heartrateSensorEnabled) {
@@ -50,6 +52,11 @@ void Logger::setup() {
m_stepCounter = new StepCounterPlugin(this,settings->value("stepCounter/interval",600000).toInt(),daemonFresh);
}
+//initialise barometer
+ if (barometerEnabled) {
+ m_barometerSensor = new BarometerSensorPlugin(this,settings->value("barometer/interval",600000).toInt());
+ }
+
if(!m_iface->isValid()) {
qDebug() << "interface is not valid";
qDebug() << m_iface->lastError();
@@ -78,6 +85,10 @@ void Logger::displayOn(QString displayState) {
if (stepCounterEnabled) {
m_stepCounter->timeUpdate();
}
+
+ if (barometerEnabled) {
+ m_barometerSensor->timeUpdate();
+ }
}
void Logger::triggerRecording() {
@@ -88,6 +99,10 @@ void Logger::triggerRecording() {
if (stepCounterEnabled) {
m_stepCounter->triggerRecording();
}
+
+ if (barometerEnabled) {
+ m_barometerSensor->triggerRecording();
+ }
}
bool Logger::getDaemonFresh() {
diff --git a/daemon/logger.h b/daemon/logger.h
index 056645b..69affda 100644
--- a/daemon/logger.h
+++ b/daemon/logger.h
@@ -22,6 +22,7 @@
#include "sensorPlugins/stepCounter.h"
#include "sensorPlugins/heartrateSensor.h"
+#include "sensorPlugins/barometerSensor.h"
class Logger : public QObject
{
@@ -42,6 +43,8 @@ private:
HeartrateSensorPlugin *m_heartrateSensor;
bool stepCounterEnabled = false;
StepCounterPlugin *m_stepCounter;
+ bool barometerEnabled = false;
+ BarometerSensorPlugin *m_barometerSensor;
bool daemonFresh;
QSettings *settings;
bool getDaemonFresh();
diff --git a/daemon/sensorPlugins/barometerSensor.cpp b/daemon/sensorPlugins/barometerSensor.cpp
new file mode 100644
index 0000000..137ccd3
--- /dev/null
+++ b/daemon/sensorPlugins/barometerSensor.cpp
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2023 Arseniy Movshev <dodoradio@outlook.com>
+ * This file is part of sensorlogd, a sensor logger for the AsteroidOS smartwatch OS.
+ *
+ * sensorlogd is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ * sensorlogd is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+
+#include <QDateTime>
+#include <QTimer>
+#include <QtSensors/QPressureSensor>
+#include <QDebug>
+#include <QString>
+
+#include "../logger.h"
+#include "../../common.h"
+
+#include "barometerSensor.h"
+
+BarometerSensorPlugin::BarometerSensorPlugin(QObject *parent, int initInterval) :
+ QObject(parent){
+ interval = initInterval;
+
+ barometerSensor = new QPressureSensor(this);
+ connect(barometerSensor,SIGNAL(readingChanged()),this,SLOT(finishRecording()));
+
+ setupFilePath(sensorPathPrefix);
+
+ qDebug() << "barometer 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 BarometerSensorPlugin::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 BarometerSensorPlugin::triggerRecording() {
+ qDebug() << "barometer interval recording";
+ recordIntervalTimer->start(interval);
+ barometerSensor->start();
+}
+
+void BarometerSensorPlugin::finishRecording() {
+ qDebug() << "barometer pressure update received";
+ int pressure = barometerSensor->reading()->pressure();
+ qDebug() << QDateTime::currentDateTime().toString("hh:mm:ss") << " : " << pressure << barometerSensor->isActive();
+ if (pressure == 0) {
+ qDebug() << "barometer sensor accuracy insufficient. waiting.";
+ return;
+ }
+ fileAddRecord(sensorPathPrefix,QString::number(pressure));
+ barometerSensor->stop();
+}
diff --git a/daemon/sensorPlugins/barometerSensor.h b/daemon/sensorPlugins/barometerSensor.h
new file mode 100644
index 0000000..0ec9fb2
--- /dev/null
+++ b/daemon/sensorPlugins/barometerSensor.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2023 Arseniy Movshev <dodoradio@outlook.com>
+ * This file is part of sensorlogd, a sensor logger for the AsteroidOS smartwatch OS.
+ *
+ * sensorlogd is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ * sensorlogd is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef BAROMETERSENSOR_H
+#define BAROMETERSENSOR_H
+
+#include <QObject>
+#include <QDateTime>
+#include <QDBusInterface>
+#include <QTimer>
+#include <QSettings>
+
+#include <QtSensors/QPressureSensor>
+
+class BarometerSensorPlugin : public QObject {
+ Q_OBJECT
+public:
+ explicit BarometerSensorPlugin(QObject* parent = 0, int initInterval = 600000);
+ virtual ~BarometerSensorPlugin() {};
+
+ void timeUpdate();
+
+public slots:
+ void triggerRecording();
+
+private slots:
+ void finishRecording();
+
+private:
+ QDateTime lastRecordTime;
+ int interval;
+ QTimer *recordIntervalTimer;
+ QPressureSensor *barometerSensor;
+ QSettings *m_settings;
+
+ const QString sensorPathPrefix = "barometer-raw";
+};
+
+#endif // BAROMETERSENSOR_H