Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / ground / gcs / src / plugins / config / configtinyfishhwwidget.cpp
blob75a987d1f65e708ec6bd4ff7cc5342a00dfe0655
1 /**
2 ******************************************************************************
4 * @file configtinyfishhwwidget.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 TinyFISH FC 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 "configtinyfishhwwidget.h"
29 #include "ui_configtinyfishhwwidget.h"
31 #include "hwsettings.h"
32 #include "hwtinyfishsettings.h"
34 #include <QDebug>
36 ConfigTinyFISHHWWidget::ConfigTinyFISHHWWidget(QWidget *parent) : ConfigTaskWidget(parent)
38 m_ui = new Ui_TinyFISHHWWidget();
39 m_ui->setupUi(this);
41 m_ui->boardImg->load(QString(":/configgadget/images/tinyfish.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("TinyFISH+Configuration");
49 addAutoBindings();
51 addUAVObject("HwSettings");
52 addUAVObject("HwTinyFISHSettings");
54 addWidgetBinding("HwTinyFISHSettings", "UART3Port", m_ui->cbUART3, 0, 1, true);
55 addWidgetBinding("HwTinyFISHSettings", "LEDPort", m_ui->cbLEDPort);
57 connect(m_ui->cbUART3, static_cast<void(QComboBox::*) (int)>(&QComboBox::currentIndexChanged), this, &ConfigTinyFISHHWWidget::UARTxChanged);
59 m_ui->commonHWSettings->registerWidgets(*this);
61 connect(m_ui->commonHWSettings, &CommonHWSettingsWidget::USBVCPFunctionChanged, this, &ConfigTinyFISHHWWidget::USBVCPFunctionChanged);
63 updateFeatures();
66 ConfigTinyFISHHWWidget::~ConfigTinyFISHHWWidget()
68 delete m_ui;
71 void ConfigTinyFISHHWWidget::refreshWidgetsValuesImpl(UAVObject *obj)
73 // UART3Changed(0);
75 m_ui->commonHWSettings->refreshWidgetsValues(obj);
78 void ConfigTinyFISHHWWidget::updateObjectsFromWidgetsImpl()
80 updateFeatures();
83 void ConfigTinyFISHHWWidget::updateFeatures()
85 quint32 features = CommonHWSettingsWidget::F_USB;
87 switch (getComboboxSelectedOption(m_ui->cbUART3)) {
88 case HwTinyFISHSettings::UART3PORT_TELEMETRY:
89 features |= CommonHWSettingsWidget::F_TELEMETRY;
90 break;
91 case HwTinyFISHSettings::UART3PORT_DSM:
92 features |= CommonHWSettingsWidget::F_DSM;
93 break;
94 case HwTinyFISHSettings::UART3PORT_SBUS:
95 features |= CommonHWSettingsWidget::F_SBUS;
96 break;
97 case HwTinyFISHSettings::UART3PORT_GPS:
98 features |= CommonHWSettingsWidget::F_GPS;
99 break;
100 case HwTinyFISHSettings::UART3PORT_DEBUGCONSOLE:
101 features |= CommonHWSettingsWidget::F_DEBUGCONSOLE;
102 break;
103 default:
104 break;
107 m_ui->commonHWSettings->setFeatures(features);
109 HwSettings::GetInstance(getObjectManager())
110 ->setOptionalModules(HwSettings::OPTIONALMODULES_GPS,
111 (features & CommonHWSettingsWidget::F_GPS)
112 ? HwSettings::OPTIONALMODULES_ENABLED : HwSettings::OPTIONALMODULES_DISABLED);
115 bool ConfigTinyFISHHWWidget::optionConflict(int uartOption, int vcpOption)
117 return (vcpOption == HwSettings::USB_VCPPORT_DEBUGCONSOLE
118 && uartOption == HwTinyFISHSettings::UART3PORT_DEBUGCONSOLE)
119 || (vcpOption == HwSettings::USB_VCPPORT_MAVLINK
120 && uartOption == HwTinyFISHSettings::UART3PORT_MAVLINK);
123 void ConfigTinyFISHHWWidget::UARTxChanged(int index)
125 Q_UNUSED(index);
127 QComboBox *cbUARTx = qobject_cast<QComboBox *>(sender());
129 if (!cbUARTx) {
130 return;
133 int option = getComboboxSelectedOption(cbUARTx);
135 if (option != HwTinyFISHSettings::UART3PORT_DISABLED && option != HwTinyFISHSettings::UART3PORT_DSM) {
136 QComboBox *cbUSBVCP = m_ui->commonHWSettings->USBVCPComboBox();
138 if (optionConflict(option, getComboboxSelectedOption(cbUSBVCP))) {
139 setComboboxSelectedOption(cbUSBVCP, HwSettings::USB_VCPPORT_DISABLED);
143 updateFeatures();
146 void ConfigTinyFISHHWWidget::USBVCPFunctionChanged(int index)
148 Q_UNUSED(index);
150 int vcpOption = getComboboxSelectedOption(m_ui->commonHWSettings->USBVCPComboBox());
152 for (int i = 0; i < 3; ++i) {
153 if (optionConflict(getComboboxSelectedOption(m_ui->cbUART3), vcpOption)) {
154 setComboboxSelectedOption(m_ui->cbUART3, HwTinyFISHSettings::UART3PORT_DISABLED);
158 updateFeatures();