diff --git a/custom-example/qgroundcontrol.qrc b/custom-example/qgroundcontrol.qrc index 58486f4c2b5..180cf912796 100644 --- a/custom-example/qgroundcontrol.qrc +++ b/custom-example/qgroundcontrol.qrc @@ -329,6 +329,7 @@ ../src/Vehicle/VehicleFact.json ../src/Vehicle/VibrationFact.json ../src/Vehicle/WindFact.json + ../src/Vehicle/HygrometerFact.json ../src/Settings/Video.SettingsGroup.json ../src/MissionManager/VTOLLandingPattern.FactMetaData.json diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index 4de7b66d383..fc91d78621e 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -430,6 +430,7 @@ contains (DEFINES, QGC_ENABLE_PAIRING) { HEADERS += \ src/QmlControls/QmlUnitsConversion.h \ src/Vehicle/VehicleEscStatusFactGroup.h \ + src/Vehicle/VehicleHygrometerFactGroup.h \ src/api/QGCCorePlugin.h \ src/api/QGCOptions.h \ src/api/QGCSettings.h \ @@ -443,6 +444,7 @@ contains (DEFINES, QGC_ENABLE_PAIRING) { SOURCES += \ src/Vehicle/VehicleEscStatusFactGroup.cc \ + src/Vehicle/VehicleHygrometerFactGroup.cc \ src/api/QGCCorePlugin.cc \ src/api/QGCOptions.cc \ src/api/QGCSettings.cc \ @@ -723,6 +725,7 @@ HEADERS += \ src/Vehicle/VehicleTemperatureFactGroup.h \ src/Vehicle/VehicleVibrationFactGroup.h \ src/Vehicle/VehicleWindFactGroup.h \ + src/Vehicle/VehicleHygrometerFactGroup.h \ src/VehicleSetup/JoystickConfigController.h \ src/comm/LinkConfiguration.h \ src/comm/LinkInterface.h \ @@ -963,6 +966,7 @@ SOURCES += \ src/Vehicle/VehicleSetpointFactGroup.cc \ src/Vehicle/VehicleTemperatureFactGroup.cc \ src/Vehicle/VehicleVibrationFactGroup.cc \ + src/Vehicle/VehicleHygrometerFactGroup.cc \ src/Vehicle/VehicleWindFactGroup.cc \ src/VehicleSetup/JoystickConfigController.cc \ src/comm/LinkConfiguration.cc \ diff --git a/qgroundcontrol.qrc b/qgroundcontrol.qrc index 36abbec4d48..45bac1de489 100644 --- a/qgroundcontrol.qrc +++ b/qgroundcontrol.qrc @@ -337,6 +337,7 @@ src/Vehicle/VehicleFact.json src/Vehicle/VibrationFact.json src/Vehicle/WindFact.json + src/Vehicle/HygrometerFact.json src/Settings/Video.SettingsGroup.json src/MissionManager/VTOLLandingPattern.FactMetaData.json diff --git a/src/Vehicle/CMakeLists.txt b/src/Vehicle/CMakeLists.txt index 9baa27f0419..a4a05f5d777 100644 --- a/src/Vehicle/CMakeLists.txt +++ b/src/Vehicle/CMakeLists.txt @@ -90,6 +90,8 @@ add_library(Vehicle VehicleVibrationFactGroup.h VehicleWindFactGroup.cc VehicleWindFactGroup.h + VehicleHygrometerFactGroup.cc + VehicleHygrometerFactGroup.h ${EXTRA_SRC} ) diff --git a/src/Vehicle/HygrometerFact.json b/src/Vehicle/HygrometerFact.json new file mode 100644 index 00000000000..b188eeb7229 --- /dev/null +++ b/src/Vehicle/HygrometerFact.json @@ -0,0 +1,27 @@ +{ + "version": 1, + "fileType": "FactMetaData", + "QGC.MetaData.Facts": +[ +{ + "name": "temperature", + "shortDesc": "Temperature", + "type": "double", + "decimalPlaces": 3, + "units": "deg" +}, +{ + "name": "humidity", + "shortDesc": "Humidity %", + "type": "double", + "decimalPlaces": 3, + "units": "%" +}, +{ + "name": "hygrometerid", + "shortDesc": "ID", + "type": "uint16", + "decimalPlaces": 0 +} +] +} diff --git a/src/Vehicle/Vehicle.cc b/src/Vehicle/Vehicle.cc index e9e0f041117..abbc77a2044 100644 --- a/src/Vehicle/Vehicle.cc +++ b/src/Vehicle/Vehicle.cc @@ -108,6 +108,7 @@ const char* Vehicle::_localPositionSetpointFactGroupName ="localPositionSetpoint const char* Vehicle::_escStatusFactGroupName = "escStatus"; const char* Vehicle::_estimatorStatusFactGroupName = "estimatorStatus"; const char* Vehicle::_terrainFactGroupName = "terrain"; +const char* Vehicle::_hygrometerFactGroupName = "hygrometer"; // Standard connected vehicle Vehicle::Vehicle(LinkInterface* link, @@ -167,6 +168,7 @@ Vehicle::Vehicle(LinkInterface* link, , _escStatusFactGroup (this) , _estimatorStatusFactGroup (this) , _terrainFactGroup (this) + , _hygrometerFactGroup (this) , _terrainProtocolHandler (new TerrainProtocolHandler(this, &_terrainFactGroup, this)) { _linkManager = _toolbox->linkManager(); @@ -445,6 +447,7 @@ void Vehicle::_commonInit() _addFactGroup(&_escStatusFactGroup, _escStatusFactGroupName); _addFactGroup(&_estimatorStatusFactGroup, _estimatorStatusFactGroupName); _addFactGroup(&_terrainFactGroup, _terrainFactGroupName); + _addFactGroup(&_hygrometerFactGroup, _hygrometerFactGroupName); // Add firmware-specific fact groups, if provided QMap* fwFactGroups = _firmwarePlugin->factGroups(); diff --git a/src/Vehicle/Vehicle.h b/src/Vehicle/Vehicle.h index e3e0c54e9d5..d1d69c52a4d 100644 --- a/src/Vehicle/Vehicle.h +++ b/src/Vehicle/Vehicle.h @@ -39,6 +39,7 @@ #include "VehicleVibrationFactGroup.h" #include "VehicleEscStatusFactGroup.h" #include "VehicleEstimatorStatusFactGroup.h" +#include "VehicleHygrometerFactGroup.h" #include "VehicleLinkManager.h" #include "MissionManager.h" #include "GeoFenceManager.h" @@ -314,6 +315,7 @@ class Vehicle : public FactGroup Q_PROPERTY(FactGroup* distanceSensors READ distanceSensorFactGroup CONSTANT) Q_PROPERTY(FactGroup* localPosition READ localPositionFactGroup CONSTANT) Q_PROPERTY(FactGroup* localPositionSetpoint READ localPositionSetpointFactGroup CONSTANT) + Q_PROPERTY(FactGroup* hygrometer READ hygrometerFactGroup CONSTANT) Q_PROPERTY(QmlObjectListModel* batteries READ batteries CONSTANT) Q_PROPERTY(int firmwareMajorVersion READ firmwareMajorVersion NOTIFY firmwareVersionChanged) @@ -655,6 +657,7 @@ class Vehicle : public FactGroup FactGroup* escStatusFactGroup () { return &_escStatusFactGroup; } FactGroup* estimatorStatusFactGroup () { return &_estimatorStatusFactGroup; } FactGroup* terrainFactGroup () { return &_terrainFactGroup; } + FactGroup* hygrometerFactGroup () { return &_hygrometerFactGroup; } QmlObjectListModel* batteries () { return &_batteryFactGroupListModel; } MissionManager* missionManager () { return _missionManager; } @@ -1308,6 +1311,7 @@ private slots: VehicleLocalPositionSetpointFactGroup _localPositionSetpointFactGroup; VehicleEscStatusFactGroup _escStatusFactGroup; VehicleEstimatorStatusFactGroup _estimatorStatusFactGroup; + VehicleHygrometerFactGroup _hygrometerFactGroup; TerrainFactGroup _terrainFactGroup; QmlObjectListModel _batteryFactGroupListModel; @@ -1359,6 +1363,7 @@ private slots: static const char* _escStatusFactGroupName; static const char* _estimatorStatusFactGroupName; static const char* _terrainFactGroupName; + static const char* _hygrometerFactGroupName; static const int _vehicleUIUpdateRateMSecs = 100; diff --git a/src/Vehicle/VehicleHygrometerFactGroup.cc b/src/Vehicle/VehicleHygrometerFactGroup.cc new file mode 100644 index 00000000000..23c7b6be8e9 --- /dev/null +++ b/src/Vehicle/VehicleHygrometerFactGroup.cc @@ -0,0 +1,52 @@ +/**************************************************************************** + * + * (c) 2009-2020 QGROUNDCONTROL PROJECT + * + * QGroundControl is licensed according to the terms in the file + * COPYING.md in the root of the source code directory. + * + ****************************************************************************/ + +#include "VehicleHygrometerFactGroup.h" +#include "Vehicle.h" +#include "QGCGeo.h" + +const char* VehicleHygrometerFactGroup::_hygroHumiFactName = "humidity"; +const char* VehicleHygrometerFactGroup::_hygroTempFactName = "temperature"; +const char* VehicleHygrometerFactGroup::_hygroIDFactName = "hygrometerid"; + +VehicleHygrometerFactGroup::VehicleHygrometerFactGroup(QObject* parent) + : FactGroup(1000, ":/json/Vehicle/HygrometerFact.json", parent) + , _hygroTempFact (0, _hygroTempFactName, FactMetaData::valueTypeDouble) + , _hygroHumiFact (0, _hygroHumiFactName, FactMetaData::valueTypeDouble) + , _hygroIDFact (0, _hygroIDFactName, FactMetaData::valueTypeUint16) +{ + _addFact(&_hygroTempFact, _hygroTempFactName); + _addFact(&_hygroHumiFact, _hygroHumiFactName); + _addFact(&_hygroIDFact, _hygroIDFactName); + + _hygroTempFact.setRawValue(std::numeric_limits::quiet_NaN()); + _hygroHumiFact.setRawValue(std::numeric_limits::quiet_NaN()); + _hygroIDFact.setRawValue(std::numeric_limits::quiet_NaN()); +} + +void VehicleHygrometerFactGroup::handleMessage(Vehicle* /* vehicle */, mavlink_message_t& message) +{ + switch (message.msgid) { + case MAVLINK_MSG_ID_HYGROMETER_SENSOR: + _handleHygrometerSensor(message); + break; + default: + break; + } +} + +void VehicleHygrometerFactGroup::_handleHygrometerSensor(mavlink_message_t& message) +{ + mavlink_hygrometer_sensor_t hygrometer; + mavlink_msg_hygrometer_sensor_decode(&message, &hygrometer); + + _hygroTempFact.setRawValue(hygrometer.temperature); + _hygroHumiFact.setRawValue(hygrometer.humidity); + _hygroIDFact.setRawValue(hygrometer.id); +} diff --git a/src/Vehicle/VehicleHygrometerFactGroup.h b/src/Vehicle/VehicleHygrometerFactGroup.h new file mode 100644 index 00000000000..2641b49ceef --- /dev/null +++ b/src/Vehicle/VehicleHygrometerFactGroup.h @@ -0,0 +1,43 @@ +/**************************************************************************** + * + * (c) 2009-2020 QGROUNDCONTROL PROJECT + * + * QGroundControl is licensed according to the terms in the file + * COPYING.md in the root of the source code directory. + * + ****************************************************************************/ + +#pragma once + +#include "FactGroup.h" +#include "QGCMAVLink.h" + +class VehicleHygrometerFactGroup : public FactGroup +{ + Q_OBJECT + +public: + VehicleHygrometerFactGroup(QObject* parent = nullptr); + + Q_PROPERTY(Fact* hygroID READ hygroID CONSTANT) + Q_PROPERTY(Fact* hygroTemp READ hygroTemp CONSTANT) + Q_PROPERTY(Fact* hygroHumi READ hygroHumi CONSTANT) + + Fact* hygroID () { return &_hygroIDFact; } + Fact* hygroTemp () { return &_hygroTempFact; } + Fact* hygroHumi () { return &_hygroHumiFact; } + + // Overrides from FactGroup + virtual void handleMessage(Vehicle* vehicle, mavlink_message_t& message) override; + + static const char* _hygroIDFactName; + static const char* _hygroTempFactName; + static const char* _hygroHumiFactName; + +protected: + void _handleHygrometerSensor (mavlink_message_t& message); + + Fact _hygroIDFact; + Fact _hygroTempFact; + Fact _hygroHumiFact; +};