diff --git a/companion/src/firmwares/edgetx/yaml_rawsource.cpp b/companion/src/firmwares/edgetx/yaml_rawsource.cpp index ba7ca7d10..21dccdf26 100644 --- a/companion/src/firmwares/edgetx/yaml_rawsource.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawsource.cpp @@ -31,16 +31,6 @@ const YamlLookupTable trimSourceLut = { { 5, "TrimT6" }, }; -// SOURCE_TYPE_CYC -const YamlLookupTable cycSourceLut = { - { 0, "CYC1" }, - { 1, "CYC2" }, - { 2, "CYC3" }, -}; - -// SOURCE_TYPE_MAX - // { MIXSRC_MAX, "MAX" }, - std::string YamlRawSourceEncode(const RawSource& rhs) { std::string src_str; @@ -74,7 +64,7 @@ std::string YamlRawSourceEncode(const RawSource& rhs) src_str += ")"; break; case SOURCE_TYPE_CYC: - src_str = YAML::LookupValue(cycSourceLut, rhs.index); + src_str = getCurrentFirmware()->getRawSourceCyclicTag(rhs.index); break; case SOURCE_TYPE_PPM: src_str += "tr("; @@ -236,10 +226,10 @@ RawSource YamlRawSourceDecode(const std::string& src_str) rhs.index = conv.as(); } - conv = node >> cycSourceLut; - if (conv.IsScalar()) { + int cyc_idx = getCurrentFirmware()->getRawSourceCyclicIndex(src_str.c_str()); + if (cyc_idx >= 0) { rhs.type = SOURCE_TYPE_CYC; - rhs.index = conv.as(); + rhs.index = cyc_idx; } int sp_idx = getCurrentFirmware()->getRawSourceSpecialTypesIndex(src_str.c_str()); diff --git a/companion/src/firmwares/eeprominterface.cpp b/companion/src/firmwares/eeprominterface.cpp index 458a69dff..56d039bbc 100644 --- a/companion/src/firmwares/eeprominterface.cpp +++ b/companion/src/firmwares/eeprominterface.cpp @@ -308,3 +308,29 @@ std::string Firmware::getRawSourceSpecialTypesTag(unsigned int index) return std::string(); } + +int Firmware::getRawSourceCyclicIndex(const char * tag) +{ + const StringTagMappingTable& lut = rawSourceCyclicLookupTable; + + auto it = + find_if(lut.begin(), lut.end(), [=](const StringTagMapping& elmt) { + if (elmt.tag == tag) return true; + return false; + }); + + if (it != lut.end()) { + return it - lut.begin(); + } + + return -1; +} + +std::string Firmware::getRawSourceCyclicTag(unsigned int index) +{ + const StringTagMappingTable& lut = rawSourceCyclicLookupTable; + if (index < lut.size()) + return lut[index].tag; + + return std::string(); +} diff --git a/companion/src/firmwares/eeprominterface.h b/companion/src/firmwares/eeprominterface.h index 049e0ba12..c61d921a5 100644 --- a/companion/src/firmwares/eeprominterface.h +++ b/companion/src/firmwares/eeprominterface.h @@ -295,7 +295,8 @@ class Firmware switchesLookupTable(Boards::getSwitchesLookupTable(board)), trimSwitchesLookupTable(Boards::getTrimSwitchesLookupTable(board)), rawSwitchTypesLookupTable(RawSwitch::getRawSwitchTypesLookupTable()), - rawSourceSpecialTypesLookupTable(RawSource::getSpecialTypesLookupTable()) + rawSourceSpecialTypesLookupTable(RawSource::getSpecialTypesLookupTable()), + rawSourceCyclicLookupTable(RawSource::getCyclicLookupTable()) { } @@ -429,6 +430,11 @@ class Firmware return &rawSourceSpecialTypesLookupTable; } + const StringTagMappingTable* getRawSourceCyclicLookupTable() + { + return &rawSourceCyclicLookupTable; + } + int getAnalogInputIndex(const char * tag); std::string getAnalogInputTag(unsigned int index); int getSwitchesIndex(const char * tag); @@ -439,6 +445,8 @@ class Firmware std::string getRawSwitchTypesTag(unsigned int index); int getRawSourceSpecialTypesIndex(const char * tag); std::string getRawSourceSpecialTypesTag(unsigned int index); + int getRawSourceCyclicIndex(const char * tag); + std::string getRawSourceCyclicTag(unsigned int index); protected: QString id; @@ -452,6 +460,7 @@ class Firmware const StringTagMappingTable trimSwitchesLookupTable; const StringTagMappingTable rawSwitchTypesLookupTable; const StringTagMappingTable rawSourceSpecialTypesLookupTable; + const StringTagMappingTable rawSourceCyclicLookupTable; QList languages; //QList ttslanguages; OptionsList opts; diff --git a/companion/src/firmwares/rawsource.cpp b/companion/src/firmwares/rawsource.cpp index 030ec3753..b1ad52e30 100644 --- a/companion/src/firmwares/rawsource.cpp +++ b/companion/src/firmwares/rawsource.cpp @@ -439,3 +439,17 @@ tbl.insert(tbl.end(), { return tbl; } + +// static +StringTagMappingTable RawSource::getCyclicLookupTable() +{ + StringTagMappingTable tbl; + +tbl.insert(tbl.end(), { + {"0", "CYC1"}, + {"1", "CYC2"}, + {"2", "CYC3"}, + }); + + return tbl; +} diff --git a/companion/src/firmwares/rawsource.h b/companion/src/firmwares/rawsource.h index 88339d514..304024446 100644 --- a/companion/src/firmwares/rawsource.h +++ b/companion/src/firmwares/rawsource.h @@ -276,6 +276,7 @@ class RawSource { QStringList getStickList(Boards board) const; QStringList getSwitchList(Boards board) const; static StringTagMappingTable getSpecialTypesLookupTable(); + static StringTagMappingTable getCyclicLookupTable(); bool operator == ( const RawSource & other) const { return (this->type == other.type) && (this->index == other.index);