2012-08-01 00:21:15 +02:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
|
2012-08-02 13:44:14 +02:00
|
|
|
#include <QMessageBox>
|
2012-08-30 22:13:44 +02:00
|
|
|
#include <QDebug>
|
2012-08-01 00:21:15 +02:00
|
|
|
#include "levellingpage.h"
|
|
|
|
#include "ui_levellingpage.h"
|
|
|
|
#include "setupwizard.h"
|
|
|
|
|
|
|
|
LevellingPage::LevellingPage(SetupWizard *wizard, QWidget *parent) :
|
2012-08-02 13:44:14 +02:00
|
|
|
AbstractWizardPage(wizard, parent),
|
|
|
|
ui(new Ui::LevellingPage), m_levellingUtil(0)
|
2012-08-01 00:21:15 +02:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2012-08-02 13:44:14 +02:00
|
|
|
connect(ui->levelButton, SIGNAL(clicked()), this, SLOT(performLevelling()));
|
2012-08-01 00:21:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
LevellingPage::~LevellingPage()
|
|
|
|
{
|
2012-08-02 13:44:14 +02:00
|
|
|
if(m_levellingUtil) {
|
|
|
|
delete m_levellingUtil;
|
|
|
|
}
|
2012-08-01 00:21:15 +02:00
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LevellingPage::validatePage()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2012-08-02 13:44:14 +02:00
|
|
|
|
2012-08-03 18:31:47 +02:00
|
|
|
bool LevellingPage::isComplete() const
|
2012-08-02 13:44:14 +02:00
|
|
|
{
|
2012-08-03 18:31:47 +02:00
|
|
|
return const_cast<LevellingPage *>(this)->getWizard()->isLevellingPerformed() &&
|
|
|
|
ui->levelButton->isEnabled();
|
2012-08-02 13:44:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void LevellingPage::performLevelling()
|
|
|
|
{
|
|
|
|
if(!getWizard()->getConnectionManager()->isConnected()) {
|
|
|
|
QMessageBox msgBox;
|
2012-08-03 18:31:47 +02:00
|
|
|
msgBox.setText(tr("An OpenPilot controller must be connected to your computer to perform bias "
|
2012-08-21 01:07:38 +02:00
|
|
|
"calculations.\nPlease connect your OpenPilot controller to your computer and try again."));
|
2012-08-02 13:44:14 +02:00
|
|
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
|
|
|
msgBox.setDefaultButton(QMessageBox::Ok);
|
|
|
|
msgBox.exec();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-05 00:58:53 +02:00
|
|
|
getWizard()->button(QWizard::BackButton)->setEnabled(false);
|
|
|
|
getWizard()->button(QWizard::NextButton)->setEnabled(false);
|
2012-08-27 07:19:46 +02:00
|
|
|
getWizard()->button(QWizard::CancelButton)->setEnabled(false);
|
2012-09-05 00:58:53 +02:00
|
|
|
|
2012-08-27 07:19:46 +02:00
|
|
|
ui->levelButton->setEnabled(false);
|
|
|
|
|
2012-08-02 13:44:14 +02:00
|
|
|
if(!m_levellingUtil)
|
|
|
|
{
|
2012-08-30 22:13:44 +02:00
|
|
|
m_levellingUtil = new LevellingUtil(BIAS_CYCLES, BIAS_RATE);
|
2012-08-02 13:44:14 +02:00
|
|
|
}
|
2012-08-21 01:07:38 +02:00
|
|
|
emit completeChanged();
|
|
|
|
|
2012-08-03 18:31:47 +02:00
|
|
|
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)));
|
2012-08-21 01:07:38 +02:00
|
|
|
|
2012-08-02 13:44:14 +02:00
|
|
|
m_levellingUtil->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LevellingPage::levellingProgress(long current, long total)
|
|
|
|
{
|
2012-08-19 23:25:50 +02:00
|
|
|
if(ui->levellinProgressBar->maximum() != (int)total) {
|
2012-08-02 13:44:14 +02:00
|
|
|
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)));
|
2012-09-05 00:58:53 +02:00
|
|
|
getWizard()->button(QWizard::BackButton)->setEnabled(true);
|
|
|
|
getWizard()->button(QWizard::NextButton)->setEnabled(true);
|
2012-08-21 01:07:38 +02:00
|
|
|
getWizard()->button(QWizard::CancelButton)->setEnabled(true);
|
2012-09-03 01:01:57 +02:00
|
|
|
ui->levelButton->setEnabled(true);
|
2012-08-02 13:44:14 +02:00
|
|
|
}
|
|
|
|
}
|