summaryrefslogtreecommitdiffstats
path: root/src/plugins/sensors/generic/generictiltsensor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/sensors/generic/generictiltsensor.cpp')
-rw-r--r--src/plugins/sensors/generic/generictiltsensor.cpp49
1 files changed, 12 insertions, 37 deletions
diff --git a/src/plugins/sensors/generic/generictiltsensor.cpp b/src/plugins/sensors/generic/generictiltsensor.cpp
index 831b03ec..bb418893 100644
--- a/src/plugins/sensors/generic/generictiltsensor.cpp
+++ b/src/plugins/sensors/generic/generictiltsensor.cpp
@@ -39,14 +39,13 @@
#include "generictiltsensor.h"
#include <QDebug>
-#define _USE_MATH_DEFINES
#include <qmath.h>
char const * const GenericTiltSensor::id("generic.tilt");
GenericTiltSensor::GenericTiltSensor(QSensor *sensor)
: QSensorBackend(sensor)
- , radAccuracy(M_PI / 180)
+ , radAccuracy(qDegreesToRadians(qreal(1)))
, pitch(0)
, roll(0)
, calibratedPitch(0)
@@ -80,24 +79,18 @@ void GenericTiltSensor::stop()
/*
Angle between Ground and X
- | Ax |
- pitch = arctan| ----------------------- |
- | sqrt(Ay * Ay + Az * Az)|
*/
static inline qreal calcPitch(double Ax, double Ay, double Az)
{
- return -qAtan2(Ax, qSqrt(Ay * Ay + Az * Az));
+ return qAtan2(-Ax, qSqrt(Ay * Ay + Az * Az));
}
/*
Angle between Ground and Y
- | Ay |
- roll = arctan| ----------------------- |
- | sqrt(Ax * Ax + Az * Az)|
*/
-static inline qreal calcRoll(double Ax, double Ay, double Az)
+static inline qreal calcRoll(double /*Ax*/, double Ay, double Az)
{
- return qAtan2(Ay, (qSqrt(Ax * Ax + Az * Az)));
+ return qAtan2(Ay, Az);
}
void GenericTiltSensor::calibrate()
@@ -106,11 +99,6 @@ void GenericTiltSensor::calibrate()
calibratedRoll = roll;
}
-static qreal rad2deg(qreal rad)
-{
- return rad / (2 * M_PI) * 360;
-}
-
bool GenericTiltSensor::filter(QAccelerometerReading *reading)
{
/*
@@ -138,39 +126,26 @@ bool GenericTiltSensor::filter(QAccelerometerReading *reading)
qreal xrot = roll - calibratedRoll;
qreal yrot = pitch - calibratedPitch;
//get angle between 0 and 180 or 0 -180
- qreal aG = 1 * qSin(xrot);
- qreal aK = 1 * qCos(xrot);
- xrot = qAtan2(aG, aK);
- if (xrot > M_PI_2)
- xrot = M_PI - xrot;
- else if (xrot < -M_PI_2)
- xrot = -(M_PI + xrot);
- aG = 1 * qSin(yrot);
- aK = 1 * qCos(yrot);
- yrot = qAtan2(aG, aK);
- if (yrot > M_PI_2)
- yrot = M_PI - yrot;
- else if (yrot < -M_PI_2)
- yrot = -(M_PI + yrot);
-
+ xrot = qAtan2(qSin(xrot), qCos(xrot));
+ yrot = qAtan2(qSin(yrot), qCos(yrot));
#ifdef LOGCALIBRATION
qDebug() << "new xrot: " << xrot;
qDebug() << "new yrot: " << yrot;
qDebug() << "----------------------------------";
#endif
- qreal dxrot = rad2deg(xrot) - xRotation;
- qreal dyrot = rad2deg(yrot) - yRotation;
+ qreal dxrot = qRadiansToDegrees(xrot) - xRotation;
+ qreal dyrot = qRadiansToDegrees(yrot) - yRotation;
if (dxrot < 0) dxrot = -dxrot;
if (dyrot < 0) dyrot = -dyrot;
bool setNewReading = false;
- if (dxrot >= rad2deg(radAccuracy) || !sensor()->skipDuplicates()) {
- xRotation = rad2deg(xrot);
+ if (dxrot >= qRadiansToDegrees(radAccuracy) || !sensor()->skipDuplicates()) {
+ xRotation = qRadiansToDegrees(xrot);
setNewReading = true;
}
- if (dyrot >= rad2deg(radAccuracy) || !sensor()->skipDuplicates()) {
- yRotation = rad2deg(yrot);
+ if (dyrot >= qRadiansToDegrees(radAccuracy) || !sensor()->skipDuplicates()) {
+ yRotation = qRadiansToDegrees(yrot);
setNewReading = true;
}