fix: Companion read/write of failsafe settings, how displayed on radio (#1399)

* Fix failsafe settings

Resolve #1393

* trigger save if failsafe numbers changed + cleanup

Co-authored-by: Peter Feerick <peter.feerick@gmail.com>
This commit is contained in:
Raphael Coeffic
2022-01-11 23:09:55 +10:00
committed by GitHub
co-authored by Peter Feerick
parent 71b0e72dd0
commit 7a628d4c15
2 changed files with 24 additions and 7 deletions
@@ -337,7 +337,6 @@ struct convert<LimitData> {
node["offset"] = YamlWriteLimitValue(rhs.offset); node["offset"] = YamlWriteLimitValue(rhs.offset);
node["ppmCenter"] = rhs.ppmCenter; node["ppmCenter"] = rhs.ppmCenter;
node["symetrical"] = (int)rhs.symetrical; node["symetrical"] = (int)rhs.symetrical;
node["failsafe"] = rhs.failsafe;
node["name"] = rhs.name; node["name"] = rhs.name;
node["curve"] = rhs.curve.value; node["curve"] = rhs.curve.value;
return node; return node;
@@ -357,7 +356,6 @@ struct convert<LimitData> {
node["revert"] >> rhs.revert; node["revert"] >> rhs.revert;
node["ppmCenter"] >> rhs.ppmCenter; node["ppmCenter"] >> rhs.ppmCenter;
node["symetrical"] >> rhs.symetrical; node["symetrical"] >> rhs.symetrical;
node["failsafe"] >> rhs.failsafe;
node["name"] >> rhs.name; node["name"] >> rhs.name;
node["curve"] >> rhs.curve.value; node["curve"] >> rhs.curve.value;
return true; return true;
@@ -873,6 +871,12 @@ Node convert<ModelData>::encode(const ModelData& rhs)
} }
} }
for (int i=0; i<CPN_MAX_CHNOUT; i++) {
if (rhs.limitData[i].failsafe != 0) {
node["failsafeChannels"][std::to_string(i)]["val"] = rhs.limitData[i].failsafe;
}
}
for (int i=0; i<CPN_MAX_SCRIPTS; i++) { for (int i=0; i<CPN_MAX_SCRIPTS; i++) {
if (strlen(rhs.scriptData[i].filename) > 0) { if (strlen(rhs.scriptData[i].filename) > 0) {
node["scriptData"][std::to_string(i)] = rhs.scriptData[i]; node["scriptData"][std::to_string(i)] = rhs.scriptData[i];
@@ -1046,6 +1050,15 @@ bool convert<ModelData>::decode(const Node& node, ModelData& rhs)
rhs.moduleData[i].modelId = modelIds[i]; rhs.moduleData[i].modelId = modelIds[i];
} }
if (node["failsafeChannels"]) {
int failsafeChans[CPN_MAX_CHNOUT];
memset(failsafeChans, 0, sizeof(failsafeChans));
node["failsafeChannels"] >> failsafeChans;
for (int i=0; i<CPN_MAX_CHNOUT; i++) {
rhs.limitData[i].failsafe = failsafeChans[i];
}
}
node["scriptData"] >> rhs.scriptData; node["scriptData"] >> rhs.scriptData;
node["telemetrySensors"] >> rhs.sensorData; node["telemetrySensors"] >> rhs.sensorData;
+9 -5
View File
@@ -113,7 +113,8 @@ class FailSafeBody : public FormGroup {
grid.setLabelWidth(60); grid.setLabelWidth(60);
grid.spacer(8); grid.spacer(8);
const int lim = (g_model.extendedLimits ? (512 * LIMIT_EXT_PERCENT / 100) : 512) * 2; const int lim = calcRESXto1000(
(g_model.extendedLimits ? (512 * LIMIT_EXT_PERCENT / 100) : 512) * 2);
for (int ch=0; ch < maxModuleChannels(moduleIdx); ch++) { for (int ch=0; ch < maxModuleChannels(moduleIdx); ch++) {
// Channel name // Channel name
@@ -122,8 +123,11 @@ class FailSafeBody : public FormGroup {
// Channel numeric value // Channel numeric value
new NumberEdit(this, grid.getFieldSlot(8, 0), -lim, lim, new NumberEdit(this, grid.getFieldSlot(8, 0), -lim, lim,
GET_DEFAULT(g_model.failsafeChannels[ch]), [=]() { return calcRESXto1000(g_model.failsafeChannels[ch]); },
SET_VALUE(g_model.failsafeChannels[ch], newValue), [=](int32_t newValue) {
g_model.failsafeChannels[ch] = calc1000toRESX(newValue);
SET_DIRTY();
},
0, PREC1 | RIGHT); 0, PREC1 | RIGHT);
// Channel bargraph // Channel bargraph
@@ -136,7 +140,7 @@ class FailSafeBody : public FormGroup {
out2fail->setPressHandler([=]() { out2fail->setPressHandler([=]() {
setCustomFailsafe(moduleIdx); setCustomFailsafe(moduleIdx);
AUDIO_WARNING1(); AUDIO_WARNING1();
storageDirty(EE_MODEL); SET_DIRTY();
return 0; return 0;
}); });
@@ -1401,7 +1405,7 @@ void ModelSetupPage::build(FormWindow * window)
for (auto &flightModeData : g_model.flightModeData) { for (auto &flightModeData : g_model.flightModeData) {
memclear(&flightModeData, TRIMS_ARRAY_SIZE); memclear(&flightModeData, TRIMS_ARRAY_SIZE);
} }
storageDirty(EE_MODEL); SET_DIRTY();
AUDIO_WARNING1(); AUDIO_WARNING1();
return 0; return 0;
}); });