Skip to content

Commit

Permalink
FactGroup: Add HygrometerFactGround
Browse files Browse the repository at this point in the history
  • Loading branch information
honglang authored and DonLakeFlyer committed Dec 2, 2021
1 parent 9eda817 commit 32bf236
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 0 deletions.
1 change: 1 addition & 0 deletions custom-example/qgroundcontrol.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@
<file alias="Vehicle/VehicleFact.json">../src/Vehicle/VehicleFact.json</file>
<file alias="Vehicle/VibrationFact.json">../src/Vehicle/VibrationFact.json</file>
<file alias="Vehicle/WindFact.json">../src/Vehicle/WindFact.json</file>
<file alias="Vehicle/HygrometerFact.json">../src/Vehicle/HygrometerFact.json</file>
<file alias="Video.SettingsGroup.json">../src/Settings/Video.SettingsGroup.json</file>
<file alias="VTOLLandingPattern.FactMetaData.json">../src/MissionManager/VTOLLandingPattern.FactMetaData.json</file>
</qresource>
Expand Down
4 changes: 4 additions & 0 deletions qgroundcontrol.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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 \
Expand Down Expand Up @@ -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 \
Expand Down Expand Up @@ -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 \
Expand Down
1 change: 1 addition & 0 deletions qgroundcontrol.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@
<file alias="Vehicle/VehicleFact.json">src/Vehicle/VehicleFact.json</file>
<file alias="Vehicle/VibrationFact.json">src/Vehicle/VibrationFact.json</file>
<file alias="Vehicle/WindFact.json">src/Vehicle/WindFact.json</file>
<file alias="Vehicle/HygrometerFact.json">src/Vehicle/HygrometerFact.json</file>
<file alias="Video.SettingsGroup.json">src/Settings/Video.SettingsGroup.json</file>
<file alias="VTOLLandingPattern.FactMetaData.json">src/MissionManager/VTOLLandingPattern.FactMetaData.json</file>
</qresource>
Expand Down
2 changes: 2 additions & 0 deletions src/Vehicle/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ add_library(Vehicle
VehicleVibrationFactGroup.h
VehicleWindFactGroup.cc
VehicleWindFactGroup.h
VehicleHygrometerFactGroup.cc
VehicleHygrometerFactGroup.h

${EXTRA_SRC}
)
Expand Down
27 changes: 27 additions & 0 deletions src/Vehicle/HygrometerFact.json
Original file line number Diff line number Diff line change
@@ -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
}
]
}
3 changes: 3 additions & 0 deletions src/Vehicle/Vehicle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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<QString, FactGroup*>* fwFactGroups = _firmwarePlugin->factGroups();
Expand Down
5 changes: 5 additions & 0 deletions src/Vehicle/Vehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -1308,6 +1311,7 @@ private slots:
VehicleLocalPositionSetpointFactGroup _localPositionSetpointFactGroup;
VehicleEscStatusFactGroup _escStatusFactGroup;
VehicleEstimatorStatusFactGroup _estimatorStatusFactGroup;
VehicleHygrometerFactGroup _hygrometerFactGroup;
TerrainFactGroup _terrainFactGroup;
QmlObjectListModel _batteryFactGroupListModel;

Expand Down Expand Up @@ -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;

Expand Down
52 changes: 52 additions & 0 deletions src/Vehicle/VehicleHygrometerFactGroup.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/****************************************************************************
*
* (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* 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<float>::quiet_NaN());
_hygroHumiFact.setRawValue(std::numeric_limits<float>::quiet_NaN());
_hygroIDFact.setRawValue(std::numeric_limits<unsigned int>::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);
}
43 changes: 43 additions & 0 deletions src/Vehicle/VehicleHygrometerFactGroup.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/****************************************************************************
*
* (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* 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;
};

0 comments on commit 32bf236

Please sign in to comment.