From 62ce0b92ee34a1ae6b2f4e81bb0efbaa2a7d53c9 Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Thu, 31 Jan 2013 17:42:18 +0100 Subject: Repair duplicate skipping for the tilt sensor Found because the compiler was warning about an unused "change" variable. Change-Id: Iac968685ba8da7a4d38a00427d22d1e01e31b25f Reviewed-by: Lorn Potter --- src/plugins/sensors/generic/generictiltsensor.cpp | 30 +++++++++++------------ src/plugins/sensors/generic/generictiltsensor.h | 2 ++ 2 files changed, 17 insertions(+), 15 deletions(-) (limited to 'src/plugins/sensors/generic') diff --git a/src/plugins/sensors/generic/generictiltsensor.cpp b/src/plugins/sensors/generic/generictiltsensor.cpp index 01281bd0..dc118bf7 100644 --- a/src/plugins/sensors/generic/generictiltsensor.cpp +++ b/src/plugins/sensors/generic/generictiltsensor.cpp @@ -159,27 +159,22 @@ bool GenericTiltSensor::filter(QAccelerometerReading *reading) qDebug() << "new yrot: " << yrot; qDebug() << "----------------------------------"; #endif - qreal dxrot = xrot - xRotation; - qreal dyrot = yrot - yRotation; + qreal dxrot = rad2deg(xrot) - xRotation; + qreal dyrot = rad2deg(yrot) - yRotation; if (dxrot < 0) dxrot = -dxrot; if (dyrot < 0) dyrot = -dyrot; - bool change = false; - if (dxrot >= radAccuracy){ - xRotation = xrot; - change = true; + bool setNewReading = false; + if (dxrot >= rad2deg(radAccuracy) || !sensor()->skipDuplicates()) { + xRotation = rad2deg(xrot); + setNewReading = true; } - if (dyrot >= radAccuracy){ - yRotation = yrot; - change = true; + if (dyrot >= rad2deg(radAccuracy) || !sensor()->skipDuplicates()) { + yRotation = rad2deg(yrot); + setNewReading = true; } - xRotation = rad2deg(xRotation); - yRotation = rad2deg(yRotation); - - if (xRotation != m_reading.xRotation() - || yRotation != m_reading.yRotation() - || m_reading.timestamp() == 0) { + if (setNewReading || m_reading.timestamp() == 0) { m_reading.setTimestamp(reading->timestamp()); m_reading.setXRotation(xRotation); m_reading.setYRotation(yRotation); @@ -188,3 +183,8 @@ bool GenericTiltSensor::filter(QAccelerometerReading *reading) return false; } + +bool GenericTiltSensor::isFeatureSupported(QSensor::Feature feature) const +{ + return (feature == QSensor::SkipDuplicates); +} diff --git a/src/plugins/sensors/generic/generictiltsensor.h b/src/plugins/sensors/generic/generictiltsensor.h index 4d228bbc..0f84ca6f 100644 --- a/src/plugins/sensors/generic/generictiltsensor.h +++ b/src/plugins/sensors/generic/generictiltsensor.h @@ -63,6 +63,8 @@ public: bool filter(QAccelerometerReading *reading); + bool isFeatureSupported(QSensor::Feature feature) const Q_DECL_OVERRIDE; + private: QTiltReading m_reading; QAccelerometer *accelerometer; -- cgit v1.2.3