X-Git-Url: http://git.maemo.org/git/?p=speedfreak;a=blobdiff_plain;f=Client%2Faccrealtimedialog.cpp;h=e572d27b72809a825a960907fa26ea14a798aa0e;hp=be150c206095d46510fcc05365d871bdb06653b1;hb=59a7180931986f4d9420f6b4f1beb85f078fd309;hpb=20d58825bd115adb8e56401a1055ff6d2a3c7850 diff --git a/Client/accrealtimedialog.cpp b/Client/accrealtimedialog.cpp index be150c2..e572d27 100644 --- a/Client/accrealtimedialog.cpp +++ b/Client/accrealtimedialog.cpp @@ -2,6 +2,7 @@ * Acceleration info in real time dialog * * @author Jukka Kurttila + * @author Toni Jussila * @copyright (c) 2010 Speed Freak team * @license http://opensource.org/licenses/gpl-license.php GNU Public License */ @@ -10,6 +11,10 @@ #include "ui_accrealtimedialog.h" #include +/** + * Default constructor for AccRealTimeDialog class. + * + */ AccRealTimeDialog::AccRealTimeDialog(QWidget *parent) : QDialog(parent), ui(new Ui::AccRealTimeDialog) @@ -18,6 +23,7 @@ AccRealTimeDialog::AccRealTimeDialog(QWidget *parent) : accelerometer = new Accelerometer(); movingAverageZ = new MovingAverage(10); + movingAverageY = new MovingAverage(10); calculate = new Calculate(); accelerationStartThreshold = 0.1; @@ -30,6 +36,10 @@ AccRealTimeDialog::AccRealTimeDialog(QWidget *parent) : resultDialog = NULL; } +/** + * Default destructor for AccRealTimeDialog class. + * Deletes all dynamic objects and sets them to NULL. + */ AccRealTimeDialog::~AccRealTimeDialog() { delete ui; @@ -37,10 +47,14 @@ AccRealTimeDialog::~AccRealTimeDialog() delete accelerometerTimer; delete calculate; delete movingAverageZ; + delete movingAverageY; if(resultDialog) delete resultDialog; } +/** + * + */ void AccRealTimeDialog::changeEvent(QEvent *e) { QDialog::changeEvent(e); @@ -52,8 +66,9 @@ void AccRealTimeDialog::changeEvent(QEvent *e) break; } } + /** - *This function is called to read (and process) data from the accelerometer + * This function is called to read (and process) data from the accelerometer */ void AccRealTimeDialog::readAccelerometerData() { @@ -63,25 +78,50 @@ void AccRealTimeDialog::readAccelerometerData() accelerometer->getAcceleration(x, y, z); - // keep the following line as close to the SetKinematicsProperties method as possible + // keep the following line as close to the SetKinematicsProperties method as possible currentTime = elapsedTime.elapsed(); - //accelerometer->smoothData(x, y, z); - - //Calculate average + // Calculate average for Z movingAverageZ->Enqueue(z); z = movingAverageZ->Average(); + // Calculate average for Y + movingAverageY->Enqueue(y); + y = movingAverageY->Average(); // Apply calibration x -= accelerometer->getCalibrationX(); y -= accelerometer->getCalibrationY(); z -= accelerometer->getCalibrationZ(); -// QString str = QString("acc x: " + QString::number(x) + "\n" + -// "acc y: " + QString::number(y) + "\n" + -// "acc z: " + QString::number(z) + "\n"); + qreal calY = accelerometer->getCalibrationY(); + qreal calZ = accelerometer->getCalibrationZ(); + + if(calY < 0) + calY = -calY; + if(calZ < 0) + calZ = -calZ; - currentAcceleration = z;//sqrt(x*x + y*y + z*z); + // Take acceleration from more affecting axel + if(calZ < calY) + { + z = z*(1+calZ/2); + currentAcceleration = z; + } + else + { + y = y*(1+calY/2); + currentAcceleration = -y; + } + + //screen up: y = 0, z = -1 + //screen front: y = -1, z = 0 + + //QString str = QString("acc x: " + QString::number(x) + "\n" + + // "acc y: " + QString::number(y) + "\n" + + // "acc z: " + QString::number(z) + "\n"); + + //currentAcceleration = z;//sqrt(x*x + y*y + z*z); + //qDebug("y: %f, calibZ: %f, calibY: %f\n",y,accelerometer->getCalibrationZ(),accelerometer->getCalibrationY()); changeInAcceleration = currentAcceleration; if (((fabs(changeInAcceleration) <= accelerationStartThreshold) @@ -142,19 +182,23 @@ void AccRealTimeDialog::readAccelerometerData() if(!resultDialog) { resultDialog = new ResultDialog(this); + connect(resultDialog, SIGNAL(rejected()), this, SLOT(killResultDialog())); + connect(resultDialog, SIGNAL(sendresult(double)), this, SLOT(sendResult(double))); } - connect(resultDialog, SIGNAL(sendresult(double)), this, SLOT(sendResult(double))); - resultDialog->setEnd(stopMeasureSpeed); - - //Put all times from all speeds - QMap tempMap = calculate->getValuesMap(); - - for( int i = 1 ; i <= tempMap.count() ; i++ ) + if(resultDialog) { - resultDialog->setValue(i*10,tempMap[i*10]); + resultDialog->setEnd(stopMeasureSpeed); + //Put all times from all speeds + QMap tempMap = calculate->getValuesMap(); + + for( int i = 1 ; i <= tempMap.count() ; i++ ) + { + resultDialog->setValue(i*10,tempMap[i*10]); + } + calculate->reset(); + resultDialog->show(); + this->hide(); } - resultDialog->show(); - this->hide(); } } @@ -176,11 +220,17 @@ void AccRealTimeDialog::resetAccelerometerMeasurements() stopMeasureSpeed = 0; } +/** + * + */ void AccRealTimeDialog::Calibrate() { accelerometer->calibrate(); } +/** + * This slot function called when ever abort button clicked. + */ void AccRealTimeDialog::on_buttonAbort_clicked() { accelerometerTimer->stop(); @@ -188,6 +238,9 @@ void AccRealTimeDialog::on_buttonAbort_clicked() this->close(); } +/** + * + */ void AccRealTimeDialog::startAccelerationMeasure() { double temp = stopMeasureSpeed; @@ -196,6 +249,10 @@ void AccRealTimeDialog::startAccelerationMeasure() accelerometerTimer->start(40); } +/** + * + * @param double speed + */ void AccRealTimeDialog::SetStopMeasureSpeed(double speed) { stopMeasureSpeed = speed; @@ -204,8 +261,22 @@ void AccRealTimeDialog::SetStopMeasureSpeed(double speed) /** *This slot function emit accelerationstart sendresult. * - **/ + * @param double result + */ void AccRealTimeDialog::sendResult(double result) { emit sendresult(result); } + +/** + *This slot function kills resultDialog. + * + **/ +void AccRealTimeDialog::killResultDialog() +{ + if(resultDialog) + { + delete resultDialog; + resultDialog = NULL; + } +}