1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-17 02:52:12 +01:00

OP-682 OP-850 fixed more uploader gadget crashes and button state issues

This commit is contained in:
Philippe Renon 2013-02-21 01:34:17 +01:00
parent e8659cf9d5
commit 4350e48bfc
4 changed files with 113 additions and 41 deletions

View File

@ -143,11 +143,28 @@ void deviceWidget::populate()
*/
void deviceWidget::freeze()
{
myDevice->description->setEnabled(false);
myDevice->pbLoad->setEnabled(false);
myDevice->youdont->setEnabled(false);
myDevice->updateButton->setEnabled(false);
myDevice->retrieveButton->setEnabled(false);
updateButtons(false);
}
void deviceWidget::updateButtons(bool enabled)
{
if (!enabled) {
myDevice->description->setEnabled(false);
myDevice->pbLoad->setEnabled(false);
myDevice->youdont->setEnabled(false);
myDevice->updateButton->setEnabled(false);
myDevice->retrieveButton->setEnabled(false);
}
else {
myDevice->description->setEnabled(true);
// Load button (i.e. chose file) is always enabled
myDevice->pbLoad->setEnabled(true);
myDevice->youdont->setEnabled(true);
// Update/Upload button is enabled if a file has be selected and the "You know what your doing" check box is checked
myDevice->updateButton->setEnabled(myDevice->youdont->isVisible() && myDevice->youdont->checkState() == Qt::Checked);
// Retreive/Download button is always enabled
myDevice->retrieveButton->setEnabled(true);
}
}
/**
@ -224,12 +241,7 @@ void deviceWidget::dfuStatus(QString str)
void deviceWidget::confirmCB(int value)
{
if(value==Qt::Checked)
{
myDevice->updateButton->setEnabled(true);
}
else
myDevice->updateButton->setEnabled(false);
updateButtons(true);
}
/**
@ -325,8 +337,6 @@ void deviceWidget::loadFirmware()
myDevice->groupCustom->setVisible(true);
}
myDevice->statusIcon->setPixmap(px);
//myDevice->updateButton->setEnabled(true);
}
/**
@ -334,10 +344,14 @@ void deviceWidget::loadFirmware()
*/
void deviceWidget::uploadFirmware()
{
myDevice->updateButton->setEnabled(false);
// clear progress bar now
// this avoids displaying an error message and the progress at 100% at the same time
setProgress(0);
updateButtons(false);
if (!m_dfu->devices[deviceID].Writable) {
status("Device not writable!", STATUSICON_FAIL);
myDevice->updateButton->setEnabled(true);
updateButtons(true);
return;
}
@ -361,7 +375,7 @@ void deviceWidget::uploadFirmware()
// These firmwares are designed to be backwards compatible
} else if (firmwareBoard != board) {
status("Error: firmware does not match board", STATUSICON_FAIL);
myDevice->updateButton->setEnabled(true);
updateButtons(true);
return;
}
// Check the firmware embedded in the file:
@ -369,7 +383,7 @@ void deviceWidget::uploadFirmware()
QByteArray fileHash = QCryptographicHash::hash(loadedFW.left(loadedFW.length()-100), QCryptographicHash::Sha1);
if (firmwareHash != fileHash) {
status("Error: firmware file corrupt", STATUSICON_FAIL);
myDevice->updateButton->setEnabled(true);
updateButtons(true);
return;
}
} else {
@ -378,16 +392,16 @@ void deviceWidget::uploadFirmware()
descriptionArray.clear();
}
status("Starting firmware upload", STATUSICON_RUNNING);
emit uploadStarted();
// We don't know which device was used previously, so we
// are cautious and reenter DFU for this deviceID:
emit uploadStarted();
if(!m_dfu->enterDFU(deviceID))
{
status("Error:Could not enter DFU mode", STATUSICON_FAIL);
myDevice->updateButton->setEnabled(true);
emit uploadEnded(false);
status("Error:Could not enter DFU mode", STATUSICON_FAIL);
updateButtons(true);
return;
}
OP_DFU::Status ret=m_dfu->StatusRequest();
@ -397,13 +411,14 @@ void deviceWidget::uploadFirmware()
connect(m_dfu, SIGNAL(progressUpdated(int)), this, SLOT(setProgress(int)));
connect(m_dfu, SIGNAL(operationProgress(QString)), this, SLOT(dfuStatus(QString)));
connect(m_dfu, SIGNAL(uploadFinished(OP_DFU::Status)), this, SLOT(uploadFinished(OP_DFU::Status)));
bool retstatus = m_dfu->UploadFirmware(filename,verify, deviceID);
if(!retstatus ) {
status("Could not start upload", STATUSICON_FAIL);
myDevice->updateButton->setEnabled(true);
bool retstatus = m_dfu->UploadFirmware(filename, verify, deviceID);
if (!retstatus) {
emit uploadEnded(false);
status("Could not start upload!", STATUSICON_FAIL);
updateButtons(true);
return;
}
status("Uploading, please wait...", STATUSICON_RUNNING);
}
@ -412,29 +427,43 @@ void deviceWidget::uploadFirmware()
*/
void deviceWidget::downloadFirmware()
{
// clear progress bar now
// this avoids displaying an error message and the progress at 100% at the same time
setProgress(0);
updateButtons(false);
if (!m_dfu->devices[deviceID].Readable) {
myDevice->statusLabel->setText(QString("Device not readable!"));
status("Device not readable!", STATUSICON_FAIL);
updateButtons(true);
return;
}
myDevice->retrieveButton->setEnabled(false);
filename = setSaveFileName();
if (filename.isEmpty()) {
status("Empty filename", STATUSICON_FAIL);
updateButtons(true);
return;
}
status("Downloading firmware from device", STATUSICON_RUNNING);
status("Starting firmware download", STATUSICON_RUNNING);
emit downloadStarted();
connect(m_dfu, SIGNAL(progressUpdated(int)), this, SLOT(setProgress(int)));
connect(m_dfu, SIGNAL(downloadFinished()), this, SLOT(downloadFinished()));
downloadedFirmware.clear(); // Empty the byte array
bool ret = m_dfu->DownloadFirmware(&downloadedFirmware,deviceID);
if(!ret) {
if (!ret) {
emit downloadEnded(false);
status("Could not start download!", STATUSICON_FAIL);
updateButtons(true);
return;
}
status("Download started, please wait", STATUSICON_RUNNING);
status("Downloading, please wait...", STATUSICON_RUNNING);
return;
}
/**
@ -444,10 +473,13 @@ void deviceWidget::downloadFinished()
{
disconnect(m_dfu, SIGNAL(downloadFinished()), this, SLOT(downloadFinished()));
disconnect(m_dfu, SIGNAL(progressUpdated(int)), this, SLOT(setProgress(int)));
status("Download successful", STATUSICON_OK);
// Now save the result (use the utility function from OP_DFU)
m_dfu->SaveByteArrayToFile(filename, downloadedFirmware);
myDevice->retrieveButton->setEnabled(true);
emit downloadEnded(true);
status("Download successful", STATUSICON_OK);
updateButtons(true);
}
/**
@ -455,13 +487,14 @@ void deviceWidget::downloadFinished()
*/
void deviceWidget::uploadFinished(OP_DFU::Status retstatus)
{
myDevice->updateButton->setEnabled(true);
disconnect(m_dfu, SIGNAL(uploadFinished(OP_DFU::Status)), this, SLOT(uploadFinished(OP_DFU::Status)));
disconnect(m_dfu, SIGNAL(progressUpdated(int)), this, SLOT(setProgress(int)));
disconnect(m_dfu, SIGNAL(operationProgress(QString)), this, SLOT(dfuStatus(QString)));
if(retstatus != OP_DFU::Last_operation_Success) {
status(QString("Upload failed with code: ") + m_dfu->StatusToString(retstatus).toLatin1().data(), STATUSICON_FAIL);
if (retstatus != OP_DFU::Last_operation_Success) {
emit uploadEnded(false);
status(QString("Upload failed with code: ") + m_dfu->StatusToString(retstatus).toLatin1().data(), STATUSICON_FAIL);
updateButtons(true);
return;
} else
if (!descriptionArray.isEmpty()) {
@ -469,9 +502,10 @@ void deviceWidget::uploadFinished(OP_DFU::Status retstatus)
status(QString("Updating description"), STATUSICON_RUNNING);
repaint(); // Make sure the text above shows right away
retstatus = m_dfu->UploadDescription(descriptionArray);
if( retstatus != OP_DFU::Last_operation_Success) {
status(QString("Upload failed with code: ") + m_dfu->StatusToString(retstatus).toLatin1().data(), STATUSICON_FAIL);
if (retstatus != OP_DFU::Last_operation_Success) {
emit uploadEnded(false);
status(QString("Upload failed with code: ") + m_dfu->StatusToString(retstatus).toLatin1().data(), STATUSICON_FAIL);
updateButtons(true);
return;
}
@ -480,16 +514,19 @@ void deviceWidget::uploadFinished(OP_DFU::Status retstatus)
status(QString("Updating description"), STATUSICON_RUNNING);
repaint(); // Make sure the text above shows right away
retstatus = m_dfu->UploadDescription(myDevice->description->text());
if( retstatus != OP_DFU::Last_operation_Success) {
status(QString("Upload failed with code: ") + m_dfu->StatusToString(retstatus).toLatin1().data(), STATUSICON_FAIL);
if (retstatus != OP_DFU::Last_operation_Success) {
emit uploadEnded(false);
status(QString("Upload failed with code: ") + m_dfu->StatusToString(retstatus).toLatin1().data(), STATUSICON_FAIL);
updateButtons(true);
return;
}
}
populate();
emit uploadEnded(true);
status("Upload successful", STATUSICON_OK);
updateButtons(true);
}
/**

View File

@ -71,10 +71,13 @@ private:
void status(QString str, StatusIcon ic);
bool populateBoardStructuredDescription(QByteArray arr);
bool populateLoadedStructuredDescription(QByteArray arr);
void updateButtons(bool enabled);
signals:
void uploadStarted();
void uploadEnded(bool success);
void downloadStarted();
void downloadEnded(bool success);
public slots:
void uploadFirmware();
void loadFirmware();

View File

@ -120,6 +120,8 @@ void UploaderGadgetWidget::connectSignalSlot(QWidget *widget)
{
connect(qobject_cast<deviceWidget *>(widget),SIGNAL(uploadStarted()),this,SLOT(uploadStarted()));
connect(qobject_cast<deviceWidget *>(widget),SIGNAL(uploadEnded(bool)),this,SLOT(uploadEnded(bool)));
connect(qobject_cast<deviceWidget *>(widget),SIGNAL(downloadStarted()),this,SLOT(downloadStarted()));
connect(qobject_cast<deviceWidget *>(widget),SIGNAL(downloadEnded(bool)),this,SLOT(downloadEnded(bool)));
}
FlightStatus *UploaderGadgetWidget::getFlightStatus()
@ -758,15 +760,44 @@ void UploaderGadgetWidget::cancel()
void UploaderGadgetWidget::uploadStarted()
{
m_config->haltButton->setEnabled(false);
m_config->bootButton->setEnabled(false);
m_config->safeBootButton->setEnabled(false);
m_config->resetButton->setEnabled(false);
m_config->rescueButton->setEnabled(false);
}
void UploaderGadgetWidget::uploadEnded(bool succeed)
{
Q_UNUSED(succeed);
// device is halted so no halt
m_config->haltButton->setEnabled(false);
m_config->bootButton->setEnabled(true);
m_config->safeBootButton->setEnabled(true);
// device is halted so no reset
m_config->resetButton->setEnabled(false);
m_config->rescueButton->setEnabled(true);
}
void UploaderGadgetWidget::downloadStarted()
{
m_config->haltButton->setEnabled(false);
m_config->bootButton->setEnabled(false);
m_config->safeBootButton->setEnabled(false);
m_config->resetButton->setEnabled(false);
m_config->rescueButton->setEnabled(false);
}
void UploaderGadgetWidget::downloadEnded(bool succeed)
{
Q_UNUSED(succeed);
// device is halted so no halt
m_config->haltButton->setEnabled(false);
m_config->bootButton->setEnabled(true);
m_config->safeBootButton->setEnabled(true);
// device is halted so no reset
m_config->resetButton->setEnabled(false);
m_config->rescueButton->setEnabled(true);
}
/**

View File

@ -115,7 +115,8 @@ private slots:
void cancel();
void uploadStarted();
void uploadEnded(bool succeed);
void downloadStarted();
void downloadEnded(bool succeed);
};
#endif // UPLOADERGADGETWIDGET_H