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:
parent
9573e141aa
commit
f4f3f74948
@ -31,6 +31,7 @@
|
|||||||
#include <coreplugin/coreconstants.h>
|
#include <coreplugin/coreconstants.h>
|
||||||
#include <uavtalk/telemetrymanager.h>
|
#include <uavtalk/telemetrymanager.h>
|
||||||
|
|
||||||
|
#include <QProgressBar>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#define DFU_DEBUG true
|
#define DFU_DEBUG true
|
||||||
@ -51,19 +52,6 @@ TimedDialog::TimedDialog(const QString &title, const QString &labelText, int tim
|
|||||||
setBar(bar);
|
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()
|
void TimedDialog::perform()
|
||||||
{
|
{
|
||||||
setValue(value() + 1);
|
setValue(value() + 1);
|
||||||
@ -71,8 +59,7 @@ void TimedDialog::perform()
|
|||||||
if (remaining > 0) {
|
if (remaining > 0) {
|
||||||
bar->setFormat(tr("Timing out in %1 seconds").arg(remaining));
|
bar->setFormat(tr("Timing out in %1 seconds").arg(remaining));
|
||||||
} else {
|
} else {
|
||||||
setResult(TimedDialog::TimedOut);
|
bar->setFormat(tr("Timed out after %1 seconds").arg(bar->maximum()));
|
||||||
close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,6 +80,11 @@ int ConnectionWaiter::exec() {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConnectionWaiter::cancel() {
|
||||||
|
quit();
|
||||||
|
result = ConnectionWaiter::Canceled;
|
||||||
|
}
|
||||||
|
|
||||||
void ConnectionWaiter::quit() {
|
void ConnectionWaiter::quit() {
|
||||||
disconnect(USBMonitor::instance(), SIGNAL(deviceDiscovered(USBPortInfo)), this, SLOT(deviceEvent()));
|
disconnect(USBMonitor::instance(), SIGNAL(deviceDiscovered(USBPortInfo)), this, SLOT(deviceEvent()));
|
||||||
disconnect(USBMonitor::instance(), SIGNAL(deviceRemoved(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)
|
UploaderGadgetWidget::UploaderGadgetWidget(QWidget *parent) : QWidget(parent)
|
||||||
{
|
{
|
||||||
m_config = new Ui_UploaderWidget();
|
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
|
// Check if boards are connected and, if yes, prompt user to disconnect them all
|
||||||
if (USBMonitor::instance()->availableDevices(0x20a0, -1, -1, -1).length() > 0) {
|
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."));
|
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);
|
int result = ConnectionWaiter::openDialog(tr("System Rescue"), labelText, 0, BOARD_EVENT_TIMEOUT, this);
|
||||||
connect(USBMonitor::instance(), SIGNAL(deviceRemoved(USBPortInfo)), &progressDlg, SLOT(accept()));
|
switch(result) {
|
||||||
switch(progressDlg.exec()) {
|
case ConnectionWaiter::Canceled:
|
||||||
case TimedDialog::Rejected:
|
|
||||||
// user canceled dialog
|
|
||||||
m_config->rescueButton->setEnabled(true);
|
m_config->rescueButton->setEnabled(true);
|
||||||
return;
|
return;
|
||||||
case TimedDialog::TimedOut:
|
case ConnectionWaiter::TimedOut:
|
||||||
QMessageBox::warning(this, tr("System Rescue"), tr("Timed out while waiting for all boards to be disconnected!"));
|
QMessageBox::warning(this, tr("System Rescue"), tr("Timed out while waiting for all boards to be disconnected!"));
|
||||||
m_config->rescueButton->setEnabled(true);
|
m_config->rescueButton->setEnabled(true);
|
||||||
return;
|
return;
|
||||||
@ -786,14 +784,12 @@ void UploaderGadgetWidget::systemRescue()
|
|||||||
|
|
||||||
// Now prompt user to connect board
|
// 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!"));
|
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);
|
int result = ConnectionWaiter::openDialog(tr("System Rescue"), labelText, 1, BOARD_EVENT_TIMEOUT, this);
|
||||||
connect(USBMonitor::instance(), SIGNAL(deviceDiscovered(USBPortInfo)), &progressDlg, SLOT(accept()));
|
switch(result) {
|
||||||
switch(progressDlg.exec()) {
|
case ConnectionWaiter::Canceled:
|
||||||
case TimedDialog::Rejected:
|
|
||||||
// user canceled dialog
|
|
||||||
m_config->rescueButton->setEnabled(true);
|
m_config->rescueButton->setEnabled(true);
|
||||||
return;
|
return;
|
||||||
case TimedDialog::TimedOut:
|
case ConnectionWaiter::TimedOut:
|
||||||
QMessageBox::warning(this, tr("System Rescue"), tr("Timed out while waiting for a board to be connected!"));
|
QMessageBox::warning(this, tr("System Rescue"), tr("Timed out while waiting for a board to be connected!"));
|
||||||
m_config->rescueButton->setEnabled(true);
|
m_config->rescueButton->setEnabled(true);
|
||||||
return;
|
return;
|
||||||
|
@ -62,18 +62,12 @@ using namespace uploader;
|
|||||||
|
|
||||||
class FlightStatus;
|
class FlightStatus;
|
||||||
|
|
||||||
// A dialog that will time out and close after a given delay
|
|
||||||
class TimedDialog: public QProgressDialog {
|
class TimedDialog: public QProgressDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TimedDialog(const QString &title, const QString &labelText, int timeout, QWidget *parent = 0, Qt::WindowFlags flags = 0);
|
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:
|
private slots:
|
||||||
void perform();
|
void perform();
|
||||||
|
|
||||||
@ -90,12 +84,15 @@ class ConnectionWaiter: public QObject {
|
|||||||
public:
|
public:
|
||||||
ConnectionWaiter(int targetDeviceCount, int timeout, QWidget *parent = 0);
|
ConnectionWaiter(int targetDeviceCount, int timeout, QWidget *parent = 0);
|
||||||
|
|
||||||
enum DialogCode { Ok, TimedOut };
|
enum ResultCode { Ok, Canceled, TimedOut };
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
int exec();
|
int exec();
|
||||||
|
void cancel();
|
||||||
void quit();
|
void quit();
|
||||||
|
|
||||||
|
static int openDialog(const QString &title, const QString &labelText, int targetDeviceCount, int timeout, QWidget *parent = 0, Qt::WindowFlags flags = 0);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void timeChanged(int elapsed);
|
void timeChanged(int elapsed);
|
||||||
|
|
||||||
@ -106,7 +103,7 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
QEventLoop eventLoop;
|
QEventLoop eventLoop;
|
||||||
QTimer timer;
|
QTimer timer;
|
||||||
// timeour in ms
|
// timeout in ms
|
||||||
int timeout;
|
int timeout;
|
||||||
// elapsed time in seconds
|
// elapsed time in seconds
|
||||||
int elapsed;
|
int elapsed;
|
||||||
|
Loading…
Reference in New Issue
Block a user