diff --git a/companion/src/firmwares/edgetx/yaml_expodata.cpp b/companion/src/firmwares/edgetx/yaml_expodata.cpp index 547c85ff4f7..f0cfa2e91b6 100644 --- a/companion/src/firmwares/edgetx/yaml_expodata.cpp +++ b/companion/src/firmwares/edgetx/yaml_expodata.cpp @@ -35,8 +35,8 @@ Node convert::encode(const ExpoData& rhs) node["chn"] = rhs.chn; node["swtch"] = rhs.swtch; node["flightModes"] = YamlWriteFlightModes(rhs.flightModes); - node["weight"] = YamlWriteMixWeight(rhs.weight); - node["offset"] = YamlWriteMixWeight(rhs.offset); + node["weight"] = YamlSourceNumRefEncode(rhs.weight); + node["offset"] = YamlSourceNumRefEncode(rhs.offset); node["curve"] = rhs.curve; node["trimSource"] = rhs.carryTrim; // temporary for 2.8.1, trimSource in 2.9 node["name"] = rhs.name; @@ -54,10 +54,10 @@ bool convert::decode(const Node& node, ExpoData& rhs) rhs.flightModes = YamlReadFlightModes(node["flightModes"]); } if (node["weight"]) { - rhs.weight = YamlReadMixWeight(node["weight"]); + rhs.weight = YamlSourceNumRefDecode(node["weight"]); } if (node["offset"]) { - rhs.offset = YamlReadMixWeight(node["offset"]); + rhs.offset = YamlSourceNumRefDecode(node["offset"]); } node["curve"] >> rhs.curve; if (node["carryTrim"]) { // 2.9 - change bugged carryTrim to trimSource diff --git a/companion/src/firmwares/edgetx/yaml_mixdata.cpp b/companion/src/firmwares/edgetx/yaml_mixdata.cpp index cb5f39e092a..1fb976df71b 100644 --- a/companion/src/firmwares/edgetx/yaml_mixdata.cpp +++ b/companion/src/firmwares/edgetx/yaml_mixdata.cpp @@ -22,6 +22,7 @@ #include "yaml_rawswitch.h" #include "yaml_rawsource.h" #include "curvereference.h" +#include "sourcenumref.h" static const YamlLookupTable mixMultiplexLut = { { MLTPX_ADD, "ADD" }, @@ -74,6 +75,51 @@ std::string YamlWriteMixWeight(int32_t sval) return std::to_string(sval); } +int32_t YamlSourceNumRefDecode(const YAML::Node& node) +{ + std::string val = node.as(); + + // start legacy for pre 2.11 + if ((val.size() >= 4) + && (val[0] == '-') + && (val[1] == 'G') + && (val[2] == 'V') + && (val[3] >= '1') + && (val[3] <= '9')) { + + return RawSource(SOURCE_TYPE_GVAR, val[3]).toValue(); + } + + if ((val.size() >= 3) + && (val[0] == 'G') + && (val[1] == 'V') + && (val[2] >= '1') + && (val[2] <= '9')) { + + return RawSource(SOURCE_TYPE_GVAR, val[2]).toValue(); + } + // end legacy for pre 2.11 + + int i = val[0] == '-' ? 1 : 0; + + if (val[i] >= '0' && val[i] <= '9') + try { + return std::stoi(val); + } catch(...) { + throw YAML::TypedBadConversion(node.Mark()); + } + else + return YamlRawSourceDecode(val).toValue(); +} + +std::string YamlSourceNumRefEncode(int32_t sval) +{ + if (SourceNumRef(sval).isNumber()) + return std::to_string(sval); + else + return YamlRawSourceEncode(RawSource(sval)); +} + uint32_t YamlReadFlightModes(const YAML::Node& node) { std::string fm_str = node.as(); @@ -108,7 +154,7 @@ Node convert::encode(const CurveReference& rhs) { Node node; node["type"] = (int)rhs.type; - node["value"] = YamlWriteMixWeight(rhs.value); + node["value"] = YamlSourceNumRefEncode(rhs.value); return node; } @@ -119,7 +165,7 @@ bool convert::decode(const Node& node, CurveReference& rhs) node["type"] >> type; rhs.type = (CurveReference::CurveRefType)type; if (node["value"]) { - rhs.value = YamlReadMixWeight(node["value"]); + rhs.value = YamlSourceNumRefDecode(node["value"]); } return true; } @@ -129,7 +175,7 @@ Node convert::encode(const MixData& rhs) Node node; node["destCh"] = rhs.destCh - 1; node["srcRaw"] = rhs.srcRaw; - node["weight"] = YamlWriteMixWeight(rhs.weight); + node["weight"] = YamlSourceNumRefEncode(rhs.weight); node["swtch"] = rhs.swtch; node["curve"] = rhs.curve; node["delayUp"] = rhs.delayUp; @@ -141,7 +187,7 @@ Node convert::encode(const MixData& rhs) node["mltpx"] = rhs.mltpx; node["mixWarn"] = rhs.mixWarn; node["flightModes"] = YamlWriteFlightModes(rhs.flightModes); - node["offset"] = YamlWriteMixWeight(rhs.sOffset); + node["offset"] = YamlSourceNumRefEncode(rhs.sOffset); node["name"] = rhs.name; return node; } @@ -151,7 +197,7 @@ bool convert::decode(const Node& node, MixData& rhs) node["destCh"] >> ioffset_int((int&)rhs.destCh, -1); node["srcRaw"] >> rhs.srcRaw; if (node["weight"]) { - rhs.weight = YamlReadMixWeight(node["weight"]); + rhs.weight = YamlSourceNumRefDecode(node["weight"]); } node["swtch"] >> rhs.swtch; node["curve"] >> rhs.curve; @@ -167,7 +213,7 @@ bool convert::decode(const Node& node, MixData& rhs) rhs.flightModes = YamlReadFlightModes(node["flightModes"]); } if (node["offset"]) { - rhs.sOffset = YamlReadMixWeight(node["offset"]); + rhs.sOffset = YamlSourceNumRefDecode(node["offset"]); } node["name"] >> rhs.name; return true; diff --git a/companion/src/firmwares/edgetx/yaml_mixdata.h b/companion/src/firmwares/edgetx/yaml_mixdata.h index 0b08702f663..edbb5088f42 100644 --- a/companion/src/firmwares/edgetx/yaml_mixdata.h +++ b/companion/src/firmwares/edgetx/yaml_mixdata.h @@ -24,6 +24,9 @@ int32_t YamlReadMixWeight(const YAML::Node& node); std::string YamlWriteMixWeight(int32_t sval); +int32_t YamlSourceNumRefDecode(const YAML::Node& node); +std::string YamlSourceNumRefEncode(int32_t sval); + uint32_t YamlReadFlightModes(const YAML::Node& node); std::string YamlWriteFlightModes(uint32_t val);