From 032c1e73ef289e64ee38c77faf26c46c74312043 Mon Sep 17 00:00:00 2001 From: Andre de la Rocha Date: Thu, 14 Dec 2017 04:45:08 +0100 Subject: 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 --- src/plugins/sensors/generic/generictiltsensor.cpp | 29 ++++------------------- 1 file changed, 5 insertions(+), 24 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/sensors/generic/generictiltsensor.cpp b/src/plugins/sensors/generic/generictiltsensor.cpp index a4ada7d8..bb418893 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; -- cgit v1.2.3