From 8b61e7b27f9672721f18eb5f1a941e09c1d2059f Mon Sep 17 00:00:00 2001 From: Vladimir Zidar Date: Thu, 26 Oct 2017 01:35:54 +0200 Subject: [PATCH] LP-525 Fixed USB function handling - not allowing USBTelemetry on both, but requiring at least one. Adjusted common option combobox sizes. --- .../plugins/config/commonhwsettingswidget.cpp | 40 ++++- .../plugins/config/commonhwsettingswidget.h | 8 +- .../plugins/config/commonhwsettingswidget.ui | 147 ++++++++++++------ 3 files changed, 140 insertions(+), 55 deletions(-) diff --git a/ground/gcs/src/plugins/config/commonhwsettingswidget.cpp b/ground/gcs/src/plugins/config/commonhwsettingswidget.cpp index 65b262db0..550adda18 100644 --- a/ground/gcs/src/plugins/config/commonhwsettingswidget.cpp +++ b/ground/gcs/src/plugins/config/commonhwsettingswidget.cpp @@ -33,20 +33,22 @@ #include "uavobjectmanager.h" -CommonHWSettingsWidget::CommonHWSettingsWidget(QWidget *parent) : QWidget(parent) +CommonHWSettingsWidget::CommonHWSettingsWidget(QWidget *parent) : ConfigTaskWidget(parent, Child) { m_ui = new Ui_CommonHWSettingsWidget(); m_ui->setupUi(this); m_ui->cbDSMxBind->addItem(tr("Disabled"), 0); -// combo->addItem(options.at(optionIndex), QVariant(optionIndex)); - setFeatures(0); // Relay signals from private members connect(m_ui->cbUSBHID, SIGNAL(currentIndexChanged(int)), this, SIGNAL(USBHIDFunctionChanged(int))); connect(m_ui->cbUSBVCP, SIGNAL(currentIndexChanged(int)), this, SIGNAL(USBVCPFunctionChanged(int))); + + // And these are here to handle conflicting VCP & HID options (such as USBTelemetry). + connect(m_ui->cbUSBHID, SIGNAL(currentIndexChanged(int)), this, SLOT(USBHIDComboChanged(int))); + connect(m_ui->cbUSBVCP, SIGNAL(currentIndexChanged(int)), this, SLOT(USBVCPComboChanged(int))); } CommonHWSettingsWidget::~CommonHWSettingsWidget() @@ -73,9 +75,7 @@ void CommonHWSettingsWidget::refreshWidgetsValues(UAVObject *obj) { Q_UNUSED(obj); - UAVObjectManager *objMngr = ExtensionSystem::PluginManager::instance()->getObject(); - - int option = HwSettings::GetInstance(objMngr)->getDSMxBind(); + int option = HwSettings::GetInstance(getObjectManager())->getDSMxBind(); if (m_ui->cbDSMxBind->count() == 0) { m_ui->cbDSMxBind->addItem(tr("None"), 0); @@ -141,3 +141,31 @@ QComboBox *CommonHWSettingsWidget::USBVCPComboBox() { return m_ui->cbUSBVCP; } + +bool CommonHWSettingsWidget::USBFunctionConflict() +{ + return (getComboboxSelectedOption(m_ui->cbUSBHID) == HwSettings::USB_HIDPORT_USBTELEMETRY) + && (getComboboxSelectedOption(m_ui->cbUSBVCP) == HwSettings::USB_VCPPORT_USBTELEMETRY); +} + +void CommonHWSettingsWidget::USBHIDComboChanged(int index) +{ + Q_UNUSED(index); + + if (USBFunctionConflict()) { + setComboboxSelectedOption(m_ui->cbUSBVCP, HwSettings::USB_VCPPORT_DISABLED); + } else if (getComboboxSelectedOption(m_ui->cbUSBHID) != HwSettings::USB_HIDPORT_USBTELEMETRY) { + setComboboxSelectedOption(m_ui->cbUSBVCP, HwSettings::USB_VCPPORT_USBTELEMETRY); + } +} + +void CommonHWSettingsWidget::USBVCPComboChanged(int index) +{ + Q_UNUSED(index); + + if (USBFunctionConflict()) { + setComboboxSelectedOption(m_ui->cbUSBHID, HwSettings::USB_HIDPORT_DISABLED); + } else if (getComboboxSelectedOption(m_ui->cbUSBVCP) != HwSettings::USB_VCPPORT_USBTELEMETRY) { + setComboboxSelectedOption(m_ui->cbUSBHID, HwSettings::USB_HIDPORT_USBTELEMETRY); + } +} diff --git a/ground/gcs/src/plugins/config/commonhwsettingswidget.h b/ground/gcs/src/plugins/config/commonhwsettingswidget.h index 77b56c29a..cb1f123a1 100644 --- a/ground/gcs/src/plugins/config/commonhwsettingswidget.h +++ b/ground/gcs/src/plugins/config/commonhwsettingswidget.h @@ -31,7 +31,7 @@ class Ui_CommonHWSettingsWidget; -class CommonHWSettingsWidget : public QWidget { +class CommonHWSettingsWidget : public ConfigTaskWidget { Q_OBJECT public: @@ -56,8 +56,14 @@ signals: void USBHIDFunctionChanged(int index); void USBVCPFunctionChanged(int index); +private slots: + void USBHIDComboChanged(int index); + void USBVCPComboChanged(int index); + private: Ui_CommonHWSettingsWidget *m_ui; + + bool USBFunctionConflict(); }; #endif // COMMONHWSETTINGSWIDGET_H diff --git a/ground/gcs/src/plugins/config/commonhwsettingswidget.ui b/ground/gcs/src/plugins/config/commonhwsettingswidget.ui index 95d8c1cce..87f07576b 100644 --- a/ground/gcs/src/plugins/config/commonhwsettingswidget.ui +++ b/ground/gcs/src/plugins/config/commonhwsettingswidget.ui @@ -6,8 +6,8 @@ 0 0 - 604 - 189 + 746 + 200 @@ -24,50 +24,7 @@ - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Qt::Horizontal - - - - - - - Options - - - Qt::AlignCenter - - - - + -1 @@ -105,7 +62,7 @@ - + Qt::Vertical @@ -183,6 +140,38 @@ + + + + Qt::Horizontal + + + QSizePolicy::Minimum + + + + 150 + 1 + + + + + + + + Qt::Horizontal + + + QSizePolicy::Minimum + + + + 180 + 1 + + + + @@ -282,7 +271,7 @@ - + Qt::Vertical @@ -298,8 +287,70 @@ + + + + Qt::Horizontal + + + QSizePolicy::Minimum + + + + 150 + 1 + + + + + + + + Qt::Horizontal + + + QSizePolicy::Minimum + + + + 180 + 1 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Horizontal + + + + + + + Options + + + Qt::AlignCenter + + +