2 ******************************************************************************
4 * @file configgadgetwidget.cpp
5 * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015.
6 * E. Lafargue & The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
7 * @addtogroup GCSPlugins GCS Plugins
9 * @addtogroup ConfigPlugin Config Plugin
11 * @brief The Configuration Gadget used to update 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
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 "configgadgetwidget.h"
31 #include "configvehicletypewidget.h"
32 #include "configccattitudewidget.h"
33 #include "configinputwidget.h"
34 #include "configoutputwidget.h"
35 #include "configstabilizationwidget.h"
36 #include "configcamerastabilizationwidget.h"
37 #include "configtxpidwidget.h"
38 #include "configrevohwwidget.h"
39 #include "config_cc_hw_widget.h"
40 #include "configoplinkwidget.h"
41 #include "configrevowidget.h"
42 #include "configrevonanohwwidget.h"
43 #include "configsparky2hwwidget.h"
44 #include "defaultattitudewidget.h"
45 #include "defaulthwsettingswidget.h"
47 #include <extensionsystem/pluginmanager.h>
48 #include <uavobjectutilmanager.h>
49 #include <uavtalk/telemetrymanager.h>
50 #include <uavtalk/oplinkmanager.h>
52 #include "utils/mytabbedstackwidget.h"
55 #include <QVBoxLayout>
56 #include <QMessageBox>
59 ConfigGadgetWidget::ConfigGadgetWidget(QWidget
*parent
) : QWidget(parent
)
61 setSizePolicy(QSizePolicy::MinimumExpanding
, QSizePolicy::MinimumExpanding
);
63 stackWidget
= new MyTabbedStackWidget(this, true, true);
64 stackWidget
->setIconSize(64);
66 QVBoxLayout
*layout
= new QVBoxLayout
;
67 layout
->setContentsMargins(0, 0, 0, 0);
68 layout
->addWidget(stackWidget
);
71 ExtensionSystem::PluginManager
*pm
= ExtensionSystem::PluginManager::instance();
77 icon
->addFile(":/configgadget/images/hardware_normal.png", QSize(), QIcon::Normal
, QIcon::Off
);
78 icon
->addFile(":/configgadget/images/hardware_selected.png", QSize(), QIcon::Selected
, QIcon::Off
);
79 widget
= new DefaultHwSettingsWidget(this);
80 stackWidget
->insertTab(ConfigGadgetWidget::hardware
, widget
, *icon
, QString("Hardware"));
83 icon
->addFile(":/configgadget/images/vehicle_normal.png", QSize(), QIcon::Normal
, QIcon::Off
);
84 icon
->addFile(":/configgadget/images/vehicle_selected.png", QSize(), QIcon::Selected
, QIcon::Off
);
85 widget
= new ConfigVehicleTypeWidget(this);
86 stackWidget
->insertTab(ConfigGadgetWidget::aircraft
, widget
, *icon
, QString("Vehicle"));
89 icon
->addFile(":/configgadget/images/input_normal.png", QSize(), QIcon::Normal
, QIcon::Off
);
90 icon
->addFile(":/configgadget/images/input_selected.png", QSize(), QIcon::Selected
, QIcon::Off
);
91 widget
= new ConfigInputWidget(this);
92 stackWidget
->insertTab(ConfigGadgetWidget::input
, widget
, *icon
, QString("Input"));
95 icon
->addFile(":/configgadget/images/output_normal.png", QSize(), QIcon::Normal
, QIcon::Off
);
96 icon
->addFile(":/configgadget/images/output_selected.png", QSize(), QIcon::Selected
, QIcon::Off
);
97 widget
= new ConfigOutputWidget(this);
98 stackWidget
->insertTab(ConfigGadgetWidget::output
, widget
, *icon
, QString("Output"));
101 icon
->addFile(":/configgadget/images/ins_normal.png", QSize(), QIcon::Normal
, QIcon::Off
);
102 icon
->addFile(":/configgadget/images/ins_selected.png", QSize(), QIcon::Selected
, QIcon::Off
);
103 widget
= new DefaultAttitudeWidget(this);
104 stackWidget
->insertTab(ConfigGadgetWidget::sensors
, widget
, *icon
, QString("Attitude"));
107 icon
->addFile(":/configgadget/images/stabilization_normal.png", QSize(), QIcon::Normal
, QIcon::Off
);
108 icon
->addFile(":/configgadget/images/stabilization_selected.png", QSize(), QIcon::Selected
, QIcon::Off
);
109 widget
= new ConfigStabilizationWidget(this);
110 stackWidget
->insertTab(ConfigGadgetWidget::stabilization
, widget
, *icon
, QString("Stabilization"));
113 icon
->addFile(":/configgadget/images/camstab_normal.png", QSize(), QIcon::Normal
, QIcon::Off
);
114 icon
->addFile(":/configgadget/images/camstab_selected.png", QSize(), QIcon::Selected
, QIcon::Off
);
115 widget
= new ConfigCameraStabilizationWidget(this);
116 stackWidget
->insertTab(ConfigGadgetWidget::camerastabilization
, widget
, *icon
, QString("Gimbal"));
119 icon
->addFile(":/configgadget/images/txpid_normal.png", QSize(), QIcon::Normal
, QIcon::Off
);
120 icon
->addFile(":/configgadget/images/txpid_selected.png", QSize(), QIcon::Selected
, QIcon::Off
);
121 widget
= new ConfigTxPIDWidget(this);
122 stackWidget
->insertTab(ConfigGadgetWidget::txpid
, widget
, *icon
, QString("TxPID"));
124 stackWidget
->setCurrentIndex(ConfigGadgetWidget::hardware
);
126 // connect to autopilot connection events
127 TelemetryManager
*tm
= pm
->getObject
<TelemetryManager
>();
128 connect(tm
, SIGNAL(connected()), this, SLOT(onAutopilotConnect()));
129 connect(tm
, SIGNAL(disconnected()), this, SLOT(onAutopilotDisconnect()));
130 // check if we are already connected
131 if (tm
->isConnected()) {
132 onAutopilotConnect();
135 // connect to oplink manager
136 OPLinkManager
*om
= pm
->getObject
<OPLinkManager
>();
137 connect(om
, SIGNAL(connected()), this, SLOT(onOPLinkConnect()));
138 connect(om
, SIGNAL(disconnected()), this, SLOT(onOPLinkDisconnect()));
139 // check if we are already connected
140 if (om
->isConnected()) {
145 connect(stackWidget
, SIGNAL(currentAboutToShow(int, bool *)), this, SLOT(tabAboutToChange(int, bool *)));
148 ConfigGadgetWidget::~ConfigGadgetWidget()
153 void ConfigGadgetWidget::startInputWizard()
155 stackWidget
->setCurrentIndex(ConfigGadgetWidget::input
);
156 ConfigInputWidget
*inputWidget
= dynamic_cast<ConfigInputWidget
*>(stackWidget
->getWidget(ConfigGadgetWidget::input
));
157 Q_ASSERT(inputWidget
);
158 inputWidget
->startInputWizard();
161 void ConfigGadgetWidget::resizeEvent(QResizeEvent
*event
)
163 QWidget::resizeEvent(event
);
166 void ConfigGadgetWidget::onAutopilotConnect()
168 qDebug() << "ConfigGadgetWidget::onAutopilotConnect";
170 // Check what Board type we are talking to, and if necessary, remove/add tabs in the config gadget
171 ExtensionSystem::PluginManager
*pm
= ExtensionSystem::PluginManager::instance();
172 UAVObjectUtilManager
*utilMngr
= pm
->getObject
<UAVObjectUtilManager
>();
174 int board
= utilMngr
->getBoardModel();
175 if ((board
& 0xff00) == 0x0400) {
176 // CopterControl family
177 ConfigTaskWidget
*widget
;
178 widget
= new ConfigCCAttitudeWidget(this);
179 widget
->forceConnectedState();
180 stackWidget
->replaceTab(ConfigGadgetWidget::sensors
, widget
);
181 widget
= new ConfigCCHWWidget(this);
182 widget
->forceConnectedState();
183 stackWidget
->replaceTab(ConfigGadgetWidget::hardware
, widget
);
184 } else if ((board
& 0xff00) == 0x0900) {
186 ConfigTaskWidget
*widget
;
187 widget
= new ConfigRevoWidget(this);
188 widget
->forceConnectedState();
189 stackWidget
->replaceTab(ConfigGadgetWidget::sensors
, widget
);
190 if (board
== 0x0903 || board
== 0x0904) {
191 widget
= new ConfigRevoHWWidget(this);
192 } else if (board
== 0x0905) {
193 widget
= new ConfigRevoNanoHWWidget(this);
195 widget
->forceConnectedState();
196 stackWidget
->replaceTab(ConfigGadgetWidget::hardware
, widget
);
197 } else if ((board
& 0xff00) == 0x9200) {
199 ConfigTaskWidget
*widget
;
200 widget
= new ConfigRevoWidget(this);
201 widget
->forceConnectedState();
202 stackWidget
->replaceTab(ConfigGadgetWidget::sensors
, widget
);
203 widget
= new ConfigSparky2HWWidget(this);
204 widget
->forceConnectedState();
205 stackWidget
->replaceTab(ConfigGadgetWidget::hardware
, widget
);
208 qDebug() << "Unknown board " << board
;
213 void ConfigGadgetWidget::onAutopilotDisconnect()
215 qDebug() << "ConfigGadgetWidget::onAutopilotDiconnect";
218 widget
= new DefaultAttitudeWidget(this);
219 stackWidget
->replaceTab(ConfigGadgetWidget::sensors
, widget
);
221 widget
= new DefaultHwSettingsWidget(this);
222 stackWidget
->replaceTab(ConfigGadgetWidget::hardware
, widget
);
225 void ConfigGadgetWidget::onOPLinkConnect()
227 qDebug() << "ConfigGadgetWidget::onOPLinkConnect";
229 ConfigTaskWidget
*widget
;
233 icon
->addFile(":/configgadget/images/pipx-normal.png", QSize(), QIcon::Normal
, QIcon::Off
);
234 icon
->addFile(":/configgadget/images/pipx-selected.png", QSize(), QIcon::Selected
, QIcon::Off
);
235 widget
= new ConfigOPLinkWidget(this);
236 widget
->forceConnectedState();
237 stackWidget
->insertTab(ConfigGadgetWidget::oplink
, widget
, *icon
, QString("OPLink"));
240 void ConfigGadgetWidget::onOPLinkDisconnect()
242 qDebug() << "ConfigGadgetWidget::onOPLinkDisconnect";
244 if (stackWidget
->currentIndex() == ConfigGadgetWidget::oplink
) {
245 stackWidget
->setCurrentIndex(0);
247 stackWidget
->removeTab(ConfigGadgetWidget::oplink
);
250 void ConfigGadgetWidget::tabAboutToChange(int i
, bool *proceed
)
254 ConfigTaskWidget
*wid
= qobject_cast
<ConfigTaskWidget
*>(stackWidget
->currentWidget());
258 if (wid
->isDirty()) {
259 int ans
= QMessageBox::warning(this, tr("Unsaved changes"), tr("The tab you are leaving has unsaved changes,"
260 "if you proceed they will be lost.\n"
261 "Do you still want to proceed?"), QMessageBox::Yes
, QMessageBox::No
);
262 if (ans
== QMessageBox::No
) {
265 wid
->setDirty(false);