From 37dffc264da23c942b870f37f3c161256b06f1d0 Mon Sep 17 00:00:00 2001 From: Neil Horne Date: Fri, 15 Jul 2022 20:32:56 +1000 Subject: [PATCH] fix(companion): Handling of Mixer Script yaml settings (#2016) --- .../src/firmwares/edgetx/yaml_modeldata.cpp | 33 +++++-------------- 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index c99366b3f..a69275118 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -519,23 +519,6 @@ struct convert { } }; -struct YamlScriptDataInput { int i; }; - -template <> -struct convert { - static Node encode(const YamlScriptDataInput& rhs) - { - Node node; - node["u"]["value"] = rhs.i; - return node; - } - static bool decode(const Node& node, YamlScriptDataInput& rhs) - { - node["u"]["value"] >> rhs.i; - return true; - } -}; - template <> struct convert { static Node encode(const ScriptData& rhs) @@ -545,7 +528,8 @@ struct convert { node["name"] = rhs.name; for (int i=0; i < 6; i++) { - node["inputs"][std::to_string(i)]["u"]["value"] = (int)rhs.inputs[i]; + if (rhs.inputs[i] != 0) + node["inputs"][std::to_string(i)]["u"]["value"] = (int)rhs.inputs[i]; } return node; @@ -556,11 +540,12 @@ struct convert { node["file"] >> rhs.filename; node["name"] >> rhs.name; - YamlScriptDataInput inputs[CPN_MAX_SCRIPT_INPUTS]; - node["inputs"] >> inputs; - for (int i=0; i < CPN_MAX_SCRIPT_INPUTS; i++) { - rhs.inputs[i] = inputs[i].i; + if (node["inputs"][std::to_string(i)]) { + if (node["inputs"][std::to_string(i)]["u"]["value"]) { + node["inputs"][std::to_string(i)]["u"]["value"] >> rhs.inputs[i]; + } + } } return true; @@ -938,7 +923,7 @@ Node convert::encode(const ModelData& rhs) for (int i=0; i 0) { - node["scriptData"][std::to_string(i)] = rhs.scriptData[i]; + node["scriptsData"][std::to_string(i)] = rhs.scriptData[i]; } } @@ -1135,7 +1120,7 @@ bool convert::decode(const Node& node, ModelData& rhs) trainer["pulsePol"] >> rhs.moduleData[2].ppm.pulsePol; } - node["scriptData"] >> rhs.scriptData; + node["scriptsData"] >> rhs.scriptData; node["telemetrySensors"] >> rhs.sensorData; node["toplcdTimer"] >> rhs.toplcdTimer;