diff options
author | Thomas McGuire <thomas.mcguire.qnx@kdab.com> | 2013-01-09 13:57:16 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-01-23 18:33:03 +0100 |
commit | 1831170d56f32530e64bbd5484a6c2cc9e1817ca (patch) | |
tree | 3499dfc2e46b97d72b17a6cfc1087add660e6e8a /src/sensors | |
parent | 02285d735e7d3bd8ddfb61b7ea5e16da4ad522d1 (diff) |
Add API for duplicate skipping
Duplicate skipping enables omitting reading values
that are very similar to the previous one, thus saving
processing power.
Implement this for the Blackberry backend.
Change-Id: Ic608d8ca795b5a2e0bca5a75a62e8005c283c620
Reviewed-by: Thomas McGuire <thomas.mcguire@kdab.com>
Diffstat (limited to 'src/sensors')
-rw-r--r-- | src/sensors/qsensor.cpp | 51 | ||||
-rw-r--r-- | src/sensors/qsensor.h | 6 | ||||
-rw-r--r-- | src/sensors/qsensor_p.h | 2 |
3 files changed, 59 insertions, 0 deletions
diff --git a/src/sensors/qsensor.cpp b/src/sensors/qsensor.cpp index 4c3715c2..f93ef883 100644 --- a/src/sensors/qsensor.cpp +++ b/src/sensors/qsensor.cpp @@ -189,6 +189,9 @@ void QSensorPrivate::init(const QByteArray &sensorType) QSensor::bufferSize property. \value AlwaysOn The backend supports changing the policy on whether to suspend when idle, controlled by the QSensor::alwaysOn property. + \value SkipDuplicates The backend supports skipping of same or very similar successive + readings. This can be enabled by setting the QSensor::skipDuplicates + property to true. The features of QMagnetometer are: @@ -434,6 +437,54 @@ bool QSensor::isAlwaysOn() const } /*! + \property QSensor::skipDuplicates + \brief Indicates whether duplicate reading values should be omitted. + \since 5.1 + + When duplicate skipping is enabled, successive readings with the same or very + similar values are omitted. This helps reducing the amount of processing done, as less sensor + readings are made available. As a consequence, readings arrive at an irregular interval. + + Duplicate skipping is not just enabled for readings that are exactly the same, but also for + readings that are quite similar, as each sensor has a bit of jitter even if the device is + not moved. + + Support for this property depends on the backend. Use isFeatureSupported() to check if it is + supported on the current platform. + + Duplicate skipping is disabled by default. + + Duplicate skipping takes effect when the sensor is started, changing the property while the + sensor is active has no immediate effect. +*/ +bool QSensor::skipDuplicates() const +{ + Q_D(const QSensor); + return d->skipDuplicates; +} + +/*! + Sets the duplicate skipping to \a skipDuplicates. + + \since 5.1 +*/ +void QSensor::setSkipDuplicates(bool skipDuplicates) +{ + Q_D(QSensor); + if (d->skipDuplicates != skipDuplicates) { + d->skipDuplicates = skipDuplicates; + emit skipDuplicatesChanged(skipDuplicates); + } +} + +/*! + \fn QSensor::skipDuplicatesChanged(bool skipDuplicates) + \since 5.1 + + This signal is emitted when the skipDuplicates property changes. +*/ + +/*! \property QSensor::availableDataRates \brief the data rates that the sensor supports. diff --git a/src/sensors/qsensor.h b/src/sensors/qsensor.h index f142ca4d..f7162753 100644 --- a/src/sensors/qsensor.h +++ b/src/sensors/qsensor.h @@ -93,6 +93,7 @@ class Q_SENSORS_EXPORT QSensor : public QObject Q_PROPERTY(QString description READ description) Q_PROPERTY(int error READ error NOTIFY sensorError) Q_PROPERTY(bool alwaysOn READ isAlwaysOn WRITE setAlwaysOn NOTIFY alwaysOnChanged REVISION 1) + Q_PROPERTY(bool skipDuplicates READ skipDuplicates WRITE setSkipDuplicates NOTIFY skipDuplicatesChanged) #ifdef Q_QDOC Q_PROPERTY(int maxBufferSize) Q_PROPERTY(int efficientBufferSize) @@ -105,6 +106,7 @@ public: GeoValues, FieldOfView, AccelerationMode, + SkipDuplicates, Reserved = 257 // Make sure at least 2 bytes are used for the enum to avoid breaking BC later }; @@ -127,6 +129,9 @@ public: bool isAlwaysOn() const; void setAlwaysOn(bool alwaysOn); + bool skipDuplicates() const; + void setSkipDuplicates(bool skipDuplicates); + qrangelist availableDataRates() const; int dataRate() const; void setDataRate(int rate); @@ -169,6 +174,7 @@ Q_SIGNALS: void availableSensorsChanged(); void alwaysOnChanged(); void dataRateChanged(); + void skipDuplicatesChanged(bool skipDuplicates); protected: explicit QSensor(const QByteArray &type, QSensorPrivate &dd, QObject* parent = 0); diff --git a/src/sensors/qsensor_p.h b/src/sensors/qsensor_p.h index 80312b65..8504a3f6 100644 --- a/src/sensors/qsensor_p.h +++ b/src/sensors/qsensor_p.h @@ -79,6 +79,7 @@ public: , cache_reading(0) , error(0) , alwaysOn(false) + , skipDuplicates(false) { } @@ -108,6 +109,7 @@ public: int error; bool alwaysOn; + bool skipDuplicates; }; class QSensorReadingPrivate |