From 0782a72a228f777a0ab4a898e37d89fab75c52ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Tue, 30 Nov 2021 13:27:08 +0100 Subject: [PATCH] Actuators: get test slider name from mixer type, if set --- src/Vehicle/Actuators/Mixer.cc | 43 +++++++++++++++++++++++++++++++++++++----- src/Vehicle/Actuators/Mixer.h | 4 +++- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/Vehicle/Actuators/Mixer.cc b/src/Vehicle/Actuators/Mixer.cc index 6b51e52..952fcc9 100644 --- a/src/Vehicle/Actuators/Mixer.cc +++ b/src/Vehicle/Actuators/Mixer.cc @@ -16,9 +16,10 @@ using namespace Mixer; MixerChannel::MixerChannel(QObject *parent, const QString &label, int actuatorFunction, int paramIndex, int actuatorTypeIndex, - QmlObjectListModel &channelConfigs, ParameterManager* parameterManager, const Rule* rule, std::function factAddedCb) : - QObject(parent), _label(label), _actuatorFunction(actuatorFunction), _paramIndex(paramIndex), _actuatorTypeIndex(actuatorTypeIndex), - _rule(rule) + QmlObjectListModel &channelConfigs, ParameterManager* parameterManager, const Rule* rule, + std::function factAddedCb) + : QObject(parent), _label(label), _actuatorFunction(actuatorFunction), _paramIndex(paramIndex), + _actuatorTypeIndex(actuatorTypeIndex), _rule(rule) { for (int i = 0; i < channelConfigs.count(); ++i) { auto channelConfig = channelConfigs.value(i); @@ -53,7 +54,7 @@ MixerChannel::MixerChannel(QObject *parent, const QString &label, int actuatorFu } else if (channelConfig->displayOption() == Parameter::DisplayOption::BoolTrueIfPositive) { fact = new FactFloatAsBool(channelConfig, fact); } - factAddedCb(fact); + factAddedCb(channelConfig->function(), fact); } else { qCDebug(ActuatorsConfigLog) << "ActuatorOutputChannel: Param does not exist:" << param; } @@ -185,6 +186,17 @@ bool MixerChannel::getGeometry(const ActuatorTypes& actuatorTypes, const MixerOp return numPositionAxis == 3; } +Fact* MixerChannel::getFact(Function function) const +{ + for (int i = 0; i < _configInstances->count(); ++i) { + ChannelConfigInstance* configInstance = _configInstances->value(i); + if (configInstance->channelConfig()->function() == Function::Type) { + return configInstance->fact(); + } + } + return nullptr; +} + void MixerConfigGroup::addChannelConfig(ChannelConfig* channelConfig) { _channelConfigs->append(channelConfig); @@ -308,8 +320,12 @@ void Mixers::update() _functionsSpecificLabel[actuatorFunction] = label; } } + auto factAdded = [this](Function function, Fact* fact) { + // Type might change more than the geometry + subscribeFact(fact, function != Function::Type); + }; MixerChannel* channel = new MixerChannel(currentMixerGroup, label, actuatorFunction, actuatorIdx, actuatorTypeIndex, - *currentMixerGroup->channelConfigs(), _parameterManager, selectedRule, [this](Fact* fact) { subscribeFact(fact, true); }); + *currentMixerGroup->channelConfigs(), _parameterManager, selectedRule, factAdded); currentMixerGroup->addChannel(channel); ++actuatorTypeIndex; } @@ -331,6 +347,23 @@ void Mixers::update() QString Mixers::getSpecificLabelForFunction(int function) const { + // Try to get it from the actuator type param + for (int mixerGroupIdx = 0; mixerGroupIdx < _groups->count(); ++mixerGroupIdx) { + Mixer::MixerConfigGroup* mixerGroup = _groups->value(mixerGroupIdx); + for (int mixerChannelIdx = 0; mixerChannelIdx < mixerGroup->channels()->count(); ++mixerChannelIdx) { + Mixer::MixerChannel* mixerChannel = mixerGroup->channels()->value(mixerChannelIdx); + + if (mixerChannel->actuatorFunction() != function) { + continue; + } + + Fact* typeFact = mixerChannel->getFact(Function::Type); + if (typeFact) { + return typeFact->enumOrValueString() + " (" + _functions.value(function).label +")"; + } + } + } + const auto iter = _functionsSpecificLabel.find(function); if (iter == _functionsSpecificLabel.end()) { return _functions.value(function).label; diff --git a/src/Vehicle/Actuators/Mixer.h b/src/Vehicle/Actuators/Mixer.h index ec45429..08bb6e6 100644 --- a/src/Vehicle/Actuators/Mixer.h +++ b/src/Vehicle/Actuators/Mixer.h @@ -207,7 +207,7 @@ class MixerChannel : public QObject public: MixerChannel(QObject* parent, const QString& label, int actuatorFunction, int paramIndex, int actuatorTypeIndex, QmlObjectListModel& channelConfigs, ParameterManager* parameterManager, - const Rule* rule, std::function factAddedCb); + const Rule* rule, std::function factAddedCb); Q_PROPERTY(QString label READ label CONSTANT) Q_PROPERTY(QmlObjectListModel* configInstances READ configInstances NOTIFY configInstancesChanged) @@ -220,6 +220,8 @@ public: bool getGeometry(const ActuatorTypes& actuatorTypes, const MixerOption::ActuatorGroup& group, ActuatorGeometry& geometry) const; + Fact* getFact(Function function) const; + public slots: void applyRule(bool noConstraints = false);