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-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
bool LevellingPage : : isComplete ( )
{
return getWizard ( ) - > isLevellingPerformed ( ) ;
}
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. \n Please connect your OpenPilot controller to continue. " ) ) ;
msgBox . setStandardButtons ( QMessageBox : : Ok ) ;
msgBox . setDefaultButton ( QMessageBox : : Ok ) ;
msgBox . exec ( ) ;
return ;
}
if ( ! m_levellingUtil )
{
ui - > levelButton - > setEnabled ( false ) ;
// 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 ) ) ) ;
}
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 ) ;
}
}