From 8bed1e02ce7e5979d1fcf56167e65b6fc1548a4d Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Sat, 15 Feb 2014 14:34:05 +0100 Subject: [PATCH 1/3] OP-1230 Automatically load the firmware in build/fw_ in development environment --- .../src/plugins/uploader/devicewidget.cpp | 42 ++++++++++++------- .../src/plugins/uploader/devicewidget.h | 2 + .../src/plugins/uploader/devicewidget.ui | 22 ++++++++++ 3 files changed, 52 insertions(+), 14 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/uploader/devicewidget.cpp b/ground/openpilotgcs/src/plugins/uploader/devicewidget.cpp index 9afbe5bdb..68e842443 100644 --- a/ground/openpilotgcs/src/plugins/uploader/devicewidget.cpp +++ b/ground/openpilotgcs/src/plugins/uploader/devicewidget.cpp @@ -134,6 +134,11 @@ void DeviceWidget::populate() } status("Ready...", STATUSICON_INFO); + QString fwFileName = getDevFirmwarePath(); + QFile fwFile(fwFileName); + if(fwFile.exists()){ + loadFirmware(fwFileName); + } } /** @@ -253,11 +258,17 @@ void DeviceWidget::status(QString str, StatusIcon ic) } void DeviceWidget::loadFirmware() +{ + QString file = setOpenFileName(); + loadFirmware(file); +} + +void DeviceWidget::loadFirmware(QString fwfilename) { myDevice->verticalGroupBox_loaded->setVisible(false); myDevice->groupCustom->setVisible(false); - filename = setOpenFileName(); + filename = fwfilename; myDevice->confirmCheckBox->setVisible(false); myDevice->confirmCheckBox->setChecked(false); @@ -312,6 +323,7 @@ void DeviceWidget::loadFirmware() myDevice->verticalGroupBox_loaded->setVisible(false); myDevice->groupCustom->setVisible(true); } + myDevice->filenameLabel->setText(tr("Firmware loaded: ") + filename); myDevice->statusIcon->setPixmap(px); } @@ -508,17 +520,10 @@ void DeviceWidget::setProgress(int percent) myDevice->progressBar->setValue(percent); } -/** - * Opens an open file dialog. - */ -QString DeviceWidget::setOpenFileName() +QString DeviceWidget::getDevFirmwarePath() { - QFileDialog::Options options; - QString selectedFilter; - QString fwDirectoryStr; QDir fwDirectory; - - // Format filename for file chooser + QString fwDirectoryStr; #ifdef Q_OS_WIN fwDirectoryStr = QCoreApplication::applicationDirPath(); fwDirectory = QDir(fwDirectoryStr); @@ -528,7 +533,7 @@ QString DeviceWidget::setOpenFileName() #elif defined Q_OS_LINUX fwDirectoryStr = QCoreApplication::applicationDirPath(); fwDirectory = QDir(fwDirectoryStr); - fwDirectory.cd("../../.."); + fwDirectory.cd("../.."); fwDirectoryStr = fwDirectory.absolutePath(); fwDirectoryStr = fwDirectoryStr + "/fw_" + myDevice->lblBrdName->text().toLower() + "/fw_" + myDevice->lblBrdName->text().toLower() + ".opfw"; #elif defined Q_OS_MAC @@ -538,12 +543,21 @@ QString DeviceWidget::setOpenFileName() fwDirectoryStr = fwDirectory.absolutePath(); fwDirectoryStr = fwDirectoryStr + "/fw_" + myDevice->lblBrdName->text().toLower() + "/fw_" + myDevice->lblBrdName->text().toLower() + ".opfw"; #endif + return fwDirectoryStr; +} + +/** + * Opens an open file dialog. + */ +QString DeviceWidget::setOpenFileName() +{ + QString fwDirectoryStr = getDevFirmwarePath(); + + // Format filename for file chooser QString fileName = QFileDialog::getOpenFileName(this, tr("Select firmware file"), fwDirectoryStr, - tr("Firmware Files (*.opfw *.bin)"), - &selectedFilter, - options); + tr("Firmware Files (*.opfw *.bin)")); return fileName; } diff --git a/ground/openpilotgcs/src/plugins/uploader/devicewidget.h b/ground/openpilotgcs/src/plugins/uploader/devicewidget.h index 489b81168..57099c4f0 100644 --- a/ground/openpilotgcs/src/plugins/uploader/devicewidget.h +++ b/ground/openpilotgcs/src/plugins/uploader/devicewidget.h @@ -72,6 +72,7 @@ private: bool populateBoardStructuredDescription(QByteArray arr); bool populateLoadedStructuredDescription(QByteArray arr); void updateButtons(bool enabled); + QString getDevFirmwarePath(); signals: void uploadStarted(); @@ -82,6 +83,7 @@ signals: public slots: void uploadFirmware(); void loadFirmware(); + void loadFirmware(QString fwfilename); void downloadFirmware(); void setProgress(int); void downloadFinished(); diff --git a/ground/openpilotgcs/src/plugins/uploader/devicewidget.ui b/ground/openpilotgcs/src/plugins/uploader/devicewidget.ui index cc1aec074..9fc02363f 100644 --- a/ground/openpilotgcs/src/plugins/uploader/devicewidget.ui +++ b/ground/openpilotgcs/src/plugins/uploader/devicewidget.ui @@ -190,6 +190,28 @@ + + + + + 0 + 0 + + + + + 75 + true + + + + filename + + + false + + + From 15b1fe88cb0119bd0958ef22da0792ab2cf441d4 Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Sat, 15 Feb 2014 14:49:14 +0100 Subject: [PATCH 2/3] OP-1230 Fix filename with empty label --- ground/openpilotgcs/src/plugins/uploader/devicewidget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ground/openpilotgcs/src/plugins/uploader/devicewidget.cpp b/ground/openpilotgcs/src/plugins/uploader/devicewidget.cpp index 68e842443..b0f6a4994 100644 --- a/ground/openpilotgcs/src/plugins/uploader/devicewidget.cpp +++ b/ground/openpilotgcs/src/plugins/uploader/devicewidget.cpp @@ -132,7 +132,7 @@ void DeviceWidget::populate() myDevice->lblGitTag->setText(tr("Unknown")); myDevice->lblBrdName->setText(tr("Unknown")); } - + myDevice->filenameLabel->setText(tr("No file loaded")); status("Ready...", STATUSICON_INFO); QString fwFileName = getDevFirmwarePath(); QFile fwFile(fwFileName); From b98fce7980d89f14e044f2affa8a125bf43ebd76 Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Sun, 9 Mar 2014 15:07:11 +0100 Subject: [PATCH 3/3] OP-1230 fix paths for Windows as suggested by Filnet --- .../src/plugins/uploader/devicewidget.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/uploader/devicewidget.cpp b/ground/openpilotgcs/src/plugins/uploader/devicewidget.cpp index b0f6a4994..1566ceb1f 100644 --- a/ground/openpilotgcs/src/plugins/uploader/devicewidget.cpp +++ b/ground/openpilotgcs/src/plugins/uploader/devicewidget.cpp @@ -524,25 +524,19 @@ QString DeviceWidget::getDevFirmwarePath() { QDir fwDirectory; QString fwDirectoryStr; + fwDirectoryStr = QCoreApplication::applicationDirPath(); + fwDirectory = QDir(fwDirectoryStr); #ifdef Q_OS_WIN - fwDirectoryStr = QCoreApplication::applicationDirPath(); - fwDirectory = QDir(fwDirectoryStr); - fwDirectory.cdUp(); - fwDirectory.cd("firmware"); - fwDirectoryStr = fwDirectory.absolutePath(); -#elif defined Q_OS_LINUX - fwDirectoryStr = QCoreApplication::applicationDirPath(); - fwDirectory = QDir(fwDirectoryStr); fwDirectory.cd("../.."); fwDirectoryStr = fwDirectory.absolutePath(); - fwDirectoryStr = fwDirectoryStr + "/fw_" + myDevice->lblBrdName->text().toLower() + "/fw_" + myDevice->lblBrdName->text().toLower() + ".opfw"; +#elif defined Q_OS_LINUX + fwDirectory.cd("../.."); + fwDirectoryStr = fwDirectory.absolutePath(); #elif defined Q_OS_MAC - fwDirectoryStr = QCoreApplication::applicationDirPath(); - fwDirectory = QDir(fwDirectoryStr); fwDirectory.cd("../../../../../.."); fwDirectoryStr = fwDirectory.absolutePath(); - fwDirectoryStr = fwDirectoryStr + "/fw_" + myDevice->lblBrdName->text().toLower() + "/fw_" + myDevice->lblBrdName->text().toLower() + ".opfw"; #endif + fwDirectoryStr = fwDirectoryStr + "/fw_" + myDevice->lblBrdName->text().toLower() + "/fw_" + myDevice->lblBrdName->text().toLower() + ".opfw"; return fwDirectoryStr; }