From 56ceaebeb8a0f5e2eabf9b82ff3e6a95f008fa6d Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Thu, 23 Dec 2021 11:02:03 +0100 Subject: [PATCH] Use proper switch lookup --- .../firmwares/edgetx/yaml_switchconfig.cpp | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_switchconfig.cpp b/companion/src/firmwares/edgetx/yaml_switchconfig.cpp index 7ba57903a..75b0e05af 100644 --- a/companion/src/firmwares/edgetx/yaml_switchconfig.cpp +++ b/companion/src/firmwares/edgetx/yaml_switchconfig.cpp @@ -69,25 +69,20 @@ std::string YamlStickLookup::idx2name(unsigned int idx) int YamlSwitchLookup::name2idx(const std::string& name) { - // TODO: replace this with a real lookup of available switches - if (name.size() == 2 - && name[0] == 'S' - && (name[1] >= 'A' && name[1] <= 'J')) { + auto fw = getCurrentFirmware(); + int idx = fw->getSwitchesIndex(name.c_str()); + if (idx < 0) return -1; - return name[1] - 'A'; - } - - return -1; + return idx; } std::string YamlSwitchLookup::idx2name(unsigned int idx) { - // TODO: replace this with a real lookup of available switches - if (idx < 10) { - return std::string("S") + (char)('A' + idx); - } + auto fw = getCurrentFirmware(); + unsigned int switches = Boards::getCapability(fw->getBoard(), Board::Switches); + if (idx >= switches) return std::string(); - return std::string(); + return fw->getSwitchesTag(idx); } int YamlPotLookup::name2idx(const std::string& name)