From 6cfecb7ddb2e5e3ad53f1a4e91183a25b36f48ac Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Thu, 30 Dec 2021 13:42:35 +0100 Subject: [PATCH] Fix output for empty params in custom functions (like "Play track") --- .../src/firmwares/edgetx/yaml_customfunctiondata.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp b/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp index 4975a207b..22d59f191 100644 --- a/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp +++ b/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp @@ -142,6 +142,7 @@ Node convert::encode(const CustomFunctionData& rhs) } node["func"] = LookupValue(customFnLut, fn); + bool add_comma = true; std::string def; switch(fn) { case FuncOverrideCH1: @@ -202,16 +203,17 @@ Node convert::encode(const CustomFunctionData& rhs) def += std::to_string(rhs.param); break; default: + add_comma = false; break; } if (fnHasEnable(rhs.func)) { - if (!def.empty()) { + if (add_comma) { def += ","; } def += std::to_string((int)rhs.enabled); } else if(fnHasRepeat(rhs.func)) { - if (!def.empty()) { + if (add_comma) { def += ","; } if (rhs.repeatParam == 0) { @@ -352,7 +354,9 @@ bool convert::decode(const Node& node, } else if (repeat == "!1x") { rhs.repeatParam = -1; } else { - rhs.repeatParam = std::stoi(repeat); + try { + rhs.repeatParam = std::stoi(repeat); + } catch(...) {} } }