From 1751a1a06cfc38e42a2c1d97bb3c687e15c8e7b2 Mon Sep 17 00:00:00 2001 From: bsongis Date: Sat, 5 Apr 2014 08:28:06 +0200 Subject: [PATCH] Duplicated code removed --- companion/src/eeprominterface.cpp | 30 +++++++++++++++++++++------ companion/src/eeprominterface.h | 10 ++------- companion/src/helpers.h | 4 +--- companion/src/modeledit/templates.cpp | 4 ++++ companion/src/wizarddata.cpp | 4 ++-- companion/src/wizarddialog.cpp | 7 +------ 6 files changed, 34 insertions(+), 25 deletions(-) diff --git a/companion/src/eeprominterface.cpp b/companion/src/eeprominterface.cpp index 6dd7bef7a..eb231f563 100644 --- a/companion/src/eeprominterface.cpp +++ b/companion/src/eeprominterface.cpp @@ -15,6 +15,13 @@ QString EEPROMWarnings; const char * switches9X[] = { "3POS", "THR", "RUD", "ELE", "AIL", "GEA", "TRN" }; const char * switchesX9D[] = { "SA", "SB", "SC", "SD", "SE", "SF", "SG", "SH" }; +const uint8_t chout_ar[] = { // First number is 0..23 -> template setup, Second is relevant channel out + 1,2,3,4 , 1,2,4,3 , 1,3,2,4 , 1,3,4,2 , 1,4,2,3 , 1,4,3,2, + 2,1,3,4 , 2,1,4,3 , 2,3,1,4 , 2,3,4,1 , 2,4,1,3 , 2,4,3,1, + 3,1,2,4 , 3,1,4,2 , 3,2,1,4 , 3,2,4,1 , 3,4,1,2 , 3,4,2,1, + 4,1,2,3 , 4,1,3,2 , 4,2,1,3 , 4,2,3,1 , 4,3,1,2 , 4,3,2,1 +}; + void setEEPROMString(char *dst, const char *src, int size) { memcpy(dst, src, size); @@ -910,16 +917,27 @@ GeneralSettings::GeneralSettings() } } -RawSource GeneralSettings::getDefaultSource(unsigned int channel) const +int GeneralSettings::getDefaultStick(unsigned int channel) const { - unsigned int stick_index = chout_ar[4*templateSetup + channel] - 1; - return RawSource(SOURCE_TYPE_STICK, stick_index); + if (channel >= NUM_STICKS) + return -1; + else + return chout_ar[4*templateSetup + channel] - 1; } -int GeneralSettings::translateSource(unsigned int channel) const +RawSource GeneralSettings::getDefaultSource(unsigned int channel) const { - for(int i=0; i<4; i++){ - if (chout_ar[4*templateSetup + i]==(channel+1)) + int stick = getDefaultStick(channel); + if (stick >= 0) + return RawSource(SOURCE_TYPE_STICK, stick); + else + return RawSource(SOURCE_TYPE_NONE); +} + +int GeneralSettings::getDefaultChannel(unsigned int stick) const +{ + for (int i=0; i<4; i++){ + if (getDefaultStick(i) == (int)stick) return i; } return -1; diff --git a/companion/src/eeprominterface.h b/companion/src/eeprominterface.h index e18902e74..ab2ad16b4 100644 --- a/companion/src/eeprominterface.h +++ b/companion/src/eeprominterface.h @@ -106,13 +106,6 @@ const uint8_t modn12x3[4][4]= { #define DSW_SG1 19 #define DSW_SG2 20 -const uint8_t chout_ar[] = { //First number is 0..23 -> template setup, Second is relevant channel out - 1,2,3,4 , 1,2,4,3 , 1,3,2,4 , 1,3,4,2 , 1,4,2,3 , 1,4,3,2, - 2,1,3,4 , 2,1,4,3 , 2,3,1,4 , 2,3,4,1 , 2,4,1,3 , 2,4,3,1, - 3,1,2,4 , 3,1,4,2 , 3,2,1,4 , 3,2,4,1 , 3,4,1,2 , 3,4,2,1, - 4,1,2,3 , 4,1,3,2 , 4,2,1,3 , 4,2,3,1 , 4,3,1,2 , 4,3,2,1 -}; // TODO delete it? - // Beep center bits #define BC_BIT_RUD (0x01) #define BC_BIT_ELE (0x02) @@ -416,8 +409,9 @@ class GeneralSettings { public: GeneralSettings(); + int getDefaultStick(unsigned int channel) const; RawSource getDefaultSource(unsigned int channel) const; - int translateSource(unsigned int channel) const; + int getDefaultChannel(unsigned int stick) const; unsigned int version; unsigned int variant; diff --git a/companion/src/helpers.h b/companion/src/helpers.h index d4f655089..bc26267c6 100644 --- a/companion/src/helpers.h +++ b/companion/src/helpers.h @@ -10,13 +10,11 @@ extern const QColor colors[C9X_MAX_CURVES]; //convert from mode 1 to mode generalSettings.stickMode //NOTICE! => 1..4 -> 1..4 -#define CONVERT_MODE(x) (((x)<=4) ? modn12x3[generalSettings.stickMode][((x)-1)] : (x)) -#define CHANNEL_ORDER(x) (chout_ar[generalSettings.templateSetup*4 + (x)-1]) +#define CONVERT_MODE(x) (((x)<=4) ? modn12x3[generalSettings.stickMode][((x)-1)] : (x)) #define CURVE_BASE 7 #define CH(x) (SRC_CH1+(x)-1-(SRC_SWC-SRC_3POS)) #define CV(x) (CURVE_BASE+(x)-1) -#define CC(x) (CHANNEL_ORDER(x)) //need to invert this to work with dest #define CURVE5(x) ((x)-1) #define CURVE9(x) (MAX_CURVE5+(x)-1) diff --git a/companion/src/modeledit/templates.cpp b/companion/src/modeledit/templates.cpp index 38bec941a..a0e0aa0ac 100644 --- a/companion/src/modeledit/templates.cpp +++ b/companion/src/modeledit/templates.cpp @@ -2,6 +2,10 @@ #include #include +#define CHANNEL_ORDER(x) generalSettings.getDefaultStick(x) +#define CC(x) (CHANNEL_ORDER(x)) //need to invert this to work with dest +// TODO ICC is GeneralSettings::getDefaultChannel(unsigned int stick) + void ModelEdit::setCurve(uint8_t c, int8_t ar[]) { int len=sizeof(ar)/sizeof(int8_t); diff --git a/companion/src/wizarddata.cpp b/companion/src/wizarddata.cpp index ae8303b58..eff44b35e 100644 --- a/companion/src/wizarddata.cpp +++ b/companion/src/wizarddata.cpp @@ -56,8 +56,8 @@ void WizMix::addMix(ModelData &model, Input input, int weight, int channel, int MixData & mix = model.mixData[mixIndex++]; mix.destCh = channel+1; if (isTaranis){ - int source = settings.translateSource(input-1); - mix.srcRaw = RawSource(SOURCE_TYPE_VIRTUAL_INPUT, source, &model); + int channel = settings.getDefaultChannel(input-1); + mix.srcRaw = RawSource(SOURCE_TYPE_VIRTUAL_INPUT, channel, &model); } else mix.srcRaw = RawSource(SOURCE_TYPE_STICK, input-1); diff --git a/companion/src/wizarddialog.cpp b/companion/src/wizarddialog.cpp index ec2a82c45..b64086ede 100644 --- a/companion/src/wizarddialog.cpp +++ b/companion/src/wizarddialog.cpp @@ -143,12 +143,7 @@ StandardPage::StandardPage(WizardPage currentPage, WizardDialog *dlg, QString im int StandardPage::getDefaultChannel(const Input input) { - for (int channel=0; channel<4; channel++) { - unsigned int stick_index = chout_ar[4*wizDlg->settings.templateSetup + channel]; - if (input == stick_index) - return channel; - } - return -1; + return wizDlg->settings.getDefaultChannel(input-1); } int StandardPage::nextFreeChannel(int channel)