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 9205400cf0 OP-39 Implemented functionality for reliable writing of UAVOs to controller board.
Removed the option to configure the board without having it connected.
Added Tri, QuadX and QuadP configuration code.
Updated some of the texts.
2012-08-19 23:25:50 +02:00

123 lines
3.9 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 "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
{
return const_cast<LevellingPage *>(this)->getWizard()->isLevellingPerformed() &&
ui->levelButton->isEnabled();
}
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 continue."));
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.exec();
return;
}
if(!m_levellingUtil)
{
// Measure every 100ms * 100times = 10s
m_levellingUtil = new LevellingUtil(BIAS_CYCLES, BIAS_PERIOD);
}
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)));
ui->levelButton->setEnabled(false);
emit completeChanged();
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)));
ui->levelButton->setEnabled(true);
}
}