diff options
-rw-r--r-- | src/plugins/sensors/generic/generictiltsensor.cpp | 30 | ||||
-rw-r--r-- | src/plugins/sensors/generic/generictiltsensor.h | 2 |
2 files changed, 17 insertions, 15 deletions
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; |