QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
FlightModesComponent.cc
Go to the documentation of this file.
2
3#include "Fact.h"
4#include "PX4FirmwarePlugin.h"
6#include "ParameterManager.h"
7#include "StandardModes.h"
8#include "Vehicle.h"
9
11 const char* param;
12 const char* name;
13};
14
16 : VehicleComponent(vehicle, autopilot, AutoPilotPlugin::KnownFlightModesVehicleComponent, parent)
17 , _name(tr("Flight Modes"))
18{
19}
20
21QString FlightModesComponent::name(void) const
22{
23 return _name;
24}
25
27{
28 return tr("Choose how the pilot selects flight modes, and what each transmitter switch does.");
29}
30
32{
33 return "/qmlimages/FlightModesComponentIcon.png";
34}
35
37{
38 return QUrl::fromUserInput("qrc:/qml/QGroundControl/AutoPilotPlugins/PX4/PX4FlightModes.qml");
39}
40
42{
43 QStringList triggers{QStringLiteral("RC_MAP_FLTMODE"), QStringLiteral("RC_MAP_FLTM_BTN"),
44 QStringLiteral("COM_FLTMODE_BOOT")};
45 for (int slot = 1; slot <= PX4FlightModeConfig::kModeSlotCount; slot++) {
46 triggers.append(QStringLiteral("COM_FLTMODE%1").arg(slot));
47 }
48
49 return triggers;
50}
51
53{
55
56 // The names of the external modes come from the vehicle
58}
59
60QString FlightModesComponent::_modeName(const QString& paramName) const
61{
62 Fact* const fact = _parameterFact(paramName);
63 if (!fact) {
64 return {};
65 }
66
67 const QStringList externalNames =
68 _vehicle->standardModes() ? PX4FirmwarePlugin::externalFlightModeNames(_vehicle->standardModes()->modeList())
69 : QStringList();
70 const QString name = PX4FlightModeConfig::modeName(paramName, fact->enumStrings(), fact->enumValues(),
71 externalNames, fact->rawValue().toInt());
72
73 return name.isEmpty() ? fact->cookedValueString() : name;
74}
75
76QList<VehicleSummaryItem> FlightModesComponent::summaryItems() const
77{
78 Fact* const modeChannel = _parameterFact(QStringLiteral("RC_MAP_FLTMODE"));
79 const Fact* const buttons = _parameterFact(QStringLiteral("RC_MAP_FLTM_BTN"));
80 const int modeChannelValue = modeChannel ? modeChannel->rawValue().toInt() : 0;
81 const int buttonMask = buttons ? buttons->rawValue().toInt() : 0;
82
83 QList<VehicleSummaryItem> items;
84 bool selectionAssigned = true;
85 switch (PX4FlightModeConfig::selectionMethod(modeChannelValue, buttonMask)) {
87 items.append({tr("Mode selection"), modeChannel->enumStringValue(), VehicleSummaryItem::Normal});
88 break;
90 QStringList channels;
91 for (const int channel : PX4FlightModeConfig::buttonChannels(buttonMask)) {
92 channels.append(tr("Ch %1").arg(channel));
93 }
94 items.append({tr("Mode selection"), tr("Buttons on %1").arg(channels.join(QStringLiteral(", "))),
95 VehicleSummaryItem::Normal});
96 break;
97 }
99 selectionAssigned = false;
100 items.append({tr("Mode selection"), tr("Not assigned"), VehicleSummaryItem::Muted});
101 break;
102 }
103
104 if (selectionAssigned) {
105 for (int slot = 1; slot <= PX4FlightModeConfig::kModeSlotCount; slot++) {
106 const QString paramName = QStringLiteral("COM_FLTMODE%1").arg(slot);
107 if (_parameterFact(paramName)) {
108 items.append({tr("Flight Mode %1").arg(slot), _modeName(paramName), VehicleSummaryItem::Normal});
109 }
110 }
111 }
112
113 if (_parameterFact(QStringLiteral("COM_FLTMODE_BOOT"))) {
114 items.append({tr("Mode on boot"), _modeName(QStringLiteral("COM_FLTMODE_BOOT")), VehicleSummaryItem::Normal});
115 }
116
117 return items;
118}
The AutoPilotPlugin class is an abstract base class which represents the methods and objects which ar...
A Fact is used to hold a single value within the system.
Definition Fact.h:15
QVariantList enumValues() const
Definition Fact.cc:304
QStringList enumStrings() const
Definition Fact.cc:294
QString cookedValueString() const
Definition Fact.cc:489
QString enumStringValue()
Definition Fact.cc:248
QVariant rawValue() const
Definition Fact.h:87
QString name(void) const final
QString description(void) const final
QList< VehicleSummaryItem > summaryItems() const final
Values for this component's card on the Summary page. A component with none falls back to summaryQmlS...
QStringList summaryChangedTriggerList() const final
Parameters whose change emits summaryItemsChanged, besides those that change setupComplete.
QString iconResource(void) const final
QUrl setupSource(void) const final
FlightModesComponent(Vehicle *vehicle, AutoPilotPlugin *autopilot, QObject *parent=nullptr)
static QStringList externalFlightModeNames(const FlightModeList &modeList)
externalFlightModeName of each of External Mode 1-8, in order
VehicleComponent(Vehicle *vehicle, AutoPilotPlugin *autopilot, AutoPilotPlugin::KnownVehicleComponent KnownVehicleComponent, QObject *parent=nullptr)
void summaryItemsChanged()
Fact * _parameterFact(const QString &name) const
Fact of a parameter of the default component, nullptr when the vehicle does not have it.
virtual void setupTriggerSignals()
void flightModesChanged()
QList< int > buttonChannels(int buttonMask)
QString modeName(const QString &paramName, const QStringList &enumStrings, const QVariantList &enumValues, const QStringList &externalNames, int value)
Label of the mode a parameter value selects, as modeChoices shows it. Empty for a value with no choic...
SelectionMethod selectionMethod(int modeChannel, int buttonMask)
PX4 ignores the mode buttons while a mode channel is set.
constexpr int kModeSlotCount
Number of mode slots, COM_FLTMODE1 to COM_FLTMODE6.