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

OP-1628 Added software reboot to wizard.

This commit is contained in:
m_thread 2014-12-29 14:50:20 +01:00
parent a1e8d7efed
commit 82c65b6b3f
6 changed files with 137 additions and 13 deletions

View File

@ -27,10 +27,6 @@
#include "rebootpage.h"
#include "ui_rebootpage.h"
#include <extensionsystem/pluginmanager.h>
#include <uavobjectutil/uavobjectutilmanager.h>
#include <extensionsystem/pluginmanager.h>
#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<UploaderGadgetFactory>();
Q_ASSERT(uploader);
connect(ui->rebootButton, SIGNAL(clicked()), uploader, SIGNAL(reboot()));
m_uploader = pm->getObject<UploaderGadgetFactory>();
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("<font color='red'>Software reboot failed!</font><p> 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("<font color='green'>Reboot complete!</font>"));
}
enableButtons(true);
} else {
ui->rebootProgress->setValue(ui->rebootProgress->value() + 1);
}
}

View File

@ -29,6 +29,9 @@
#define REBOOTPAGE_H
#include "abstractwizardpage.h"
#include <extensionsystem/pluginmanager.h>
#include <extensionsystem/pluginmanager.h>
#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

View File

@ -49,15 +49,13 @@ p, li { white-space: pre-wrap; }
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<widget class="QLabel" name="infoLabel">
<property name="text">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:10pt; color:#000000;&quot;&gt;The configuration created by the wizard contains settings that require a reboot of your controller. &lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:10pt; color:#000000;&quot;&gt;There are two ways to reboot your board:&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:10pt; font-weight:600; color:#000000;&quot;&gt;1. Software Reboot&lt;/span&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:10pt; color:#000000;&quot;&gt;&lt;br /&gt;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.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:10pt; font-weight:600; color:#000000;&quot;&gt;2. Power Cycle &lt;/span&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:10pt; color:#000000;&quot;&gt;&lt;br /&gt;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.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
&lt;p style=&quot; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:10pt; color:#000000;&quot;&gt;The configuration created by the wizard contains settings that require a reboot of your controller. &lt;br /&gt;&lt;br /&gt;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.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
@ -67,6 +65,45 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="messageLabel">
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QProgressBar" name="rebootProgress">
<property name="maximum">
<number>6</number>
</property>
<property name="value">
<number>0</number>
</property>
<property name="textVisible">
<bool>false</bool>
</property>
</widget>
</item>
<item alignment="Qt::AlignHCenter">
<widget class="QPushButton" name="rebootButton">
<property name="text">
@ -77,8 +114,11 @@ p, li { white-space: pre-wrap; }
</layout>
<zorder>yellowLabel</zorder>
<zorder>redLabel</zorder>
<zorder>label_3</zorder>
<zorder>infoLabel</zorder>
<zorder>rebootButton</zorder>
<zorder>verticalSpacer</zorder>
<zorder>messageLabel</zorder>
<zorder>rebootProgress</zorder>
</widget>
<resources/>
<connections/>

View File

@ -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);
}

View File

@ -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<TelemetryManager>();
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

View File

@ -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();