Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: better iteration through mixers on display #3999

Merged
merged 2 commits into from
Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions radio/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ set(SRC
strhelpers.cpp
switches.cpp
analogs.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 @@ -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);
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 @@ -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();
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
126 changes: 5 additions & 121 deletions radio/src/gui/colorlcd/model_mixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
{
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand All @@ -569,7 +454,6 @@ void ModelMixesPage::build(FormWindow * window)
}
++index;
++line;
skip_mix = (ch == 0 && is_memclear(line, sizeof(MixData)));
}
}
}
Expand Down
Loading