diff --git a/companion/src/firmwares/edgetx/yaml_rawsource.cpp b/companion/src/firmwares/edgetx/yaml_rawsource.cpp index 1b345d3a1..e05c10dd2 100644 --- a/companion/src/firmwares/edgetx/yaml_rawsource.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawsource.cpp @@ -19,25 +19,7 @@ */ #include "yaml_rawsource.h" - -// SOURCE_TYPE_STICK -const YamlLookupTable analogSourceLut = { - { 0, "Rud" }, - { 1, "Ele" }, - { 2, "Thr" }, - { 3, "Ail" }, - { 4, "S1" }, - { 5, "6POS" }, - { 6, "S2" }, - { 7, "EXT1" }, { 7, "S3" }, // rename to use only S3 - { 8, "EXT2" }, { 8, "S4" }, // rename to use only S4 - // { 9, "EXT3" }, - // { 10, "EXT4" }, - { 9, "LS" }, - { 10, "RS" }, - { 11, "MOUSE1" }, - { 12, "MOUSE2" }, -}; +#include "eeprominterface.h" // SOURCE_TYPE_TRIM const YamlLookupTable trimSourceLut = { @@ -85,7 +67,7 @@ Node convert::encode(const RawSource& rhs) src_str += ")"; break; case SOURCE_TYPE_STICK: - src_str = LookupValue(analogSourceLut, rhs.index); + src_str = getCurrentFirmware()->getAnalogInputTag(rhs.index); break; case SOURCE_TYPE_TRIM: src_str = LookupValue(trimSourceLut, rhs.index); @@ -239,35 +221,36 @@ bool convert::decode(const Node& node, RawSource& rhs) } else { - YAML::Node conv = node >> analogSourceLut; - if (conv.IsScalar()) { - rhs.type = SOURCE_TYPE_STICK; - rhs.index = conv.as(); - } + std::string ana_str; + node >> ana_str; + int ana_idx = getCurrentFirmware()->getAnalogInputIndex(ana_str.c_str()); + if (ana_idx >= 0) { + rhs.type = SOURCE_TYPE_STICK; + rhs.index = ana_idx; + } - conv = node >> trimSourceLut; - if (conv.IsScalar()) { - rhs.type = SOURCE_TYPE_TRIM; - rhs.index = conv.as(); - } + YAML::Node conv = node >> trimSourceLut; + if (conv.IsScalar()) { + rhs.type = SOURCE_TYPE_TRIM; + rhs.index = conv.as(); + } - conv = node >> cycSourceLut; - if (conv.IsScalar()) { - rhs.type = SOURCE_TYPE_CYC; - rhs.index = conv.as(); - } + conv = node >> cycSourceLut; + if (conv.IsScalar()) { + rhs.type = SOURCE_TYPE_CYC; + rhs.index = conv.as(); + } - conv = node >> specialSourceLut; - if (conv.IsScalar()) { - rhs.type = SOURCE_TYPE_SPECIAL; - rhs.index = conv.as(); - } + conv = node >> specialSourceLut; + if (conv.IsScalar()) { + rhs.type = SOURCE_TYPE_SPECIAL; + rhs.index = conv.as(); + } - if (node.IsScalar() - && node.as() == "MAX") { - rhs.type = SOURCE_TYPE_MAX; - rhs.index = 0; - } + if (node.IsScalar() && node.as() == "MAX") { + rhs.type = SOURCE_TYPE_MAX; + rhs.index = 0; + } } // TODO: raw analogs diff --git a/companion/src/firmwares/eeprominterface.cpp b/companion/src/firmwares/eeprominterface.cpp index e11716cba..cfa5ab5d1 100644 --- a/companion/src/firmwares/eeprominterface.cpp +++ b/companion/src/firmwares/eeprominterface.cpp @@ -195,3 +195,12 @@ int Firmware::getAnalogInputIndex(const char * tag) return -1; } + +std::string Firmware::getAnalogInputTag(unsigned int index) +{ + const StringTagMappingTable& lut = analogInputNamesLookupTable; + 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 6024ef1fd..cba7362fb 100644 --- a/companion/src/firmwares/eeprominterface.h +++ b/companion/src/firmwares/eeprominterface.h @@ -34,6 +34,7 @@ #include #include +#include const uint8_t modn12x3[4][4]= { {1, 2, 3, 4}, @@ -404,6 +405,7 @@ class Firmware } int getAnalogInputIndex(const char * tag); + std::string getAnalogInputTag(unsigned int index); protected: QString id;