LP-245 config: simplify access to HWSettings
[librepilot.git] / ground / gcs / src / plugins / config / config_cc_hw_widget.cpp
blob1b69082088891eeac7d362b921f7b226c7d80daa
1 /**
2 ******************************************************************************
4 * @file config_cc_hw_widget.cpp
5 * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015.
6 * The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
7 * @addtogroup GCSPlugins GCS Plugins
8 * @{
9 * @addtogroup ConfigPlugin Config Plugin
10 * @{
11 * @brief The Configuration Gadget used to update hardware settings in the firmware
12 *****************************************************************************/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "config_cc_hw_widget.h"
31 #include "ui_cc_hw_settings.h"
33 #include <extensionsystem/pluginmanager.h>
34 #include <uavobjectutilmanager.h>
36 #include "hwsettings.h"
38 #include <QDebug>
39 #include <QStringList>
40 #include <QWidget>
41 #include <QSvgRenderer>
43 ConfigCCHWWidget::ConfigCCHWWidget(QWidget *parent) : ConfigTaskWidget(parent)
45 m_telemetry = new Ui_CC_HW_Widget();
46 m_telemetry->setupUi(this);
48 // must be done before auto binding !
49 setWikiURL("CC+Hardware+Configuration");
51 addAutoBindings();
53 ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
54 UAVObjectUtilManager *utilMngr = pm->getObject<UAVObjectUtilManager>();
55 int id = utilMngr->getBoardModel();
56 switch (id) {
57 case 0x0101:
58 m_telemetry->label_2->setPixmap(QPixmap(":/uploader/images/deviceID-0101.svg"));
59 break;
60 case 0x0301:
61 m_telemetry->label_2->setPixmap(QPixmap(":/uploader/images/deviceID-0301.svg"));
62 break;
63 case 0x0401:
64 m_telemetry->label_2->setPixmap(QPixmap(":/configgadget/images/coptercontrol.svg"));
65 break;
66 case 0x0402:
67 m_telemetry->label_2->setPixmap(QPixmap(":/configgadget/images/cc3d_top.png"));
68 break;
69 case 0x0201:
70 m_telemetry->label_2->setPixmap(QPixmap(":/uploader/images/deviceID-0201.svg"));
71 break;
72 default:
73 m_telemetry->label_2->setPixmap(QPixmap(":/configgadget/images/coptercontrol.svg"));
74 break;
77 addWidgetBinding("HwSettings", "CC_FlexiPort", m_telemetry->cbFlexi);
78 addWidgetBinding("HwSettings", "CC_MainPort", m_telemetry->cbTele);
79 addWidgetBinding("HwSettings", "CC_RcvrPort", m_telemetry->cbRcvr);
80 addWidgetBinding("HwSettings", "USB_HIDPort", m_telemetry->cbUsbHid);
81 addWidgetBinding("HwSettings", "USB_VCPPort", m_telemetry->cbUsbVcp);
82 addWidgetBinding("HwSettings", "TelemetrySpeed", m_telemetry->telemetrySpeed);
83 addWidgetBinding("HwSettings", "GPSSpeed", m_telemetry->gpsSpeed);
84 // Add Gps protocol configuration
86 HwSettings *hwSettings = HwSettings::GetInstance(getObjectManager());
88 if (hwSettings->getOptionalModules(HwSettings::OPTIONALMODULES_GPS) != HwSettings::OPTIONALMODULES_ENABLED) {
89 m_telemetry->gpsProtocol->setEnabled(false);
90 m_telemetry->gpsProtocol->setToolTip(tr("Enable GPS module and reboot the board to be able to select GPS protocol"));
91 } else {
92 addWidgetBinding("GPSSettings", "DataProtocol", m_telemetry->gpsProtocol);
96 ConfigCCHWWidget::~ConfigCCHWWidget()
98 // Do nothing
101 void ConfigCCHWWidget::refreshValues()
104 void ConfigCCHWWidget::widgetsContentsChanged()
106 ConfigTaskWidget::widgetsContentsChanged();
108 if (((m_telemetry->cbTele->currentIndex() == HwSettings::CC_MAINPORT_DEBUGCONSOLE) &&
109 (m_telemetry->cbFlexi->currentIndex() == HwSettings::CC_FLEXIPORT_DEBUGCONSOLE)) ||
110 ((m_telemetry->cbFlexi->currentIndex() == HwSettings::CC_FLEXIPORT_DEBUGCONSOLE) &&
111 (m_telemetry->cbUsbVcp->currentIndex() == HwSettings::USB_VCPPORT_DEBUGCONSOLE)) ||
112 ((m_telemetry->cbUsbVcp->currentIndex() == HwSettings::USB_VCPPORT_DEBUGCONSOLE) &&
113 (m_telemetry->cbTele->currentIndex() == HwSettings::CC_MAINPORT_DEBUGCONSOLE))) {
114 enableSaveButtons(false);
115 m_telemetry->problems->setText(tr("Warning: you have configured more than one DebugConsole, this currently is not supported"));
116 } else if (((m_telemetry->cbTele->currentIndex() == HwSettings::CC_MAINPORT_TELEMETRY) && (m_telemetry->cbFlexi->currentIndex() == HwSettings::CC_FLEXIPORT_TELEMETRY)) ||
117 ((m_telemetry->cbTele->currentIndex() == HwSettings::CC_MAINPORT_GPS) && (m_telemetry->cbFlexi->currentIndex() == HwSettings::CC_FLEXIPORT_GPS)) ||
118 ((m_telemetry->cbTele->currentIndex() == HwSettings::CC_MAINPORT_DEBUGCONSOLE) && (m_telemetry->cbFlexi->currentIndex() == HwSettings::CC_FLEXIPORT_DEBUGCONSOLE)) ||
119 ((m_telemetry->cbTele->currentIndex() == HwSettings::CC_MAINPORT_COMBRIDGE) && (m_telemetry->cbFlexi->currentIndex() == HwSettings::CC_FLEXIPORT_COMBRIDGE))) {
120 enableSaveButtons(false);
121 m_telemetry->problems->setText(tr("Warning: you have configured both MainPort and FlexiPort for the same function, this currently is not supported"));
122 } else if ((m_telemetry->cbUsbHid->currentIndex() == HwSettings::USB_HIDPORT_USBTELEMETRY) && (m_telemetry->cbUsbVcp->currentIndex() == HwSettings::USB_VCPPORT_USBTELEMETRY)) {
123 enableSaveButtons(false);
124 m_telemetry->problems->setText(tr("Warning: you have configured both USB HID Port and USB VCP Port for the same function, this currently is not supported"));
125 } else if ((m_telemetry->cbUsbHid->currentIndex() != HwSettings::USB_HIDPORT_USBTELEMETRY) && (m_telemetry->cbUsbVcp->currentIndex() != HwSettings::USB_VCPPORT_USBTELEMETRY)) {
126 enableSaveButtons(false);
127 m_telemetry->problems->setText(tr("Warning: you have disabled USB Telemetry on both USB HID Port and USB VCP Port, this currently is not supported"));
128 } else {
129 m_telemetry->problems->setText("");
130 enableSaveButtons(true);
134 void ConfigCCHWWidget::enableSaveButtons(bool enable)
136 m_telemetry->applyButton->setEnabled(enable);
137 m_telemetry->saveButton->setEnabled(enable);