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

Merge remote-tracking branch 'remotes/origin/PT-bugfix-ground' into bugfix-ground

This commit is contained in:
zedamota 2011-05-29 10:57:57 +01:00
commit d591d509ed
2 changed files with 128 additions and 104 deletions

View File

@ -33,7 +33,6 @@ UploaderGadgetWidget::UploaderGadgetWidget(QWidget *parent) : QWidget(parent)
m_config = new Ui_UploaderWidget(); m_config = new Ui_UploaderWidget();
m_config->setupUi(this); m_config->setupUi(this);
currentStep = IAP_STATE_READY; currentStep = IAP_STATE_READY;
rescueStep = RESCUE_STEP0;
resetOnly=false; resetOnly=false;
dfu = NULL; dfu = NULL;
@ -393,89 +392,93 @@ void UploaderGadgetWidget::systemBoot()
void UploaderGadgetWidget::systemRescue() void UploaderGadgetWidget::systemRescue()
{ {
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager(); Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
switch (rescueStep) { cm->disconnectDevice();
case RESCUE_STEP0: { // stop the polling thread: otherwise it will mess up DFU
cm->disconnectDevice(); cm->suspendPolling();
// stop the polling thread: otherwise it will mess up DFU // Delete all previous tabs:
cm->suspendPolling(); while (m_config->systemElements->count()) {
// Delete all previous tabs: QWidget *qw = m_config->systemElements->widget(0);
while (m_config->systemElements->count()) { m_config->systemElements->removeTab(0);
QWidget *qw = m_config->systemElements->widget(0); delete qw;
m_config->systemElements->removeTab(0);
delete qw;
}
// Existing DFU objects will have a handle over USB and will
// disturb everything for the rescue process:
if (dfu) {
delete dfu;
dfu = NULL;
}
// Avoid dumb users pressing Rescue twice. It can happen.
m_config->rescueButton->setEnabled(false);
// Now we're good to go:
clearLog();
log("**********************************************************");
log("** Follow those instructions to attempt a system rescue **");
log("**********************************************************");
log("You will be prompted to first connect USB, then system power");
log ("Connect USB in 2 seconds...");
rescueStep = RESCUE_STEP1;
QTimer::singleShot(1000, this, SLOT(systemRescue()));
} }
break; // Existing DFU objects will have a handle over USB and will
case RESCUE_STEP1: // disturb everything for the rescue process:
rescueStep = RESCUE_STEP2; if (dfu) {
log (" ...1..."); delete dfu;
QTimer::singleShot(1000, this, SLOT(systemRescue())); dfu = NULL;
break; }
case RESCUE_STEP2: // Avoid dumb users pressing Rescue twice. It can happen.
rescueStep = RESCUE_STEP3; m_config->rescueButton->setEnabled(false);
log(" ...Now!");
QTimer::singleShot(1000, this, SLOT(systemRescue())); // Now we're good to go:
break; clearLog();
case RESCUE_STEP3: log("**********************************************************");
log("... Detecting First Board..."); log("** Follow those instructions to attempt a system rescue **");
repaint(); log("**********************************************************");
dfu = new DFUObject(DFU_DEBUG, false, QString()); log("You will be prompted to first connect USB, then system power");
dfu->AbortOperation(); if(USBMonitor::instance()->availableDevices(0x20a0,-1,-1,-1).length()>0)
if(!dfu->enterDFU(0)) {
if(QMessageBox::warning(this,tr("OpenPilot Uploader"),tr("Please disconnect all openpilot boards"),QMessageBox::Ok,QMessageBox::Cancel)==QMessageBox::Cancel)
{ {
rescueStep = RESCUE_STEP0;
log("Could not enter DFU mode.");
delete dfu;
dfu = NULL;
cm->resumePolling();
m_config->rescueButton->setEnabled(true); m_config->rescueButton->setEnabled(true);
return; return;
} }
if(!dfu->findDevices() || (dfu->numberOfDevices != 1)) }
{ // Now we're good to go:
rescueStep = RESCUE_STEP0; clearLog();
log("Could not detect a board, aborting!"); log("**********************************************************");
delete dfu; log("** Follow those instructions to attempt a system rescue **");
dfu = NULL; log("**********************************************************");
cm->resumePolling(); log("You will be prompted to first connect USB, then system power");
m_config->rescueButton->setEnabled(true); pd = new QProgressDialog(tr("Please connect the board (USB only!)"), tr("Cancel"), 0, 20);
return; QProgressBar * bar=new QProgressBar(pd);
} bar->setFormat("Timeout");
rescueStep = RESCUE_POWER1; pd->setBar(bar);
log("Connect Power in 2 second..."); pd->setMinimumDuration(0);
log("(not required on CopterControl)"); pd->setRange(0,20);
QTimer::singleShot(1000, this, SLOT(systemRescue())); connect(pd, SIGNAL(canceled()), this, SLOT(cancel()));
break; t = new QTimer(this);
case RESCUE_POWER1: connect(t, SIGNAL(timeout()), this, SLOT(perform()));
rescueStep = RESCUE_POWER2; t->start(1000);
log(" ...1..."); connect(USBMonitor::instance(), SIGNAL(deviceDiscovered(USBPortInfo)),&q, SLOT(quit()));
QTimer::singleShot(1000, this, SLOT(systemRescue())); q.exec();
break; if(!t->isActive())
case RESCUE_POWER2: {
log("... NOW!\n***\nWaiting..."); pd->close();
rescueStep = RESCUE_DETECT; t->stop();
QTimer::singleShot(5000, this, SLOT(systemRescue())); QMessageBox::warning(this,tr("Openpilot Uploader"),tr("No board connection was detected!"));
break; m_config->rescueButton->setEnabled(true);
case RESCUE_DETECT: return;
rescueStep = RESCUE_STEP0; }
pd->close();
t->stop();
log("... Detecting First Board...");
repaint();
dfu = new DFUObject(DFU_DEBUG, false, QString());
dfu->AbortOperation();
if(!dfu->enterDFU(0))
{
log("Could not enter DFU mode.");
delete dfu;
dfu = NULL;
cm->resumePolling();
m_config->rescueButton->setEnabled(true);
return;
}
if(!dfu->findDevices() || (dfu->numberOfDevices != 1))
{
log("Could not detect a board, aborting!");
delete dfu;
dfu = NULL;
cm->resumePolling();
m_config->rescueButton->setEnabled(true);
return;
}
if(QMessageBox::question(this,tr("OpenPilot Uploader"),tr("If you want to search for other boards connect power now and press Yes"),QMessageBox::Yes,QMessageBox::No)==QMessageBox::Yes)
{
log("\nWaiting...");
QTimer::singleShot(3000, &q, SLOT(quit()));
q.exec();
log("Detecting second board..."); log("Detecting second board...");
repaint(); repaint();
if(!dfu->findDevices()) if(!dfu->findDevices())
@ -489,28 +492,42 @@ void UploaderGadgetWidget::systemRescue()
m_config->rescueButton->setEnabled(true); m_config->rescueButton->setEnabled(true);
return; return;
} }
log(QString("Found ") + QString::number(dfu->numberOfDevices) + QString(" device(s)."));
if (dfu->numberOfDevices > 5) {
log("Inconsistent number of devices, aborting!");
delete dfu;
dfu = NULL;
cm->resumePolling();
m_config->rescueButton->setEnabled(true);
return;
}
for(int i=0;i<dfu->numberOfDevices;i++) {
deviceWidget* dw = new deviceWidget(this);
dw->setDeviceID(i);
dw->setDfu(dfu);
dw->populate();
m_config->systemElements->addTab(dw, QString("Device") + QString::number(i));
}
m_config->haltButton->setEnabled(false);
m_config->resetButton->setEnabled(false);
m_config->bootButton->setEnabled(true);
m_config->rescueButton->setEnabled(false);
currentStep = IAP_STATE_BOOTLOADER; // So that we can boot from the GUI afterwards.
} }
log(QString("Found ") + QString::number(dfu->numberOfDevices) + QString(" device(s)."));
if (dfu->numberOfDevices > 5) {
log("Inconsistent number of devices, aborting!");
delete dfu;
dfu = NULL;
cm->resumePolling();
m_config->rescueButton->setEnabled(true);
return;
}
for(int i=0;i<dfu->numberOfDevices;i++) {
deviceWidget* dw = new deviceWidget(this);
dw->setDeviceID(i);
dw->setDfu(dfu);
dw->populate();
m_config->systemElements->addTab(dw, QString("Device") + QString::number(i));
}
m_config->haltButton->setEnabled(false);
m_config->resetButton->setEnabled(false);
m_config->bootButton->setEnabled(true);
m_config->rescueButton->setEnabled(false);
currentStep = IAP_STATE_BOOTLOADER; // So that we can boot from the GUI afterwards.
}
void UploaderGadgetWidget::perform()
{
if(pd->value()==19)
{
t->stop();
q.exit();
}
pd->setValue(pd->value()+1);
}
void UploaderGadgetWidget::cancel()
{
t->stop();
q.exit();
} }
/** /**
@ -538,6 +555,11 @@ UploaderGadgetWidget::~UploaderGadgetWidget()
m_config->systemElements->removeTab(0); m_config->systemElements->removeTab(0);
delete qw; delete qw;
} }
if (pd)
delete pd;
if (t)
delete t;
} }

View File

@ -53,6 +53,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <QTimer> #include <QTimer>
#include <QProgressDialog>
using namespace OP_DFU; using namespace OP_DFU;
@ -64,7 +65,6 @@ public:
UploaderGadgetWidget(QWidget *parent = 0); UploaderGadgetWidget(QWidget *parent = 0);
~UploaderGadgetWidget(); ~UploaderGadgetWidget();
typedef enum { IAP_STATE_READY, IAP_STATE_STEP_1, IAP_STATE_STEP_2, IAP_STEP_RESET, IAP_STATE_BOOTLOADER} IAPStep; typedef enum { IAP_STATE_READY, IAP_STATE_STEP_1, IAP_STATE_STEP_2, IAP_STEP_RESET, IAP_STATE_BOOTLOADER} IAPStep;
typedef enum { RESCUE_STEP0, RESCUE_STEP1, RESCUE_STEP2, RESCUE_STEP3, RESCUE_POWER1, RESCUE_POWER2, RESCUE_DETECT } RescueStep;
void log(QString str); void log(QString str);
public slots: public slots:
@ -75,13 +75,13 @@ private:
Ui_UploaderWidget *m_config; Ui_UploaderWidget *m_config;
DFUObject *dfu; DFUObject *dfu;
IAPStep currentStep; IAPStep currentStep;
RescueStep rescueStep;
bool resetOnly; bool resetOnly;
void clearLog(); void clearLog();
QString getPortDevice(const QString &friendName); QString getPortDevice(const QString &friendName);
QProgressDialog* pd;
QTimer* t;
QLineEdit* openFileNameLE; QLineEdit* openFileNameLE;
QEventLoop q;
private slots: private slots:
void error(QString errorString,int errorNumber); void error(QString errorString,int errorNumber);
void info(QString infoString,int infoNumber); void info(QString infoString,int infoNumber);
@ -90,6 +90,8 @@ private slots:
void systemBoot(); void systemBoot();
void systemRescue(); void systemRescue();
void getSerialPorts(); void getSerialPorts();
void perform();
void cancel();
}; };