From 3969b2b7e356cb1cbacad721ec6834bebb90d942 Mon Sep 17 00:00:00 2001 From: Peter Feerick Date: Sun, 25 Sep 2022 19:51:35 +1000 Subject: [PATCH] feat: Remove TR# mixsrc when trainer disabled (#2323) * feat: Remove TR# mixsrc when trainer disabled When trainer mode is not enabled, there is no point showing the TR# mixer sources. Once you enable a trainer option, they will become visible again. * fix: Add missing "Input" check for B&W radios * fix(cpn): Trainer mode default is off * chore(cpn): If trainer mode off, hide TR/PPM srcs * (cpn) Refresh all source lists on change of trainer mode Co-authored-by: elecpower --- companion/src/firmwares/modeldata.cpp | 2 +- companion/src/firmwares/rawsource.cpp | 3 +++ companion/src/modeledit/setup.cpp | 2 ++ radio/src/gui/common/stdlcd/model_inputs.cpp | 7 ++++++- radio/src/gui/gui_common.cpp | 5 ++++- 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/companion/src/firmwares/modeldata.cpp b/companion/src/firmwares/modeldata.cpp index c75cf47c5..855cd7f08 100644 --- a/companion/src/firmwares/modeldata.cpp +++ b/companion/src/firmwares/modeldata.cpp @@ -177,7 +177,7 @@ void ModelData::clear() for (unsigned i = 0; i < CPN_MAX_SENSORS; i++) sensorData[i].clear(); - trainerMode = TRAINER_MODE_MASTER_JACK; + trainerMode = TRAINER_MODE_OFF; const char * layoutId = "Layout2P1"; // currently all using same default though might change for NV14 RadioLayout::init(layoutId, customScreens); diff --git a/companion/src/firmwares/rawsource.cpp b/companion/src/firmwares/rawsource.cpp index a415c4708..86c13ef2d 100644 --- a/companion/src/firmwares/rawsource.cpp +++ b/companion/src/firmwares/rawsource.cpp @@ -333,6 +333,9 @@ bool RawSource::isAvailable(const ModelData * const model, const GeneralSettings if (type == SOURCE_TYPE_VIRTUAL_INPUT && !model->isInputValid(index)) return false; + if (type == SOURCE_TYPE_PPM && model->trainerMode == TRAINER_MODE_OFF) + return false; + if (type == SOURCE_TYPE_CUSTOM_SWITCH && model->logicalSw[index].isEmpty()) return false; diff --git a/companion/src/modeledit/setup.cpp b/companion/src/modeledit/setup.cpp index 217b2671f..0ba5d360a 100644 --- a/companion/src/modeledit/setup.cpp +++ b/companion/src/modeledit/setup.cpp @@ -247,6 +247,7 @@ ModulePanel::ModulePanel(QWidget * parent, ModelData & model, ModuleData & modul ui->trainerMode->setField(model.trainerMode); connect(ui->trainerMode, &AutoComboBox::currentDataChanged, this, [=] () { update(); + emit updateItemModels(); emit modified(); }); } @@ -1538,6 +1539,7 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge modules[CPN_MAX_MODULES] = new ModulePanel(this, model, model.moduleData[CPN_MAX_MODULES], generalSettings, firmware, -1, panelFilteredModels); ui->modulesLayout->addWidget(modules[CPN_MAX_MODULES]); connect(modules[CPN_MAX_MODULES], &ModulePanel::modified, this, &SetupPanel::modified); + connect(modules[CPN_MAX_MODULES], &ModulePanel::updateItemModels, this, &SetupPanel::onModuleUpdateItemModels); } disableMouseScrolling(); diff --git a/radio/src/gui/common/stdlcd/model_inputs.cpp b/radio/src/gui/common/stdlcd/model_inputs.cpp index 04c063933..d5da00322 100644 --- a/radio/src/gui/common/stdlcd/model_inputs.cpp +++ b/radio/src/gui/common/stdlcd/model_inputs.cpp @@ -55,7 +55,12 @@ void insertExpo(uint8_t idx) ExpoData * expo = expoAddress(idx); memmove(expo+1, expo, (MAX_EXPOS-(idx+1))*sizeof(ExpoData)); memclear(expo, sizeof(ExpoData)); - expo->srcRaw = (s_currCh > 4 ? MIXSRC_Rud - 1 + s_currCh : MIXSRC_Rud - 1 + channelOrder(s_currCh)); + for (int i = s_currCh; i < INPUTSRC_LAST; i++) { + expo->srcRaw = (s_currCh > 4 ? MIXSRC_Rud - 1 + i: MIXSRC_Rud - 1 + channelOrder(i)); + if (isSourceAvailableInInputs(expo->srcRaw)) { + break; + } + } expo->curve.type = CURVE_REF_EXPO; expo->mode = 3; // pos+neg expo->chn = s_currCh - 1; diff --git a/radio/src/gui/gui_common.cpp b/radio/src/gui/gui_common.cpp index 15ff140cc..8b81ca99a 100644 --- a/radio/src/gui/gui_common.cpp +++ b/radio/src/gui/gui_common.cpp @@ -230,6 +230,9 @@ bool isSourceAvailable(int source) if (source >= MIXSRC_FIRST_RESERVE && source <= MIXSRC_LAST_RESERVE) return false; + if (source >= MIXSRC_FIRST_TRAINER && source <= MIXSRC_LAST_TRAINER) + return g_model.trainerData.mode > 0; + if (source >= MIXSRC_FIRST_TELEM && source <= MIXSRC_LAST_TELEM) { div_t qr = div(source - MIXSRC_FIRST_TELEM, 3); if (qr.rem == 0) @@ -289,7 +292,7 @@ bool isSourceAvailableInInputs(int source) } if (source >= MIXSRC_FIRST_TRAINER && source <= MIXSRC_LAST_TRAINER) - return true; + return g_model.trainerData.mode > 0; if (source >= MIXSRC_FIRST_TELEM && source <= MIXSRC_LAST_TELEM) { div_t qr = div(source - MIXSRC_FIRST_TELEM, 3);