diff --git a/companion/src/firmwares/edgetx/yaml_mixdata.cpp b/companion/src/firmwares/edgetx/yaml_mixdata.cpp index 614497450..4fbb0daa3 100644 --- a/companion/src/firmwares/edgetx/yaml_mixdata.cpp +++ b/companion/src/firmwares/edgetx/yaml_mixdata.cpp @@ -96,35 +96,30 @@ namespace YAML { ENUM_CONVERTER(MltpxValue, mixMultiplexLut); -template <> -struct convert { - static Node encode(const CurveReference& rhs) - { - Node node; - node["type"] = (int)rhs.type; - node["value"] = rhs.value; - return node; - } +Node convert::encode(const CurveReference& rhs) +{ + Node node; + node["type"] = (int)rhs.type; + node["value"] = rhs.value; + return node; +} - static bool decode(const Node& node, CurveReference& rhs) - { - // no symbolic value defined in radio - int type = 0; - node["type"] >> type; - rhs.type = (CurveReference::CurveRefType)type; +bool convert::decode(const Node& node, CurveReference& rhs) +{ + // no symbolic value defined in radio + int type = 0; + node["type"] >> type; + rhs.type = (CurveReference::CurveRefType)type; - node["value"] >> rhs.value; - return true; - } -}; + node["value"] >> rhs.value; + return true; +} Node convert::encode(const MixData& rhs) { Node node; node["destCh"] = rhs.destCh - 1; - - // node["srcRaw"] = rhs.srcRaw; // r_mixSrcRaw - + node["srcRaw"] = rhs.srcRaw; node["weight"] = writeMixWeight(rhs.weight); node["swtch"] = rhs.swtch; node["curve"] = rhs.curve; @@ -159,7 +154,6 @@ bool convert::decode(const Node& node, MixData& rhs) if (!weight_str.empty()) { rhs.weight = readMixWeight(weight_str); } - node["swtch"] >> rhs.swtch; node["curve"] >> rhs.curve; node["delayUp"] >> rhs.delayUp; diff --git a/companion/src/firmwares/edgetx/yaml_mixdata.h b/companion/src/firmwares/edgetx/yaml_mixdata.h index 1ef01db7a..2c20166a8 100644 --- a/companion/src/firmwares/edgetx/yaml_mixdata.h +++ b/companion/src/firmwares/edgetx/yaml_mixdata.h @@ -21,7 +21,13 @@ #include "yaml_ops.h" #include "mixdata.h" -namespace YAML { +namespace YAML +{ +template <> +struct convert { + static Node encode(const CurveReference& rhs); + static bool decode(const Node& node, CurveReference& rhs); +}; template <> struct convert { diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index 2adb23b6e..cf8348129 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -22,6 +22,7 @@ #include "yaml_rawswitch.h" #include "yaml_mixdata.h" #include "modeldata.h" +#include "output_data.h" #include @@ -77,6 +78,38 @@ bool convert::decode(const Node& node, TimerData& rhs) return true; } +template <> +struct convert { + static Node encode(const LimitData& rhs) + { + Node node; + node["min"] = rhs.min; + node["max"] = rhs.max; + node["revert"] = rhs.revert; + node["offset"] = rhs.offset; + node["ppmCenter"] = rhs.ppmCenter; + node["symetrical"] = rhs.symetrical; + node["failsafe"] = rhs.failsafe; + node["name"] = rhs.name; + node["curve"] = rhs.curve; + return node; + } + + static bool decode(const Node& node, LimitData& rhs) + { + node["min"] >> rhs.min; + node["max"] >> rhs.max; + node["revert"] >> rhs.revert; + node["offset"] >> rhs.offset; + node["ppmCenter"] >> rhs.ppmCenter; + node["symetrical"] >> rhs.symetrical; + node["failsafe"] >> rhs.failsafe; + node["name"] >> rhs.name; + node["curve"] >> rhs.curve; + return true; + } +}; + Node convert::encode(const ModelData& rhs) { Node node; @@ -101,6 +134,7 @@ Node convert::encode(const ModelData& rhs) node["throttleReversed"] = (int)rhs.throttleReversed; // flightModeData[] + for (int i=0; i::encode(const ModelData& rhs) node["mixData"].push_back(mixNode); } } - // limitData[] + + for (int i=0; i::decode(const Node& node, ModelData& rhs) node["throttleReversed"] >> rhs.throttleReversed; // flightModeData[] - // mixData[] + node["mixData"] >> rhs.mixData; - // limitData[] + node["limitData"] >> rhs.limitData; + // inputNames[] // expoData[] // curves[] diff --git a/companion/src/firmwares/edgetx/yaml_rawsource.cpp b/companion/src/firmwares/edgetx/yaml_rawsource.cpp index 426a9a743..0c459fbce 100644 --- a/companion/src/firmwares/edgetx/yaml_rawsource.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawsource.cpp @@ -71,11 +71,74 @@ const YamlLookupTable specialSourceLut = { namespace YAML { -//ENUM_CONVERTER(RawSourceType, sourceTypeLut); - Node convert::encode(const RawSource& rhs) { std::string src_str; + switch(rhs.type) { + case SOURCE_TYPE_VIRTUAL_INPUT: + src_str += "I" + std::to_string(rhs.index); + break; + case SOURCE_TYPE_LUA_OUTPUT: + src_str += "lua("; + src_str += std::to_string(rhs.index / 16); + src_str += ","; + src_str += std::to_string(rhs.index % 16); + src_str += ")"; + break; + case SOURCE_TYPE_STICK: + src_str = LookupValue(analogSourceLut, rhs.index); + break; + case SOURCE_TYPE_TRIM: + src_str = LookupValue(trimSourceLut, rhs.index); + break; + case SOURCE_TYPE_MAX: + src_str += "MAX"; + break; + case SOURCE_TYPE_SWITCH: + src_str += "S" + (rhs.index + 'A'); + break; + case SOURCE_TYPE_CUSTOM_SWITCH: + src_str += "ls("; + src_str += std::to_string(rhs.index); + src_str += ")"; + break; + case SOURCE_TYPE_CYC: + src_str = LookupValue(cycSourceLut, rhs.index); + break; + case SOURCE_TYPE_PPM: + src_str += "tr("; + src_str += std::to_string(rhs.index); + src_str += ")"; + break; + case SOURCE_TYPE_CH: + src_str += "ch("; + src_str += std::to_string(rhs.index); + src_str += ")"; + break; + case SOURCE_TYPE_GVAR: + src_str += "gv("; + src_str += std::to_string(rhs.index); + src_str += ")"; + break; + case SOURCE_TYPE_SPECIAL: + src_str = LookupValue(specialSourceLut, rhs.index); + break; + case SOURCE_TYPE_TELEMETRY: + src_str = "tele("; + switch(rhs.index % 3) { + case 0: + break; + case 1: + src_str += '-'; + break; + case 2: + src_str += '+'; + break; + } + src_str += std::to_string(rhs.index / 3); + break; + } + return Node(src_str); } @@ -89,6 +152,13 @@ bool convert::decode(const Node& node, RawSource& rhs) rhs = RawSource(SOURCE_TYPE_VIRTUAL_INPUT, std::stoi(src_str.substr(1))); + } else if (val_len >= 2 + && val[0] == 'S' + && val[1] >= 'A' + && val[1] <= 'Z') { + + rhs = RawSource(SOURCE_TYPE_SWITCH, val[1] - 'A'); + } else if (val_len > 4 && val[0] == 'l' && val[1] == 'u' && @@ -189,6 +259,12 @@ bool convert::decode(const Node& node, RawSource& rhs) rhs.type = SOURCE_TYPE_SPECIAL; rhs.index = conv.as(); } + + if (node.IsScalar() + && node.as() == "MAX") { + rhs.type = SOURCE_TYPE_MAX; + rhs.index = 0; + } } // TODO: raw analogs