Add calib data write
This commit is contained in:
@@ -37,6 +37,9 @@ static void writeYamlToByteArray(const YAML::Node& node, QByteArray& data)
|
||||
std::stringstream data_ostream;
|
||||
data_ostream << node;
|
||||
data = QByteArray::fromStdString(data_ostream.str());
|
||||
|
||||
qDebug() << "Saving radio.yml:";
|
||||
qDebug() << data_ostream.str().c_str();
|
||||
}
|
||||
|
||||
bool loadModelsListFromYaml(std::vector<CategoryData> categories,
|
||||
@@ -109,5 +112,6 @@ bool writeRadioSettingsToYaml(const GeneralSettings& settings, QByteArray& data)
|
||||
YAML::Node node;
|
||||
node = settings;
|
||||
writeYamlToByteArray(node, data);
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -31,34 +31,21 @@ struct YamlCalibData {
|
||||
CalibData calib[CPN_MAX_ANALOGS];
|
||||
|
||||
YamlCalibData();
|
||||
YamlCalibData(const int* calibMid, const int* calibSpanNeg, const int* calibSpanPos);
|
||||
void copy(int* calibMid, int* calibSpanNeg, int* calibSpanPos) const;
|
||||
};
|
||||
|
||||
extern const YamlLookupTable calibIdxLut;
|
||||
namespace YAML
|
||||
{
|
||||
template <>
|
||||
struct convert<CalibData> {
|
||||
static Node encode(const CalibData& rhs);
|
||||
static bool decode(const Node& node, CalibData& rhs);
|
||||
};
|
||||
|
||||
namespace YAML {
|
||||
|
||||
template<>
|
||||
struct convert<CalibData> {
|
||||
static bool 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;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct convert<YamlCalibData> {
|
||||
static bool 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;
|
||||
}
|
||||
};
|
||||
}
|
||||
template <>
|
||||
struct convert<YamlCalibData> {
|
||||
static Node encode(const YamlCalibData& rhs);
|
||||
static bool decode(const Node& node, YamlCalibData& rhs);
|
||||
};
|
||||
} // namespace YAML
|
||||
|
||||
@@ -45,9 +45,8 @@ namespace YAML {
|
||||
node["version"] = rhs.version;
|
||||
|
||||
// Radio calib
|
||||
// YamlCalibData calib;
|
||||
// node["calib"] = calib;
|
||||
// calib.copy(rhs.calibMid, rhs.calibSpanNeg, rhs.calibSpanPos);
|
||||
YamlCalibData calib(rhs.calibMid, rhs.calibSpanNeg, rhs.calibSpanPos);
|
||||
node["calib"] = calib;
|
||||
|
||||
node["currModel"] = rhs.currModelIndex;
|
||||
node["currModelFilename"] = rhs.currModelFilename;
|
||||
@@ -61,11 +60,11 @@ namespace YAML {
|
||||
node["backlightMode"] = backlightModeLut << rhs.backlightMode;
|
||||
node["trainer"] = rhs.trainer;
|
||||
node["view"] = rhs.view;
|
||||
node["fai"] = rhs.fai;
|
||||
node["disableMemoryWarning"] = rhs.disableMemoryWarning;
|
||||
node["fai"] = (int)rhs.fai;
|
||||
node["disableMemoryWarning"] = (int)rhs.disableMemoryWarning;
|
||||
node["beepMode"] = rhs.beeperMode;
|
||||
node["disableAlarmWarning"] = rhs.disableAlarmWarning;
|
||||
node["disableRssiPoweroffAlarm"] = rhs.disableRssiPoweroffAlarm;
|
||||
node["disableAlarmWarning"] = (int)rhs.disableAlarmWarning;
|
||||
node["disableRssiPoweroffAlarm"] = (int)rhs.disableRssiPoweroffAlarm;
|
||||
node["USBMode"] = rhs.usbMode;
|
||||
node["jackMode"] = rhs.jackMode;
|
||||
node["hapticMode"] = rhs.hapticMode;
|
||||
@@ -89,9 +88,9 @@ namespace YAML {
|
||||
node["bluetoothBaudrate"] = rhs.bluetoothBaudrate;
|
||||
node["bluetoothMode"] = bluetoothModeLut << rhs.bluetoothMode;
|
||||
node["countryCode"] = rhs.countryCode;
|
||||
node["jitterFilter"] = rhs.jitterFilter;
|
||||
node["disableRtcWarning"] = rhs.rtcCheckDisable; // TODO: verify
|
||||
node["keysBacklight"] = rhs.keysBacklight;
|
||||
node["jitterFilter"] = (int)rhs.jitterFilter;
|
||||
node["disableRtcWarning"] = (int)rhs.rtcCheckDisable; // TODO: verify
|
||||
node["keysBacklight"] = (int)rhs.keysBacklight;
|
||||
node["imperial"] = rhs.imperial;
|
||||
node["ttsLanguage"] = rhs.ttsLanguage;
|
||||
node["beepVolume"] = rhs.beepVolume + 2;
|
||||
|
||||
@@ -33,14 +33,16 @@ namespace YAML
|
||||
Node convert<TrainerMix>::encode(const TrainerMix& rhs)
|
||||
{
|
||||
Node node;
|
||||
// TODO: convert struct into Node
|
||||
node["srcChn"] = rhs.src;
|
||||
node["mode"] = trainerMixMode << rhs.mode;
|
||||
node["studWeight"] = rhs.weight;
|
||||
return node;
|
||||
}
|
||||
|
||||
bool convert<TrainerMix>::decode(const Node& node, TrainerMix& rhs)
|
||||
{
|
||||
node["srcChn"] >> rhs.src;
|
||||
// node["mode"] >> rhs.mode; // TODO: string mapping
|
||||
node["mode"] >> trainerMixMode >> rhs.mode;
|
||||
node["studWeight"] >> rhs.weight;
|
||||
return true;
|
||||
}
|
||||
@@ -48,7 +50,12 @@ bool convert<TrainerMix>::decode(const Node& node, TrainerMix& rhs)
|
||||
Node convert<TrainerData>::encode(const TrainerData& rhs)
|
||||
{
|
||||
Node node;
|
||||
// TODO: convert struct into Node
|
||||
for (int i = 0; i < 4; i++) {
|
||||
node["calib"][std::to_string(i)]["val"] = rhs.calib[i];
|
||||
}
|
||||
for (int i = 0; i < 4; i++) {
|
||||
node["mix"][std::to_string(i)] = rhs.mix[i];
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
@@ -57,14 +64,14 @@ bool convert<TrainerData>::decode(const Node& node, TrainerData& rhs)
|
||||
if (node["calib"]) {
|
||||
const Node& calib = node["calib"];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
calib[i] >> rhs.calib[i];
|
||||
calib[std::to_string(i)]["val"] >> rhs.calib[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (node["mix"]) {
|
||||
const Node& mix = node["mix"];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
mix[i] >> rhs.mix[i];
|
||||
mix[std::to_string(i)] >> rhs.mix[i];
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user