Enroute Flight Navigation
A navigation app for VFR pilots
Sensors.h
1/***************************************************************************
2 * Copyright (C) 2023-2025 by Stefan Kebekus *
3 * stefan.kebekus@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21#pragma once
22
23#include "GlobalObject.h"
24#include "units/Distance.h"
25#include "units/Pressure.h"
26#include "units/Temperature.h"
27
28#include <QProperty>
29#include <QQmlEngine>
30#if defined(Q_OS_ANDROID) or defined(Q_OS_IOS)
31#include <QAmbientTemperatureSensor>
32#include <QPressureSensor>
33#endif
34
35
41
42class Sensors : public GlobalObject
43{
44 Q_OBJECT
45 QML_ELEMENT
46 QML_SINGLETON
47
48public:
49 //
50 // Constructors and destructors
51 //
52
57 explicit Sensors(QObject* parent = nullptr);
58
59 // deferred initialization
60 void deferredInitialization() override;
61
62 // No default constructor, important for QML singleton
63 explicit Sensors() = delete;
64
66 ~Sensors() override = default;
67
68 // factory function for QML singleton
69 static Sensors* create(QQmlEngine* /*unused*/, QJSEngine* /*unused*/)
70 {
71 return GlobalObject::sensors();
72 }
73
74
75 //
76 // PROPERTIES
77 //
83
84
89
96
98 Q_PROPERTY(QString statusString READ statusString BINDABLE bindableStatusString)
99
100
101 //
102 // Getter Methods
103 //
104
109 [[nodiscard]] Units::Pressure ambientPressure() const { return m_ambientPressure.value(); }
110
115 [[nodiscard]] QBindable<Units::Pressure> bindableAmbientPressure() { return &m_ambientPressure; }
116
121 [[nodiscard]] Units::Temperature ambientTemperature() const { return m_ambientTemperature.value(); }
122
127 [[nodiscard]] QBindable<Units::Temperature> bindableAmbientTemperature() { return &m_ambientTemperature; }
128
133 [[nodiscard]] Units::Distance pressureAltitude() const { return m_pressureAltitude.value(); }
134
139 [[nodiscard]] QBindable<Units::Distance> bindablePressureAltitude() { return &m_pressureAltitude; }
140
145 [[nodiscard]] QString statusString() const { return m_statusString.value(); }
146
151 [[nodiscard]] QBindable<QString> bindableStatusString() { return &m_statusString; }
152
153private slots:
154 // Update sensor readings. For performance reasons, we poll sensors.
155 void updateSensorReadings();
156
157 // Update the status string
158 void updateStatusString();
159
160private:
161 Q_DISABLE_COPY_MOVE(Sensors)
162
163#if defined(Q_OS_ANDROID) or defined(Q_OS_IOS)
164 // Ambient temperature sensor
165 QAmbientTemperatureSensor m_temperatureSensor;
166
167 // Ambient pressure sensor
168 QPressureSensor m_pressureSensor;
169#endif
170
171 QProperty<Units::Pressure> m_ambientPressure;
172 QProperty<Units::Distance> m_pressureAltitude;
173 QProperty<Units::Temperature> m_ambientTemperature;
174 QProperty<QString> m_statusString;
175};
static Q_INVOKABLE Sensors * sensors()
Pointer to appplication-wide static Navigation::Clock instance.
GlobalObject(QObject *parent=nullptr)
Standard constructor.
Sensor data.
Definition Sensors.h:43
void deferredInitialization() override
Non-constructor initialization.
QBindable< QString > bindableStatusString()
Getter function for the property with the same name.
Definition Sensors.h:151
QString statusString() const
Getter function for the property with the same name.
Definition Sensors.h:145
QBindable< Units::Temperature > bindableAmbientTemperature()
Getter function for the property with the same name.
Definition Sensors.h:127
QBindable< Units::Distance > bindablePressureAltitude()
Getter function for the property with the same name.
Definition Sensors.h:139
QBindable< Units::Pressure > bindableAmbientPressure()
Getter function for the property with the same name.
Definition Sensors.h:115
~Sensors() override=default
Standard destructor.
Units::Temperature ambientTemperature
Ambient temperature.
Definition Sensors.h:88
Units::Pressure ambientPressure
Ambient pressure.
Definition Sensors.h:82
Units::Temperature ambientTemperature() const
Getter function for the property with the same name.
Definition Sensors.h:121
QString statusString
Status string.
Definition Sensors.h:98
Units::Distance pressureAltitude() const
Getter function for the property with the same name.
Definition Sensors.h:133
Sensors(QObject *parent=nullptr)
Standard constructor.
Units::Distance pressureAltitude
Pressure altitude.
Definition Sensors.h:95
Convenience class for distance computations.
Definition Distance.h:35
Convenience class for pressure computations.
Definition Pressure.h:35
Convenience class for temperature computations.
Definition Temperature.h:35
Conversion between units used in aviation.
Definition Angle.h:34