From 745ada0781c6e7aa26ef2cbae18c54c04f6b043c Mon Sep 17 00:00:00 2001 From: Laurent Lalanne Date: Wed, 18 Feb 2015 00:34:38 +0100 Subject: [PATCH 1/5] OP-1728 First commit - Maybe better behavior - Display motors with red handle --- .../src/plugins/config/outputchannelform.cpp | 120 +++++++++++------- .../src/plugins/config/outputchannelform.h | 2 + 2 files changed, 77 insertions(+), 45 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/config/outputchannelform.cpp b/ground/openpilotgcs/src/plugins/config/outputchannelform.cpp index 06d0f443b..18103f7ca 100644 --- a/ground/openpilotgcs/src/plugins/config/outputchannelform.cpp +++ b/ground/openpilotgcs/src/plugins/config/outputchannelform.cpp @@ -56,6 +56,8 @@ OutputChannelForm::OutputChannelForm(const int index, QWidget *parent) : ui.actuatorMax->setMinimum(MINOUTPUT_VALUE); ui.actuatorValue->setMinimum(MINOUTPUT_VALUE); + setChannelRange(); + disableMouseWheelEvents(); } @@ -120,11 +122,12 @@ void OutputChannelForm::enableChannelTest(bool state) } else { ui.actuatorMin->setEnabled(true); ui.actuatorMax->setEnabled(true); - ui.actuatorRev->setEnabled(true); + if (m_mixerType != "Motor") { + ui.actuatorRev->setEnabled(true); + } } } - /** * Toggles the channel linked state for use in testing mode */ @@ -139,7 +142,7 @@ void OutputChannelForm::linkToggled(bool state) if (!parent()) { return; } - int min = 10000; + int min = MAXOUTPUT_VALUE; int linked_count = 0; QList outputChannelForms = parent()->findChildren(); // set the linked channels of the parent widget to the same value @@ -179,7 +182,7 @@ int OutputChannelForm::max() const */ void OutputChannelForm::setMax(int maximum) { - setRange(ui.actuatorMin->value(), maximum); + setRange(ui.actuatorMax->value(), maximum); } int OutputChannelForm::min() const @@ -192,7 +195,7 @@ int OutputChannelForm::min() const */ void OutputChannelForm::setMin(int minimum) { - setRange(minimum, ui.actuatorMax->value()); + setRange(minimum, ui.actuatorMin->value()); } int OutputChannelForm::neutral() const @@ -216,11 +219,6 @@ void OutputChannelForm::setRange(int minimum, int maximum) ui.actuatorMin->setValue(minimum); ui.actuatorMax->setValue(maximum); setChannelRange(); - if (ui.actuatorMin->value() > ui.actuatorMax->value()) { - ui.actuatorRev->setChecked(true); - } else { - ui.actuatorRev->setChecked(false); - } } /** @@ -232,39 +230,60 @@ void OutputChannelForm::setRange(int minimum, int maximum) */ void OutputChannelForm::setChannelRange() { - int oldMini = ui.actuatorNeutral->minimum(); - int minValue = ui.actuatorMin->value(); - int maxValue = ui.actuatorMax->value(); + int minValue = ui.actuatorMin->value(); + int maxValue = ui.actuatorMax->value(); + int neutralValue = ui.actuatorValue->value(); - // int oldMaxi = ui.actuatorNeutral->maximum(); + int oldMini = ui.actuatorNeutral->minimum(); + int oldMaxi = ui.actuatorNeutral->maximum(); - if (minValue <= maxValue) { - ui.actuatorNeutral->setRange(ui.actuatorMin->value(), ui.actuatorMax->value()); - ui.actuatorRev->setChecked(false); + m_mixerType = outputMixerType(); + + // Red handle for Motors + if ((m_mixerType == "Motor") || (m_mixerType == "ReversableMotor")) { + ui.actuatorNeutral->setStyleSheet("QSlider::handle:horizontal { background: rgb(255, 100, 100); width: 18px; height: 28px;" + "margin: -3px 0; border-radius: 3px; border: 1px solid #777; }"); } else { - ui.actuatorNeutral->setRange(ui.actuatorMax->value(), ui.actuatorMin->value()); - ui.actuatorRev->setChecked(true); + ui.actuatorNeutral->setStyleSheet("QSlider::handle:horizontal { background: rgb(196, 196, 196); width: 18px; height: 28px;" + "margin: -3px 0; border-radius: 3px; border: 1px solid #777; }"); } + // Normal motor will be *** never *** reversed : without arming a "Min" value (like 1900) can be applied ! + if (m_mixerType == "Motor") { + if (minValue >= maxValue) { + // Keep old values + ui.actuatorMin->setValue(oldMini); + ui.actuatorMax->setValue(oldMaxi); + } + ui.actuatorRev->setChecked(false); + ui.actuatorRev->setEnabled(false); + ui.actuatorNeutral->setInvertedAppearance(false); + ui.actuatorNeutral->setRange(ui.actuatorMin->value(), ui.actuatorMax->value()); + } else { + // Others output (!Motor) + // Auto check reverse checkbox SpinBox Min/Max changes + ui.actuatorRev->setEnabled(true); + if (minValue <= maxValue) { + ui.actuatorRev->setChecked(false); + ui.actuatorNeutral->setInvertedAppearance(false); + ui.actuatorNeutral->setRange(minValue, maxValue); + } else { + ui.actuatorRev->setChecked(true); + ui.actuatorNeutral->setInvertedAppearance(true); + ui.actuatorNeutral->setRange(maxValue, minValue); + } + } + // If old neutral was Min, stay Min if (ui.actuatorNeutral->value() == oldMini) { ui.actuatorNeutral->setValue(ui.actuatorNeutral->minimum()); } // Enable only outputs already set in mixer - if (name() != "-") { + if (m_mixerType != "Disabled") { ui.actuatorMin->setEnabled(true); ui.actuatorMax->setEnabled(true); ui.actuatorNeutral->setEnabled(true); ui.actuatorValue->setEnabled(true); - - // Enable checkboxes Rev and Link if some range - if (minValue != maxValue) { - ui.actuatorRev->setEnabled(true); - ui.actuatorLink->setEnabled(true); - } else { - ui.actuatorRev->setEnabled(false); - ui.actuatorLink->setEnabled(false); - } } else { ui.actuatorMin->setEnabled(false); ui.actuatorMax->setEnabled(false); @@ -273,13 +292,9 @@ void OutputChannelForm::setChannelRange() ui.actuatorMin->setValue(1000); ui.actuatorMax->setValue(1000); ui.actuatorNeutral->setRange(minValue, maxValue); - ui.actuatorNeutral->setEnabled(false); + ui.actuatorNeutral->setValue(minValue); ui.actuatorValue->setEnabled(false); } - - // if (ui.actuatorNeutral->value() == oldMaxi) - // this can be dangerous if it happens to be controlling a motor at the time! - // ui.actuatorNeutral->setValue(ui.actuatorNeutral->maximum()); } /** @@ -287,19 +302,16 @@ void OutputChannelForm::setChannelRange() */ void OutputChannelForm::reverseChannel(bool state) { - // Sanity check: if state became true, make sure the Maxvalue was higher than Minvalue - // the situations below can happen! - if (state && (ui.actuatorMax->value() < ui.actuatorMin->value())) { + // if 'state' (reverse channel requested) apply only if not already reversed + if ((state && (ui.actuatorMax->value() > ui.actuatorMin->value())) + || (!state && (ui.actuatorMax->value() < ui.actuatorMin->value()))) { + // Now, swap the min & max values (spin boxes) + int temp = ui.actuatorMax->value(); + ui.actuatorMax->setValue(ui.actuatorMin->value()); + ui.actuatorMin->setValue(temp); + ui.actuatorNeutral->setInvertedAppearance(state); return; } - if (!state && (ui.actuatorMax->value() > ui.actuatorMin->value())) { - return; - } - - // Now, swap the min & max values (only on the spinboxes, the slider does not change!) - int temp = ui.actuatorMax->value(); - ui.actuatorMax->setValue(ui.actuatorMin->value()); - ui.actuatorMin->setValue(temp); // Also update the channel value // This is a trick to force the slider to update its value and @@ -370,3 +382,21 @@ void OutputChannelForm::sendChannelTest(int value) } emit channelChanged(index(), value); } + +/** + * + * Returns MixerType + */ +QString OutputChannelForm::outputMixerType() +{ + UAVDataObject *mixer = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); + + Q_ASSERT(mixer); + + QString mixerNumType = QString("Mixer%1Type").arg(index() + 1); + UAVObjectField *field = mixer->getField(mixerNumType); + Q_ASSERT(field); + QString mixerType = field->getValue().toString(); + + return mixerType; +} diff --git a/ground/openpilotgcs/src/plugins/config/outputchannelform.h b/ground/openpilotgcs/src/plugins/config/outputchannelform.h index e17155f41..e10891c2a 100644 --- a/ground/openpilotgcs/src/plugins/config/outputchannelform.h +++ b/ground/openpilotgcs/src/plugins/config/outputchannelform.h @@ -58,6 +58,7 @@ public slots: void setNeutral(int value); void setRange(int minimum, int maximum); void enableChannelTest(bool state); + QString outputMixerType(); signals: void channelChanged(int index, int value); @@ -65,6 +66,7 @@ signals: private: Ui::outputChannelForm ui; bool m_inChannelTest; + QString m_mixerType; private slots: void linkToggled(bool state); From 4b24707f82feb57e17a9778475db89c13ed1a52e Mon Sep 17 00:00:00 2001 From: Laurent Lalanne Date: Wed, 18 Feb 2015 00:51:42 +0100 Subject: [PATCH 2/5] OP-1728 Remove unused code --- .../src/plugins/config/outputchannelform.cpp | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/config/outputchannelform.cpp b/ground/openpilotgcs/src/plugins/config/outputchannelform.cpp index 18103f7ca..b604d9027 100644 --- a/ground/openpilotgcs/src/plugins/config/outputchannelform.cpp +++ b/ground/openpilotgcs/src/plugins/config/outputchannelform.cpp @@ -232,7 +232,6 @@ void OutputChannelForm::setChannelRange() { int minValue = ui.actuatorMin->value(); int maxValue = ui.actuatorMax->value(); - int neutralValue = ui.actuatorValue->value(); int oldMini = ui.actuatorNeutral->minimum(); int oldMaxi = ui.actuatorNeutral->maximum(); @@ -312,18 +311,6 @@ void OutputChannelForm::reverseChannel(bool state) ui.actuatorNeutral->setInvertedAppearance(state); return; } - - // Also update the channel value - // This is a trick to force the slider to update its value and - // emit the right signal itself, because our sendChannelTest(int) method - // relies on the object sender's identity. - if (ui.actuatorNeutral->value() < ui.actuatorNeutral->maximum()) { - ui.actuatorNeutral->setValue(ui.actuatorNeutral->value() + 1); - ui.actuatorNeutral->setValue(ui.actuatorNeutral->value() - 1); - } else { - ui.actuatorNeutral->setValue(ui.actuatorNeutral->value() - 1); - ui.actuatorNeutral->setValue(ui.actuatorNeutral->value() + 1); - } } /** From ee3efc535efc2a1579dd892045addd22bc9286b5 Mon Sep 17 00:00:00 2001 From: Laurent Lalanne Date: Wed, 18 Feb 2015 01:50:38 +0100 Subject: [PATCH 3/5] OP-1728 Fix output value --- .../openpilotgcs/src/plugins/config/outputchannelform.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/config/outputchannelform.cpp b/ground/openpilotgcs/src/plugins/config/outputchannelform.cpp index b604d9027..b14181951 100644 --- a/ground/openpilotgcs/src/plugins/config/outputchannelform.cpp +++ b/ground/openpilotgcs/src/plugins/config/outputchannelform.cpp @@ -309,8 +309,11 @@ void OutputChannelForm::reverseChannel(bool state) ui.actuatorMax->setValue(ui.actuatorMin->value()); ui.actuatorMin->setValue(temp); ui.actuatorNeutral->setInvertedAppearance(state); + + setChannelRange(); return; } + } /** @@ -327,10 +330,6 @@ void OutputChannelForm::sendChannelTest(int value) return; } - if (ui.actuatorRev->isChecked()) { - // the channel is reversed - value = ui.actuatorMin->value() - value + ui.actuatorMax->value(); - } // update the label ui.actuatorValue->setValue(value); From f44a663e27182fdc79c19c844318f2254635b8e2 Mon Sep 17 00:00:00 2001 From: Laurent Lalanne Date: Wed, 18 Feb 2015 02:46:53 +0100 Subject: [PATCH 4/5] OP-1728 Add message dialog if something to save --- .../src/plugins/config/configoutputwidget.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ground/openpilotgcs/src/plugins/config/configoutputwidget.cpp b/ground/openpilotgcs/src/plugins/config/configoutputwidget.cpp index 330911bf4..93d367b9a 100644 --- a/ground/openpilotgcs/src/plugins/config/configoutputwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configoutputwidget.cpp @@ -196,6 +196,15 @@ void ConfigOutputWidget::runChannelTests(bool state) if (state) { sendAllChannelTests(); } + + // Add info at end + if (!state && isDirty()) { + QMessageBox mbox; + mbox.setText(QString(tr("You may want to save our neutral settings." ))); + mbox.setStandardButtons(QMessageBox::Ok); + mbox.setIcon(QMessageBox::Information); + mbox.exec(); + } } OutputChannelForm *ConfigOutputWidget::getOutputChannelForm(const int index) const From a9c442916ffe55b9f50e55454b1f756da83f80bf Mon Sep 17 00:00:00 2001 From: Laurent Lalanne Date: Wed, 18 Feb 2015 12:37:23 +0100 Subject: [PATCH 5/5] OP-1728 Remove keyboard focus on Spin/Checkboxes - Typo - Uncrustify --- .../src/plugins/config/configoutputwidget.cpp | 2 +- .../src/plugins/config/outputchannelform.cpp | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/config/configoutputwidget.cpp b/ground/openpilotgcs/src/plugins/config/configoutputwidget.cpp index 93d367b9a..689e8ab2f 100644 --- a/ground/openpilotgcs/src/plugins/config/configoutputwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configoutputwidget.cpp @@ -200,7 +200,7 @@ void ConfigOutputWidget::runChannelTests(bool state) // Add info at end if (!state && isDirty()) { QMessageBox mbox; - mbox.setText(QString(tr("You may want to save our neutral settings." ))); + mbox.setText(QString(tr("You may want to save your neutral settings."))); mbox.setStandardButtons(QMessageBox::Ok); mbox.setIcon(QMessageBox::Information); mbox.exec(); diff --git a/ground/openpilotgcs/src/plugins/config/outputchannelform.cpp b/ground/openpilotgcs/src/plugins/config/outputchannelform.cpp index b14181951..a57a7126e 100644 --- a/ground/openpilotgcs/src/plugins/config/outputchannelform.cpp +++ b/ground/openpilotgcs/src/plugins/config/outputchannelform.cpp @@ -56,6 +56,13 @@ OutputChannelForm::OutputChannelForm(const int index, QWidget *parent) : ui.actuatorMax->setMinimum(MINOUTPUT_VALUE); ui.actuatorValue->setMinimum(MINOUTPUT_VALUE); + // Remove keyboard focus + ui.actuatorMin->setFocusPolicy(Qt::ClickFocus); + ui.actuatorMax->setFocusPolicy(Qt::ClickFocus); + ui.actuatorRev->setFocusPolicy(Qt::ClickFocus); + ui.actuatorLink->setFocusPolicy(Qt::ClickFocus); + ui.actuatorValue->setFocusPolicy(Qt::NoFocus); + setChannelRange(); disableMouseWheelEvents(); @@ -230,11 +237,11 @@ void OutputChannelForm::setRange(int minimum, int maximum) */ void OutputChannelForm::setChannelRange() { - int minValue = ui.actuatorMin->value(); - int maxValue = ui.actuatorMax->value(); + int minValue = ui.actuatorMin->value(); + int maxValue = ui.actuatorMax->value(); - int oldMini = ui.actuatorNeutral->minimum(); - int oldMaxi = ui.actuatorNeutral->maximum(); + int oldMini = ui.actuatorNeutral->minimum(); + int oldMaxi = ui.actuatorNeutral->maximum(); m_mixerType = outputMixerType(); @@ -313,7 +320,6 @@ void OutputChannelForm::reverseChannel(bool state) setChannelRange(); return; } - } /**