fix(radio): Better iteration through mixers on display, sanitize invalid sources (#3999)
* fix: mixer lines with empty source Fixes #3367 * Fix color mixes display. --------- Co-authored-by: Phil Mitchell <phil.a.mitchell@gmail.com>
This commit is contained in:
co-authored by
Phil Mitchell
parent
c502dbeaee
commit
47ff7284fd
@@ -388,6 +388,7 @@ set(SRC
|
|||||||
strhelpers.cpp
|
strhelpers.cpp
|
||||||
switches.cpp
|
switches.cpp
|
||||||
analogs.cpp
|
analogs.cpp
|
||||||
|
mixes.cpp
|
||||||
mixer.cpp
|
mixer.cpp
|
||||||
mixer_scheduler.cpp
|
mixer_scheduler.cpp
|
||||||
stamp.cpp
|
stamp.cpp
|
||||||
|
|||||||
@@ -158,9 +158,6 @@ extern uint8_t editNameCursorPos;
|
|||||||
uint8_t getExposCount();
|
uint8_t getExposCount();
|
||||||
void insertExpo(uint8_t idx);
|
void insertExpo(uint8_t idx);
|
||||||
void deleteExpo(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 onSwitchLongEnterPress(const char *result);
|
||||||
void onSourceLongEnterPress(const char *result);
|
void onSourceLongEnterPress(const char *result);
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "opentx.h"
|
#include "opentx.h"
|
||||||
|
#include "mixes.h"
|
||||||
|
|
||||||
enum MixFields {
|
enum MixFields {
|
||||||
MIX_FIELD_NAME,
|
MIX_FIELD_NAME,
|
||||||
|
|||||||
@@ -157,10 +157,6 @@ uint8_t getExposCount();
|
|||||||
void deleteExpo(uint8_t idx);
|
void deleteExpo(uint8_t idx);
|
||||||
void insertExpo(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
|
#define STATUS_LINE_LENGTH 32
|
||||||
extern char statusLineMsg[STATUS_LINE_LENGTH];
|
extern char statusLineMsg[STATUS_LINE_LENGTH];
|
||||||
void showStatusLine();
|
void showStatusLine();
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "opentx.h"
|
#include "opentx.h"
|
||||||
|
#include "mixes.h"
|
||||||
|
|
||||||
enum MixFields {
|
enum MixFields {
|
||||||
MIX_FIELD_NAME,
|
MIX_FIELD_NAME,
|
||||||
|
|||||||
@@ -101,11 +101,6 @@ uint8_t getExposCount();
|
|||||||
void deleteExpo(uint8_t idx);
|
void deleteExpo(uint8_t idx);
|
||||||
void insertExpo(uint8_t idx, uint8_t input);
|
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);
|
typedef int (*FnFuncP) (int x);
|
||||||
void drawFunction(FnFuncP fn, int x, int y, int width);
|
void drawFunction(FnFuncP fn, int x, int y, int width);
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
#include "channel_bar.h"
|
#include "channel_bar.h"
|
||||||
#include "gvar_numberedit.h"
|
#include "gvar_numberedit.h"
|
||||||
#include "curve_param.h"
|
#include "curve_param.h"
|
||||||
|
#include "mixes.h"
|
||||||
|
|
||||||
#include "opentx.h"
|
#include "opentx.h"
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include "mixer_edit_adv.h"
|
#include "mixer_edit_adv.h"
|
||||||
#include "numberedit.h"
|
#include "numberedit.h"
|
||||||
#include "fm_matrix.h"
|
#include "fm_matrix.h"
|
||||||
|
#include "mixes.h"
|
||||||
|
|
||||||
#include "opentx.h"
|
#include "opentx.h"
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
#include "input_mix_button.h"
|
#include "input_mix_button.h"
|
||||||
#include "mixer_edit.h"
|
#include "mixer_edit.h"
|
||||||
#include "input_mapping.h"
|
#include "input_mapping.h"
|
||||||
|
#include "mixes.h"
|
||||||
|
|
||||||
#include "tasks/mixer_task.h"
|
#include "tasks/mixer_task.h"
|
||||||
#include "hal/adc_driver.h"
|
#include "hal/adc_driver.h"
|
||||||
@@ -54,119 +55,6 @@ static const uint8_t _mask_mplex_replace[] = {
|
|||||||
};
|
};
|
||||||
STATIC_LZ4_BITMAP(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
|
class MixLineButton : public InputMixButton
|
||||||
{
|
{
|
||||||
@@ -312,7 +200,7 @@ ModelMixesPage::ModelMixesPage() :
|
|||||||
|
|
||||||
bool ModelMixesPage::reachMixesLimit()
|
bool ModelMixesPage::reachMixesLimit()
|
||||||
{
|
{
|
||||||
if (getMixesCount() >= MAX_MIXERS) {
|
if (getMixCount() >= MAX_MIXERS) {
|
||||||
new MessageDialog(form, STR_WARNING, STR_NOFREEMIXER);
|
new MessageDialog(form, STR_WARNING, STR_NOFREEMIXER);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -550,17 +438,14 @@ void ModelMixesPage::build(FormWindow * window)
|
|||||||
bool focusSet = false;
|
bool focusSet = false;
|
||||||
uint8_t index = 0;
|
uint8_t index = 0;
|
||||||
MixData* line = g_model.mixData;
|
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;
|
if (line->destCh == ch) {
|
||||||
|
|
||||||
bool skip_mix = (ch == 0 && is_memclear(line, sizeof(MixData)));
|
|
||||||
if (line->destCh == ch && !skip_mix) {
|
|
||||||
|
|
||||||
// one group for the complete mixer channel
|
// one group for the complete mixer channel
|
||||||
auto group = createGroup(form, MIXSRC_FIRST_CH + ch);
|
auto group = createGroup(form, MIXSRC_FIRST_CH + ch);
|
||||||
groups.emplace_back(group);
|
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
|
// one button per input line
|
||||||
auto btn = createLineButton(group, index);
|
auto btn = createLineButton(group, index);
|
||||||
if (!focusSet) {
|
if (!focusSet) {
|
||||||
@@ -569,7 +454,6 @@ void ModelMixesPage::build(FormWindow * window)
|
|||||||
}
|
}
|
||||||
++index;
|
++index;
|
||||||
++line;
|
++line;
|
||||||
skip_mix = (ch == 0 && is_memclear(line, sizeof(MixData)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,118 +23,20 @@
|
|||||||
#include "tasks/mixer_task.h"
|
#include "tasks/mixer_task.h"
|
||||||
#include "hal/adc_driver.h"
|
#include "hal/adc_driver.h"
|
||||||
#include "input_mapping.h"
|
#include "input_mapping.h"
|
||||||
|
#include "mixes.h"
|
||||||
|
|
||||||
#define _STR_MAX(x) "/" #x
|
#define _STR_MAX(x) "/" #x
|
||||||
#define STR_MAX(x) _STR_MAX(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()
|
bool reachMixesLimit()
|
||||||
{
|
{
|
||||||
if (getMixesCount() >= MAX_MIXERS) {
|
if (getMixCount() >= MAX_MIXERS) {
|
||||||
POPUP_WARNING(STR_NOFREEMIXER);
|
POPUP_WARNING(STR_NOFREEMIXER);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
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 (destCh<MAX_OUTPUT_CHANNELS-1) x->destCh++;
|
|
||||||
else return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
mixerTaskStop();
|
|
||||||
memswap(x, y, sizeof(MixData));
|
|
||||||
mixerTaskStart();
|
|
||||||
|
|
||||||
idx = tgt_idx;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void onMixesMenu(const char * result)
|
void onMixesMenu(const char * result)
|
||||||
{
|
{
|
||||||
uint8_t chn = mixAddress(s_currIdx)->destCh + 1;
|
uint8_t chn = mixAddress(s_currIdx)->destCh + 1;
|
||||||
@@ -146,7 +48,7 @@ void onMixesMenu(const char * result)
|
|||||||
if (!reachMixesLimit()) {
|
if (!reachMixesLimit()) {
|
||||||
s_currCh = chn;
|
s_currCh = chn;
|
||||||
if (result == STR_INSERT_AFTER) { s_currIdx++; menuVerticalPosition++; }
|
if (result == STR_INSERT_AFTER) { s_currIdx++; menuVerticalPosition++; }
|
||||||
insertMix(s_currIdx);
|
insertMix(s_currIdx, s_currCh - 1);
|
||||||
pushMenu(menuModelMixOne);
|
pushMenu(menuModelMixOne);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -289,7 +191,7 @@ void menuModelMixAll(event_t event)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
do {
|
do {
|
||||||
swapMixes(s_currIdx, s_copyTgtOfs > 0);
|
s_currIdx = moveMix(s_currIdx, s_copyTgtOfs > 0);
|
||||||
s_copyTgtOfs += (s_copyTgtOfs < 0 ? +1 : -1);
|
s_copyTgtOfs += (s_copyTgtOfs < 0 ? +1 : -1);
|
||||||
} while (s_copyTgtOfs != 0);
|
} while (s_copyTgtOfs != 0);
|
||||||
storageDirty(EE_MODEL);
|
storageDirty(EE_MODEL);
|
||||||
@@ -327,7 +229,7 @@ void menuModelMixAll(event_t event)
|
|||||||
if (s_copyMode) s_currCh = 0;
|
if (s_copyMode) s_currCh = 0;
|
||||||
if (s_currCh) {
|
if (s_currCh) {
|
||||||
if (reachMixesLimit()) break;
|
if (reachMixesLimit()) break;
|
||||||
insertMix(s_currIdx);
|
insertMix(s_currIdx, s_currCh - 1);
|
||||||
pushMenu(menuModelMixOne);
|
pushMenu(menuModelMixOne);
|
||||||
s_copyMode = 0;
|
s_copyMode = 0;
|
||||||
}
|
}
|
||||||
@@ -353,7 +255,7 @@ void menuModelMixAll(event_t event)
|
|||||||
// if (reachMixesLimit()) break;
|
// if (reachMixesLimit()) break;
|
||||||
// s_currCh = chn;
|
// s_currCh = chn;
|
||||||
// if (event == EVT_KEY_LONG(KEY_RIGHT)) { s_currIdx++; menuVerticalPosition++; }
|
// if (event == EVT_KEY_LONG(KEY_RIGHT)) { s_currIdx++; menuVerticalPosition++; }
|
||||||
// insertMix(s_currIdx);
|
// insertMix(s_currIdx, s_currCh - 1);
|
||||||
// pushMenu(menuModelMixOne);
|
// pushMenu(menuModelMixOne);
|
||||||
// s_copyMode = 0;
|
// s_copyMode = 0;
|
||||||
// killEvents(event);
|
// killEvents(event);
|
||||||
@@ -369,7 +271,7 @@ void menuModelMixAll(event_t event)
|
|||||||
if (s_copyTgtOfs==0 && s_copyMode==COPY_MODE) {
|
if (s_copyTgtOfs==0 && s_copyMode==COPY_MODE) {
|
||||||
// insert a mix on the same channel (just above / just below)
|
// insert a mix on the same channel (just above / just below)
|
||||||
if (!reachMixesLimit()) {
|
if (!reachMixesLimit()) {
|
||||||
copyMix(s_currIdx);
|
copyMix(s_currIdx, s_currIdx, mixAddress(s_currIdx)->destCh);
|
||||||
if (IS_NEXT_EVENT(event))
|
if (IS_NEXT_EVENT(event))
|
||||||
s_currIdx++;
|
s_currIdx++;
|
||||||
else if (sub - menuVerticalOffset >= 6)
|
else if (sub - menuVerticalOffset >= 6)
|
||||||
@@ -384,15 +286,13 @@ void menuModelMixAll(event_t event)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// only swap the mix with its neighbor
|
// only swap the mix with its neighbor
|
||||||
if (swapMixes(s_currIdx, IS_PREVIOUS_EVENT(event))) {
|
moveMix(s_currIdx, IS_PREVIOUS_EVENT(event));
|
||||||
storageDirty(EE_MODEL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s_copyTgtOfs = next_ofs;
|
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));
|
lcdDrawText(lcdNextPos, 0, STR_MAX(MAX_MIXERS));
|
||||||
|
|
||||||
// Value
|
// Value
|
||||||
@@ -419,9 +319,9 @@ void menuModelMixAll(event_t event)
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
for (uint8_t ch=1; ch<=MAX_OUTPUT_CHANNELS; ch++) {
|
for (uint8_t ch=1; ch<=MAX_OUTPUT_CHANNELS; ch++) {
|
||||||
MixData * md;
|
|
||||||
coord_t y = MENU_HEADER_HEIGHT+1+(cur-menuVerticalOffset)*FH;
|
coord_t y = MENU_HEADER_HEIGHT+1+(cur-menuVerticalOffset)*FH;
|
||||||
if (i<MAX_MIXERS && (md=mixAddress(i))->srcRaw && md->destCh+1 == ch) {
|
MixData * md = mixAddress(i);
|
||||||
|
if (i < getMixCount() && (md->destCh + 1 == ch)) {
|
||||||
if (cur-menuVerticalOffset >= 0 && cur-menuVerticalOffset < NUM_BODY_LINES) {
|
if (cur-menuVerticalOffset >= 0 && cur-menuVerticalOffset < NUM_BODY_LINES) {
|
||||||
putsChn(0, y, ch, 0); // show CHx
|
putsChn(0, y, ch, 0); // show CHx
|
||||||
}
|
}
|
||||||
@@ -473,7 +373,7 @@ void menuModelMixAll(event_t event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
cur++; y+=FH; mixCnt++; i++; md++;
|
cur++; y+=FH; mixCnt++; i++; md++;
|
||||||
} while (i<MAX_MIXERS && md->srcRaw && 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))) {
|
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);
|
lcdDrawRect(22, y-1, LCD_W-22, 9, DOTTED);
|
||||||
cur++;
|
cur++;
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include "hal/adc_driver.h"
|
#include "hal/adc_driver.h"
|
||||||
#include "hal/switch_driver.h"
|
#include "hal/switch_driver.h"
|
||||||
#include "switches.h"
|
#include "switches.h"
|
||||||
|
#include "mixes.h"
|
||||||
|
|
||||||
#undef CPN
|
#undef CPN
|
||||||
#include "MultiSubtypeDefs.h"
|
#include "MultiSubtypeDefs.h"
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
#include "../timers.h"
|
#include "../timers.h"
|
||||||
#include "model_init.h"
|
#include "model_init.h"
|
||||||
#include "gvars.h"
|
#include "gvars.h"
|
||||||
|
#include "mixes.h"
|
||||||
|
|
||||||
#if defined(SDCARD_YAML)
|
#if defined(SDCARD_YAML)
|
||||||
#include <storage/sdcard_yaml.h>
|
#include <storage/sdcard_yaml.h>
|
||||||
@@ -887,10 +888,9 @@ static int luaModelInsertMix(lua_State *L)
|
|||||||
unsigned int first = getFirstMix(chn);
|
unsigned int first = getFirstMix(chn);
|
||||||
unsigned int count = getMixesCountFromFirst(chn, first);
|
unsigned int count = getMixesCountFromFirst(chn, first);
|
||||||
|
|
||||||
if (chn<MAX_OUTPUT_CHANNELS && getMixesCount()<MAX_MIXERS && idx<=count) {
|
if (chn<MAX_OUTPUT_CHANNELS && getMixCount()<MAX_MIXERS && idx<=count) {
|
||||||
idx += first;
|
idx += first;
|
||||||
s_currCh = chn+1;
|
insertMix(idx, chn + 1);
|
||||||
insertMix(idx);
|
|
||||||
MixData *mix = mixAddress(idx);
|
MixData *mix = mixAddress(idx);
|
||||||
luaL_checktype(L, -1, LUA_TTABLE);
|
luaL_checktype(L, -1, LUA_TTABLE);
|
||||||
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) {
|
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) {
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include "timers.h"
|
#include "timers.h"
|
||||||
#include "switches.h"
|
#include "switches.h"
|
||||||
#include "input_mapping.h"
|
#include "input_mapping.h"
|
||||||
|
#include "mixes.h"
|
||||||
|
|
||||||
#include "hal/adc_driver.h"
|
#include "hal/adc_driver.h"
|
||||||
#include "hal/trainer_driver.h"
|
#include "hal/trainer_driver.h"
|
||||||
|
|||||||
@@ -0,0 +1,159 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "mixes.h"
|
||||||
|
#include "tasks/mixer_task.h"
|
||||||
|
#include "hal/adc_driver.h"
|
||||||
|
|
||||||
|
#include "opentx.h"
|
||||||
|
|
||||||
|
static uint8_t _nb_mix_lines;
|
||||||
|
|
||||||
|
MixData* mixAddress(uint8_t idx) { return &g_model.mixData[idx]; }
|
||||||
|
|
||||||
|
uint8_t getMixCount() { return _nb_mix_lines; }
|
||||||
|
|
||||||
|
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 (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();
|
||||||
|
}
|
||||||
@@ -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 <stdint.h>
|
||||||
|
|
||||||
|
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();
|
||||||
@@ -22,6 +22,7 @@
|
|||||||
#include "opentx.h"
|
#include "opentx.h"
|
||||||
#include "hal/adc_driver.h"
|
#include "hal/adc_driver.h"
|
||||||
#include "input_mapping.h"
|
#include "input_mapping.h"
|
||||||
|
#include "mixes.h"
|
||||||
|
|
||||||
void clearInputs()
|
void clearInputs()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -215,11 +215,6 @@ ExpoData *expoAddress(uint8_t idx )
|
|||||||
return &g_model.expoData[idx];
|
return &g_model.expoData[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
MixData *mixAddress(uint8_t idx)
|
|
||||||
{
|
|
||||||
return &g_model.mixData[idx];
|
|
||||||
}
|
|
||||||
|
|
||||||
LimitData *limitAddress(uint8_t idx)
|
LimitData *limitAddress(uint8_t idx)
|
||||||
{
|
{
|
||||||
return &g_model.limitData[idx];
|
return &g_model.limitData[idx];
|
||||||
|
|||||||
@@ -627,7 +627,6 @@ uint16_t anaIn(uint8_t chan);
|
|||||||
|
|
||||||
FlightModeData * flightModeAddress(uint8_t idx);
|
FlightModeData * flightModeAddress(uint8_t idx);
|
||||||
ExpoData * expoAddress(uint8_t idx);
|
ExpoData * expoAddress(uint8_t idx);
|
||||||
MixData * mixAddress(uint8_t idx);
|
|
||||||
LimitData * limitAddress(uint8_t idx);
|
LimitData * limitAddress(uint8_t idx);
|
||||||
LogicalSwitchData * lswAddress(uint8_t idx);
|
LogicalSwitchData * lswAddress(uint8_t idx);
|
||||||
USBJoystickChData * usbJChAddress(uint8_t idx);
|
USBJoystickChData * usbJChAddress(uint8_t idx);
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include "opentx.h"
|
#include "opentx.h"
|
||||||
#include "timers_driver.h"
|
#include "timers_driver.h"
|
||||||
#include "tasks/mixer_task.h"
|
#include "tasks/mixer_task.h"
|
||||||
|
#include "mixes.h"
|
||||||
|
|
||||||
#if defined(USBJ_EX)
|
#if defined(USBJ_EX)
|
||||||
#include "usb_joystick.h"
|
#include "usb_joystick.h"
|
||||||
@@ -106,7 +107,7 @@ void postRadioSettingsLoad()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sortMixerLines()
|
static bool sortMixerLines()
|
||||||
{
|
{
|
||||||
// simple bubble sort
|
// simple bubble sort
|
||||||
unsigned passes = 0;
|
unsigned passes = 0;
|
||||||
@@ -132,9 +133,16 @@ static void sortMixerLines()
|
|||||||
++passes;
|
++passes;
|
||||||
} while(swaps > 0);
|
} while(swaps > 0);
|
||||||
|
|
||||||
if (passes > 1) {
|
// anything above 1 means that
|
||||||
storageDirty(EE_MODEL);
|
// we changed something
|
||||||
}
|
return passes > 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void sanitizeMixerLines()
|
||||||
|
{
|
||||||
|
bool dirty = sortMixerLines();
|
||||||
|
updateMixCount();
|
||||||
|
if (dirty) storageDirty(EE_MODEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void postModelLoad(bool alarms)
|
void postModelLoad(bool alarms)
|
||||||
@@ -226,7 +234,7 @@ if(g_model.rssiSource) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadCurves();
|
loadCurves();
|
||||||
sortMixerLines();
|
sanitizeMixerLines();
|
||||||
|
|
||||||
#if defined(GUI)
|
#if defined(GUI)
|
||||||
if (alarms) {
|
if (alarms) {
|
||||||
|
|||||||
Reference in New Issue
Block a user