Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / ground / gcs / src / plugins / config / configspracingf3evohwwidget.cpp
blob7d582b2a6201cce5a17a99e60493199ee274a988
1 /**
2 ******************************************************************************
4 * @file configspracingf3evohwwidget.cpp
5 * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016-2017.
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 SPRacingF3EVO hardware configuration panel
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
28 #include "configspracingf3evohwwidget.h"
30 #include "ui_configspracingf3evohwwidget.h"
32 #include "hwsettings.h"
34 #include <QDebug>
36 ConfigSPRacingF3EVOHWWidget::ConfigSPRacingF3EVOHWWidget(QWidget *parent) : ConfigTaskWidget(parent)
38 m_ui = new Ui_SPRacingF3EVOHWWidget();
39 m_ui->setupUi(this);
41 m_ui->boardImg->load(QString(":/configgadget/images/spracingf3evo.svg"));
42 QSize picSize = m_ui->boardImg->sizeHint();
43 picSize.scale(360, 360, Qt::KeepAspectRatio);
44 m_ui->boardImg->setFixedSize(picSize);
46 // must be done before auto binding !
47 setWikiURL("SPRacingF3EVO+Configuration");
49 addAutoBindings();
51 addUAVObject("HwSettings");
52 addUAVObject("HwSPRacingF3EVOSettings");
54 addWidgetBinding("HwSPRacingF3EVOSettings", "UARTPort", m_ui->cbUART1, 0, 1, true);
55 addWidgetBinding("HwSPRacingF3EVOSettings", "UARTPort", m_ui->cbUART2, 1, 1, true);
56 addWidgetBinding("HwSPRacingF3EVOSettings", "UARTPort", m_ui->cbUART3, 2, 1, true);
57 addWidgetBinding("HwSPRacingF3EVOSettings", "LEDPort", m_ui->cbLEDPort);
58 addWidgetBinding("HwSPRacingF3EVOSettings", "I2CPort", m_ui->cbI2C1);
60 m_cbUART[0] = m_ui->cbUART1;
61 m_cbUART[1] = m_ui->cbUART2;
62 m_cbUART[2] = m_ui->cbUART3;
64 for (quint32 i = 0; i < HwSPRacingF3EVOSettings::UARTPORT_NUMELEM; ++i) {
65 connect(m_cbUART[i], static_cast<void(QComboBox::*) (int)>(&QComboBox::currentIndexChanged), this, &ConfigSPRacingF3EVOHWWidget::UARTxChanged);
68 m_ui->commonHWSettings->registerWidgets(*this);
70 connect(m_ui->commonHWSettings, &CommonHWSettingsWidget::USBVCPFunctionChanged, this, &ConfigSPRacingF3EVOHWWidget::USBVCPFunctionChanged);
72 updateFeatures();
75 ConfigSPRacingF3EVOHWWidget::~ConfigSPRacingF3EVOHWWidget()
77 delete m_ui;
80 void ConfigSPRacingF3EVOHWWidget::refreshWidgetsValuesImpl(UAVObject *obj)
82 // is this needed? This is to force sane state
83 // UART1Changed(0);
84 // UART2Changed(0);
85 // UART3Changed(0);
87 m_ui->commonHWSettings->refreshWidgetsValues(obj);
90 void ConfigSPRacingF3EVOHWWidget::updateObjectsFromWidgetsImpl()
92 updateFeatures();
95 void ConfigSPRacingF3EVOHWWidget::updateFeatures()
97 quint32 features = CommonHWSettingsWidget::F_USB;
99 for (quint32 i = 0; i < HwSPRacingF3EVOSettings::UARTPORT_NUMELEM; ++i) {
100 switch (getComboboxSelectedOption(m_cbUART[i])) {
101 case HwSPRacingF3EVOSettings::UARTPORT_TELEMETRY:
102 features |= CommonHWSettingsWidget::F_TELEMETRY;
103 break;
104 case HwSPRacingF3EVOSettings::UARTPORT_DSM:
105 features |= CommonHWSettingsWidget::F_DSM;
106 break;
107 case HwSPRacingF3EVOSettings::UARTPORT_SBUS:
108 features |= CommonHWSettingsWidget::F_SBUS;
109 break;
110 case HwSPRacingF3EVOSettings::UARTPORT_GPS:
111 features |= CommonHWSettingsWidget::F_GPS;
112 break;
113 case HwSPRacingF3EVOSettings::UARTPORT_DEBUGCONSOLE:
114 features |= CommonHWSettingsWidget::F_DEBUGCONSOLE;
115 break;
116 default:
117 break;
121 m_ui->commonHWSettings->setFeatures(features);
123 HwSettings::GetInstance(getObjectManager())
124 ->setOptionalModules(HwSettings::OPTIONALMODULES_GPS,
125 (features & CommonHWSettingsWidget::F_GPS)
126 ? HwSettings::OPTIONALMODULES_ENABLED : HwSettings::OPTIONALMODULES_DISABLED);
129 bool ConfigSPRacingF3EVOHWWidget::optionConflict(int uartOption, int vcpOption)
131 return (vcpOption == HwSettings::USB_VCPPORT_DEBUGCONSOLE
132 && uartOption == HwSPRacingF3EVOSettings::UARTPORT_DEBUGCONSOLE)
133 || (vcpOption == HwSettings::USB_VCPPORT_MAVLINK
134 && uartOption == HwSPRacingF3EVOSettings::UARTPORT_MAVLINK);
137 void ConfigSPRacingF3EVOHWWidget::UARTxChanged(int index)
139 Q_UNUSED(index);
141 QComboBox *cbUARTx = qobject_cast<QComboBox *>(sender());
143 if (!cbUARTx) {
144 return;
147 // Everything except HwSPRacingF3EVOSettings::UARTPORT_DISABLED and HwSPRacingF3EVOSettings::UARTPORT_DSM
148 // is allowed on single port only.
149 // HoTT SUMD & SUMH belong to the same receiver group, therefore cannot be configure at the same time
152 int option = getComboboxSelectedOption(cbUARTx);
154 if (option == HwSPRacingF3EVOSettings::UARTPORT_HOTTSUMD) {
155 option = HwSPRacingF3EVOSettings::UARTPORT_HOTTSUMH;
158 if (option != HwSPRacingF3EVOSettings::UARTPORT_DISABLED && option != HwSPRacingF3EVOSettings::UARTPORT_DSM) {
159 for (quint32 i = 0; i < HwSPRacingF3EVOSettings::UARTPORT_NUMELEM; ++i) {
160 if (m_cbUART[i] == cbUARTx) {
161 continue;
163 int other = getComboboxSelectedOption(m_cbUART[i]);
164 if (other == HwSPRacingF3EVOSettings::UARTPORT_HOTTSUMD) {
165 other = HwSPRacingF3EVOSettings::UARTPORT_HOTTSUMH;
167 if (other == option) {
168 setComboboxSelectedOption(m_cbUART[i], HwSPRacingF3EVOSettings::UARTPORT_DISABLED);
172 QComboBox *cbUSBVCP = m_ui->commonHWSettings->USBVCPComboBox();
174 if (optionConflict(option, getComboboxSelectedOption(cbUSBVCP))) {
175 setComboboxSelectedOption(cbUSBVCP, HwSettings::USB_VCPPORT_DISABLED);
179 updateFeatures();
182 void ConfigSPRacingF3EVOHWWidget::USBVCPFunctionChanged(int index)
184 Q_UNUSED(index);
186 int vcpOption = getComboboxSelectedOption(m_ui->commonHWSettings->USBVCPComboBox());
188 for (quint32 i = 0; i < HwSPRacingF3EVOSettings::UARTPORT_NUMELEM; ++i) {
189 if (optionConflict(getComboboxSelectedOption(m_cbUART[i]), vcpOption)) {
190 setComboboxSelectedOption(m_cbUART[i], HwSPRacingF3EVOSettings::UARTPORT_DISABLED);
194 updateFeatures();