1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-02 10:24:11 +01:00

OP-1174 uploader gadget - now wait for all boards to be disconnected (used to wait for *one* board to be disconnected).

This was acheived by reusing new ConnectionWaiter.
This commit is contained in:
Philippe Renon 2014-05-02 08:55:46 +02:00
parent 9573e141aa
commit f4f3f74948
2 changed files with 28 additions and 35 deletions

View File

@ -31,6 +31,7 @@
#include <coreplugin/coreconstants.h>
#include <uavtalk/telemetrymanager.h>
#include <QProgressBar>
#include <QDebug>
#define DFU_DEBUG true
@ -51,19 +52,6 @@ TimedDialog::TimedDialog(const QString &title, const QString &labelText, int tim
setBar(bar);
}
int TimedDialog::exec() {
QTimer timer(this);
connect(&timer, SIGNAL(timeout()), this, SLOT(perform()));
setValue(0);
timer.start(1000);
int result = QProgressDialog::exec();
timer.stop();
return result;
}
void TimedDialog::perform()
{
setValue(value() + 1);
@ -71,8 +59,7 @@ void TimedDialog::perform()
if (remaining > 0) {
bar->setFormat(tr("Timing out in %1 seconds").arg(remaining));
} else {
setResult(TimedDialog::TimedOut);
close();
bar->setFormat(tr("Timed out after %1 seconds").arg(bar->maximum()));
}
}
@ -93,6 +80,11 @@ int ConnectionWaiter::exec() {
return result;
}
void ConnectionWaiter::cancel() {
quit();
result = ConnectionWaiter::Canceled;
}
void ConnectionWaiter::quit() {
disconnect(USBMonitor::instance(), SIGNAL(deviceDiscovered(USBPortInfo)), this, SLOT(deviceEvent()));
disconnect(USBMonitor::instance(), SIGNAL(deviceRemoved(USBPortInfo)), this, SLOT(deviceEvent()));
@ -118,6 +110,14 @@ void ConnectionWaiter::deviceEvent()
}
}
int ConnectionWaiter::openDialog(const QString &title, const QString &labelText, int targetDeviceCount, int timeout, QWidget *parent, Qt::WindowFlags flags) {
TimedDialog dlg(title, labelText, timeout / 1000, parent, flags);
ConnectionWaiter waiter(targetDeviceCount, timeout, parent);
connect(&dlg, SIGNAL(canceled()), &waiter, SLOT(cancel()));
connect(&waiter, SIGNAL(timeChanged(int)), &dlg, SLOT(perform()));
return waiter.exec();
}
UploaderGadgetWidget::UploaderGadgetWidget(QWidget *parent) : QWidget(parent)
{
m_config = new Ui_UploaderWidget();
@ -770,14 +770,12 @@ void UploaderGadgetWidget::systemRescue()
// Check if boards are connected and, if yes, prompt user to disconnect them all
if (USBMonitor::instance()->availableDevices(0x20a0, -1, -1, -1).length() > 0) {
QString labelText = QString("<p align=\"left\">%1</p>").arg(tr("Please disconnect your OpenPilot board."));
TimedDialog progressDlg(tr("System Rescue"), labelText, BOARD_EVENT_TIMEOUT / 1000);
connect(USBMonitor::instance(), SIGNAL(deviceRemoved(USBPortInfo)), &progressDlg, SLOT(accept()));
switch(progressDlg.exec()) {
case TimedDialog::Rejected:
// user canceled dialog
int result = ConnectionWaiter::openDialog(tr("System Rescue"), labelText, 0, BOARD_EVENT_TIMEOUT, this);
switch(result) {
case ConnectionWaiter::Canceled:
m_config->rescueButton->setEnabled(true);
return;
case TimedDialog::TimedOut:
case ConnectionWaiter::TimedOut:
QMessageBox::warning(this, tr("System Rescue"), tr("Timed out while waiting for all boards to be disconnected!"));
m_config->rescueButton->setEnabled(true);
return;
@ -786,14 +784,12 @@ void UploaderGadgetWidget::systemRescue()
// Now prompt user to connect board
QString labelText = QString("<p align=\"left\">%1<br>%2</p>").arg(tr("Please connect your OpenPilot board.")).arg(tr("Board must be connected to the USB port!"));
TimedDialog progressDlg(tr("System Rescue"), labelText, BOARD_EVENT_TIMEOUT / 1000);
connect(USBMonitor::instance(), SIGNAL(deviceDiscovered(USBPortInfo)), &progressDlg, SLOT(accept()));
switch(progressDlg.exec()) {
case TimedDialog::Rejected:
// user canceled dialog
int result = ConnectionWaiter::openDialog(tr("System Rescue"), labelText, 1, BOARD_EVENT_TIMEOUT, this);
switch(result) {
case ConnectionWaiter::Canceled:
m_config->rescueButton->setEnabled(true);
return;
case TimedDialog::TimedOut:
case ConnectionWaiter::TimedOut:
QMessageBox::warning(this, tr("System Rescue"), tr("Timed out while waiting for a board to be connected!"));
m_config->rescueButton->setEnabled(true);
return;

View File

@ -62,18 +62,12 @@ using namespace uploader;
class FlightStatus;
// A dialog that will time out and close after a given delay
class TimedDialog: public QProgressDialog {
Q_OBJECT
public:
TimedDialog(const QString &title, const QString &labelText, int timeout, QWidget *parent = 0, Qt::WindowFlags flags = 0);
enum DialogCode { Rejected, Accepted, TimedOut };
public slots:
int exec();
private slots:
void perform();
@ -90,12 +84,15 @@ class ConnectionWaiter: public QObject {
public:
ConnectionWaiter(int targetDeviceCount, int timeout, QWidget *parent = 0);
enum DialogCode { Ok, TimedOut };
enum ResultCode { Ok, Canceled, TimedOut };
public slots:
int exec();
void cancel();
void quit();
static int openDialog(const QString &title, const QString &labelText, int targetDeviceCount, int timeout, QWidget *parent = 0, Qt::WindowFlags flags = 0);
signals:
void timeChanged(int elapsed);
@ -106,7 +103,7 @@ private slots:
private:
QEventLoop eventLoop;
QTimer timer;
// timeour in ms
// timeout in ms
int timeout;
// elapsed time in seconds
int elapsed;