summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre de la Rocha <andre.rocha@qt.io>2017-12-14 04:45:08 +0100
committerLorn Potter <lorn.potter@gmail.com>2017-12-27 22:03:19 +0000
commit032c1e73ef289e64ee38c77faf26c46c74312043 (patch)
tree132afe7e83ef6f3213b0b1553d0de9c821745000
parent93ab7107ebae0ca72c1632b665a199973ea278be (diff)
downloadqtsensors-032c1e73ef289e64ee38c77faf26c46c74312043.tar.gz
Fix device orientation angles provided by QTiltSensor
The device orientation angles provided by QTiltSensor were being incorrectly calculated from the accelerator sensor measurements, in all supported devices. This resulted in a restricted range of values reported for the roll angle, thus making non-equivalent device orientations, like a tablet lying horizontally with the screen up, and the flipped configuration with the screen down, report equivalent orientation angles, making it impossible to distinguish between them. Task-number: QTBUG-57898 Change-Id: I82c1d4d2c1eab435f389b89dbb537fa7b349cbf1 Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
-rw-r--r--src/plugins/sensors/generic/generictiltsensor.cpp29
1 files changed, 5 insertions, 24 deletions
diff --git a/src/plugins/sensors/generic/generictiltsensor.cpp b/src/plugins/sensors/generic/generictiltsensor.cpp
index a4ada7d..bb41889 100644
--- a/src/plugins/sensors/generic/generictiltsensor.cpp
+++ b/src/plugins/sensors/generic/generictiltsensor.cpp
@@ -79,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()
@@ -132,21 +126,8 @@ 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;