From 10dc3503c26553992e8a9a3db9e38644f84e31f0 Mon Sep 17 00:00:00 2001 From: Andre Bernet Date: Mon, 3 Feb 2014 21:32:19 +0100 Subject: [PATCH] Pot warning UI in companion --- companion/src/eeprominterface.h | 1 - .../src/firmwares/opentx/opentxeeprom.cpp | 4 +- .../src/firmwares/opentx/opentxinterface.cpp | 2 - companion/src/modeledit/setup.cpp | 88 ++++++-- companion/src/modeledit/setup.h | 9 +- companion/src/modeledit/setup.ui | 198 +++++++++++------- 6 files changed, 200 insertions(+), 102 deletions(-) diff --git a/companion/src/eeprominterface.h b/companion/src/eeprominterface.h index 8dccc276b..898b7a576 100644 --- a/companion/src/eeprominterface.h +++ b/companion/src/eeprominterface.h @@ -1053,7 +1053,6 @@ enum Capability { LCDWidth, GetThrSwitch, HasDisplayText, - PotWarnings, VirtualInputs, LuaInputs, LimitsPer1000, diff --git a/companion/src/firmwares/opentx/opentxeeprom.cpp b/companion/src/firmwares/opentx/opentxeeprom.cpp index 75ae30c7a..010d785ae 100644 --- a/companion/src/firmwares/opentx/opentxeeprom.cpp +++ b/companion/src/firmwares/opentx/opentxeeprom.cpp @@ -1970,7 +1970,7 @@ Open9xModelDataNew::Open9xModelDataNew(ModelData & modelData, BoardEnum board, u if (IS_ARM(board) && version >= 216) { internalField.Append(new UnsignedField<8>(modelData.nSwToWarn)); internalField.Append(new UnsignedField<8>(modelData.nPotsToWarn)); - for (int i=0; i < GetEepromInterface()->getCapability(PotWarnings); i++) { + for (int i=0; i < GetEepromInterface()->getCapability(Pots); i++) { internalField.Append(new SignedField<8>(modelData.potPosition[i])); } } @@ -1988,7 +1988,7 @@ Open9xModelDataNew::Open9xModelDataNew(ModelData & modelData, BoardEnum board, u internalField.Append(new ZCharField<4>(modelData.inputNames[i])); internalField.Append(new UnsignedField<8>(modelData.nSwToWarn)); internalField.Append(new UnsignedField<8>(modelData.nPotsToWarn)); - for (int i=0; i < GetEepromInterface()->getCapability(PotWarnings); i++) { + for (int i=0; i < GetEepromInterface()->getCapability(Pots); i++) { internalField.Append(new SignedField<8>(modelData.potPosition[i])); } } diff --git a/companion/src/firmwares/opentx/opentxinterface.cpp b/companion/src/firmwares/opentx/opentxinterface.cpp index adfa8101a..93792f0ef 100644 --- a/companion/src/firmwares/opentx/opentxinterface.cpp +++ b/companion/src/firmwares/opentx/opentxinterface.cpp @@ -671,8 +671,6 @@ int Open9xInterface::getCapability(const Capability capability) return (IS_TARANIS(board) ? 212 : 128) ; case GetThrSwitch: return (IS_TARANIS(board) ? DSW_SF1 : DSW_THR) ; - case PotWarnings: - return (IS_TARANIS(board) ? 4 : IS_ARM(board) ? 3 : 0); case HasDisplayText: case VirtualInputs: return IS_TARANIS(board) ? 32 : 0; diff --git a/companion/src/modeledit/setup.cpp b/companion/src/modeledit/setup.cpp index 04b816faa..c806e503e 100644 --- a/companion/src/modeledit/setup.cpp +++ b/companion/src/modeledit/setup.cpp @@ -409,13 +409,12 @@ Setup::Setup(QWidget *parent, ModelData & model): connect(checkbox, SIGNAL(toggled(bool)), this, SLOT(onBeepCenterToggled(bool))); centerBeepCheckboxes << checkbox; } - ui->switchesStartupLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, analogs+GetEepromInterface()->getCapability(RotaryEncoders)); // Startup switches warnings for (int i=0; igetCapability(Switches)-1; i++) { - QLabel * label = new QLabel(); - QSlider * slider = new QSlider(); - QCheckBox * cb = new QCheckBox(); + QLabel * label = new QLabel(this); + QSlider * slider = new QSlider(this); + QCheckBox * cb = new QCheckBox(this); slider->setProperty("index", i+1); slider->setOrientation(Qt::Vertical); slider->setMinimum(0); @@ -441,13 +440,28 @@ Setup::Setup(QWidget *parent, ModelData & model): ui->switchesStartupLayout->setAlignment(slider, Qt::AlignCenter); ui->switchesStartupLayout->addWidget(cb, 2, i+1); ui->switchesStartupLayout->setAlignment(cb, Qt::AlignCenter); - connect(slider, SIGNAL(valueChanged(int)), this, SLOT(startupSwitchEdited(int))); - connect(cb, SIGNAL(toggled(bool)), this, SLOT(startupSwitchToggled(bool))); + connect(slider, SIGNAL(valueChanged(int)), this, SLOT(on_startupSwitchEdited(int))); + connect(cb, SIGNAL(toggled(bool)), this, SLOT(on_startupSwitchToggled(bool))); startupSwitchesSliders << slider; startupSwitchesCheckboxes << cb; } ui->switchesStartupLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, GetEepromInterface()->getCapability(Switches)); + // Pot warnings + if(IS_TARANIS(GetEepromInterface()->getBoard())) { + for (int i=0; igetCapability(Pots); i++) { + QCheckBox * cb = new QCheckBox(this); + cb->setProperty("index", i+1); + cb->setText(AnalogString(i+4)); + ui->potWarningLayout->addWidget(cb, 0, i+1); + connect(cb, SIGNAL(toggled(bool)), this, SLOT(on_potWarningToggled(bool))); + potWarningCheckboxes << cb; + } + } + else { + ui->label_potWarning->hide(); + ui->potWarningMode->hide(); + } lock = false; } @@ -549,6 +563,7 @@ void Setup::update() updateBeepCenter(); updateStartupSwitches(); + updatePotWarnings(); for (int i=0; iupdate(); @@ -591,7 +606,7 @@ void Setup::updateStartupSwitches() lock = false; } -void Setup::startupSwitchEdited(int value) +void Setup::on_startupSwitchEdited(int value) { if (!lock) { int shift = 0; @@ -635,16 +650,61 @@ void Setup::startupSwitchEdited(int value) } } -void Setup::startupSwitchToggled(bool checked) +void Setup::on_startupSwitchToggled(bool checked) { - int index = sender()->property("index").toInt()-1; + if (!lock) { + int index = sender()->property("index").toInt()-1; - if (checked) - model.nSwToWarn &= ~(1 << index); - else - model.nSwToWarn |= (1 << index); + if (checked) + model.nSwToWarn &= ~(1 << index); + else + model.nSwToWarn |= (1 << index); - updateStartupSwitches(); + updateStartupSwitches(); + emit modified(); + } +} + +void Setup::updatePotWarnings() +{ + lock = true; + int mode = model.nPotsToWarn >> 6; + ui->potWarningMode->setCurrentIndex(mode); + + if (mode == 0) + model.nPotsToWarn = 0x3F; + + for (int i=0; igetCapability(Pots); i++) { + bool enabled = !(model.nPotsToWarn & (1 << i)); + + potWarningCheckboxes[i]->setChecked(enabled); + potWarningCheckboxes[i]->setDisabled(mode == 0); + } + lock = false; +} + +void Setup::on_potWarningToggled(bool checked) +{ + if (!lock) { + int index = sender()->property("index").toInt()-1; + + if(checked) + model.nPotsToWarn &= ~(1 << index); + else + model.nPotsToWarn |= (1 << index); + + updatePotWarnings(); + emit modified(); + } +} + +void Setup::on_potWarningMode_currentIndexChanged(int index) +{ + int mask = 0xC0; + model.nPotsToWarn = model.nPotsToWarn & ~mask; + model.nPotsToWarn = model.nPotsToWarn | ((index << 6) & mask); + + updatePotWarnings(); emit modified(); } diff --git a/companion/src/modeledit/setup.h b/companion/src/modeledit/setup.h index 2e88bd02b..ec7a28dac 100644 --- a/companion/src/modeledit/setup.h +++ b/companion/src/modeledit/setup.h @@ -6,6 +6,7 @@ #include #include #include +#include namespace Ui { class Setup; @@ -87,18 +88,22 @@ class Setup : public ModelPanel void on_image_currentIndexChanged(int index); void on_trimIncrement_currentIndexChanged(int index); void onBeepCenterToggled(bool checked); - void startupSwitchEdited(int value); - void startupSwitchToggled(bool checked); + void on_startupSwitchEdited(int value); + void on_startupSwitchToggled(bool checked); + void on_potWarningToggled(bool checked); + void on_potWarningMode_currentIndexChanged(int index); void onChildModified(); private: Ui::Setup *ui; QVector startupSwitchesSliders; QVector startupSwitchesCheckboxes; + QVector potWarningCheckboxes; QVector centerBeepCheckboxes; ModulePanel * modules[C9X_NUM_MODULES+1]; TimerPanel * timers[C9X_MAX_TIMERS]; void updateStartupSwitches(); + void updatePotWarnings(); void updateBeepCenter(); }; diff --git a/companion/src/modeledit/setup.ui b/companion/src/modeledit/setup.ui index aa440a56d..29753cdb3 100644 --- a/companion/src/modeledit/setup.ui +++ b/companion/src/modeledit/setup.ui @@ -6,8 +6,8 @@ 0 0 - 782 - 334 + 787 + 727 @@ -16,85 +16,6 @@ - - - - Model Name - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Timer2 - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Timer1 - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Throttle Source - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 0 - 0 - - - - Switch Warnings - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Center beep - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - - - Trim Increment - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - @@ -182,6 +103,85 @@ + + + + Model Name + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Timer2 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Timer1 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Throttle Source + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + Switch Warnings + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Center beep + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + Trim Increment + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + @@ -343,6 +343,42 @@ If this is checked the throttle will be reversed. Idle will be forward, trim wi + + + + true + + + Pot Warnings + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + OFF + + + + + Manual + + + + + Auto + + + + + +