Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / ground / gcs / src / plugins / config / commonhwsettingswidget.cpp
blob550adda181c36e76b7ac7be8513c856f536c5cd4
1 /**
2 ******************************************************************************
4 * @file commonhwsettingswidget.cpp
5 * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2017.
6 * @addtogroup GCSPlugins GCS Plugins
7 * @{
8 * @addtogroup ConfigPlugin Config Plugin
9 * @{
10 * @brief Common hardware configuration panel
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "commonhwsettingswidget.h"
28 #include "ui_commonhwsettingswidget.h"
29 #include "hwsettings.h"
31 #include <QDebug>
32 #include <extensionsystem/pluginmanager.h>
33 #include "uavobjectmanager.h"
36 CommonHWSettingsWidget::CommonHWSettingsWidget(QWidget *parent) : ConfigTaskWidget(parent, Child)
38 m_ui = new Ui_CommonHWSettingsWidget();
39 m_ui->setupUi(this);
41 m_ui->cbDSMxBind->addItem(tr("Disabled"), 0);
43 setFeatures(0);
45 // Relay signals from private members
46 connect(m_ui->cbUSBHID, SIGNAL(currentIndexChanged(int)), this, SIGNAL(USBHIDFunctionChanged(int)));
47 connect(m_ui->cbUSBVCP, SIGNAL(currentIndexChanged(int)), this, SIGNAL(USBVCPFunctionChanged(int)));
49 // And these are here to handle conflicting VCP & HID options (such as USBTelemetry).
50 connect(m_ui->cbUSBHID, SIGNAL(currentIndexChanged(int)), this, SLOT(USBHIDComboChanged(int)));
51 connect(m_ui->cbUSBVCP, SIGNAL(currentIndexChanged(int)), this, SLOT(USBVCPComboChanged(int)));
54 CommonHWSettingsWidget::~CommonHWSettingsWidget()
56 delete m_ui;
59 void CommonHWSettingsWidget::registerWidgets(ConfigTaskWidget &ct)
61 ct.addWidgetBinding("HwSettings", "USB_HIDPort", m_ui->cbUSBHID);
62 ct.addWidgetBinding("HwSettings", "USB_VCPPort", m_ui->cbUSBVCP);
64 ct.addWidgetBinding("HwSettings", "TelemetrySpeed", m_ui->cbTelemetrySpeed);
65 ct.addWidgetBinding("HwSettings", "GPSSpeed", m_ui->cbGPSSpeed);
66 ct.addWidgetBinding("HwSettings", "DebugConsoleSpeed", m_ui->cbDebugConsoleSpeed);
67 ct.addWidgetBinding("HwSettings", "SBusMode", m_ui->cbSBUSMode);
69 ct.addWidgetBinding("HwSettings", "DSMxBind", m_ui->cbDSMxBind, 0, 1, true);
71 ct.addWidgetBinding("GPSSettings", "DataProtocol", m_ui->cbGPSProtocol);
74 void CommonHWSettingsWidget::refreshWidgetsValues(UAVObject *obj)
76 Q_UNUSED(obj);
78 int option = HwSettings::GetInstance(getObjectManager())->getDSMxBind();
80 if (m_ui->cbDSMxBind->count() == 0) {
81 m_ui->cbDSMxBind->addItem(tr("None"), 0);
82 m_ui->cbDSMxBind->addItem(tr("DSM2 1024bit/22ms"), 3);
83 m_ui->cbDSMxBind->addItem(tr("DSM2 2048bit/11ms"), 5);
84 m_ui->cbDSMxBind->addItem(tr("DSMX 1024bit/22ms"), 7);
85 m_ui->cbDSMxBind->addItem(tr("DSMX 2048bit/22ms"), 8);
86 m_ui->cbDSMxBind->addItem(tr("DSMX 2048bit/11ms"), 9);
89 int index = m_ui->cbDSMxBind->findData(option);
91 if (index == -1) {
92 m_ui->cbDSMxBind->addItem(tr("%1 Pulses").arg(option), option);
93 m_ui->cbDSMxBind->setCurrentIndex(m_ui->cbDSMxBind->count() - 1);
94 } else {
95 m_ui->cbDSMxBind->setCurrentIndex(index);
99 void CommonHWSettingsWidget::setFeatures(quint32 features)
101 bool flag = features != 0;
103 setVisible(flag);
105 flag = (features & F_USB) != 0;
107 m_ui->lbUSBHID->setVisible(flag);
108 m_ui->cbUSBHID->setVisible(flag);
109 m_ui->lbUSBVCP->setVisible(flag);
110 m_ui->cbUSBVCP->setVisible(flag);
112 flag = (features & F_SBUS) != 0;
114 m_ui->lbSBUSMode->setVisible(flag);
115 m_ui->cbSBUSMode->setVisible(flag);
117 flag = (features & F_DSM) != 0;
119 m_ui->lbDSMxBind->setVisible(flag);
120 m_ui->cbDSMxBind->setVisible(flag);
122 flag = (features & F_TELEMETRY) != 0;
124 m_ui->lbTelemetrySpeed->setVisible(flag);
125 m_ui->cbTelemetrySpeed->setVisible(flag);
127 flag = (features & F_DEBUGCONSOLE) != 0;
129 m_ui->lbDebugConsoleSpeed->setVisible(flag);
130 m_ui->cbDebugConsoleSpeed->setVisible(flag);
132 flag = (features & F_GPS) != 0;
134 m_ui->lbGPSSpeed->setVisible(flag);
135 m_ui->cbGPSSpeed->setVisible(flag);
136 m_ui->lbGPSProtocol->setVisible(flag);
137 m_ui->cbGPSProtocol->setVisible(flag);
140 QComboBox *CommonHWSettingsWidget::USBVCPComboBox()
142 return m_ui->cbUSBVCP;
145 bool CommonHWSettingsWidget::USBFunctionConflict()
147 return (getComboboxSelectedOption(m_ui->cbUSBHID) == HwSettings::USB_HIDPORT_USBTELEMETRY)
148 && (getComboboxSelectedOption(m_ui->cbUSBVCP) == HwSettings::USB_VCPPORT_USBTELEMETRY);
151 void CommonHWSettingsWidget::USBHIDComboChanged(int index)
153 Q_UNUSED(index);
155 if (USBFunctionConflict()) {
156 setComboboxSelectedOption(m_ui->cbUSBVCP, HwSettings::USB_VCPPORT_DISABLED);
157 } else if (getComboboxSelectedOption(m_ui->cbUSBHID) != HwSettings::USB_HIDPORT_USBTELEMETRY) {
158 setComboboxSelectedOption(m_ui->cbUSBVCP, HwSettings::USB_VCPPORT_USBTELEMETRY);
162 void CommonHWSettingsWidget::USBVCPComboChanged(int index)
164 Q_UNUSED(index);
166 if (USBFunctionConflict()) {
167 setComboboxSelectedOption(m_ui->cbUSBHID, HwSettings::USB_HIDPORT_DISABLED);
168 } else if (getComboboxSelectedOption(m_ui->cbUSBVCP) != HwSettings::USB_VCPPORT_USBTELEMETRY) {
169 setComboboxSelectedOption(m_ui->cbUSBHID, HwSettings::USB_HIDPORT_USBTELEMETRY);