diff --git a/ground/openpilotgcs/src/plugins/setupwizard/pages/rebootpage.cpp b/ground/openpilotgcs/src/plugins/setupwizard/pages/rebootpage.cpp index e534eda0b..cf3091ab0 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/pages/rebootpage.cpp +++ b/ground/openpilotgcs/src/plugins/setupwizard/pages/rebootpage.cpp @@ -27,10 +27,6 @@ #include "rebootpage.h" #include "ui_rebootpage.h" -#include -#include -#include -#include "uploader/uploadergadgetfactory.h" RebootPage::RebootPage(SetupWizard *wizard, QWidget *parent) : AbstractWizardPage(wizard, parent), @@ -39,11 +35,11 @@ RebootPage::RebootPage(SetupWizard *wizard, QWidget *parent) : ui->setupUi(this); ui->yellowLabel->setVisible(false); ui->redLabel->setVisible(true); + connect(ui->rebootButton, SIGNAL(clicked()), this, SLOT(reboot())); ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); Q_ASSERT(pm); - UploaderGadgetFactory *uploader = pm->getObject(); - Q_ASSERT(uploader); - connect(ui->rebootButton, SIGNAL(clicked()), uploader, SIGNAL(reboot())); + m_uploader = pm->getObject(); + Q_ASSERT(m_uploader); } RebootPage::~RebootPage() @@ -55,6 +51,8 @@ RebootPage::~RebootPage() void RebootPage::initializePage() { + ui->messageLabel->setText(""); + ui->rebootProgress->setValue(0); if (!m_timer.isActive()) { connect(&m_timer, SIGNAL(timeout()), this, SLOT(toggleLabel())); m_timer.setInterval(500); @@ -74,3 +72,40 @@ void RebootPage::toggleLabel() ui->yellowLabel->setVisible(m_toggl); ui->redLabel->setVisible(!m_toggl); } + +void RebootPage::enableButtons(bool enable) +{ + getWizard()->button(QWizard::NextButton)->setEnabled(enable); + getWizard()->button(QWizard::CancelButton)->setEnabled(enable); + getWizard()->button(QWizard::BackButton)->setEnabled(enable); + getWizard()->button(QWizard::CustomButton1)->setEnabled(enable); + ui->rebootButton->setEnabled(enable); +} + +void RebootPage::reboot() +{ + enableButtons(false); + ui->rebootProgress->setValue(0); + QApplication::processEvents(); + connect(m_uploader, SIGNAL(progressUpdate(uploader::ProgressStep,QVariant)), this, SLOT(progressUpdate(uploader::ProgressStep,QVariant))); + ui->messageLabel->setText(tr("Reboot in progress...")); + m_uploader->reboot(); +} + +void RebootPage::progressUpdate(uploader::ProgressStep progress, QVariant message) +{ + Q_UNUSED(message); + if (progress == uploader::SUCCESS || progress == uploader::FAILURE) { + disconnect(m_uploader, SIGNAL(progressUpdate(uploader::ProgressStep,QVariant)), this, SLOT(progressUpdate(uploader::ProgressStep,QVariant))); + if (progress == uploader::FAILURE) { + ui->messageLabel->setText(tr("Software reboot failed!

