Add calib data write
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
//
|
||||
// This is only valid for X10, T16, TX16S (not X12S)
|
||||
//
|
||||
const YamlLookupTable calibIdxLut = {
|
||||
static const YamlLookupTable calibIdxLut = {
|
||||
{ 0, "Rud" },
|
||||
{ 1, "Ele" },
|
||||
{ 2, "Thr" },
|
||||
@@ -46,6 +46,16 @@ const YamlLookupTable calibIdxLut = {
|
||||
|
||||
YamlCalibData::YamlCalibData() { memset(calib, 0, sizeof(calib)); }
|
||||
|
||||
YamlCalibData::YamlCalibData(const int* calibMid, const int* calibSpanNeg,
|
||||
const int* calibSpanPos)
|
||||
{
|
||||
for (int i = 0; i < CPN_MAX_ANALOGS; i++) {
|
||||
calib[i].mid = calibMid[i];
|
||||
calib[i].spanNeg = calibSpanNeg[i];
|
||||
calib[i].spanPos = calibSpanPos[i];
|
||||
}
|
||||
}
|
||||
|
||||
void YamlCalibData::copy(int* calibMid, int* calibSpanNeg,
|
||||
int* calibSpanPos) const
|
||||
{
|
||||
@@ -55,3 +65,47 @@ void YamlCalibData::copy(int* calibMid, int* calibSpanNeg,
|
||||
calibSpanPos[i] = calib[i].spanPos;
|
||||
}
|
||||
}
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
|
||||
Node convert<CalibData>::encode(const CalibData& rhs)
|
||||
{
|
||||
Node node;
|
||||
node["mid"] = rhs.mid;
|
||||
node["spanNeg"] = rhs.spanNeg;
|
||||
node["spanPos"] = rhs.spanPos;
|
||||
return node;
|
||||
}
|
||||
|
||||
bool convert<CalibData>::decode(const Node& node, CalibData& rhs)
|
||||
{
|
||||
if (!node.IsMap()) return false;
|
||||
node["mid"] >> rhs.mid;
|
||||
node["spanNeg"] >> rhs.spanNeg;
|
||||
node["spanPos"] >> rhs.spanPos;
|
||||
return true;
|
||||
}
|
||||
|
||||
Node convert<YamlCalibData>::encode(const YamlCalibData& rhs)
|
||||
{
|
||||
Node node;
|
||||
// TODO: we need something better here!
|
||||
for (const auto& kv : calibIdxLut) {
|
||||
node[kv.second] = rhs.calib[kv.first];
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
bool convert<YamlCalibData>::decode(const Node& node, YamlCalibData& rhs)
|
||||
{
|
||||
if (!node.IsMap()) return false;
|
||||
int idx = 0;
|
||||
for (const auto& kv : node) {
|
||||
kv.first >> calibIdxLut >> idx;
|
||||
kv.second >> rhs.calib[idx];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace YAML
|
||||
|
||||
Reference in New Issue
Block a user