Skip to content

Commit

Permalink
cpn yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
elecpower committed Jul 16, 2024
1 parent e4de23d commit efbe27f
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 10 deletions.
8 changes: 4 additions & 4 deletions companion/src/firmwares/edgetx/yaml_expodata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ Node convert<ExpoData>::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;
Expand All @@ -54,10 +54,10 @@ bool convert<ExpoData>::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
Expand Down
58 changes: 52 additions & 6 deletions companion/src/firmwares/edgetx/yaml_mixdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down Expand Up @@ -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<std::string>();

// 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<int>(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<std::string>();
Expand Down Expand Up @@ -108,7 +154,7 @@ Node convert<CurveReference>::encode(const CurveReference& rhs)
{
Node node;
node["type"] = (int)rhs.type;
node["value"] = YamlWriteMixWeight(rhs.value);
node["value"] = YamlSourceNumRefEncode(rhs.value);
return node;
}

Expand All @@ -119,7 +165,7 @@ bool convert<CurveReference>::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;
}
Expand All @@ -129,7 +175,7 @@ Node convert<MixData>::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;
Expand All @@ -141,7 +187,7 @@ Node convert<MixData>::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;
}
Expand All @@ -151,7 +197,7 @@ bool convert<MixData>::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;
Expand All @@ -167,7 +213,7 @@ bool convert<MixData>::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;
Expand Down
3 changes: 3 additions & 0 deletions companion/src/firmwares/edgetx/yaml_mixdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit efbe27f

Please sign in to comment.