X-Git-Url: http://git.maemo.org/git/?p=speedfreak;a=blobdiff_plain;f=Client%2Faccrealtimedialog.cpp;h=4b46af184afaa4621e1d8b4a4f2b49ed877f6cb5;hp=dc5862778471f04688ba3bfd88d663e71a555ab1;hb=e7ab1f1b6219bf316acff1d1a3719cf1f22ec3c0;hpb=418c218ef417574ba034cb26d65da388aba852d0 diff --git a/Client/accrealtimedialog.cpp b/Client/accrealtimedialog.cpp index dc58627..4b46af1 100644 --- a/Client/accrealtimedialog.cpp +++ b/Client/accrealtimedialog.cpp @@ -1,3 +1,12 @@ +/* + * 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 + */ + #include "accrealtimedialog.h" #include "ui_accrealtimedialog.h" #include @@ -10,6 +19,7 @@ AccRealTimeDialog::AccRealTimeDialog(QWidget *parent) : accelerometer = new Accelerometer(); movingAverageZ = new MovingAverage(10); + movingAverageY = new MovingAverage(10); calculate = new Calculate(); accelerationStartThreshold = 0.1; @@ -19,9 +29,7 @@ AccRealTimeDialog::AccRealTimeDialog(QWidget *parent) : updateScreenCounter = 0; resetAccelerometerMeasurements(); - //Load image - QPixmap pixMap("back.png",0,Qt::AutoColor); - ui->pictureLabel->setPixmap(pixMap); + resultDialog = NULL; } AccRealTimeDialog::~AccRealTimeDialog() @@ -31,6 +39,9 @@ AccRealTimeDialog::~AccRealTimeDialog() delete accelerometerTimer; delete calculate; delete movingAverageZ; + delete movingAverageY; + if(resultDialog) + delete resultDialog; } void AccRealTimeDialog::changeEvent(QEvent *e) @@ -60,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(); - 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; + + //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) @@ -128,9 +166,28 @@ void AccRealTimeDialog::readAccelerometerData() updateScreenCounter++; //Open result dialog if target speed reached - if( speed > stopMeasureSpeed ) + if( (stopMeasureSpeed > 0) && (speed > stopMeasureSpeed) ) { this->accelerometerTimer->stop(); + if(!resultDialog) + { + resultDialog = new ResultDialog(this); + connect(resultDialog, SIGNAL(rejected()), this, SLOT(killResultDialog())); + connect(resultDialog, SIGNAL(sendresult(double)), this, SLOT(sendResult(double))); + } + if(resultDialog) + { + 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(); + } } } @@ -151,6 +208,7 @@ void AccRealTimeDialog::resetAccelerometerMeasurements() vehicleStartedMoving = false; stopMeasureSpeed = 0; } + void AccRealTimeDialog::Calibrate() { accelerometer->calibrate(); @@ -162,11 +220,38 @@ void AccRealTimeDialog::on_buttonAbort_clicked() resetAccelerometerMeasurements(); this->close(); } + void AccRealTimeDialog::startAccelerationMeasure() { + double temp = stopMeasureSpeed; + resetAccelerometerMeasurements(); + 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; + } +}