Please perform a manual reboot by power cycling the board. " + "To power cycle the controller remove all batteries and the USB cable for at least 30 seconds. " + "After 30 seconds, plug in the board again and wait for it to connect, this can take a few seconds. Then press Next.")); + } else { + ui->messageLabel->setText(tr("Reboot complete!")); + } + enableButtons(true); + } else { + ui->rebootProgress->setValue(ui->rebootProgress->value() + 1); + } +} diff --git a/ground/openpilotgcs/src/plugins/setupwizard/pages/rebootpage.h b/ground/openpilotgcs/src/plugins/setupwizard/pages/rebootpage.h index 786a77253..75442368c 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/pages/rebootpage.h +++ b/ground/openpilotgcs/src/plugins/setupwizard/pages/rebootpage.h @@ -29,6 +29,9 @@ #define REBOOTPAGE_H #include "abstractwizardpage.h" +#include +#include +#include "uploader/uploadergadgetfactory.h" namespace Ui { class RebootPage; @@ -44,13 +47,17 @@ public: void initializePage(); bool validatePage(); + void enableButtons(bool enable); private: Ui::RebootPage *ui; QTimer m_timer; bool m_toggl; + UploaderGadgetFactory *m_uploader; private slots: void toggleLabel(); + void reboot(); + void progressUpdate(uploader::ProgressStep progress, QVariant message); }; #endif // REBOOTPAGE_H diff --git a/ground/openpilotgcs/src/plugins/setupwizard/pages/rebootpage.ui b/ground/openpilotgcs/src/plugins/setupwizard/pages/rebootpage.ui index 2c63f6928..2434c688c 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/pages/rebootpage.ui +++ b/ground/openpilotgcs/src/plugins/setupwizard/pages/rebootpage.ui @@ -49,15 +49,13 @@ p, li { white-space: pre-wrap; } - + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } </style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'MS Shell Dlg 2'; font-size:10pt; color:#000000;">The configuration created by the wizard contains settings that require a reboot of your controller. </span></p> -<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'MS Shell Dlg 2'; font-size:10pt; color:#000000;">There are two ways to reboot your board:</span></p> -<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'MS Shell Dlg 2'; font-size:10pt; font-weight:600; color:#000000;">1. Software Reboot</span><span style=" font-family:'MS Shell Dlg 2'; font-size:10pt; color:#000000;"><br />Press the button below to reboot board. Wait for the board to connect again before pressing Next. After board is connected press Next to continue wizard.<br /><br /></span><span style=" font-family:'MS Shell Dlg 2'; font-size:10pt; font-weight:600; color:#000000;">2. Power Cycle </span><span style=" font-family:'MS Shell Dlg 2'; font-size:10pt; color:#000000;"><br />To power cycle the controller remove all batteries and the USB cable for at least 30 seconds. After 30 seconds, plug in the board again and wait for it to connect, this can take a few seconds. Then press next.</span></p></body></html> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'MS Shell Dlg 2'; font-size:10pt; color:#000000;">The configuration created by the wizard contains settings that require a reboot of your controller. <br /><br />Press the button below to reboot board. Wait for the board to connect again and the Next button to be enabled before continuing. After board is connected press Next to continue wizard.</span></p></body></html> Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop @@ -67,6 +65,45 @@ p, li { white-space: pre-wrap; } + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + true + + + + + + + 6 + + + 0 + + + false + + + @@ -77,8 +114,11 @@ p, li { white-space: pre-wrap; } yellowLabel redLabel - label_3 + infoLabel rebootButton + verticalSpacer + messageLabel + rebootProgress diff --git a/ground/openpilotgcs/src/plugins/uploader/uploadergadgetfactory.cpp b/ground/openpilotgcs/src/plugins/uploader/uploadergadgetfactory.cpp index ab086320a..390369624 100644 --- a/ground/openpilotgcs/src/plugins/uploader/uploadergadgetfactory.cpp +++ b/ground/openpilotgcs/src/plugins/uploader/uploadergadgetfactory.cpp @@ -45,7 +45,7 @@ Core::IUAVGadget *UploaderGadgetFactory::createGadget(QWidget *parent) isautocapable = gadgetWidget->autoUpdateCapable(); connect(this, SIGNAL(autoUpdate(bool)), gadgetWidget, SLOT(autoUpdate(bool))); - connect(this, SIGNAL(reboot()), gadgetWidget, SLOT(systemReset())); + connect(this, SIGNAL(reboot()), gadgetWidget, SLOT(systemReboot())); connect(gadgetWidget, SIGNAL(progressUpdate(uploader::ProgressStep, QVariant)), this, SIGNAL(progressUpdate(uploader::ProgressStep, QVariant))); return new UploaderGadget(QString("Uploader"), gadgetWidget, parent); } diff --git a/ground/openpilotgcs/src/plugins/uploader/uploadergadgetwidget.cpp b/ground/openpilotgcs/src/plugins/uploader/uploadergadgetwidget.cpp index b162a98b2..213c678a5 100644 --- a/ground/openpilotgcs/src/plugins/uploader/uploadergadgetwidget.cpp +++ b/ground/openpilotgcs/src/plugins/uploader/uploadergadgetwidget.cpp @@ -548,6 +548,47 @@ void UploaderGadgetWidget::systemEraseBoot() } } +void UploaderGadgetWidget::systemReboot() +{ + ResultEventLoop eventLoop; + + connect(this, SIGNAL(bootloaderSuccess()), &eventLoop, SLOT(success())); + connect(this, SIGNAL(bootloaderFailed()), &eventLoop, SLOT(fail())); + + goToBootloader(); + + if (eventLoop.run(AUTOUPDATE_TIMEOUT) != 0) { + emit progressUpdate(FAILURE, QVariant()); + return; + } + + disconnect(this, SIGNAL(bootloaderSuccess()), &eventLoop, SLOT(success())); + disconnect(this, SIGNAL(bootloaderFailed()), &eventLoop, SLOT(fail())); + + commonSystemBoot(false, false); + + ExtensionSystem::PluginManager *pluginManager = ExtensionSystem::PluginManager::instance(); + Q_ASSERT(pluginManager); + TelemetryManager *telemetryManager = pluginManager->getObject(); + Q_ASSERT(telemetryManager); + + if (!telemetryManager->isConnected()) { + progressUpdate(BOOTING, QVariant()); + ResultEventLoop eventLoop; + + connect(telemetryManager, SIGNAL(connected()), &eventLoop, SLOT(success())); + + if (eventLoop.run(AUTOUPDATE_TIMEOUT) != 0) { + emit progressUpdate(FAILURE, QVariant()); + return; + } + + disconnect(telemetryManager, SIGNAL(connected()), &eventLoop, SLOT(success())); + } + + emit progressUpdate(SUCCESS, QVariant()); +} + /** * Tells the system to boot (from Bootloader state) * @param[in] safeboot Indicates whether the firmware should use the stock HWSettings diff --git a/ground/openpilotgcs/src/plugins/uploader/uploadergadgetwidget.h b/ground/openpilotgcs/src/plugins/uploader/uploadergadgetwidget.h index 59ee13efc..b40c79022 100644 --- a/ground/openpilotgcs/src/plugins/uploader/uploadergadgetwidget.h +++ b/ground/openpilotgcs/src/plugins/uploader/uploadergadgetwidget.h @@ -160,6 +160,7 @@ private slots: void systemBoot(); void systemSafeBoot(); void systemEraseBoot(); + void systemReboot(); void commonSystemBoot(bool safeboot = false, bool erase = false); void systemRescue(); void getSerialPorts();