OP-1900 have path_progress updated correctly for leg_remaining and error_below end...
[librepilot.git] / ground / openpilotgcs / src / plugins / uploader / uploadergadgetwidget.h
blob5490a9046f004f2946fb2c27195afe6f6dc820e7
1 /**
2 ******************************************************************************
4 * @file uploadergadgetwidget.h
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * @addtogroup GCSPlugins GCS Plugins
7 * @{
8 * @addtogroup YModemUploader YModem Serial Uploader Plugin
9 * @{
10 * @brief The YModem protocol serial uploader plugin
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
28 #ifndef UPLOADERGADGETWIDGET_H
29 #define UPLOADERGADGETWIDGET_H
31 #include "ui_uploader.h"
32 #include "uploader_global.h"
34 #include "enums.h"
35 #include "op_dfu.h"
37 #include <QProgressDialog>
38 #include "oplinkwatchdog.h"
40 using namespace OP_DFU;
41 using namespace uploader;
43 class FlightStatus;
44 class UAVObject;
45 class OPLinkStatus;
46 class OPLinkWatchdog;
48 class TimedDialog : public QProgressDialog {
49 Q_OBJECT
51 public:
52 TimedDialog(const QString &title, const QString &labelText, int timeout, QWidget *parent = 0, Qt::WindowFlags flags = 0);
54 private slots:
55 void perform();
57 private:
58 QProgressBar *bar;
61 // A helper class to wait for board connection and disconnection events
62 // until a the desired number of connected boards is found
63 // or until a timeout is reached
64 class ConnectionWaiter : public QObject {
65 Q_OBJECT
67 public:
68 ConnectionWaiter(int targetDeviceCount, int timeout, QWidget *parent = 0);
70 enum ResultCode { Ok, Canceled, TimedOut };
72 public slots:
73 int exec();
74 void cancel();
75 void quit();
77 static int openDialog(const QString &title, const QString &labelText, int targetDeviceCount, int timeout, QWidget *parent = 0, Qt::WindowFlags flags = 0);
79 signals:
80 void timeChanged(int elapsed);
82 private slots:
83 void perform();
84 void deviceEvent();
86 private:
87 QEventLoop eventLoop;
88 QTimer timer;
89 // timeout in ms
90 int timeout;
91 // elapsed time in seconds
92 int elapsed;
93 int targetDeviceCount;
94 int result;
97 class ResultEventLoop : public QEventLoop {
98 Q_OBJECT
99 public:
100 int run(int millisTimout);
102 public slots:
103 void success();
104 void fail();
106 private:
107 QTimer m_timer;
110 class UPLOADER_EXPORT UploaderGadgetWidget : public QWidget {
111 Q_OBJECT
113 public:
114 UploaderGadgetWidget(QWidget *parent = 0);
115 ~UploaderGadgetWidget();
117 static const int BOARD_EVENT_TIMEOUT;
118 static const int AUTOUPDATE_CLOSE_TIMEOUT;
119 static const int REBOOT_TIMEOUT;
120 static const int ERASE_TIMEOUT;
121 static const int BOOTLOADER_TIMEOUT;
123 void log(QString str);
124 bool autoUpdateCapable();
126 public slots:
127 void onAutopilotConnect();
128 void onAutopilotDisconnect();
129 void populate();
130 void openHelp();
131 void autoUpdateDisconnectProgress(int);
132 void autoUpdateConnectProgress(int);
133 void autoUpdateFlashProgress(int);
135 signals:
136 void progressUpdate(uploader::ProgressStep, QVariant);
137 void bootloaderFailed();
138 void bootloaderSuccess();
139 void bootFailed();
140 void bootSuccess();
141 void autoUpdateFailed();
142 void autoUpdateSuccess();
144 private:
145 Ui_UploaderWidget *m_config;
146 DFUObject *m_dfu;
147 IAPStep m_currentIAPStep;
148 bool m_resetOnly;
149 OPLinkWatchdog m_oplinkwatchdog;
150 bool m_autoUpdateClosing;
152 void clearLog();
153 QString getPortDevice(const QString &friendName);
154 void connectSignalSlot(QWidget *widget);
155 FlightStatus *getFlightStatus();
156 void bootButtonsSetEnable(bool enabled);
157 int confirmEraseSettingsMessageBox();
158 int cannotHaltMessageBox();
159 int cannotResetMessageBox();
160 void startAutoUpdate(bool erase);
162 private slots:
163 void onPhysicalHWConnect();
164 void goToBootloader(UAVObject * = NULL, bool = false);
165 void systemHalt();
166 void systemReset();
167 void systemBoot();
168 void systemSafeBoot();
169 void systemEraseBoot();
170 void rebootWithDialog();
171 void systemReboot();
172 void commonSystemBoot(bool safeboot = false, bool erase = false);
173 void systemRescue();
174 void getSerialPorts();
175 void uploadStarted();
176 void uploadEnded(bool succeed);
177 void downloadStarted();
178 void downloadEnded(bool succeed);
179 void startAutoUpdate();
180 void startAutoUpdateErase();
181 bool autoUpdate(bool erase);
182 void finishAutoUpdate();
183 void closeAutoUpdate();
184 void autoUpdateStatus(uploader::ProgressStep status, QVariant value);
187 #endif // UPLOADERGADGETWIDGET_H