From d9d58d637b9b61d2660cf1053ba39895126d186c Mon Sep 17 00:00:00 2001 From: 3djc Date: Sat, 14 Nov 2020 14:59:12 +0100 Subject: [PATCH] Prevent selection of impossible switch type in radio hardware (#8083) * Prevent selection of impossible switch type in radio hardware --- companion/src/firmwares/boards.cpp | 18 ++++++++++++++- companion/src/generaledit/hardware.cpp | 31 +++++++++++++++++--------- companion/src/generaledit/hardware.h | 1 + 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/companion/src/firmwares/boards.cpp b/companion/src/firmwares/boards.cpp index 570b3cdfc..35f7a0bab 100644 --- a/companion/src/firmwares/boards.cpp +++ b/companion/src/firmwares/boards.cpp @@ -231,7 +231,23 @@ SwitchInfo Boards::getSwitchInfo(Board::Type board, int index) if (index < DIM(switches)) return switches[index]; } - else if (IS_HORUS_OR_TARANIS(board)) { + else if (IS_FAMILY_HORUS_OR_T16(board)) { + const Board::SwitchInfo switches[] = { + {SWITCH_3POS, "SA"}, + {SWITCH_3POS, "SB"}, + {SWITCH_3POS, "SC"}, + {SWITCH_3POS, "SD"}, + {SWITCH_3POS, "SE"}, + {SWITCH_2POS, "SF"}, + {SWITCH_3POS, "SG"}, + {SWITCH_TOGGLE, "SH"}, + {SWITCH_2POS, "SI"}, + {SWITCH_2POS, "SJ"} + }; + if (index < DIM(switches)) + return switches[index]; + } + else if (IS_TARANIS(board)) { const Board::SwitchInfo switches[] = { {SWITCH_3POS, "SA"}, {SWITCH_3POS, "SB"}, diff --git a/companion/src/generaledit/hardware.cpp b/companion/src/generaledit/hardware.cpp index babf828dd..9d2e8e452 100644 --- a/companion/src/generaledit/hardware.cpp +++ b/companion/src/generaledit/hardware.cpp @@ -109,6 +109,15 @@ void HardwarePanel::setupSliderType(int index, QLabel *label, AutoLineEdit *name } } +bool HardwarePanel::isSwitch3Pos(int idx) +{ + Board::Type board = firmware->getBoard(); + Board::SwitchInfo switchInfo = Boards::getSwitchInfo(board, idx); + + switchInfo.config = Board::SwitchType(generalSettings.switchConfig[idx]); + return switchInfo.config == Board::SWITCH_3POS; +}; + HardwarePanel::HardwarePanel(QWidget * parent, GeneralSettings & generalSettings, Firmware * firmware): GeneralPanel(parent, generalSettings, firmware), ui(new Ui::Hardware) @@ -155,17 +164,17 @@ HardwarePanel::HardwarePanel(QWidget * parent, GeneralSettings & generalSettings setupSliderType(2, ui->ls2Label, ui->ls2Name, ui->ls2Type); setupSliderType(3, ui->rs2Label, ui->rs2Name, ui->rs2Type); - setupSwitchType(0, ui->saLabel, ui->saName, ui->saType); - setupSwitchType(1, ui->sbLabel, ui->sbName, ui->sbType); - setupSwitchType(2, ui->scLabel, ui->scName, ui->scType); - setupSwitchType(3, ui->sdLabel, ui->sdName, ui->sdType); - setupSwitchType(4, ui->seLabel, ui->seName, ui->seType); - setupSwitchType(5, ui->sfLabel, ui->sfName, ui->sfType); - setupSwitchType(6, ui->sgLabel, ui->sgName, ui->sgType); - setupSwitchType(7, ui->shLabel, ui->shName, ui->shType, false); //switch does not support 3POS - setupSwitchType(8, ui->siLabel, ui->siName, ui->siType); - setupSwitchType(9, ui->sjLabel, ui->sjName, ui->sjType); - setupSwitchType(10, ui->skLabel, ui->skName, ui->skType); + setupSwitchType(0, ui->saLabel, ui->saName, ui->saType, isSwitch3Pos(0)); + setupSwitchType(1, ui->sbLabel, ui->sbName, ui->sbType, isSwitch3Pos(1)); + setupSwitchType(2, ui->scLabel, ui->scName, ui->scType, isSwitch3Pos(2)); + setupSwitchType(3, ui->sdLabel, ui->sdName, ui->sdType, isSwitch3Pos(3)); + setupSwitchType(4, ui->seLabel, ui->seName, ui->seType, isSwitch3Pos(4)); + setupSwitchType(5, ui->sfLabel, ui->sfName, ui->sfType, isSwitch3Pos(5)); + setupSwitchType(6, ui->sgLabel, ui->sgName, ui->sgType, isSwitch3Pos(6)); + setupSwitchType(7, ui->shLabel, ui->shName, ui->shType, isSwitch3Pos(7)); + setupSwitchType(8, ui->siLabel, ui->siName, ui->siType, isSwitch3Pos(8)); + setupSwitchType(9, ui->sjLabel, ui->sjName, ui->sjType, isSwitch3Pos(9)); + setupSwitchType(10, ui->skLabel, ui->skName, ui->skType); // Here starts X9E, only 3 switches setupSwitchType(11, ui->slLabel, ui->slName, ui->slType); setupSwitchType(12, ui->smLabel, ui->smName, ui->smType); setupSwitchType(13, ui->snLabel, ui->snName, ui->snType); diff --git a/companion/src/generaledit/hardware.h b/companion/src/generaledit/hardware.h index 39d3fcd53..3b63a1d77 100644 --- a/companion/src/generaledit/hardware.h +++ b/companion/src/generaledit/hardware.h @@ -63,6 +63,7 @@ class HardwarePanel : public GeneralPanel Ui::Hardware *ui; void setValues(); + bool isSwitch3Pos(int idx); }; #endif // _HARDWARE_H_