Raw source encoding and limit data
This commit is contained in:
@@ -96,35 +96,30 @@ namespace YAML
|
||||
{
|
||||
ENUM_CONVERTER(MltpxValue, mixMultiplexLut);
|
||||
|
||||
template <>
|
||||
struct convert<CurveReference> {
|
||||
static Node encode(const CurveReference& rhs)
|
||||
{
|
||||
Node node;
|
||||
node["type"] = (int)rhs.type;
|
||||
node["value"] = rhs.value;
|
||||
return node;
|
||||
}
|
||||
Node convert<CurveReference>::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<CurveReference>::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<MixData>::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<MixData>::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;
|
||||
|
||||
@@ -21,7 +21,13 @@
|
||||
#include "yaml_ops.h"
|
||||
#include "mixdata.h"
|
||||
|
||||
namespace YAML {
|
||||
namespace YAML
|
||||
{
|
||||
template <>
|
||||
struct convert<CurveReference> {
|
||||
static Node encode(const CurveReference& rhs);
|
||||
static bool decode(const Node& node, CurveReference& rhs);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct convert<MixData> {
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "yaml_rawswitch.h"
|
||||
#include "yaml_mixdata.h"
|
||||
#include "modeldata.h"
|
||||
#include "output_data.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -77,6 +78,38 @@ bool convert<TimerData>::decode(const Node& node, TimerData& rhs)
|
||||
return true;
|
||||
}
|
||||
|
||||
template <>
|
||||
struct convert<LimitData> {
|
||||
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<ModelData>::encode(const ModelData& rhs)
|
||||
{
|
||||
Node node;
|
||||
@@ -101,6 +134,7 @@ Node convert<ModelData>::encode(const ModelData& rhs)
|
||||
node["throttleReversed"] = (int)rhs.throttleReversed;
|
||||
|
||||
// flightModeData[]
|
||||
|
||||
for (int i=0; i<CPN_MAX_MIXERS; i++) {
|
||||
const MixData& mix = rhs.mixData[i];
|
||||
if (!mix.isEmpty()) {
|
||||
@@ -109,7 +143,16 @@ Node convert<ModelData>::encode(const ModelData& rhs)
|
||||
node["mixData"].push_back(mixNode);
|
||||
}
|
||||
}
|
||||
// limitData[]
|
||||
|
||||
for (int i=0; i<CPN_MAX_CHNOUT; i++) {
|
||||
const LimitData& limit = rhs.limitData[i];
|
||||
if (!limit.isEmpty()) {
|
||||
Node limitNode;
|
||||
limitNode = rhs.limitData[i];
|
||||
node["limitData"].push_back(limitNode);
|
||||
}
|
||||
}
|
||||
|
||||
// inputNames[]
|
||||
// expoData[]
|
||||
// curves[]
|
||||
@@ -179,9 +222,10 @@ bool convert<ModelData>::decode(const Node& node, ModelData& rhs)
|
||||
node["throttleReversed"] >> rhs.throttleReversed;
|
||||
|
||||
// flightModeData[]
|
||||
// mixData[]
|
||||
|
||||
node["mixData"] >> rhs.mixData;
|
||||
// limitData[]
|
||||
node["limitData"] >> rhs.limitData;
|
||||
|
||||
// inputNames[]
|
||||
// expoData[]
|
||||
// curves[]
|
||||
|
||||
@@ -71,11 +71,74 @@ const YamlLookupTable specialSourceLut = {
|
||||
|
||||
namespace YAML {
|
||||
|
||||
//ENUM_CONVERTER(RawSourceType, sourceTypeLut);
|
||||
|
||||
Node convert<RawSource>::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<RawSource>::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<RawSource>::decode(const Node& node, RawSource& rhs)
|
||||
rhs.type = SOURCE_TYPE_SPECIAL;
|
||||
rhs.index = conv.as<int>();
|
||||
}
|
||||
|
||||
if (node.IsScalar()
|
||||
&& node.as<std::string>() == "MAX") {
|
||||
rhs.type = SOURCE_TYPE_MAX;
|
||||
rhs.index = 0;
|
||||
}
|
||||
}
|
||||
// TODO: raw analogs
|
||||
|
||||
|
||||
Reference in New Issue
Block a user