diff --git a/companion/src/eeprominterface.cpp b/companion/src/eeprominterface.cpp index 54a94fda7..f6bea20af 100644 --- a/companion/src/eeprominterface.cpp +++ b/companion/src/eeprominterface.cpp @@ -279,34 +279,39 @@ QString RawSwitch::toString() QObject::tr("REa"), QObject::tr("REb") }; - if (index == 0) { - return QObject::tr("----"); - } - else if (index < 0) { + static const QString timerModes[] = { + QObject::tr("OFF"), QObject::tr("ABS"), + QObject::tr("THs"), QObject::tr("TH%"), QObject::tr("THt") + }; + + if (index < 0) { return QString("!") + RawSwitch(type, -index).toString(); } else { - index = index - 1; switch(type) { case SWITCH_TYPE_SWITCH: if (IS_TARANIS(GetEepromInterface()->getBoard())) - return CHECK_IN_ARRAY(switchesX9D, index); + return CHECK_IN_ARRAY(switchesX9D, index-1); else - return CHECK_IN_ARRAY(switches9X, index); + return CHECK_IN_ARRAY(switches9X, index-1); case SWITCH_TYPE_VIRTUAL: - return CHECK_IN_ARRAY(virtualSwitches, index); + return CHECK_IN_ARRAY(virtualSwitches, index-1); case SWITCH_TYPE_MULTIPOS_POT: - return CHECK_IN_ARRAY(multiposPots, index); + return CHECK_IN_ARRAY(multiposPots, index-1); case SWITCH_TYPE_TRIM: - return CHECK_IN_ARRAY(trimsSwitches, index); + return CHECK_IN_ARRAY(trimsSwitches, index-1); case SWITCH_TYPE_ROTARY_ENCODER: - return CHECK_IN_ARRAY(rotaryEncoders, index); + return CHECK_IN_ARRAY(rotaryEncoders, index-1); case SWITCH_TYPE_ON: return QObject::tr("ON"); case SWITCH_TYPE_OFF: return QObject::tr("OFF"); + case SWITCH_TYPE_NONE: + return QObject::tr("----"); + case SWITCH_TYPE_TIMER_MODE: + return CHECK_IN_ARRAY(timerModes, index); default: - break; + return QObject::tr("???"); } } } @@ -859,7 +864,8 @@ void ModelData::clear() if (IS_TARANIS(board)) { moduleData[0].protocol=PXX_XJT_X16; moduleData[1].protocol=OFF; - } else { + } + else { moduleData[0].protocol=PPM; moduleData[1].protocol=OFF; } @@ -878,9 +884,10 @@ void ModelData::clear() expoData[i].clear(); for (int i=0; i off, abs, THs, TH%, THt, sw/!sw, !m_sw/!m_sw + RawSwitch mode; bool minuteBeep; unsigned int countdownBeep; bool dir; // 0=>Count Down, 1=>Count Up unsigned int val; bool persistent; int pvalue; - void clear() { memset(this, 0, sizeof(TimerData)); } + void clear() { memset(this, 0, sizeof(TimerData)); mode = RawSwitch(SWITCH_TYPE_TIMER_MODE, 0); } }; enum Protocol { @@ -1085,10 +1074,6 @@ class EEPROMInterface virtual int isAvailable(Protocol proto, int port=0) = 0; - virtual bool isAvailable(const RawSwitch & swtch, UseContext context) { return true; } - - virtual bool isAvailable(const RawSource & source, UseContext context) { return true; } - virtual SimulatorInterface * getSimulator() = 0; virtual const int getEEpromSize() = 0; diff --git a/companion/src/firmwares/er9x/er9xeeprom.cpp b/companion/src/firmwares/er9x/er9xeeprom.cpp index c095a1789..2a74458d1 100644 --- a/companion/src/firmwares/er9x/er9xeeprom.cpp +++ b/companion/src/firmwares/er9x/er9xeeprom.cpp @@ -335,8 +335,9 @@ t_Er9xFrSkyData::operator FrSkyData () return c9x; } -TimerMode getEr9xTimerMode(int mode) +RawSwitch getEr9xTimerMode(int mode) { + /* if (mode <= -33) return TimerMode(TMRMODE_FIRST_NEG_SWITCH+(mode+33)); else if (mode <= -1) @@ -347,6 +348,8 @@ TimerMode getEr9xTimerMode(int mode) return TimerMode(TMRMODE_FIRST_SWITCH+(mode-16)); else return TimerMode(TMRMODE_FIRST_SWITCH+(mode-16-21)); + */ + return RawSwitch(); } t_Er9xModelData::operator ModelData () diff --git a/companion/src/firmwares/ersky9x/ersky9xeeprom.cpp b/companion/src/firmwares/ersky9x/ersky9xeeprom.cpp index 677607f0c..62508515e 100644 --- a/companion/src/firmwares/ersky9x/ersky9xeeprom.cpp +++ b/companion/src/firmwares/ersky9x/ersky9xeeprom.cpp @@ -5,14 +5,12 @@ extern RawSwitch er9xToSwitch(int8_t sw); -TimerMode getErSky9xTimerMode(int mode) +RawSwitch getErSky9xTimerMode(int mode) { if (mode<4) - return TimerMode(mode); - else if (mode < 20) - return TimerMode(TMRMODE_FIRST_CHPERC+(mode-4)); + return RawSwitch(SWITCH_TYPE_TIMER_MODE, mode); else - return TimerMode(0); + return RawSwitch(); } RawSwitch ersky9xToSwitch(int8_t sw) diff --git a/companion/src/firmwares/ersky9x/ersky9xeeprom.h b/companion/src/firmwares/ersky9x/ersky9xeeprom.h index 38e88cec3..e92a48983 100644 --- a/companion/src/firmwares/ersky9x/ersky9xeeprom.h +++ b/companion/src/firmwares/ersky9x/ersky9xeeprom.h @@ -19,8 +19,7 @@ #include #include "eeprominterface.h" -extern TimerMode getEr9xTimerMode(int mode); -extern int setEr9xTimerMode(TimerMode mode); +extern RawSwitch getEr9xTimerMode(int mode); //eeprom data #define ERSKY9X_MAX_MIXERS_V10 32 diff --git a/companion/src/firmwares/gruvin9x/gruvin9xeeprom.cpp b/companion/src/firmwares/gruvin9x/gruvin9xeeprom.cpp index 5930dea02..41724c5e0 100644 --- a/companion/src/firmwares/gruvin9x/gruvin9xeeprom.cpp +++ b/companion/src/firmwares/gruvin9x/gruvin9xeeprom.cpp @@ -373,7 +373,7 @@ t_Gruvin9xPhaseData_v106::operator PhaseData () return c9x; } -extern TimerMode getEr9xTimerMode(int mode); +extern RawSwitch getEr9xTimerMode(int mode); t_Gruvin9xTimerData::operator TimerData () { diff --git a/companion/src/firmwares/opentx/open9xSky9xeeprom.cpp b/companion/src/firmwares/opentx/open9xSky9xeeprom.cpp index b33711902..393833cc4 100644 --- a/companion/src/firmwares/opentx/open9xSky9xeeprom.cpp +++ b/companion/src/firmwares/opentx/open9xSky9xeeprom.cpp @@ -124,7 +124,7 @@ RawSource open9xArm210ToSource(int8_t value) t_Open9xArmTimerData_v202::operator TimerData () { TimerData c9x; - +/* if (mode <= -42) c9x.mode = TimerMode(TMRMODE_FIRST_NEG_SWITCH+(mode+22)); else if (mode <= -1) @@ -135,7 +135,7 @@ t_Open9xArmTimerData_v202::operator TimerData () c9x.mode = TimerMode(TMRMODE_FIRST_SWITCH+(mode-5)); else c9x.mode = TimerMode(TMRMODE_FIRST_SWITCH+(mode-5-21)); - +*/ c9x.val = val; c9x.persistent = false; c9x.dir = (val == 0); diff --git a/companion/src/firmwares/opentx/open9xStockeeprom.cpp b/companion/src/firmwares/opentx/open9xStockeeprom.cpp index 1791d78cd..0e6e010b6 100644 --- a/companion/src/firmwares/opentx/open9xStockeeprom.cpp +++ b/companion/src/firmwares/opentx/open9xStockeeprom.cpp @@ -701,7 +701,7 @@ t_Open9xPhaseData_v201::operator PhaseData () t_Open9xTimerData_v201::operator TimerData () { TimerData c9x; - c9x.mode = TMRMODE_OFF; + // c9x.mode = TMRMODE_OFF; c9x.val = val; c9x.persistent = persistent; c9x.dir = dir; @@ -711,7 +711,7 @@ t_Open9xTimerData_v201::operator TimerData () t_Open9xTimerData_v202::operator TimerData () { TimerData c9x; - +/* if (mode <= -22) c9x.mode = TimerMode(TMRMODE_FIRST_NEG_SWITCH+(mode+22)); else if (mode <= -1) @@ -722,7 +722,7 @@ t_Open9xTimerData_v202::operator TimerData () c9x.mode = TimerMode(TMRMODE_FIRST_SWITCH+(mode-5)); else c9x.mode = TimerMode(TMRMODE_FIRST_SWITCH+(mode-5-21)); - +*/ c9x.val = val; c9x.persistent = false; c9x.dir = (val == 0); diff --git a/companion/src/firmwares/opentx/opentxeeprom.cpp b/companion/src/firmwares/opentx/opentxeeprom.cpp index b0d2cab59..9b7154a9d 100644 --- a/companion/src/firmwares/opentx/opentxeeprom.cpp +++ b/companion/src/firmwares/opentx/opentxeeprom.cpp @@ -42,29 +42,50 @@ class SwitchesConversionTable: public ConversionTable { SwitchesConversionTable(BoardEnum board, unsigned int version, unsigned long flags=0) { int val=0; - - addConversion(RawSwitch(SWITCH_TYPE_NONE), val++); + int offset=0; + if (flags & POPULATE_TIMER_MODES) { + offset = 4; + for (int i=0; i<5; i++) { + addConversion(RawSwitch(SWITCH_TYPE_TIMER_MODE, i), val++); + } + } + else { + addConversion(RawSwitch(SWITCH_TYPE_NONE), val++); + } for (int i=1; i<=MAX_SWITCHES_POSITION(board); i++) { int s = switchIndex(i, board, version); - addConversion(RawSwitch(SWITCH_TYPE_SWITCH, -s), -val); + addConversion(RawSwitch(SWITCH_TYPE_SWITCH, -s), -val+offset); addConversion(RawSwitch(SWITCH_TYPE_SWITCH, s), val++); } - for (int i=1; i<=MAX_CUSTOM_SWITCHES(board, version); i++) { - addConversion(RawSwitch(SWITCH_TYPE_VIRTUAL, -i), -val); - addConversion(RawSwitch(SWITCH_TYPE_VIRTUAL, i), val++); - } - - if (IS_TARANIS(board) && version >= 216) { - for (int i=0; i<2; i++) { - for (int j=0; j<6; j++) { - addConversion(RawSwitch(SWITCH_TYPE_MULTIPOS_POT, i*6+j), val++); - } + if (version >= 216) { + for (int i=1; i<=GetEepromInterface()->getCapability(MultiposPots) * GetEepromInterface()->getCapability(MultiposPotsPositions); i++) { + addConversion(RawSwitch(SWITCH_TYPE_MULTIPOS_POT, -i), -val+offset); + addConversion(RawSwitch(SWITCH_TYPE_MULTIPOS_POT, i), val++); } } - addConversion(RawSwitch(SWITCH_TYPE_OFF), -val); + if (version >= 216) { + for (int i=1; i<=8; i++) { + addConversion(RawSwitch(SWITCH_TYPE_TRIM, -i), -val+offset); + addConversion(RawSwitch(SWITCH_TYPE_TRIM, i), val++); + } + } + + if (version >= 216) { + for (int i=1; i<=MAX_ROTARY_ENCODERS(board); i++) { + addConversion(RawSwitch(SWITCH_TYPE_ROTARY_ENCODER, -i), -val+offset); + addConversion(RawSwitch(SWITCH_TYPE_ROTARY_ENCODER, i), val++); + } + } + + for (int i=1; i<=MAX_CUSTOM_SWITCHES(board, version); i++) { + addConversion(RawSwitch(SWITCH_TYPE_VIRTUAL, -i), -val+offset); + addConversion(RawSwitch(SWITCH_TYPE_VIRTUAL, i), val++); + } + + addConversion(RawSwitch(SWITCH_TYPE_OFF), -val+offset); addConversion(RawSwitch(SWITCH_TYPE_ON), val++); if (version < 216) { @@ -261,59 +282,6 @@ class SourcesConversionTable: public ConversionTable { } }; -class TimerModeConversionTable: public ConversionTable { - - public: - TimerModeConversionTable(BoardEnum board, unsigned int version, unsigned long flags=0) - { - int val=0; - - addConversion(TMRMODE_OFF, val++); - addConversion(TMRMODE_ABS, val++); - addConversion(TMRMODE_THs, val++); - addConversion(TMRMODE_THp, val++); - addConversion(TMRMODE_THt, val++); - - int swCount = MAX_SWITCHES_POSITION(board) + MAX_CUSTOM_SWITCHES(board, version); - - for (int i=0; i > { - public: - TimerModeField(TimerMode & mode, BoardEnum board, unsigned int version, unsigned long flags=0): - ConversionField< SignedField<8> >(_mode, &conversionTable, "TimerMode"), - conversionTable(board, version, flags), - mode(mode), - _mode(0) - { - } - - virtual void beforeExport() - { - _mode = mode; - ConversionField< SignedField<8> >::beforeExport(); - } - - virtual void afterImport() - { - ConversionField< SignedField<8> >::afterImport(); - mode = (TimerMode)_mode; - } - - protected: - TimerModeConversionTable conversionTable; - TimerMode & mode; - int _mode; -}; - template class SwitchField: public ConversionField< SignedField > { public: @@ -1086,10 +1054,10 @@ class CustomSwitchesFunctionsTable: public ConversionTable { } }; -class CustomSwitchesAndSwitchesConversionTable: public ConversionTable { +class AndSwitchesConversionTable: public ConversionTable { public: - CustomSwitchesAndSwitchesConversionTable(BoardEnum board, unsigned int version) + AndSwitchesConversionTable(BoardEnum board, unsigned int version) { int val=0; addConversion(RawSwitch(SWITCH_TYPE_NONE), val++); @@ -1127,6 +1095,29 @@ class CustomSwitchesAndSwitchesConversionTable: public ConversionTable { } } + static ConversionTable * getInstance(BoardEnum board, unsigned int version) + { + if (IS_ARM(board) && version >= 216) + return new SwitchesConversionTable(board, version); + else + return new AndSwitchesConversionTable(board, version); + +#if 0 + static std::list internalCache; + + for (std::list::iterator it=internalCache.begin(); it!=internalCache.end(); it++) { + Cache element = *it; + if (element.board == board && element.version == version && element.flags == flags) + return element.table; + } + + Cache element(board, version, flags, new SwitchesConversionTable(board, version, flags)); + internalCache.push_back(element); + return element.table; +#endif + } + + protected: void addConversion(const RawSwitch & sw, const int b) @@ -1147,7 +1138,7 @@ class CustomSwitchField: public TransformedField { functionsConversionTable(board, version), sourcesConversionTable(SourcesConversionTable::getInstance(board, version, variant, (version >= 214 || (!IS_ARM(board) && version >= 213)) ? 0 : FLAG_NOSWITCHES)), switchesConversionTable(SwitchesConversionTable::getInstance(board, version)), - andswitchesConversionTable(board, version) + andswitchesConversionTable(AndSwitchesConversionTable::getInstance(board, version)) { if (IS_ARM(board) && version >= 215) { internalField.Append(new SignedField<16>(v1)); @@ -1163,13 +1154,13 @@ class CustomSwitchField: public TransformedField { internalField.Append(new UnsignedField<8>(csw.delay)); internalField.Append(new UnsignedField<8>(csw.duration)); if (version >= 214) { - internalField.Append(new ConversionField< SignedField<8> >((int &)csw.andsw, &andswitchesConversionTable, "AND switch")); + internalField.Append(new ConversionField< SignedField<8> >((int &)csw.andsw, andswitchesConversionTable, "AND switch")); } } else { if (version >= 213) { internalField.Append(new ConversionField< UnsignedField<4> >(csw.func, &functionsConversionTable, "Function")); - internalField.Append(new ConversionField< UnsignedField<4> >(csw.andsw, &andswitchesConversionTable, "AND switch")); + internalField.Append(new ConversionField< UnsignedField<4> >((unsigned int &)csw.andsw, andswitchesConversionTable, "AND switch")); } else { internalField.Append(new ConversionField< UnsignedField<8> >(csw.func, &functionsConversionTable, "Function")); @@ -1224,7 +1215,7 @@ class CustomSwitchField: public TransformedField { CustomSwitchesFunctionsTable functionsConversionTable; SourcesConversionTable * sourcesConversionTable; SwitchesConversionTable * switchesConversionTable; - CustomSwitchesAndSwitchesConversionTable andswitchesConversionTable; + ConversionTable * andswitchesConversionTable; int v1; int v2; }; @@ -1977,7 +1968,7 @@ Open9xModelDataNew::Open9xModelDataNew(ModelData & modelData, BoardEnum board, u } for (int i=0; i(modelData.timers[i].mode, board, version, POPULATE_TIMER_MODES)); if ((IS_ARM(board) || IS_2560(board)) && version >= 216) { internalField.Append(new UnsignedField<16>(modelData.timers[i].val)); internalField.Append(new UnsignedField<2>(modelData.timers[i].countdownBeep)); diff --git a/companion/src/firmwares/th9x/th9xeeprom.cpp b/companion/src/firmwares/th9x/th9xeeprom.cpp index 8df98e04b..e8cb72353 100644 --- a/companion/src/firmwares/th9x/th9xeeprom.cpp +++ b/companion/src/firmwares/th9x/th9xeeprom.cpp @@ -2,18 +2,6 @@ #include "helpers.h" #include "th9xeeprom.h" -int8_t th9xFromSwitch(const RawSwitch & sw) -{ - switch (sw.type) { - case SWITCH_TYPE_SWITCH: - return sw.index; - case SWITCH_TYPE_VIRTUAL: - return sw.index > 0 ? (9 + sw.index) : (-9 -sw.index); - default: - return 0; - } -} - RawSwitch th9xToSwitch(int8_t sw) { if (sw == 0) @@ -266,7 +254,7 @@ t_Th9xModelData::operator ModelData () ModelData c9x; c9x.used = true; getEEPROMString(c9x.name, name, sizeof(name)); - switch(tmrMode) { + /*switch(tmrMode) { case 1: c9x.timers[0].mode = TMRMODE_ABS; break; @@ -279,7 +267,7 @@ t_Th9xModelData::operator ModelData () default: c9x.timers[0].mode = TMRMODE_OFF; break; - } + }*/ // c9x.timers[0].dir = tmrDir; c9x.timers[0].val = tmrVal; /*c9x.protocol = (Protocol)protocol; diff --git a/companion/src/helpers.cpp b/companion/src/helpers.cpp index 9f3359946..7864dc100 100644 --- a/companion/src/helpers.cpp +++ b/companion/src/helpers.cpp @@ -368,53 +368,6 @@ void populateGvarUseCB(QComboBox *b, unsigned int phase) } } -void populateTimerSwitchCB(QComboBox *b, int value) -{ - b->clear(); - uint8_t count=0; - for (int i=-128; i<128; i++) { - QString timerMode = getTimerMode(i); - if (!timerMode.isEmpty()) { - b->addItem(getTimerMode(i), i); - if (i==value) - b->setCurrentIndex(b->count()-1); - count++; - } - } - b->setMaxVisibleItems(10); -} - -QString getTimerMode(int tm) { - - QString stt = "OFFABSTHsTH%THt"; - - QString s; - - if (tm >= 0 && tm <= TMRMODE_THt) { - return stt.mid(abs(tm)*3, 3); - } - - int tma = abs(tm); - - if (tma >= TMRMODE_FIRST_SWITCH && tma < TMRMODE_FIRST_SWITCH + GetEepromInterface()->getCapability(SwitchesPositions)) { - s = RawSwitch(SWITCH_TYPE_SWITCH, tma - TMRMODE_FIRST_SWITCH + 1).toString(); - if (tm < 0) s.prepend("!"); - return s; - } - - if (tma >= TMRMODE_FIRST_SWITCH + GetEepromInterface()->getCapability(SwitchesPositions) && tma < TMRMODE_FIRST_SWITCH + GetEepromInterface()->getCapability(SwitchesPositions) + GetEepromInterface()->getCapability(CustomSwitches)) { - s = RawSwitch(SWITCH_TYPE_VIRTUAL, tma - TMRMODE_FIRST_SWITCH - GetEepromInterface()->getCapability(SwitchesPositions) + 1).toString(); - if (tm < 0) s.prepend("!"); - return s; - } - - if (tma >=TMRMODE_FIRST_CHPERC && tma getBoard())) { + populateSwitchCB(b, value); + } + else { + RawSwitch item; - b->clear(); + b->clear(); - if (GetEepromInterface()->getCapability(HasNegAndSwitches)) { - for (int i=-GetEepromInterface()->getCapability(CustomAndSwitches); i<=-1; i++) { + item = RawSwitch(SWITCH_TYPE_NONE); + b->addItem(item.toString(), item.toValue()); + if (item == value) b->setCurrentIndex(b->count()-1); + + for (int i=1; i<=GetEepromInterface()->getCapability(SwitchesPositions); i++) { + item = RawSwitch(SWITCH_TYPE_SWITCH, i); + b->addItem(item.toString(), item.toValue()); + if (item == value) b->setCurrentIndex(b->count()-1); + } + + for (int i=1; i<=6; i++) { item = RawSwitch(SWITCH_TYPE_VIRTUAL, i); b->addItem(item.toString(), item.toValue()); if (item == value) b->setCurrentIndex(b->count()-1); } - for (int i=-GetEepromInterface()->getCapability(SwitchesPositions); i<=-1; i++) { - item = RawSwitch(SWITCH_TYPE_SWITCH, i); - if (GetEepromInterface()->isAvailable(item, context)) { - b->addItem(item.toString(), item.toValue()); - if (item == value) b->setCurrentIndex(b->count()-1); - } - } - } - - item = RawSwitch(SWITCH_TYPE_NONE); - - if (GetEepromInterface()->isAvailable(item, context)) { - b->addItem(item.toString(), item.toValue()); - if (item == value) b->setCurrentIndex(b->count()-1); - } - for (int i=1; i<=GetEepromInterface()->getCapability(SwitchesPositions); i++) { - item = RawSwitch(SWITCH_TYPE_SWITCH, i); - if (GetEepromInterface()->isAvailable(item, context)) { - b->addItem(item.toString(), item.toValue()); - if (item == value) b->setCurrentIndex(b->count()-1); - } - } - for (int i=1; i<=GetEepromInterface()->getCapability(CustomAndSwitches); i++) { - item = RawSwitch(SWITCH_TYPE_VIRTUAL, i); - b->addItem(item.toString(), item.toValue()); - if (item == value) b->setCurrentIndex(b->count()-1); } } -void populateSwitchCB(QComboBox *b, const RawSwitch & value, unsigned long attr, UseContext context) +void populateSwitchCB(QComboBox *b, const RawSwitch & value, unsigned long attr) { RawSwitch item; @@ -476,18 +416,14 @@ void populateSwitchCB(QComboBox *b, const RawSwitch & value, unsigned long attr, if (attr & POPULATE_ONOFF) { item = RawSwitch(SWITCH_TYPE_OFF); - if (GetEepromInterface()->isAvailable(item, context)) { - b->addItem(item.toString(), item.toValue()); - if (item == value) b->setCurrentIndex(b->count()-1); - } + b->addItem(item.toString(), item.toValue()); + if (item == value) b->setCurrentIndex(b->count()-1); } for (int i=-GetEepromInterface()->getCapability(CustomSwitches); i<0; i++) { item = RawSwitch(SWITCH_TYPE_VIRTUAL, i); - if (GetEepromInterface()->isAvailable(item, context)) { - b->addItem(item.toString(), item.toValue()); - if (item == value) b->setCurrentIndex(b->count()-1); - } + b->addItem(item.toString(), item.toValue()); + if (item == value) b->setCurrentIndex(b->count()-1); } for (int i=-GetEepromInterface()->getCapability(RotaryEncoders); i<0; i++) { @@ -510,24 +446,27 @@ void populateSwitchCB(QComboBox *b, const RawSwitch & value, unsigned long attr, for (int i=-GetEepromInterface()->getCapability(SwitchesPositions); i<0; i++) { item = RawSwitch(SWITCH_TYPE_SWITCH, i); - if (GetEepromInterface()->isAvailable(item, context)) { + b->addItem(item.toString(), item.toValue()); + if (item == value) b->setCurrentIndex(b->count()-1); + } + + if (attr & POPULATE_TIMER_MODES) { + for (int i=0; i<5; i++) { + item = RawSwitch(SWITCH_TYPE_TIMER_MODE, i); b->addItem(item.toString(), item.toValue()); if (item == value) b->setCurrentIndex(b->count()-1); } } - - item = RawSwitch(SWITCH_TYPE_NONE); - if (GetEepromInterface()->isAvailable(item, context)) { + else { + item = RawSwitch(SWITCH_TYPE_NONE); b->addItem(item.toString(), item.toValue()); if (item == value) b->setCurrentIndex(b->count()-1); } for (int i=1; i<=GetEepromInterface()->getCapability(SwitchesPositions); i++) { item = RawSwitch(SWITCH_TYPE_SWITCH, i); - if (GetEepromInterface()->isAvailable(item, context)) { - b->addItem(item.toString(), item.toValue()); - if (item == value) b->setCurrentIndex(b->count()-1); - } + b->addItem(item.toString(), item.toValue()); + if (item == value) b->setCurrentIndex(b->count()-1); } for (int i=1; i<=GetEepromInterface()->getCapability(MultiposPots) * GetEepromInterface()->getCapability(MultiposPotsPositions); i++) { @@ -927,7 +866,7 @@ QString getTrimInc(ModelData * g_model) QString getTimerStr(TimerData & timer) { QString str = ", " + (timer.dir ? QObject::tr("Count Up") : QObject::tr("Count Down")); - return QObject::tr("%1:%2, ").arg(timer.val/60, 2, 10, QChar('0')).arg(timer.val%60, 2, 10, QChar('0')) + getTimerMode(timer.mode) + str; + return QObject::tr("%1:%2, ").arg(timer.val/60, 2, 10, QChar('0')).arg(timer.val%60, 2, 10, QChar('0')) + timer.mode.toString() + str; } QString getProtocol(ModelData * g_model) diff --git a/companion/src/helpers.h b/companion/src/helpers.h index d8f5d4a73..4e0ab1a35 100644 --- a/companion/src/helpers.h +++ b/companion/src/helpers.h @@ -80,13 +80,14 @@ class CurveGroup : public QObject { }; #define POPULATE_ONOFF 0x01 -void populateAndSwitchCB(QComboBox *b, const RawSwitch & value, unsigned long attr=0, UseContext context=DefaultContext); -void populateSwitchCB(QComboBox *b, const RawSwitch & value, unsigned long attr=0, UseContext context=DefaultContext); +#define POPULATE_TIMER_MODES 0x02 +void populateAndSwitchCB(QComboBox *b, const RawSwitch & value); +void populateSwitchCB(QComboBox *b, const RawSwitch & value, unsigned long attr=0); + void populatePhasesCB(QComboBox *b, int value); void populateTrimUseCB(QComboBox *b, unsigned int phase); void populateGvarUseCB(QComboBox *b, unsigned int phase); void populateCustomScreenFieldCB(QComboBox *b, unsigned int value, bool last, int hubproto); -void populateTimerSwitchCB(QComboBox *b, int value); QString getProtocolStr(const int proto); QString getPhasesStr(unsigned int phases, ModelData & model); @@ -105,7 +106,6 @@ QString getPhasesStr(unsigned int phases, ModelData & model); void populateGVCB(QComboBox *b, int value); void populateSourceCB(QComboBox *b, const RawSource &source, const ModelData & model, unsigned int flags); void populateCSWCB(QComboBox *b, int value); -QString getTimerMode(int tm); QString getPhaseName(int val, char * phasename=NULL); QString getInputStr(ModelData & model, int index); QString getSignedStr(int value); diff --git a/companion/src/modeledit/customswitches.cpp b/companion/src/modeledit/customswitches.cpp index db3f69311..aea3dd602 100644 --- a/companion/src/modeledit/customswitches.cpp +++ b/companion/src/modeledit/customswitches.cpp @@ -46,7 +46,7 @@ CustomSwitchesPanel::CustomSwitchesPanel(QWidget * parent, ModelData & model): // V1 cswitchSource1[i] = new QComboBox(this); cswitchSource1[i]->setProperty("index",i); - connect(cswitchSource1[i], SIGNAL(currentIndexChanged(int)), this, SLOT(edited())); + connect(cswitchSource1[i], SIGNAL(currentIndexChanged(int)), this, SLOT(v1Edited(int))); gridLayout->addWidget(cswitchSource1[i], i+1, 2); cswitchSource1[i]->setVisible(false); cswitchValue[i] = new QDoubleSpinBox(this); @@ -62,7 +62,7 @@ CustomSwitchesPanel::CustomSwitchesPanel(QWidget * parent, ModelData & model): // V2 cswitchSource2[i] = new QComboBox(this); cswitchSource2[i]->setProperty("index", i); - connect(cswitchSource2[i], SIGNAL(currentIndexChanged(int)), this, SLOT(edited())); + connect(cswitchSource2[i], SIGNAL(currentIndexChanged(int)), this, SLOT(v2Edited(int))); gridLayout->addWidget(cswitchSource2[i], i+1, 3); cswitchSource2[i]->setVisible(false); cswitchOffset[i] = new QDoubleSpinBox(this); @@ -80,7 +80,6 @@ CustomSwitchesPanel::CustomSwitchesPanel(QWidget * parent, ModelData & model): cswitchAnd[i]->setProperty("index", i); connect(cswitchAnd[i], SIGNAL(currentIndexChanged(int)), this, SLOT(andEdited(int))); gridLayout->addWidget(cswitchAnd[i], i+1, 4); - cswitchAnd[i]->setVisible(false); if (GetEepromInterface()->getCapability(CustomSwitchesExt)) { // Duration @@ -93,7 +92,6 @@ CustomSwitchesPanel::CustomSwitchesPanel(QWidget * parent, ModelData & model): cswitchDuration[i]->setDecimals(1); connect(cswitchDuration[i], SIGNAL(valueChanged(double)), this, SLOT(durationEdited(double))); gridLayout->addWidget(cswitchDuration[i], i+1, 5); - cswitchDuration[i]->setVisible(false); // Delay cswitchDelay[i] = new QDoubleSpinBox(this); @@ -105,7 +103,6 @@ CustomSwitchesPanel::CustomSwitchesPanel(QWidget * parent, ModelData & model): cswitchDelay[i]->setDecimals(1); connect(cswitchDelay[i], SIGNAL(valueChanged(double)), this, SLOT(delayEdited(double))); gridLayout->addWidget(cswitchDelay[i], i+1, 6); - cswitchDelay[i]->setVisible(false); } } @@ -116,6 +113,54 @@ CustomSwitchesPanel::~CustomSwitchesPanel() { } +void CustomSwitchesPanel::v1Edited(int value) +{ + if (!lock) { + int i = sender()->property("index").toInt(); + model.customSw[i].val1 = cswitchSource1[i]->itemData(value).toInt(); + if (model.customSw[i].getFunctionFamily() == CS_FAMILY_VOFS) { + RawSource source = RawSource(model.customSw[i].val1, &model); + if (source.type == SOURCE_TYPE_TELEMETRY) { + if (model.customSw[i].func > CS_FN_ELESS && model.customSw[i].func < CS_FN_VEQUAL) { + model.customSw[i].val2 = 0; + } + else { + model.customSw[i].val2 = -128; + } + } + else { + RawSourceRange range = source.getRange(); + if (model.customSw[i].func > CS_FN_ELESS && model.customSw[i].func < CS_FN_VEQUAL) { + model.customSw[i].val2 = (cswitchOffset[i]->value() / range.step); + } + else { + model.customSw[i].val2 = (cswitchOffset[i]->value() - range.offset) / range.step/* TODO - source.getRawOffset(model)*/; + } + } + setSwitchWidgetVisibility(i); + } + emit modified(); + } +} + +void CustomSwitchesPanel::v2Edited(int value) +{ + if (!lock) { + int i = sender()->property("index").toInt(); + model.customSw[i].val2 = cswitchSource2[i]->itemData(value).toInt(); + emit modified(); + } +} + +void CustomSwitchesPanel::andEdited(int value) +{ + if (!lock) { + int index = sender()->property("index").toInt(); + model.customSw[index].andsw = cswitchAnd[index]->itemData(value).toInt(); + emit modified(); + } +} + void CustomSwitchesPanel::durationEdited(double duration) { int index = sender()->property("index").toInt(); @@ -130,13 +175,6 @@ void CustomSwitchesPanel::delayEdited(double delay) emit modified(); } -void CustomSwitchesPanel::andEdited(int value) -{ - int index = sender()->property("index").toInt(); - model.customSw[index].andsw = cswitchAnd[index]->itemData(value).toInt(); - emit modified(); -} - void CustomSwitchesPanel::edited() { if (!lock) { @@ -164,30 +202,7 @@ void CustomSwitchesPanel::edited() switch (model.customSw[i].getFunctionFamily()) { case CS_FAMILY_VOFS: - if (model.customSw[i].val1 != cswitchSource1[i]->itemData(cswitchSource1[i]->currentIndex()).toInt()) { - source = RawSource(model.customSw[i].val1, &model); - model.customSw[i].val1 = cswitchSource1[i]->itemData(cswitchSource1[i]->currentIndex()).toInt(); - RawSource newSource = RawSource(model.customSw[i].val1, &model); - if (newSource.type == SOURCE_TYPE_TELEMETRY) { - if (model.customSw[i].func>CS_FN_ELESS && model.customSw[i].funcCS_FN_ELESS && model.customSw[i].funcvalue() / range.step); - } - else { - model.customSw[i].val2 = (cswitchOffset[i]->value() - range.offset) / range.step/* TODO - source.getRawOffset(model)*/; - } - } - setSwitchWidgetVisibility(i); - } - else { + { source = RawSource(model.customSw[i].val1, &model); RawSourceRange range = source.getRange(); if (model.customSw[i].func>CS_FN_ELESS && model.customSw[i].funcsetSingleStep(step); break; } - case CS_FAMILY_VBOOL: - case CS_FAMILY_VCOMP: - case CS_FAMILY_STICKY: - model.customSw[i].val1 = cswitchSource1[i]->itemData(cswitchSource1[i]->currentIndex()).toInt(); - model.customSw[i].val2 = cswitchSource2[i]->itemData(cswitchSource2[i]->currentIndex()).toInt(); + default: break; } emit modified(); @@ -274,6 +285,8 @@ void CustomSwitchesPanel::edited() void CustomSwitchesPanel::setSwitchWidgetVisibility(int i) { + lock = true; + RawSource source = RawSource(model.customSw[i].val1, &model); RawSourceRange range = source.getRange(); @@ -345,24 +358,25 @@ void CustomSwitchesPanel::setSwitchWidgetVisibility(int i) cswitchValue[i]->setValue(value); break; } - cswitchAnd[i]->setVisible(true); - populateSwitchCB(cswitchAnd[i], RawSwitch(model.customSw[i].andsw), POPULATE_AND_SWITCHES); - if (GetEepromInterface()->getCapability(CustomSwitchesExt)) { - cswitchDuration[i]->setVisible(true); - cswitchDuration[i]->setValue(model.customSw[i].duration/2.0); - cswitchDelay[i]->setVisible(true); - cswitchDelay[i]->setValue(model.customSw[i].delay/2.0); - } + + lock = false; } void CustomSwitchesPanel::update() { - lock = true; for (int i=0; igetCapability(CustomSwitches); i++) { + lock = true; populateCSWCB(csw[i], model.customSw[i].func); + lock = false; setSwitchWidgetVisibility(i); + lock = true; + populateAndSwitchCB(cswitchAnd[i], RawSwitch(model.customSw[i].andsw)); + if (GetEepromInterface()->getCapability(CustomSwitchesExt)) { + cswitchDuration[i]->setValue(model.customSw[i].duration/2.0); + cswitchDelay[i]->setValue(model.customSw[i].delay/2.0); + } + lock = false; } - lock = false; } void CustomSwitchesPanel::cswPaste() diff --git a/companion/src/modeledit/customswitches.h b/companion/src/modeledit/customswitches.h index 219249aae..f4354bcb9 100644 --- a/companion/src/modeledit/customswitches.h +++ b/companion/src/modeledit/customswitches.h @@ -17,9 +17,11 @@ class CustomSwitchesPanel : public ModelPanel private slots: void edited(); + void v1Edited(int value); + void v2Edited(int value); + void andEdited(int value); void durationEdited(double duration); void delayEdited(double delay); - void andEdited(int value); void csw_customContextMenuRequested(QPoint pos); void cswDelete(); void cswCopy(); @@ -39,6 +41,7 @@ class CustomSwitchesPanel : public ModelPanel int selectedSwitch; void updateSelectedSwitch(); + void updateV2(int index); }; diff --git a/companion/src/modeledit/setup.cpp b/companion/src/modeledit/setup.cpp index 4d0b24efa..a3ee674a1 100644 --- a/companion/src/modeledit/setup.cpp +++ b/companion/src/modeledit/setup.cpp @@ -11,8 +11,10 @@ TimerPanel::TimerPanel(QWidget *parent, ModelData & model, TimerData & timer): { ui->setupUi(this); + lock = true; + // Mode - populateTimerSwitchCB(ui->mode, timer.mode); + populateSwitchCB(ui->mode, timer.mode, POPULATE_TIMER_MODES); if (!GetEepromInterface()->getCapability(PermTimers)) { ui->persistent->hide(); @@ -23,6 +25,8 @@ TimerPanel::TimerPanel(QWidget *parent, ModelData & model, TimerData & timer): ui->countdownBeep->addItem(tr("Beeps")); if (IS_ARM(GetEepromInterface()->getBoard()) || IS_2560(GetEepromInterface()->getBoard())) ui->countdownBeep->addItem(tr("Countdown")); + + lock = false; } TimerPanel::~TimerPanel() @@ -63,8 +67,10 @@ void TimerPanel::on_value_editingFinished() void TimerPanel::on_mode_currentIndexChanged(int index) { - timer.mode = TimerMode(ui->mode->itemData(index).toInt()); - emit modified(); + if (!lock) { + timer.mode = RawSwitch(ui->mode->itemData(index).toInt()); + emit modified(); + } } void TimerPanel::on_persistent_toggled(bool checked)