1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-08 19:46:06 +01:00
LibrePilot/ground/openpilotgcs/src/plugins/setupwizard/pages/levellingpage.cpp
Fredrik Arvidsson 3ef26a633a OP-39 Moved reboot page to directly after Rx config page.
Added partial save to support changed hardware settings.
Made it possible to skip leveling procedure.
Changed some texts.
Changed isRebootRequired() criteria.
2012-09-23 21:58:37 +02:00

134 lines
4.1 KiB
C++

/**
******************************************************************************
*
* @file levellingpage.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @addtogroup
* @{
* @addtogroup LevellingPage
* @{
* @brief
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <QMessageBox>
#include <QDebug>
#include "levellingpage.h"
#include "ui_levellingpage.h"
#include "setupwizard.h"
LevellingPage::LevellingPage(SetupWizard *wizard, QWidget *parent) :
AbstractWizardPage(wizard, parent),
ui(new Ui::LevellingPage), m_levellingUtil(0)
{
ui->setupUi(this);
connect(ui->levelButton, SIGNAL(clicked()), this, SLOT(performLevelling()));
}
LevellingPage::~LevellingPage()
{
if(m_levellingUtil) {
delete m_levellingUtil;
}
delete ui;
}
bool LevellingPage::validatePage()
{
return true;
}
bool LevellingPage::isComplete() const
{
//const_cast<LevellingPage *>(this)->getWizard()->isLevellingPerformed() &&
return ui->levelButton->isEnabled();
}
void LevellingPage::enableButtons(bool enable)
{
ui->levelButton->setEnabled(enable);
getWizard()->button(QWizard::NextButton)->setEnabled(enable);
getWizard()->button(QWizard::CancelButton)->setEnabled(enable);
getWizard()->button(QWizard::BackButton)->setEnabled(enable);
QApplication::processEvents();
}
void LevellingPage::performLevelling()
{
if(!getWizard()->getConnectionManager()->isConnected()) {
QMessageBox msgBox;
msgBox.setText(tr("An OpenPilot controller must be connected to your computer to perform bias "
"calculations.\nPlease connect your OpenPilot controller to your computer and try again."));
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.exec();
return;
}
enableButtons(false);
if(!m_levellingUtil)
{
m_levellingUtil = new LevellingUtil(BIAS_CYCLES, BIAS_RATE);
}
connect(m_levellingUtil, SIGNAL(progress(long,long)), this, SLOT(levellingProgress(long,long)));
connect(m_levellingUtil, SIGNAL(done(accelGyroBias)), this, SLOT(levellingDone(accelGyroBias)));
connect(m_levellingUtil, SIGNAL(timeout(QString)), this, SLOT(levellingTimeout(QString)));
m_levellingUtil->start();
}
void LevellingPage::levellingProgress(long current, long total)
{
if(ui->levellinProgressBar->maximum() != (int)total) {
ui->levellinProgressBar->setMaximum((int)total);
}
if(ui->levellinProgressBar->value() != (int)current) {
ui->levellinProgressBar->setValue((int)current);
}
}
void LevellingPage::levellingDone(accelGyroBias bias)
{
stopLevelling();
getWizard()->setLevellingBias(bias);
emit completeChanged();
}
void LevellingPage::levellingTimeout(QString message)
{
stopLevelling();
QMessageBox msgBox;
msgBox.setText(message);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.exec();
}
void LevellingPage::stopLevelling()
{
if(m_levellingUtil)
{
disconnect(m_levellingUtil, SIGNAL(progress(long,long)), this, SLOT(levellingProgress(long,long)));
disconnect(m_levellingUtil, SIGNAL(done(accelGyroBias)), this, SLOT(levellingDone(accelGyroBias)));
disconnect(m_levellingUtil, SIGNAL(timeout(QString)), this, SLOT(levellingTimeout(QString)));
enableButtons(true);
}
}