fix: Sort mixer lines after loading model (#3172)
* fix: sort mixer lines after loading model Fixes #2806 * fix(cpn): sort mixer lines after loading model * More efficient swap --------- Co-authored-by: elecpower <neilh713@tpg.com.au>
This commit is contained in:
co-authored by
elecpower
parent
d57afea89e
commit
3695930242
@@ -312,7 +312,7 @@ bool convert<TimerData>::decode(const Node& node, TimerData& rhs)
|
|||||||
node["showElapsed"] >> rhs.showElapsed;
|
node["showElapsed"] >> rhs.showElapsed;
|
||||||
node["extraHaptic"] >> rhs.extraHaptic;
|
node["extraHaptic"] >> rhs.extraHaptic;
|
||||||
|
|
||||||
if (rhs.extraHaptic)
|
if (rhs.extraHaptic)
|
||||||
rhs.countdownBeep += TimerData::COUNTDOWNBEEP_VOICE + 1;
|
rhs.countdownBeep += TimerData::COUNTDOWNBEEP_VOICE + 1;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -577,7 +577,7 @@ struct RFAlarms {
|
|||||||
int critical = 0;
|
int critical = 0;
|
||||||
|
|
||||||
RFAlarms() {}
|
RFAlarms() {}
|
||||||
|
|
||||||
RFAlarms(const RSSIAlarmData& rhs)
|
RFAlarms(const RSSIAlarmData& rhs)
|
||||||
: warning(rhs.warning), critical(rhs.critical)
|
: warning(rhs.warning), critical(rhs.critical)
|
||||||
{}
|
{}
|
||||||
@@ -1206,6 +1206,10 @@ bool convert<ModelData>::decode(const Node& node, ModelData& rhs)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// perform integrity checks and fix-ups
|
||||||
|
|
||||||
|
rhs.sortMixes(); // critical for Companion and radio that mix lines are in sequence
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -230,6 +230,7 @@ class ModelData {
|
|||||||
int linkedFlightModeValueToIndex(const int phaseIdx, const int val, const int maxOwnValue);
|
int linkedFlightModeValueToIndex(const int phaseIdx, const int val, const int maxOwnValue);
|
||||||
|
|
||||||
void clearMixes();
|
void clearMixes();
|
||||||
|
void sortMixes();
|
||||||
void clearInputs();
|
void clearInputs();
|
||||||
|
|
||||||
int getChannelsMax(bool forceExtendedLimits=false) const;
|
int getChannelsMax(bool forceExtendedLimits=false) const;
|
||||||
@@ -363,6 +364,5 @@ class ModelData {
|
|||||||
if (value != swtch.toValue())
|
if (value != swtch.toValue())
|
||||||
value = swtch.toValue();
|
value = swtch.toValue();
|
||||||
}
|
}
|
||||||
void sortMixes();
|
|
||||||
void updateResetParam(CustomFunctionData * cfd);
|
void updateResetParam(CustomFunctionData * cfd);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -95,6 +95,37 @@ void postRadioSettingsLoad()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void sortMixerLines()
|
||||||
|
{
|
||||||
|
// simple bubble sort
|
||||||
|
unsigned passes = 0;
|
||||||
|
unsigned swaps;
|
||||||
|
MixData tmp;
|
||||||
|
|
||||||
|
do {
|
||||||
|
swaps = 0;
|
||||||
|
for (int i = 0; i < MAX_MIXERS - 1; i++) {
|
||||||
|
auto a = mixAddress(i);
|
||||||
|
auto b = mixAddress(i + 1);
|
||||||
|
|
||||||
|
if (b->destCh < a->destCh) {
|
||||||
|
if (is_memclear(b, sizeof(MixData)))
|
||||||
|
break;
|
||||||
|
|
||||||
|
memcpy(&tmp, a, sizeof(MixData));
|
||||||
|
memcpy(a, b, sizeof(MixData));
|
||||||
|
memcpy(b, &tmp, sizeof(MixData));
|
||||||
|
++swaps;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
++passes;
|
||||||
|
} while(swaps > 0);
|
||||||
|
|
||||||
|
if (passes > 1) {
|
||||||
|
storageDirty(EE_MODEL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void postModelLoad(bool alarms)
|
void postModelLoad(bool alarms)
|
||||||
{
|
{
|
||||||
#if defined(PXX2)
|
#if defined(PXX2)
|
||||||
@@ -126,6 +157,7 @@ void postModelLoad(bool alarms)
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadCurves();
|
loadCurves();
|
||||||
|
sortMixerLines();
|
||||||
|
|
||||||
#if defined(GUI)
|
#if defined(GUI)
|
||||||
if (alarms) {
|
if (alarms) {
|
||||||
|
|||||||
Reference in New Issue
Block a user