summaryrefslogtreecommitdiffstats
path: root/src/plugins/sensors/generic
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/sensors/generic')
-rw-r--r--src/plugins/sensors/generic/genericrotationsensor.cpp8
-rw-r--r--src/plugins/sensors/generic/generictiltsensor.cpp20
2 files changed, 10 insertions, 18 deletions
diff --git a/src/plugins/sensors/generic/genericrotationsensor.cpp b/src/plugins/sensors/generic/genericrotationsensor.cpp
index adf28e43..40768297 100644
--- a/src/plugins/sensors/generic/genericrotationsensor.cpp
+++ b/src/plugins/sensors/generic/genericrotationsensor.cpp
@@ -41,8 +41,6 @@
#include <QDebug>
#include <qmath.h>
-#define RADIANS_TO_DEGREES 57.2957795
-
char const * const genericrotationsensor::id("generic.rotation");
genericrotationsensor::genericrotationsensor(QSensor *sensor)
@@ -88,8 +86,8 @@ bool genericrotationsensor::filter(QSensorReading *reading)
// Note that the formula used come from this document:
// http://www.freescale.com/files/sensors/doc/app_note/AN3461.pdf
- pitch = qAtan(y / qSqrt(x*x + z*z)) * RADIANS_TO_DEGREES;
- roll = qAtan(x / qSqrt(y*y + z*z)) * RADIANS_TO_DEGREES;
+ pitch = qRadiansToDegrees(qAtan(y / qSqrt(x * x + z * z)));
+ roll = qRadiansToDegrees(qAtan(x / qSqrt(y * y + z * z)));
// Roll is a left-handed rotation but we need right-handed rotation
roll = -roll;
@@ -98,7 +96,7 @@ bool genericrotationsensor::filter(QSensorReading *reading)
// Note that theta is defined as the angle of the Z axis relative
// to gravity (see referenced document). It's negative when the
// face of the device points downward.
- qreal theta = qAtan(qSqrt(x*x + y*y) / z) * RADIANS_TO_DEGREES;
+ qreal theta = qRadiansToDegrees(qAtan(qSqrt(x * x + y * y) / z));
if (theta < 0) {
if (roll > 0)
roll = 180 - roll;
diff --git a/src/plugins/sensors/generic/generictiltsensor.cpp b/src/plugins/sensors/generic/generictiltsensor.cpp
index 831b03ec..a4ada7d8 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)
@@ -106,11 +105,6 @@ void GenericTiltSensor::calibrate()
calibratedRoll = roll;
}
-static qreal rad2deg(qreal rad)
-{
- return rad / (2 * M_PI) * 360;
-}
-
bool GenericTiltSensor::filter(QAccelerometerReading *reading)
{
/*
@@ -159,18 +153,18 @@ bool GenericTiltSensor::filter(QAccelerometerReading *reading)
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;
}