X-Git-Url: http://git.maemo.org/git/?p=speedfreak;a=blobdiff_plain;f=Client%2Faccrealtimedialog.cpp;h=4b46af184afaa4621e1d8b4a4f2b49ed877f6cb5;hp=9b5bc3f2381e82573cd51dbec6dda6e5671408e6;hb=e7ab1f1b6219bf316acff1d1a3719cf1f22ec3c0;hpb=d1eaf0805e80ba0e9de04d6d91eca7f9dda769e7 diff --git a/Client/accrealtimedialog.cpp b/Client/accrealtimedialog.cpp index 9b5bc3f..4b46af1 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 */ @@ -18,6 +19,7 @@ AccRealTimeDialog::AccRealTimeDialog(QWidget *parent) : accelerometer = new Accelerometer(); movingAverageZ = new MovingAverage(10); + movingAverageY = new MovingAverage(10); calculate = new Calculate(); accelerationStartThreshold = 0.1; @@ -37,6 +39,7 @@ AccRealTimeDialog::~AccRealTimeDialog() delete accelerometerTimer; delete calculate; delete movingAverageZ; + delete movingAverageY; if(resultDialog) delete resultDialog; } @@ -68,20 +71,47 @@ void AccRealTimeDialog::readAccelerometerData() //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(); + qreal calY = accelerometer->getCalibrationY(); + qreal calZ = accelerometer->getCalibrationZ(); + + if(calY < 0) + calY = -calY; + if(calZ < 0) + calZ = -calZ; + + //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); + //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,18 +172,22 @@ 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))); } - 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]); + } + resultDialog->show(); + this->hide(); } - resultDialog->show(); - this->hide(); } } @@ -174,6 +208,7 @@ void AccRealTimeDialog::resetAccelerometerMeasurements() vehicleStartedMoving = false; stopMeasureSpeed = 0; } + void AccRealTimeDialog::Calibrate() { accelerometer->calibrate(); @@ -185,6 +220,7 @@ void AccRealTimeDialog::on_buttonAbort_clicked() resetAccelerometerMeasurements(); this->close(); } + void AccRealTimeDialog::startAccelerationMeasure() { double temp = stopMeasureSpeed; @@ -192,7 +228,30 @@ void AccRealTimeDialog::startAccelerationMeasure() stopMeasureSpeed = temp; accelerometerTimer->start(40); } + void AccRealTimeDialog::SetStopMeasureSpeed(double speed) { stopMeasureSpeed = speed; } + +/** + *This slot function emit accelerationstart sendresult. + * + **/ +void AccRealTimeDialog::sendResult(double result) +{ + emit sendresult(result); +} + +/** + *This slot function kills resultDialog. + * + **/ +void AccRealTimeDialog::killResultDialog() +{ + if(resultDialog) + { + delete resultDialog; + resultDialog = NULL; + } +}