feat: use any source for expo/weight/offset (#5220)
Co-authored-by: philmoz <phil.a.mitchell@gmail.com> Co-authored-by: 3djc <3djc@gh.com> Co-authored-by: elecpower <elecpower@users.noreply.github.com>
This commit is contained in:
co-authored by
philmoz
3djc
elecpower
parent
326c58a7fd
commit
4b917b762c
@@ -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;
|
||||
@@ -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
|
||||
|
||||
@@ -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" },
|
||||
@@ -32,46 +33,55 @@ static const YamlLookupTable mixMultiplexLut = {
|
||||
#define GVAR_SMALL 128
|
||||
#define CPN_GV1 1024
|
||||
|
||||
int32_t YamlReadMixWeight(const YAML::Node& node)
|
||||
int32_t YamlSourceNumRefDecode(const YAML::Node& node)
|
||||
{
|
||||
std::string val = node.as<std::string>();
|
||||
if ((val.size() >= 4)
|
||||
|
||||
if (modelSettingsVersion < SemanticVersion(QString("2.11.0"))) {
|
||||
if ((val.size() >= 4)
|
||||
&& (val[0] == '-')
|
||||
&& (val[1] == 'G')
|
||||
&& (val[2] == 'V')
|
||||
&& (val[3] >= '1')
|
||||
&& (val[3] <= '9')) {
|
||||
|
||||
return -10000 - std::stoi(val.substr(3));
|
||||
}
|
||||
std::stringstream src(val.substr(3));
|
||||
int gv = 0;
|
||||
src >> gv;
|
||||
return RawSource(SOURCE_TYPE_GVAR, gv).toValue() * -1;
|
||||
}
|
||||
|
||||
if ((val.size() >= 3)
|
||||
if ((val.size() >= 3)
|
||||
&& (val[0] == 'G')
|
||||
&& (val[1] == 'V')
|
||||
&& (val[2] >= '1')
|
||||
&& (val[2] <= '9')) {
|
||||
|
||||
return 10000 + std::stoi(val.substr(2));
|
||||
std::stringstream src(val.substr(2));
|
||||
int gv = 0;
|
||||
src >> gv;
|
||||
return RawSource(SOURCE_TYPE_GVAR, gv).toValue();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
return std::stoi(val);
|
||||
} catch(...) {
|
||||
throw YAML::TypedBadConversion<int>(node.Mark());
|
||||
}
|
||||
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 YamlWriteMixWeight(int32_t sval)
|
||||
std::string YamlSourceNumRefEncode(int32_t sval)
|
||||
{
|
||||
if (sval < -10000) {
|
||||
int n = -sval - 10000;
|
||||
return std::string("-GV") + std::to_string(n);
|
||||
} else if (sval > 10000) {
|
||||
int n = sval - 10000;
|
||||
return std::string("GV") + std::to_string(n);
|
||||
}
|
||||
|
||||
return std::to_string(sval);
|
||||
if (SourceNumRef(sval).isNumber())
|
||||
return std::to_string(sval);
|
||||
else
|
||||
return YamlRawSourceEncode(RawSource(sval));
|
||||
}
|
||||
|
||||
uint32_t YamlReadFlightModes(const YAML::Node& node)
|
||||
@@ -108,7 +118,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;
|
||||
}
|
||||
|
||||
@@ -119,7 +129,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;
|
||||
}
|
||||
@@ -129,7 +139,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;
|
||||
@@ -141,7 +151,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;
|
||||
}
|
||||
@@ -151,7 +161,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;
|
||||
@@ -167,7 +177,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;
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
#include "yaml_ops.h"
|
||||
#include "mixdata.h"
|
||||
|
||||
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);
|
||||
|
||||
@@ -546,6 +546,7 @@ struct convert<LimitData> {
|
||||
node["symetrical"] = (int)rhs.symetrical;
|
||||
node["name"] = rhs.name;
|
||||
node["curve"] = rhs.curve.value;
|
||||
// rhs.curve.type is not encoded
|
||||
return node;
|
||||
}
|
||||
|
||||
@@ -565,6 +566,7 @@ struct convert<LimitData> {
|
||||
node["symetrical"] >> rhs.symetrical;
|
||||
node["name"] >> rhs.name;
|
||||
node["curve"] >> rhs.curve.value;
|
||||
rhs.curve.type = CurveReference::CURVE_REF_CUSTOM; // this is not encoded but needed internally so force type
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user