diff --git a/companion/src/eeprominterface.cpp b/companion/src/eeprominterface.cpp index e8d47a139..24d0cdf3f 100644 --- a/companion/src/eeprominterface.cpp +++ b/companion/src/eeprominterface.cpp @@ -507,6 +507,21 @@ QString RawSource::toString(const ModelData * model) const } } +bool RawSource::isPot() const +{ + return (type == SOURCE_TYPE_STICK && + index >= NUM_STICKS && + index < NUM_STICKS+GetCurrentFirmware()->getCapability(Pots)); +} + +bool RawSource::isSlider() const +{ + return (type == SOURCE_TYPE_STICK && + index >= NUM_STICKS+GetCurrentFirmware()->getCapability(Pots) && + index < NUM_STICKS+GetCurrentFirmware()->getCapability(Pots)+GetCurrentFirmware()->getCapability(Sliders)); +} + + QString SwitchUp(const char sw) { const char result[] = {'S', sw, upArrow[0], upArrow[1], upArrow[2], 0}; @@ -1016,6 +1031,18 @@ bool GeneralSettings::switchSourceAllowedTaranis(int index) const return switchConfig[index] != SWITCH_NONE; } +bool GeneralSettings::isPotAvailable(int index) const +{ + if (index<0 || index>4) return false; + return potConfig[index] != POT_NONE; +} + +bool GeneralSettings::isSliderAvailable(int index) const +{ + if (index<0 || index>4) return false; + return sliderConfig[index] != SLIDER_NONE; +} + GeneralSettings::GeneralSettings() { memset(this, 0, sizeof(GeneralSettings)); diff --git a/companion/src/eeprominterface.h b/companion/src/eeprominterface.h index c20edeeda..9dfa19690 100644 --- a/companion/src/eeprominterface.h +++ b/companion/src/eeprominterface.h @@ -346,6 +346,8 @@ class RawSource { } bool isTimeBased() const; + bool isPot() const; + bool isSlider() const; RawSourceType type; int index; @@ -1204,6 +1206,8 @@ class GeneralSettings { static SwitchInfo switchInfoFromSwitchPositionTaranis(unsigned int index); bool switchPositionAllowedTaranis(int index) const; bool switchSourceAllowedTaranis(int index) const; + bool isPotAvailable(int index) const; + bool isSliderAvailable(int index) const; }; class RadioData { diff --git a/companion/src/firmwares/opentx/opentxinterface.cpp b/companion/src/firmwares/opentx/opentxinterface.cpp index 822afb8da..c59679ced 100644 --- a/companion/src/firmwares/opentx/opentxinterface.cpp +++ b/companion/src/firmwares/opentx/opentxinterface.cpp @@ -576,10 +576,8 @@ int OpenTxFirmware::getCapability(const Capability capability) case Pots: if (IS_TARANIS_X9E(board)) return 4; - else if (IS_TARANIS_PLUS(board)) - return 3; else if (IS_TARANIS(board)) - return 2; + return 3; //Taranis has only 2 pots but still has a placeholder in settings for 3 pots else return 3; case Sliders: diff --git a/companion/src/helpers.cpp b/companion/src/helpers.cpp index 0ca4208f5..a431385ec 100644 --- a/companion/src/helpers.cpp +++ b/companion/src/helpers.cpp @@ -562,8 +562,11 @@ void populateSourceCB(QComboBox *b, const RawSource & source, const GeneralSetti } if (flags & POPULATE_SOURCES) { - for (int i=0; i<4+GetCurrentFirmware()->getCapability(Pots); i++) { + for (int i=0; igetCapability(Pots)+GetCurrentFirmware()->getCapability(Sliders); i++) { item = RawSource(SOURCE_TYPE_STICK, i); + // skip unavailable pots and sliders + if (item.isPot() && !generalSettings.isPotAvailable(i-NUM_STICKS)) continue; + if (item.isSlider() && !generalSettings.isSliderAvailable(i-NUM_STICKS-GetCurrentFirmware()->getCapability(Pots))) continue; b->addItem(item.toString(model), item.toValue()); if (item == source) b->setCurrentIndex(b->count()-1); } @@ -938,7 +941,7 @@ void startSimulation(QWidget * parent, RadioData & radioData, int modelIdx) SimulatorDialog * sd; if (IS_TARANIS(board)) { for (int i=0; igetCapability(Pots); i++) { - if (radioData.generalSettings.potConfig[i] != GeneralSettings::POT_NONE) { + if (radioData.generalSettings.isPotAvailable(i)) { flags |= (SIMULATOR_FLAGS_S1 << i); if (radioData.generalSettings.potConfig[1] == GeneralSettings::POT_MULTIPOS_SWITCH ) { flags |= (SIMULATOR_FLAGS_S1_MULTI << i); diff --git a/companion/src/modeledit/setup.cpp b/companion/src/modeledit/setup.cpp index e12ec95fc..0483b81d7 100644 --- a/companion/src/modeledit/setup.cpp +++ b/companion/src/modeledit/setup.cpp @@ -517,15 +517,12 @@ SetupPanel::SetupPanel(QWidget *parent, ModelData & model, GeneralSettings & gen connect(checkbox, SIGNAL(toggled(bool)), this, SLOT(onBeepCenterToggled(bool))); centerBeepCheckboxes << checkbox; if (IS_TARANIS(board)) { - if (i >= NUM_STICKS && i < NUM_STICKS + firmware->getCapability(Pots)) { - if (generalSettings.potConfig[i-NUM_STICKS] == GeneralSettings::POT_NONE) { - checkbox->hide(); - } + RawSource src(SOURCE_TYPE_STICK, i); + if (src.isPot() && !generalSettings.isPotAvailable(i-NUM_STICKS)) { + checkbox->hide(); } - else if (i >= NUM_STICKS + firmware->getCapability(Pots) && i < analogs) { - if (generalSettings.sliderConfig[i-NUM_STICKS-firmware->getCapability(Pots)] == GeneralSettings::SLIDER_NONE) { - checkbox->hide(); - } + else if (src.isSlider() && !generalSettings.isSliderAvailable(i-NUM_STICKS-firmware->getCapability(Pots))) { + checkbox->hide(); } } QWidget::setTabOrder(prevFocus, checkbox); @@ -592,13 +589,13 @@ SetupPanel::SetupPanel(QWidget *parent, ModelData & model, GeneralSettings & gen ui->potWarningLayout->addWidget(cb, 0, i+1); connect(cb, SIGNAL(toggled(bool)), this, SLOT(potWarningToggled(bool))); potWarningCheckboxes << cb; - if (i < firmware->getCapability(Pots)) { - if (generalSettings.potConfig[i] == GeneralSettings::POT_NONE) { + if (RawSource(SOURCE_TYPE_STICK,i).isPot()) { + if (!generalSettings.isPotAvailable(i)) { cb->hide(); } } else { - if (generalSettings.sliderConfig[i-firmware->getCapability(Pots)] == GeneralSettings::SLIDER_NONE) { + if (!generalSettings.isSliderAvailable(i-firmware->getCapability(Pots))) { cb->hide(); } }