QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
ActuatorOutputs.cc
Go to the documentation of this file.
1#include "ActuatorOutputs.h"
2#include "ParameterManager.h"
3
4using namespace ActuatorOutputs;
5
10
11ActuatorOutputChannel::ActuatorOutputChannel(QObject *parent, const QString &label, int paramIndex,
12 QmlObjectListModel &channelConfigs, ParameterManager* parameterManager, std::function<void(Fact*)> factAddedCb) :
13 QObject(parent), _label(label), _paramIndex(paramIndex)
14{
15 for (int i = 0; i < channelConfigs.count(); ++i) {
16 auto channelConfig = channelConfigs.value<ChannelConfig*>(i);
17 QString param = channelConfig->parameter();
18 QString sparamIndex = QString::number(paramIndex + channelConfig->indexOffset());
19 param.replace("${i}", sparamIndex);
20
21 Fact* fact = nullptr;
22 if (parameterManager->parameterExists(ParameterManager::defaultComponentId, param)) {
23 fact = parameterManager->getParameter(ParameterManager::defaultComponentId, param);
24 if (channelConfig->displayOption() == Parameter::DisplayOption::Bitset) {
25 fact = new FactBitset(channelConfig, fact, paramIndex + channelConfig->indexOffset());
26 } else if (channelConfig->displayOption() == Parameter::DisplayOption::BoolTrueIfPositive) {
27 fact = new FactFloatAsBool(channelConfig, fact);
28 }
29 factAddedCb(fact);
30 } else {
31 qCDebug(ActuatorsConfigLog) << "ActuatorOutputChannel: Param does not exist:" << param;
32 }
33
34 ChannelConfigInstance *instance = new ChannelConfigInstance(this, fact, *channelConfig);
35 _configInstances->append(instance);
36 }
37}
38
40{
41 _channelConfigs->append(channelConfig);
43}
44
46{
47 _channels->append(channel);
48 emit channelsChanged();
49}
50
52{
54 delete _primaryParam;
55 _primaryParam = param;
56 } else {
57 _params->append(param);
58 }
59}
60
61ActuatorOutput::ActuatorOutput(QObject* parent, const QString& label, const Condition& groupVisibilityCondition)
62 : QObject(parent), _label(label), _groupVisibilityCondition(groupVisibilityCondition)
63{
64 if (_groupVisibilityCondition.fact()) {
65 connect(_groupVisibilityCondition.fact(), &Fact::rawValueChanged, this, &ActuatorOutput::groupsVisibleChanged);
66 }
67}
68
70{
71 _subgroups->append(subgroup);
72 emit subgroupsChanged();
73}
74
76{
78 delete _enableParam;
79 _enableParam = param;
80 } else {
81 _params->append(param);
82 }
83}
84
85void ActuatorOutput::getAllChannelFunctions(QList<Fact*> &allFunctions) const
86{
88 allFunctions.append(fact);
89 });
90}
91
93 bool hasExistingOutputFunction = false;
94 forEachOutputFunction([&hasExistingOutputFunction](
96 [[maybe_unused]] Fact *fact) { hasExistingOutputFunction = true; });
97 return hasExistingOutputFunction;
98}
99
101{
102 for (int subgroupIdx = 0; subgroupIdx < _subgroups->count(); subgroupIdx++) {
103 ActuatorOutputSubgroup *subgroup = qobject_cast<ActuatorOutputSubgroup*>(_subgroups->get(subgroupIdx));
104 for (int channelIdx = 0; channelIdx < subgroup->channels()->count(); channelIdx++) {
105 ActuatorOutputChannel *channel = qobject_cast<ActuatorOutputChannel*>(subgroup->channels()->get(channelIdx));
106 for (int configIdx = 0; configIdx < channel->configInstances()->count(); configIdx++) {
107 ChannelConfigInstance *configInstance = qobject_cast<ChannelConfigInstance*>(channel->configInstances()->get(configIdx));
108 Fact* fact = configInstance->fact();
109 if (configInstance->channelConfig()->function() == ChannelConfig::Function::OutputFunction && fact) {
110 callback(subgroup, configInstance, fact);
111 }
112 }
113 }
114 }
115}
ActuatorOutputChannel(QObject *parent, const QString &label, int paramIndex, QmlObjectListModel &channelConfigs, ParameterManager *parameterManager, std::function< void(Fact *)> factAddedCb)
void addConfigParam(ConfigParameter *param)
void addChannel(ActuatorOutputChannel *channel)
void addChannelConfig(ChannelConfig *channelConfig)
ActuatorOutput(QObject *parent, const QString &label, const Condition &groupVisibilityCondition)
void forEachOutputFunction(std::function< void(ActuatorOutputSubgroup *, ChannelConfigInstance *, Fact *)> callback) const
void getAllChannelFunctions(QList< Fact * > &allFunctions) const
void addConfigParam(ConfigParameter *param)
void addSubgroup(ActuatorOutputSubgroup *subgroup)
const QString & parameter() const
@ Primary
Primary parameter to configure the group of outputs.
@ Enable
Parameter to enable/disable the outputs.
Fact * fact() const
Definition Common.h:105
A Fact is used to hold a single value within the system.
Definition Fact.h:19
void rawValueChanged(const QVariant &value)
bool parameterExists(int componentId, const QString &paramName) const
Fact * getParameter(int componentId, const QString &paramName)
static constexpr int defaultComponentId
void append(QObject *object)
Caller maintains responsibility for object ownership and deletion.
T value(int index) const
QObject * get(int index)
int count() const override final
@ Bitset
integer displayed as boolean (checkbox), where the index defines the bit
@ BoolTrueIfPositive
Show checkbox for float/int value.