1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-19 14:25:11 +03:00

Duplicated code removed

This commit is contained in:
bsongis 2014-04-05 08:28:06 +02:00
parent f2af6bf854
commit 1751a1a06c
6 changed files with 34 additions and 25 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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)

View file

@ -2,6 +2,10 @@
#include <QListWidget>
#include <QMessageBox>
#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);

View file

@ -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);

View file

@ -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)