* Acceleration info in real time dialog
*
* @author Jukka Kurttila <jukka.kurttila@fudeco.com>
+ * @author Toni Jussila <toni.jussila@fudeco.com>
* @copyright (c) 2010 Speed Freak team
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/
accelerometer = new Accelerometer();
movingAverageZ = new MovingAverage(10);
+ movingAverageY = new MovingAverage(10);
calculate = new Calculate();
accelerationStartThreshold = 0.1;
delete accelerometerTimer;
delete calculate;
delete movingAverageZ;
+ delete movingAverageY;
if(resultDialog)
delete resultDialog;
}
//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)
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<int,double> 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<int,double> 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();
}
}
vehicleStartedMoving = false;
stopMeasureSpeed = 0;
}
+
void AccRealTimeDialog::Calibrate()
{
accelerometer->calibrate();
resetAccelerometerMeasurements();
this->close();
}
+
void AccRealTimeDialog::startAccelerationMeasure()
{
double temp = stopMeasureSpeed;
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;
+ }
+}