2 ******************************************************************************
4 * @file configtinyfishhwwidget.cpp
5 * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2017.
6 * @addtogroup GCSPlugins GCS Plugins
8 * @addtogroup ConfigPlugin Config Plugin
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
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"
36 ConfigTinyFISHHWWidget::ConfigTinyFISHHWWidget(QWidget
*parent
) : ConfigTaskWidget(parent
)
38 m_ui
= new Ui_TinyFISHHWWidget();
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");
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
);
66 ConfigTinyFISHHWWidget::~ConfigTinyFISHHWWidget()
71 void ConfigTinyFISHHWWidget::refreshWidgetsValuesImpl(UAVObject
*obj
)
75 m_ui
->commonHWSettings
->refreshWidgetsValues(obj
);
78 void ConfigTinyFISHHWWidget::updateObjectsFromWidgetsImpl()
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
;
91 case HwTinyFISHSettings::UART3PORT_DSM
:
92 features
|= CommonHWSettingsWidget::F_DSM
;
94 case HwTinyFISHSettings::UART3PORT_SBUS
:
95 features
|= CommonHWSettingsWidget::F_SBUS
;
97 case HwTinyFISHSettings::UART3PORT_GPS
:
98 features
|= CommonHWSettingsWidget::F_GPS
;
100 case HwTinyFISHSettings::UART3PORT_DEBUGCONSOLE
:
101 features
|= CommonHWSettingsWidget::F_DEBUGCONSOLE
;
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
)
127 QComboBox
*cbUARTx
= qobject_cast
<QComboBox
*>(sender());
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
);
146 void ConfigTinyFISHHWWidget::USBVCPFunctionChanged(int 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
);