diff --git a/companion/src/firmwares/io_data.h b/companion/src/firmwares/io_data.h index 05136f210..b70b174ea 100644 --- a/companion/src/firmwares/io_data.h +++ b/companion/src/firmwares/io_data.h @@ -109,7 +109,8 @@ class LimitData { int offset; int ppmCenter; bool symetrical; - char name[LIMITDATA_NAME_LEN+1]; + int failsafe; + char name[LIMITDATA_NAME_LEN + 1]; CurveReference curve; QString minToString() const; QString maxToString() const; diff --git a/companion/src/firmwares/modeldata.cpp b/companion/src/firmwares/modeldata.cpp index b72cc328a..3386ba41d 100644 --- a/companion/src/firmwares/modeldata.cpp +++ b/companion/src/firmwares/modeldata.cpp @@ -1174,8 +1174,7 @@ void ModelData::updateModuleFailsafes(ModuleData * md) bool updated = false; - switch (updRefInfo.action) - { + switch (updRefInfo.action) { case REF_UPD_ACT_CLEAR: break; case REF_UPD_ACT_SHIFT: @@ -1183,16 +1182,16 @@ void ModelData::updateModuleFailsafes(ModuleData * md) return; if (updRefInfo.shift > 0) { - for (int i = (CPN_MAX_CHNOUT - 1); i > updRefInfo.index1; i--) { - md->failsafeChannels[i] = md->failsafeChannels[i - 1]; + for (int i = CPN_MAX_CHNOUT - 1; i > updRefInfo.index1; i--) { + limitData[i].failsafe = limitData[i - 1].failsafe; } - md->failsafeChannels[updRefInfo.index1] = 0; + limitData[updRefInfo.index1].failsafe = 0; } else { - for (int i = (updRefInfo.index1 + 1); i < (CPN_MAX_CHNOUT - 1); i++) { - md->failsafeChannels[i - 1] = md->failsafeChannels[i]; + for (int i = updRefInfo.index1 + 1; i < CPN_MAX_CHNOUT - 1; i++) { + limitData[i - 1].failsafe = limitData[i].failsafe; } - md->failsafeChannels[CPN_MAX_CHNOUT - 1] = 0; + limitData[CPN_MAX_CHNOUT - 1].failsafe = 0; } updated = true; break; @@ -1200,17 +1199,18 @@ void ModelData::updateModuleFailsafes(ModuleData * md) int tmp; if (updRefInfo.index1 >= 0 && updRefInfo.index1 < CPN_MAX_CHNOUT) { updated = true; - tmp = md->failsafeChannels[updRefInfo.index1]; + tmp = limitData[updRefInfo.index1].failsafe; if (updRefInfo.index2 >= 0 && updRefInfo.index2 < CPN_MAX_CHNOUT) - md->failsafeChannels[updRefInfo.index1] = md->failsafeChannels[updRefInfo.index2]; + limitData[updRefInfo.index1].failsafe = limitData[updRefInfo.index2].failsafe; else - md->failsafeChannels[updRefInfo.index1] = 0; + limitData[updRefInfo.index1].failsafe = 0; } else tmp = 0; - if (updRefInfo.index2 >= 0 && updRefInfo.index2 < CPN_MAX_CHNOUT) + if (updRefInfo.index2 >= 0 && updRefInfo.index2 < CPN_MAX_CHNOUT) { updated = true; - md->failsafeChannels[updRefInfo.index2] = tmp; + limitData[updRefInfo.index2].failsafe = tmp; + } break; default: qDebug() << "Error - unhandled action:" << updRefInfo.action; diff --git a/companion/src/firmwares/moduledata.h b/companion/src/firmwares/moduledata.h index 1df7380a1..d356c3012 100644 --- a/companion/src/firmwares/moduledata.h +++ b/companion/src/firmwares/moduledata.h @@ -158,7 +158,11 @@ class ModuleData { Q_DECLARE_TR_FUNCTIONS(ModuleData) public: - ModuleData() { clear(); } + ModuleData() + { + clear(); + } + unsigned int modelId; unsigned int protocol; // type in datastructs.h int rfProtocol; // rfProtocol in datastructs.h @@ -168,7 +172,6 @@ class ModuleData { unsigned int channelsStart; int channelsCount; // 0=8 channels unsigned int failsafeMode; - int failsafeChannels[CPN_MAX_CHNOUT]; struct PPM { int delay; diff --git a/companion/src/firmwares/opentx/opentxeeprom.cpp b/companion/src/firmwares/opentx/opentxeeprom.cpp index ec702514c..17c5b03a5 100644 --- a/companion/src/firmwares/opentx/opentxeeprom.cpp +++ b/companion/src/firmwares/opentx/opentxeeprom.cpp @@ -2184,7 +2184,7 @@ class ModuleUnionField: public UnionField { class ModuleField: public TransformedField { public: - ModuleField(DataField * parent, ModuleData & module, Board::Type board, unsigned int version): + ModuleField(DataField * parent, ModuleData & module, ModelData & model, Board::Type board, unsigned int version): TransformedField(parent, internalField), internalField(this, "Module"), module(module), @@ -2198,8 +2198,8 @@ class ModuleField: public TransformedField { internalField.Append(new UnsignedField<3>(this, module.subType)); internalField.Append(new BoolField<1>(this, module.invertedSerial)); if (version <= 218) { - for (int i=0; i<32; i++) { - internalField.Append(new SignedField<16>(this, module.failsafeChannels[i])); + for (int i = 0; i < 32; i++) { + internalField.Append(new SignedField<16>(this, model.limitData[i].failsafe)); } } @@ -2393,12 +2393,12 @@ OpenTxModelData::OpenTxModelData(ModelData & modelData, Board::Type board, unsig int modulesCount = (version <= 218 ? 3 : 2); for (int module = 0; module < modulesCount; module++) { - internalField.Append(new ModuleField(this, modelData.moduleData[module], board, version)); + internalField.Append(new ModuleField(this, modelData.moduleData[module], modelData, board, version)); } if (version >= 219) { for (int i = 0; i < 32; i++) { - internalField.Append(new SignedField<16>(this, modelData.moduleData[0].failsafeChannels[i])); + internalField.Append(new SignedField<16>(this, modelData.limitData[i].failsafe)); } } diff --git a/companion/src/modeledit/setup.cpp b/companion/src/modeledit/setup.cpp index c813b0b9c..43eaf11fe 100644 --- a/companion/src/modeledit/setup.cpp +++ b/companion/src/modeledit/setup.cpp @@ -792,18 +792,22 @@ void ModulePanel::on_lowPower_stateChanged(int state) module.multi.lowPowerMode = (state == Qt::Checked); } -// updtSb (update spin box(es)): 0=none or bitmask of FailsafeValueDisplayTypes -void ModulePanel::setChannelFailsafeValue(const int channel, const int value, quint8 updtSb) +void ModulePanel::onFailsafeModified(unsigned channel) { - if (channel < 0 || channel >= CPN_MAX_CHNOUT) - return; + updateFailsafeUI(channel, FAILSAFE_DISPLAY_PERCENT | FAILSAFE_DISPLAY_USEC); +} - module.failsafeChannels[channel] = value; +void ModulePanel::updateFailsafeUI(unsigned channel, quint8 updtSb) +{ + int value = model->limitData[channel].failsafe; double pctVal = divRoundClosest(value * 1000, 1024) / 10.0; - // qDebug() << value << pctVal; if (failsafeGroupsMap.contains(channel)) { const ChannelFailsafeWidgetsGroup & grp = failsafeGroupsMap.value(channel); + bool disable = (value == FAILSAFE_CHANNEL_HOLD || value == FAILSAFE_CHANNEL_NOPULSE); + if (grp.combo) { + grp.combo->setCurrentIndex(grp.combo->findData(disable ? value : 0)); + } if ((updtSb & FAILSAFE_DISPLAY_PERCENT) && grp.sbPercent) { grp.sbPercent->blockSignals(true); grp.sbPercent->setValue(pctVal); @@ -815,8 +819,21 @@ void ModulePanel::setChannelFailsafeValue(const int channel, const int value, qu grp.sbUsec->blockSignals(false); } } - if (!lock) +} + +// updtSb (update spin box(es)): 0=none or bitmask of FailsafeValueDisplayTypes +void ModulePanel::setChannelFailsafeValue(const int channel, const int value, quint8 updtSb) +{ + if (channel < 0 || channel >= CPN_MAX_CHNOUT) + return; + + model->limitData[channel].failsafe = value; + updateFailsafeUI(channel, updtSb); + + if (!lock) { + emit failsafeModified(channel); emit modified(); + } } void ModulePanel::onFailsafeUsecChanged(int value) @@ -853,8 +870,9 @@ void ModulePanel::onFailsafeComboIndexChanged(int index) bool ok = false; int channel = sender()->property("index").toInt(&ok); if (ok) { - module.failsafeChannels[channel] = cb->itemData(index).toInt(); + model->limitData[channel].failsafe = cb->itemData(index).toInt(); updateFailsafe(channel); + emit failsafeModified(channel); emit modified(); } lock = false; @@ -886,12 +904,12 @@ void ModulePanel::onExtendedLimitsToggled() } } -void ModulePanel::updateFailsafe(int channel) +void ModulePanel::updateFailsafe(unsigned channel) { if (channel >= CPN_MAX_CHNOUT || !failsafeGroupsMap.contains(channel)) return; - const int failsafeValue = module.failsafeChannels[channel]; + const int failsafeValue = model->limitData[channel].failsafe; const ChannelFailsafeWidgetsGroup & grp = failsafeGroupsMap.value(channel); const bool valDisable = (failsafeValue == FAILSAFE_CHANNEL_HOLD || failsafeValue == FAILSAFE_CHANNEL_NOPULSE); @@ -903,7 +921,7 @@ void ModulePanel::updateFailsafe(int channel) grp.sbUsec->setDisabled(valDisable); if (!valDisable) - setChannelFailsafeValue(channel, failsafeValue, (FAILSAFE_DISPLAY_PERCENT | FAILSAFE_DISPLAY_USEC)); + setChannelFailsafeValue(channel, failsafeValue, FAILSAFE_DISPLAY_PERCENT | FAILSAFE_DISPLAY_USEC); } void ModulePanel::onClearAccessRxClicked() @@ -1166,13 +1184,21 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge ui->trimsDisplay->hide(); } - for (int i=firmware->getCapability(NumFirstUsableModule); igetCapability(NumModules); i++) { + for (int i = firmware->getCapability(NumFirstUsableModule); i < firmware->getCapability(NumModules); i++) { modules[i] = new ModulePanel(this, model, model.moduleData[i], generalSettings, firmware, i); ui->modulesLayout->addWidget(modules[i]); connect(modules[i], &ModulePanel::modified, this, &SetupPanel::modified); connect(this, &SetupPanel::extendedLimitsToggled, modules[i], &ModulePanel::onExtendedLimitsToggled); } + for (int i = firmware->getCapability(NumFirstUsableModule); i < firmware->getCapability(NumModules); i++) { + for (int j = firmware->getCapability(NumFirstUsableModule); j < firmware->getCapability(NumModules); j++) { + if (i != j) { + connect(modules[i], SIGNAL(failsafeModified(unsigned)), modules[j], SLOT(onFailsafeModified(unsigned))); + } + } + } + if (firmware->getCapability(ModelTrainerEnable)) { modules[CPN_MAX_MODULES] = new ModulePanel(this, model, model.moduleData[CPN_MAX_MODULES], generalSettings, firmware, -1); ui->modulesLayout->addWidget(modules[CPN_MAX_MODULES]); diff --git a/companion/src/modeledit/setup.h b/companion/src/modeledit/setup.h index fa9e4ad5b..1470e4e2f 100644 --- a/companion/src/modeledit/setup.h +++ b/companion/src/modeledit/setup.h @@ -61,15 +61,17 @@ class ModulePanel : public ModelPanel Q_OBJECT public: - ModulePanel(QWidget *parent, ModelData & model, ModuleData & module, GeneralSettings & generalSettings, Firmware * firmware, int moduleIdx); + ModulePanel(QWidget * parent, ModelData & model, ModuleData & module, GeneralSettings & generalSettings, Firmware * firmware, int moduleIdx); virtual ~ModulePanel(); virtual void update(); public slots: void onExtendedLimitsToggled(); + void onFailsafeModified(unsigned index); signals: void channelsRangeChanged(); + void failsafeModified(unsigned index); private slots: void setupFailsafes(); @@ -95,7 +97,7 @@ class ModulePanel : public ModelPanel void onFailsafeUsecChanged(int value); void onFailsafePercentChanged(double value); void onFailsafesDisplayValueTypeChanged(int type); - void updateFailsafe(int channel); + void updateFailsafe(unsigned channel); void on_optionValue_editingFinished(); void onClearAccessRxClicked(); @@ -114,6 +116,7 @@ class ModulePanel : public ModelPanel Ui::Module *ui; QMap failsafeGroupsMap; static quint8 failsafesValueDisplayType; // FailsafeValueDisplayTypes + void updateFailsafeUI(unsigned channel, quint8 updtSb); }; class SetupPanel : public ModelPanel diff --git a/companion/src/modelprinter.cpp b/companion/src/modelprinter.cpp index ac9f6f066..dde8517e0 100644 --- a/companion/src/modelprinter.cpp +++ b/companion/src/modelprinter.cpp @@ -897,9 +897,8 @@ QString ModelPrinter::printFailsafe(int idx) ModuleData module = model.moduleData[idx]; strl << printLabelValue(tr("Failsafe Mode"), printFailsafeMode(module.failsafeMode)); if (module.failsafeMode == FAILSAFE_CUSTOM) { - for (int i=0; i