diff --git a/companion/src/eeprominterface.h b/companion/src/eeprominterface.h index 1b8ec876f..105230592 100644 --- a/companion/src/eeprominterface.h +++ b/companion/src/eeprominterface.h @@ -646,7 +646,7 @@ class FuncSwData { // Function Switches data char paramarm[10]; unsigned int enabled; // TODO perhaps not any more the right name unsigned int adjustMode; - unsigned int repeatParam; + int repeatParam; void clear() { memset(this, 0, sizeof(FuncSwData)); } }; diff --git a/companion/src/firmwares/opentx/opentxeeprom.cpp b/companion/src/firmwares/opentx/opentxeeprom.cpp index 0bd5d7528..5a7fc5312 100644 --- a/companion/src/firmwares/opentx/opentxeeprom.cpp +++ b/companion/src/firmwares/opentx/opentxeeprom.cpp @@ -1338,10 +1338,10 @@ class CustomFunctionField: public TransformedField { internalField.Append(new CharField<6>(_arm_param)); if (version >= 214) { internalField.Append(new UnsignedField<2>(_mode)); - internalField.Append(new UnsignedField<6>(_delay)); + internalField.Append(new SignedField<6>(_delay)); } else { - internalField.Append(new UnsignedField<8>(_delay)); + internalField.Append(new UnsignedField<8>((unsigned int &)_delay)); } if (version < 214) internalField.Append(new SpareBitsField<8>()); @@ -1364,7 +1364,7 @@ class CustomFunctionField: public TransformedField { if (IS_ARM(board)) { _mode = 0; if (fn.func == FuncPlaySound || fn.func == FuncPlayPrompt || fn.func == FuncPlayValue) - _delay = fn.repeatParam / 5; + _delay = (version >= 216 ? fn.repeatParam : (fn.repeatParam/5)); else _delay = (fn.enabled ? 1 : 0); if (fn.func <= FuncInstantTrim) { @@ -1439,7 +1439,7 @@ class CustomFunctionField: public TransformedField { { if (IS_ARM(board)) { if (fn.func == FuncPlaySound || fn.func == FuncPlayPrompt || fn.func == FuncPlayValue) - fn.repeatParam = _delay * 5; + fn.repeatParam = (version >= 216 ? _delay : (_delay*5)); else fn.enabled = (_delay & 0x01); @@ -1529,7 +1529,7 @@ class CustomFunctionField: public TransformedField { SourcesConversionTable * sourcesConversionTable; char _arm_param[10]; unsigned int _param; - unsigned int _delay; + int _delay; unsigned int _mode; unsigned int _union_param; }; diff --git a/companion/src/helpers.cpp b/companion/src/helpers.cpp index d5904a77e..04d6b5ed3 100644 --- a/companion/src/helpers.cpp +++ b/companion/src/helpers.cpp @@ -449,17 +449,6 @@ void populateFuncParamCB(QComboBox *b, const ModelData & model, uint function, u } } -void populateRepeatCB(QComboBox *b, unsigned int value) -{ - b->clear(); - b->addItem(QObject::tr("No repeat", 0)); - unsigned int step = IS_ARM(GetEepromInterface()->getBoard()) ? 5 : 10; - for (unsigned int i=step; i<=60; i+=step) { - b->addItem(QObject::tr("%1s").arg(i), i); - if (i==value) b->setCurrentIndex(b->count()-1); - } -} - void populateGVmodeCB(QComboBox *b, unsigned int value) { b->clear(); diff --git a/companion/src/helpers.h b/companion/src/helpers.h index f62e9b39e..d3141083d 100644 --- a/companion/src/helpers.h +++ b/companion/src/helpers.h @@ -84,7 +84,6 @@ class CurveGroup : public QObject { #define POPULATE_AND_SWITCHES 0x04 void populateSwitchCB(QComboBox *b, const RawSwitch & value, unsigned long attr=0, UseContext context=DefaultContext); void populateFuncCB(QComboBox *b, unsigned int value); -void populateRepeatCB(QComboBox *b, unsigned int value); void populateGVmodeCB(QComboBox *b, unsigned int value); QString FuncParam(uint function, int value, QString paramT="",unsigned int adjustmode=0); void populateFuncParamCB(QComboBox *b, const ModelData & model, uint function, unsigned int value, unsigned int adjustmode=0); diff --git a/companion/src/modeledit/customfunctions.cpp b/companion/src/modeledit/customfunctions.cpp index 0dc818581..0f2466b4b 100644 --- a/companion/src/modeledit/customfunctions.cpp +++ b/companion/src/modeledit/customfunctions.cpp @@ -7,6 +7,35 @@ #include #include "helpers.h" +RepeatComboBox::RepeatComboBox(QWidget *parent, int & repeatParam): + QComboBox(parent), + repeatParam(repeatParam) +{ + unsigned int step = IS_ARM(GetEepromInterface()->getBoard()) ? 1 : 10; + int value = repeatParam/step; + + if (step == 1) { + addItem(QObject::tr("Played once, not during startup"), -1); + value++; + } + + addItem(QObject::tr("No repeat"), 0); + + for (unsigned int i=step; i<=60; i+=step) { + addItem(QObject::tr("%1s").arg(i), i); + } + + setCurrentIndex(value); + + connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(onIndexChanged(int))); +} + +void RepeatComboBox::onIndexChanged(int index) +{ + repeatParam = itemData(index).toInt(); + emit modified(); +} + CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData & model, GeneralSettings & generalSettings): ModelPanel(parent, model), generalSettings(generalSettings), @@ -132,12 +161,9 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData & model, QHBoxLayout *repeatLayout = new QHBoxLayout(); gridLayout->addLayout(repeatLayout, i+1, 4); - - fswtchRepeat[i] = new QComboBox(this); - fswtchRepeat[i]->setProperty("index", i); - connect(fswtchRepeat[i], SIGNAL(currentIndexChanged(int)), this, SLOT(customFunctionEdited())); + fswtchRepeat[i] = new RepeatComboBox(this, model.funcSw[i].repeatParam); repeatLayout->addWidget(fswtchRepeat[i], i+1); - populateRepeatCB(fswtchRepeat[i], model.funcSw[i].repeatParam); + connect(fswtchRepeat[i], SIGNAL(modified()), this, SLOT(onChildModified())); fswtchEnable[i] = new QCheckBox(this); fswtchEnable[i]->setProperty("index", i); @@ -252,6 +278,11 @@ void CustomFunctionsPanel::customFunctionEdited() } } +void CustomFunctionsPanel::onChildModified() +{ + emit modified(); +} + void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified) { unsigned int widgetsMask = 0; @@ -259,7 +290,6 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified) model.funcSw[i].swtch = RawSwitch(fswtchSwtch[i]->itemData(fswtchSwtch[i]->currentIndex()).toInt()); model.funcSw[i].func = (AssignFunc)fswtchFunc[i]->currentIndex(); model.funcSw[i].enabled = fswtchEnable[i]->isChecked(); - model.funcSw[i].repeatParam = (AssignFunc)fswtchRepeat[i]->currentIndex(); model.funcSw[i].adjustMode = (AssignFunc)fswtchGVmode[i]->currentIndex(); } @@ -314,11 +344,8 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified) widgetsMask |= CUSTOM_FUNCTION_SOURCE_PARAM + CUSTOM_FUNCTION_ENABLE; } else if (index==FuncPlaySound || index==FuncPlayHaptic || index==FuncPlayValue || index==FuncPlayPrompt || index==FuncPlayBoth || index==FuncBackgroundMusic) { - if (modified) model.funcSw[i].repeatParam = fswtchRepeat[i]->itemData(fswtchRepeat[i]->currentIndex()).toInt(); - if (index != FuncBackgroundMusic) { - if (GetEepromInterface()->getCapability(HasFuncRepeat)) { - widgetsMask |= CUSTOM_FUNCTION_REPEAT; - } + if (index != FuncBackgroundMusic && GetEepromInterface()->getCapability(HasFuncRepeat)) { + widgetsMask |= CUSTOM_FUNCTION_REPEAT; } if (index==FuncPlayValue) { if (modified) model.funcSw[i].param = fswtchParamT[i]->itemData(fswtchParamT[i]->currentIndex()).toInt(); @@ -422,9 +449,11 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified) void CustomFunctionsPanel::update() { + lock = true; for (int i=0; igetCapability(CustomFunctions); i++) { refreshCustomFunction(i); } + lock = false; } void CustomFunctionsPanel::fswPaste() diff --git a/companion/src/modeledit/customfunctions.h b/companion/src/modeledit/customfunctions.h index e6729da6a..ccb73582e 100644 --- a/companion/src/modeledit/customfunctions.h +++ b/companion/src/modeledit/customfunctions.h @@ -13,6 +13,23 @@ #include #endif +class RepeatComboBox: public QComboBox +{ + Q_OBJECT + + public: + RepeatComboBox(QWidget *parent, int & repeatParam); + + signals: + void modified(); + + private slots: + void onIndexChanged(int); + + protected: + int & repeatParam; +}; + class CustomFunctionsPanel : public ModelPanel { Q_OBJECT @@ -28,6 +45,7 @@ class CustomFunctionsPanel : public ModelPanel void fsw_customContextMenuRequested(QPoint pos); void refreshCustomFunction(int index, bool modified=false); void playMusic(); + void onChildModified(); #ifdef PHONON void mediaPlayer_state(Phonon::State newState, Phonon::State oldState); #endif