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.cpp49
-rw-r--r--src/plugins/sensors/generic/main.cpp6
3 files changed, 18 insertions, 45 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..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;
}
diff --git a/src/plugins/sensors/generic/main.cpp b/src/plugins/sensors/generic/main.cpp
index 9bed9011..44bfff09 100644
--- a/src/plugins/sensors/generic/main.cpp
+++ b/src/plugins/sensors/generic/main.cpp
@@ -61,12 +61,12 @@ class genericSensorPlugin : public QObject, public QSensorPluginInterface, publi
Q_PLUGIN_METADATA(IID "com.qt-project.Qt.QSensorPluginInterface/1.0" FILE "plugin.json")
Q_INTERFACES(QSensorPluginInterface QSensorChangesInterface)
public:
- void registerSensors()
+ void registerSensors() override
{
// Nothing to register here
}
- void sensorsChanged()
+ void sensorsChanged() override
{
if (!QSensor::defaultSensorForType(QAccelerometer::type).isEmpty()) {
// There is an accelerometer available. Register the backends
@@ -110,7 +110,7 @@ public:
}
}
- QSensorBackend *createBackend(QSensor *sensor)
+ QSensorBackend *createBackend(QSensor *sensor) override
{
#ifdef QTSENSORS_GENERICORIENTATIONSENSOR
if (sensor->identifier() == genericorientationsensor::id)