Skip to content

Commit

Permalink
fix(radio): Better iteration through mixers on display, sanitize inva…
Browse files Browse the repository at this point in the history
…lid sources (#4008)

* fix: mixer lines with empty source

Backport of #3999, fixes #3367 for 2.9

* Fix color mixes display.

# Conflicts:
#	radio/src/gui/colorlcd/model_mixes.cpp

---------

Co-authored-by: Phil Mitchell <phil.a.mitchell@gmail.com>
  • Loading branch information
raphaelcoeffic and Phil Mitchell authored Sep 24, 2023
1 parent 96c773a commit 7bb146f
Show file tree
Hide file tree
Showing 19 changed files with 245 additions and 251 deletions.
1 change: 1 addition & 0 deletions radio/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ set(SRC
functions.cpp
strhelpers.cpp
switches.cpp
mixes.cpp
mixer.cpp
mixer_scheduler.cpp
stamp.cpp
Expand Down
3 changes: 0 additions & 3 deletions radio/src/gui/128x64/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,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 onSourceLongEnterPress(const char *result);

Expand Down
1 change: 1 addition & 0 deletions radio/src/gui/128x64/model_mix_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/

#include "opentx.h"
#include "mixes.h"

enum MixFields {
MIX_FIELD_NAME,
Expand Down
4 changes: 0 additions & 4 deletions radio/src/gui/212x64/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,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();
Expand Down
1 change: 1 addition & 0 deletions radio/src/gui/212x64/model_mix_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/

#include "opentx.h"
#include "mixes.h"

enum MixFields {
MIX_FIELD_NAME,
Expand Down
5 changes: 0 additions & 5 deletions radio/src/gui/colorlcd/menus.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions radio/src/gui/colorlcd/mixer_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "channel_bar.h"
#include "gvar_numberedit.h"
#include "curve_param.h"
#include "mixes.h"

#include "opentx.h"

Expand Down
1 change: 1 addition & 0 deletions radio/src/gui/colorlcd/mixer_edit_adv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "mixer_edit_adv.h"
#include "numberedit.h"
#include "fm_matrix.h"
#include "mixes.h"

#include "opentx.h"

Expand Down
123 changes: 5 additions & 118 deletions radio/src/gui/colorlcd/model_mixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "input_mix_group.h"
#include "input_mix_button.h"
#include "mixer_edit.h"
#include "mixes.h"

#include "tasks/mixer_task.h"

Expand All @@ -52,116 +53,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)) {
mix->srcRaw = (channel > 3 ? MIXSRC_Rud - 1 + channel
: MIXSRC_Rud - 1 + channelOrder(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
{
Expand Down Expand Up @@ -307,7 +198,7 @@ ModelMixesPage::ModelMixesPage() :

bool ModelMixesPage::reachMixesLimit()
{
if (getMixesCount() >= MAX_MIXERS) {
if (getMixCount() >= MAX_MIXERS) {
new MessageDialog(form, STR_WARNING, STR_NOFREEMIXER);
return true;
}
Expand Down Expand Up @@ -523,22 +414,18 @@ void ModelMixesPage::build(FormWindow * window)

uint8_t index = 0;
MixData* line = g_model.mixData;
for (uint8_t ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++) {

if (index >= MAX_MIXERS) break;
for (uint8_t ch = 0; (ch < MAX_OUTPUT_CHANNELS) && (index < MAX_MIXERS); ch++) {

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_CH1 + 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
createLineButton(group, index);
++index;
++line;
skip_mix = (ch == 0 && is_memclear(line, sizeof(MixData)));
}
}
}
Expand Down
Loading

0 comments on commit 7bb146f

Please sign in to comment.