+ * Processes Accelerometer data
+ *
+ * Opens the accelerometer value file for reading and reads and parses accelerometer values.
+ * Forwards data to Calculate class for processing
+ *
+ */
+void Accelerometer::processData()
+{
+ getAcceleration(accelerationX, accelerationY, accelerationZ);
+ //smoothData(accelerationX, accelerationY, accelerationZ);
+
+ // Apply calibration
+ accelerationX = accelerationX - calibrationX;
+ accelerationY = accelerationY - calibrationY;
+ accelerationZ = accelerationZ - calibrationZ;
+
+ // If the function is run the first time, make sure that there
+ // are no differences with previous and current acceleration
+ if (firstRun) {
+ previousAccelerationX = accelerationX;
+ previousAccelerationY = accelerationY;
+ previousAccelerationZ = accelerationZ;
+ firstRun = false;
+ }
+
+ // Calculate the current acceleration for each axis
+ trueAccelerationX = (accelerationX - previousAccelerationX);
+ trueAccelerationY = (accelerationY - previousAccelerationY);
+ trueAccelerationZ = (accelerationZ - previousAccelerationZ);
+
+ previousAccelerationX = accelerationX;
+ previousAccelerationY = accelerationY;
+ previousAccelerationZ = accelerationZ;
+
+ currentAcceleration = sqrt((trueAccelerationX * trueAccelerationX) +
+ (trueAccelerationY * trueAccelerationY) +
+ (trueAccelerationZ * trueAccelerationZ));
+
+ // Discrimination window for currentAcceleration
+ if ( fabs(currentAcceleration) < 0.10 ) { currentAcceleration = 0; }
+
+ // Measure time interval
+ intervalTime = now.restart();
+ intervalTime = intervalTime/1000; // millisecs to secs
+ totalTime = totalTime + intervalTime;
+
+ // Using calculate class to calculate velocity and distance etc.
+ calculate->calculateParameters(currentAcceleration,intervalTime );
+
+ currentSpeed = calculate->getCurrentSpeed();
+ distanceTraveled = calculate->getDistanceTraveled();
+}
+
+/**
+ * Smooths Accelerometer data
+ *
+ * @param x accelerometer's x-axis input
+ * @param y accelerometer's y-axis input
+ * @param z accelerometer's z-axis input
+ */
+void Accelerometer::smoothData(qreal x, qreal y, qreal z)
+{
+ accelerationX = x;
+ accelerationY = y;
+ accelerationZ = z;
+ if (sampleIndex > 0)
+ {
+ accelerationX = previousAccelerationX + (accelerationX-previousAccelerationX) * kFilteringFactor;
+ accelerationY = previousAccelerationY + (accelerationY-previousAccelerationY) * kFilteringFactor;
+ accelerationZ = previousAccelerationZ + (accelerationZ-previousAccelerationZ) * kFilteringFactor;
+ }
+ sampleIndex++;
+}
+
+void Accelerometer::getAcceleration(qreal &x, qreal &y, qreal &z)
+{
+ /*
+ QFile file(kFileName);
+ if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
+ {
+ return;
+ }
+
+ // Read data, parse with regular expressions and process it
+ QByteArray line = file.readLine();
+ QRegExp rx("([0-9-]+) ([0-9-]+) ([0-9-]+)");
+ rx.indexIn(line);
+
+ x = rx.cap(1).toInt()/1000;
+ y = rx.cap(2).toInt()/1000;
+ z = rx.cap(3).toInt()/1000;
+
+ file.close();
+ */
+
+ QDBusConnection connection(QDBusConnection::systemBus());
+ if (connection.isConnected()) {
+ QDBusInterface interface("com.nokia.mce", "/com/nokia/icd", QString(), connection);
+ QDBusPendingReply<QString, QString, QString, int, int, int> reply;
+ reply = interface.asyncCall("get_device_orientation");
+ reply.waitForFinished();
+ x = static_cast<qreal>(reply.argumentAt<3>()) / 1000;
+ y = static_cast<qreal>(reply.argumentAt<4>()) / 1000;
+ z = static_cast<qreal>(reply.argumentAt<5>()) / 1000;
+ }
+}
+
+/**