diff --git a/radio/src/CMakeLists.txt b/radio/src/CMakeLists.txt index 2bdd9c8a074..f30dbee3e76 100644 --- a/radio/src/CMakeLists.txt +++ b/radio/src/CMakeLists.txt @@ -395,6 +395,7 @@ set(SRC strhelpers.cpp switches.cpp analogs.cpp + mixes.cpp mixer.cpp mixer_scheduler.cpp stamp.cpp diff --git a/radio/src/gui/128x64/gui.h b/radio/src/gui/128x64/gui.h index 477155f70a3..c767ab8a892 100644 --- a/radio/src/gui/128x64/gui.h +++ b/radio/src/gui/128x64/gui.h @@ -158,9 +158,6 @@ extern uint8_t editNameCursorPos; uint8_t getExposCount(); void insertExpo(uint8_t idx); void deleteExpo(uint8_t idx); -uint8_t getMixesCount(); -void insertMix(uint8_t idx); -void deleteMix(uint8_t idx); void onSwitchLongEnterPress(const char *result); void onSourceLongEnterPress(const char *result); diff --git a/radio/src/gui/128x64/model_mix_edit.cpp b/radio/src/gui/128x64/model_mix_edit.cpp index 735157111c6..bb01ad2c8bc 100644 --- a/radio/src/gui/128x64/model_mix_edit.cpp +++ b/radio/src/gui/128x64/model_mix_edit.cpp @@ -20,6 +20,7 @@ */ #include "opentx.h" +#include "mixes.h" enum MixFields { MIX_FIELD_NAME, diff --git a/radio/src/gui/212x64/gui.h b/radio/src/gui/212x64/gui.h index 0bee01de875..f7ff0490490 100644 --- a/radio/src/gui/212x64/gui.h +++ b/radio/src/gui/212x64/gui.h @@ -157,10 +157,6 @@ uint8_t getExposCount(); void deleteExpo(uint8_t idx); void insertExpo(uint8_t idx); -uint8_t getMixesCount(); -void deleteMix(uint8_t idx); -void insertMix(uint8_t idx); - #define STATUS_LINE_LENGTH 32 extern char statusLineMsg[STATUS_LINE_LENGTH]; void showStatusLine(); diff --git a/radio/src/gui/212x64/model_mix_edit.cpp b/radio/src/gui/212x64/model_mix_edit.cpp index 3bca95c5785..6fc15a43ad0 100644 --- a/radio/src/gui/212x64/model_mix_edit.cpp +++ b/radio/src/gui/212x64/model_mix_edit.cpp @@ -20,6 +20,7 @@ */ #include "opentx.h" +#include "mixes.h" enum MixFields { MIX_FIELD_NAME, diff --git a/radio/src/gui/colorlcd/menus.h b/radio/src/gui/colorlcd/menus.h index 7c338d949f8..2c6740ddc0a 100644 --- a/radio/src/gui/colorlcd/menus.h +++ b/radio/src/gui/colorlcd/menus.h @@ -101,11 +101,6 @@ uint8_t getExposCount(); void deleteExpo(uint8_t idx); void insertExpo(uint8_t idx, uint8_t input); -uint8_t getMixesCount(); -void deleteMix(uint8_t idx); -void insertMix(uint8_t idx); -void copyMix(uint8_t source, uint8_t dest, int8_t ch); - typedef int (*FnFuncP) (int x); void drawFunction(FnFuncP fn, int x, int y, int width); diff --git a/radio/src/gui/colorlcd/mixer_edit.cpp b/radio/src/gui/colorlcd/mixer_edit.cpp index 2ff64b9aed2..08ded25f2ec 100644 --- a/radio/src/gui/colorlcd/mixer_edit.cpp +++ b/radio/src/gui/colorlcd/mixer_edit.cpp @@ -24,6 +24,7 @@ #include "channel_bar.h" #include "gvar_numberedit.h" #include "curve_param.h" +#include "mixes.h" #include "opentx.h" diff --git a/radio/src/gui/colorlcd/mixer_edit_adv.cpp b/radio/src/gui/colorlcd/mixer_edit_adv.cpp index c753b5d979a..faf8661fa42 100644 --- a/radio/src/gui/colorlcd/mixer_edit_adv.cpp +++ b/radio/src/gui/colorlcd/mixer_edit_adv.cpp @@ -22,6 +22,7 @@ #include "mixer_edit_adv.h" #include "numberedit.h" #include "fm_matrix.h" +#include "mixes.h" #include "opentx.h" diff --git a/radio/src/gui/colorlcd/model_mixes.cpp b/radio/src/gui/colorlcd/model_mixes.cpp index 8385fcb4e3f..0ab6eb2b535 100644 --- a/radio/src/gui/colorlcd/model_mixes.cpp +++ b/radio/src/gui/colorlcd/model_mixes.cpp @@ -31,6 +31,7 @@ #include "input_mix_button.h" #include "mixer_edit.h" #include "input_mapping.h" +#include "mixes.h" #include "tasks/mixer_task.h" #include "hal/adc_driver.h" @@ -54,119 +55,6 @@ static const uint8_t _mask_mplex_replace[] = { }; STATIC_LZ4_BITMAP(mask_mplex_replace); -uint8_t getMixesCount() -{ - uint8_t count = 0; - uint8_t ch; - - for (int i = MAX_MIXERS - 1; i >= 0; i--) { - ch = mixAddress(i)->srcRaw; - if (ch != 0) { - count++; - } - } - return count; -} - -void insertMix(uint8_t idx, uint8_t channel) -{ - mixerTaskStop(); - MixData *mix = mixAddress(idx); - memmove(mix + 1, mix, (MAX_MIXERS - (idx + 1)) * sizeof(MixData)); - memclear(mix, sizeof(MixData)); - mix->destCh = channel; - mix->srcRaw = channel + 1; - if (!isSourceAvailable(mix->srcRaw)) { - if (channel >= adcGetMaxInputs(ADC_INPUT_MAIN)) { - mix->srcRaw = MIXSRC_FIRST_STICK + channel; - } else { - mix->srcRaw = MIXSRC_FIRST_STICK + inputMappingChannelOrder(channel); - } - while (!isSourceAvailable(mix->srcRaw)) { - mix->srcRaw += 1; - } - } - mix->weight = 100; - mixerTaskStart(); - storageDirty(EE_MODEL); -} - -void deleteMix(uint8_t idx) -{ - mixerTaskStop(); - MixData * mix = mixAddress(idx); - memmove(mix, mix + 1, (MAX_MIXERS - (idx + 1)) * sizeof(MixData)); - memclear(&g_model.mixData[MAX_MIXERS - 1], sizeof(MixData)); - mixerTaskStart(); - storageDirty(EE_MODEL); -} - -#if defined(LUA) -// This is necessary as the LUA API uses th old interface -// where insertMix() has only one param. The channel is -// passed through s_currCh -void insertMix(uint8_t idx) -{ - insertMix(idx, s_currCh - 1); -} -#endif - -void copyMix(uint8_t source, uint8_t dest, int8_t ch) -{ - mixerTaskStop(); - MixData sourceMix; - memcpy(&sourceMix, mixAddress(source), sizeof(MixData)); - MixData *mix = mixAddress(dest); - size_t trailingMixes = MAX_MIXERS - (dest + 1); - memmove(mix + 1, mix, trailingMixes * sizeof(MixData)); - memcpy(mix, &sourceMix, sizeof(MixData)); - mix->destCh = ch; - mixerTaskStart(); - storageDirty(EE_MODEL); -} - -bool swapMixes(uint8_t &idx, uint8_t up) -{ - MixData * x, * y; - int8_t tgt_idx = (up ? idx - 1 : idx + 1); - - x = mixAddress(idx); - - if (tgt_idx < 0) { - if (x->destCh == 0) - return false; - x->destCh--; - return true; - } - - if (tgt_idx == MAX_MIXERS) { - if (x->destCh == MAX_OUTPUT_CHANNELS - 1) - return false; - x->destCh++; - return true; - } - - y = mixAddress(tgt_idx); - uint8_t destCh = x->destCh; - if (!y->srcRaw || destCh != y->destCh) { - if (up) { - if (destCh > 0) x->destCh--; - else return false; - } - else { - if (destCh < MAX_OUTPUT_CHANNELS - 1) x->destCh++; - else return false; - } - return true; - } - - mixerTaskStop(); - memswap(x, y, sizeof(MixData)); - mixerTaskStart(); - - idx = tgt_idx; - return true; -} class MixLineButton : public InputMixButton { @@ -312,7 +200,7 @@ ModelMixesPage::ModelMixesPage() : bool ModelMixesPage::reachMixesLimit() { - if (getMixesCount() >= MAX_MIXERS) { + if (getMixCount() >= MAX_MIXERS) { new MessageDialog(form, STR_WARNING, STR_NOFREEMIXER); return true; } @@ -550,17 +438,14 @@ void ModelMixesPage::build(FormWindow * window) bool focusSet = false; uint8_t index = 0; MixData* line = g_model.mixData; - for (uint8_t ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++) { + for (uint8_t ch = 0; (ch < MAX_OUTPUT_CHANNELS) && (index < MAX_MIXERS); ch++) { - if (index >= MAX_MIXERS) break; - - bool skip_mix = (ch == 0 && is_memclear(line, sizeof(MixData))); - if (line->destCh == ch && !skip_mix) { + if (line->destCh == ch) { // one group for the complete mixer channel auto group = createGroup(form, MIXSRC_FIRST_CH + ch); groups.emplace_back(group); - while (index < MAX_MIXERS && (line->destCh == ch) && !skip_mix) { + while (index < MAX_MIXERS && (line->destCh == ch)) { // one button per input line auto btn = createLineButton(group, index); if (!focusSet) { @@ -569,7 +454,6 @@ void ModelMixesPage::build(FormWindow * window) } ++index; ++line; - skip_mix = (ch == 0 && is_memclear(line, sizeof(MixData))); } } } diff --git a/radio/src/gui/common/stdlcd/model_mixes.cpp b/radio/src/gui/common/stdlcd/model_mixes.cpp index 3cf4bb0a774..681a174ed4e 100644 --- a/radio/src/gui/common/stdlcd/model_mixes.cpp +++ b/radio/src/gui/common/stdlcd/model_mixes.cpp @@ -23,118 +23,20 @@ #include "tasks/mixer_task.h" #include "hal/adc_driver.h" #include "input_mapping.h" +#include "mixes.h" #define _STR_MAX(x) "/" #x #define STR_MAX(x) _STR_MAX(x) -uint8_t getMixesCount() -{ - uint8_t count = 0; - uint8_t ch; - - for (int i=MAX_MIXERS-1; i>=0; i--) { - ch = mixAddress(i)->srcRaw; - if (ch != 0) { - count++; - } - } - return count; -} - bool reachMixesLimit() { - if (getMixesCount() >= MAX_MIXERS) { + if (getMixCount() >= MAX_MIXERS) { POPUP_WARNING(STR_NOFREEMIXER); return true; } return false; } -void deleteMix(uint8_t idx) -{ - mixerTaskStop(); - MixData * mix = mixAddress(idx); - memmove(mix, mix+1, (MAX_MIXERS-(idx+1))*sizeof(MixData)); - memclear(&g_model.mixData[MAX_MIXERS-1], sizeof(MixData)); - mixerTaskStart(); - storageDirty(EE_MODEL); -} - -void insertMix(uint8_t idx) -{ - mixerTaskStop(); - MixData * mix = mixAddress(idx); - memmove(mix+1, mix, (MAX_MIXERS-(idx+1))*sizeof(MixData)); - memclear(mix, sizeof(MixData)); - mix->destCh = s_currCh-1; - mix->srcRaw = s_currCh; - if (!isSourceAvailable(mix->srcRaw)) { - if (s_currCh > adcGetMaxInputs(ADC_INPUT_MAIN)) { - mix->srcRaw = MIXSRC_FIRST_STICK - 1 + s_currCh; - } else { - mix->srcRaw = MIXSRC_FIRST_STICK + inputMappingChannelOrder(s_currCh - 1); - } - while (!isSourceAvailable(mix->srcRaw)) { - mix->srcRaw += 1; - } - } - mix->weight = 100; - mixerTaskStart(); - storageDirty(EE_MODEL); -} - -void copyMix(uint8_t idx) -{ - mixerTaskStop(); - MixData * mix = mixAddress(idx); - memmove(mix+1, mix, (MAX_MIXERS-(idx+1))*sizeof(MixData)); - mixerTaskStart(); - storageDirty(EE_MODEL); -} - -bool swapMixes(uint8_t & idx, uint8_t up) -{ - MixData * x, * y; - int8_t tgt_idx = (up ? idx-1 : idx+1); - - x = mixAddress(idx); - - if (tgt_idx < 0) { - if (x->destCh == 0) - return false; - x->destCh--; - return true; - } - - if (tgt_idx == MAX_MIXERS) { - if (x->destCh == MAX_OUTPUT_CHANNELS-1) - return false; - x->destCh++; - return true; - } - - y = mixAddress(tgt_idx); - uint8_t destCh = x->destCh; - if(!y->srcRaw || destCh != y->destCh) { - if (up) { - if (destCh>0) x->destCh--; - else return false; - } - else { - if (destChdestCh++; - else return false; - } - return true; - } - - mixerTaskStop(); - memswap(x, y, sizeof(MixData)); - mixerTaskStart(); - - idx = tgt_idx; - return true; -} - void onMixesMenu(const char * result) { uint8_t chn = mixAddress(s_currIdx)->destCh + 1; @@ -146,7 +48,7 @@ void onMixesMenu(const char * result) if (!reachMixesLimit()) { s_currCh = chn; if (result == STR_INSERT_AFTER) { s_currIdx++; menuVerticalPosition++; } - insertMix(s_currIdx); + insertMix(s_currIdx, s_currCh - 1); pushMenu(menuModelMixOne); } } @@ -289,7 +191,7 @@ void menuModelMixAll(event_t event) } else { do { - swapMixes(s_currIdx, s_copyTgtOfs > 0); + s_currIdx = moveMix(s_currIdx, s_copyTgtOfs > 0); s_copyTgtOfs += (s_copyTgtOfs < 0 ? +1 : -1); } while (s_copyTgtOfs != 0); storageDirty(EE_MODEL); @@ -327,7 +229,7 @@ void menuModelMixAll(event_t event) if (s_copyMode) s_currCh = 0; if (s_currCh) { if (reachMixesLimit()) break; - insertMix(s_currIdx); + insertMix(s_currIdx, s_currCh - 1); pushMenu(menuModelMixOne); s_copyMode = 0; } @@ -353,7 +255,7 @@ void menuModelMixAll(event_t event) // if (reachMixesLimit()) break; // s_currCh = chn; // if (event == EVT_KEY_LONG(KEY_RIGHT)) { s_currIdx++; menuVerticalPosition++; } - // insertMix(s_currIdx); + // insertMix(s_currIdx, s_currCh - 1); // pushMenu(menuModelMixOne); // s_copyMode = 0; // killEvents(event); @@ -369,7 +271,7 @@ void menuModelMixAll(event_t event) if (s_copyTgtOfs==0 && s_copyMode==COPY_MODE) { // insert a mix on the same channel (just above / just below) if (!reachMixesLimit()) { - copyMix(s_currIdx); + copyMix(s_currIdx, s_currIdx, mixAddress(s_currIdx)->destCh); if (IS_NEXT_EVENT(event)) s_currIdx++; else if (sub - menuVerticalOffset >= 6) @@ -384,15 +286,13 @@ void menuModelMixAll(event_t event) } else { // only swap the mix with its neighbor - if (swapMixes(s_currIdx, IS_PREVIOUS_EVENT(event))) { - storageDirty(EE_MODEL); - } + moveMix(s_currIdx, IS_PREVIOUS_EVENT(event)); } s_copyTgtOfs = next_ofs; } - lcdDrawNumber(FW*sizeof(TR_MIXES)+FW/2, 0, getMixesCount(), 0); + lcdDrawNumber(FW*sizeof(TR_MIXES)+FW/2, 0, getMixCount(), 0); lcdDrawText(lcdNextPos, 0, STR_MAX(MAX_MIXERS)); // Value @@ -419,9 +319,9 @@ void menuModelMixAll(event_t event) int i = 0; for (uint8_t ch=1; ch<=MAX_OUTPUT_CHANNELS; ch++) { - MixData * md; coord_t y = MENU_HEADER_HEIGHT+1+(cur-menuVerticalOffset)*FH; - if (isrcRaw && md->destCh+1 == ch) { + MixData * md = mixAddress(i); + if (i < getMixCount() && (md->destCh + 1 == ch)) { if (cur-menuVerticalOffset >= 0 && cur-menuVerticalOffset < NUM_BODY_LINES) { putsChn(0, y, ch, 0); // show CHx } @@ -473,7 +373,7 @@ void menuModelMixAll(event_t event) } } cur++; y+=FH; mixCnt++; i++; md++; - } while (isrcRaw && md->destCh+1 == ch); + } while (i < getMixCount() && (md->destCh + 1 == ch)); if (s_copyMode == MOVE_MODE && cur-menuVerticalOffset >= 0 && cur-menuVerticalOffset < NUM_BODY_LINES && s_copySrcCh == ch && i == (s_copySrcIdx + (s_copyTgtOfs<0))) { lcdDrawRect(22, y-1, LCD_W-22, 9, DOTTED); cur++; diff --git a/radio/src/gui/gui_common.cpp b/radio/src/gui/gui_common.cpp index 7069efc00d9..2ea8a53cbc7 100644 --- a/radio/src/gui/gui_common.cpp +++ b/radio/src/gui/gui_common.cpp @@ -25,6 +25,7 @@ #include "hal/adc_driver.h" #include "hal/switch_driver.h" #include "switches.h" +#include "mixes.h" #undef CPN #include "MultiSubtypeDefs.h" diff --git a/radio/src/lua/api_model.cpp b/radio/src/lua/api_model.cpp index b5aee1f298a..2e59feefd2e 100644 --- a/radio/src/lua/api_model.cpp +++ b/radio/src/lua/api_model.cpp @@ -28,6 +28,7 @@ #include "../timers.h" #include "model_init.h" #include "gvars.h" +#include "mixes.h" #if defined(SDCARD_YAML) #include @@ -887,10 +888,9 @@ static int luaModelInsertMix(lua_State *L) unsigned int first = getFirstMix(chn); unsigned int count = getMixesCountFromFirst(chn, first); - if (chndestCh = channel; + mix->srcRaw = channel + 1; + if (!isSourceAvailable(mix->srcRaw)) { + if (s_currCh > adcGetMaxInputs(ADC_INPUT_MAIN)) { + mix->srcRaw = MIXSRC_FIRST_STICK + channel; + } else { + mix->srcRaw = MIXSRC_FIRST_STICK + inputMappingChannelOrder(channel); + } + while (!isSourceAvailable(mix->srcRaw)) { + mix->srcRaw += 1; + } + } + mix->weight = 100; + mixerTaskStart(); + + _nb_mix_lines += 1; + storageDirty(EE_MODEL); +} + +void deleteMix(uint8_t idx) +{ + mixerTaskStop(); + MixData * mix = mixAddress(idx); + memmove(mix, mix + 1, (MAX_MIXERS - (idx + 1)) * sizeof(MixData)); + memclear(&g_model.mixData[MAX_MIXERS - 1], sizeof(MixData)); + mixerTaskStart(); + + _nb_mix_lines -= 1; + storageDirty(EE_MODEL); +} + +void copyMix(uint8_t src, uint8_t dst, uint8_t channel) +{ + mixerTaskStop(); + MixData sourceMix; + memcpy(&sourceMix, mixAddress(src), sizeof(MixData)); + MixData* mix = mixAddress(dst); + size_t trailingMixes = MAX_MIXERS - (dst + 1); + memmove(mix + 1, mix, trailingMixes * sizeof(MixData)); + memcpy(mix, &sourceMix, sizeof(MixData)); + mix->destCh = channel; + mixerTaskStart(); + + _nb_mix_lines += 1; + storageDirty(EE_MODEL); +} + +// Move the mixer line at 'idx' up or down +// by one position and return the new index. +uint8_t moveMix(uint8_t idx, bool up) +{ + MixData * x, * y; + int8_t tgt_idx = (up ? idx-1 : idx+1); + + x = mixAddress(idx); + + if (tgt_idx < 0) { + if (x->destCh > 0) { + x->destCh--; + storageDirty(EE_MODEL); + } + return idx; + } + + if (tgt_idx == MAX_MIXERS) { + if (x->destCh < MAX_OUTPUT_CHANNELS - 1) { + x->destCh++; + storageDirty(EE_MODEL); + } + return idx; + } + + y = mixAddress(tgt_idx); + uint8_t destCh = x->destCh; + + // If current target is empty or + // assigned to a different channel: + // + // TODO: check what happens with the mixer + // when channel is changed on-the-fly + // + if(!y->srcRaw || destCh != y->destCh) { + if (up) { + if (destCh > 0) { + x->destCh--; + storageDirty(EE_MODEL); + } + } + else { + if (destCh < MAX_OUTPUT_CHANNELS - 1) { + x->destCh++; + storageDirty(EE_MODEL); + } + } + return idx; + } + + mixerTaskStop(); + memswap(x, y, sizeof(MixData)); + mixerTaskStart(); + + storageDirty(EE_MODEL); + return tgt_idx; +} + +static uint8_t _countMixLines() +{ + // search for first blank + uint8_t i = 0; + do { + if (is_memclear(mixAddress(i), sizeof(MixData))) break; + } while (++i < MAX_MIXERS); + + return i; +} + +void updateMixCount() +{ + _nb_mix_lines = _countMixLines(); +} diff --git a/radio/src/mixes.h b/radio/src/mixes.h new file mode 100644 index 00000000000..de3805482d5 --- /dev/null +++ b/radio/src/mixes.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) EdgeTX + * + * Based on code named + * opentx - https://github.com/opentx/opentx + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#pragma once + +#include + +struct MixData; + +// Get a pointer to a mixer line +MixData* mixAddress(uint8_t idx); + +// Insert a new mixer line at 'idx' +void insertMix(uint8_t idx, uint8_t channel); + +// Delete mixer line at 'idx' +void deleteMix(uint8_t idx); + +// Duplicate mixer line at 'idx' in place +void copyMix(uint8_t idx, uint8_t dst, uint8_t channel); + +// Move the mixer line at 'idx' up or down +// by one position and return the new index. +uint8_t moveMix(uint8_t idx, bool up); + +uint8_t getMixCount(); + +// Should only be called from storage +// right after a model has been loaded +void updateMixCount(); diff --git a/radio/src/model_init.cpp b/radio/src/model_init.cpp index 4eebb733009..c122a5f4142 100644 --- a/radio/src/model_init.cpp +++ b/radio/src/model_init.cpp @@ -22,6 +22,7 @@ #include "opentx.h" #include "hal/adc_driver.h" #include "input_mapping.h" +#include "mixes.h" void clearInputs() { diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index 91fc18d41f5..3f689d5974c 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -216,11 +216,6 @@ ExpoData *expoAddress(uint8_t idx ) return &g_model.expoData[idx]; } -MixData *mixAddress(uint8_t idx) -{ - return &g_model.mixData[idx]; -} - LimitData *limitAddress(uint8_t idx) { return &g_model.limitData[idx]; diff --git a/radio/src/opentx.h b/radio/src/opentx.h index 24590a7486e..ccb789437f6 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -627,7 +627,6 @@ uint16_t anaIn(uint8_t chan); FlightModeData * flightModeAddress(uint8_t idx); ExpoData * expoAddress(uint8_t idx); -MixData * mixAddress(uint8_t idx); LimitData * limitAddress(uint8_t idx); LogicalSwitchData * lswAddress(uint8_t idx); USBJoystickChData * usbJChAddress(uint8_t idx); diff --git a/radio/src/storage/storage_common.cpp b/radio/src/storage/storage_common.cpp index d10c244db10..45940a54240 100644 --- a/radio/src/storage/storage_common.cpp +++ b/radio/src/storage/storage_common.cpp @@ -22,6 +22,7 @@ #include "opentx.h" #include "timers_driver.h" #include "tasks/mixer_task.h" +#include "mixes.h" #if defined(USBJ_EX) #include "usb_joystick.h" @@ -106,7 +107,7 @@ void postRadioSettingsLoad() #endif } -static void sortMixerLines() +static bool sortMixerLines() { // simple bubble sort unsigned passes = 0; @@ -132,9 +133,16 @@ static void sortMixerLines() ++passes; } while(swaps > 0); - if (passes > 1) { - storageDirty(EE_MODEL); - } + // anything above 1 means that + // we changed something + return passes > 1; +} + +static void sanitizeMixerLines() +{ + bool dirty = sortMixerLines(); + updateMixCount(); + if (dirty) storageDirty(EE_MODEL); } void postModelLoad(bool alarms) @@ -226,7 +234,7 @@ if(g_model.rssiSource) { } loadCurves(); - sortMixerLines(); + sanitizeMixerLines(); #if defined(GUI) if (alarms) {