diff options
author | Simo Piiroinen <simo.piiroinen@jollamobile.com> | 2017-06-14 10:53:57 +0300 |
---|---|---|
committer | Lorn Potter <lorn.potter@gmail.com> | 2018-09-04 23:12:20 +0000 |
commit | 4ab2e8f086441c06a2dabbd4c62756fc0f029053 (patch) | |
tree | 27ae1189ab84fb8424f009387b05eb85558b8338 /src | |
parent | a2d3d45f3e9f779a4fc10f8df07b9bd921e755c6 (diff) | |
download | qtsensors-4ab2e8f086441c06a2dabbd4c62756fc0f029053.tar.gz |
sensorfw: Fix initial proximity sensor state evaluation
The sensorfw plugin assumes that both proximity state query and change
notifications use the same withinProximity boolean type values. Because
the state query actually returns integer distance, the initial value
visible in for example QML ProximitySensor is logically reversed from
what it should be and it requires one or two sensor state transitions
before changes get notified in the expected manner.
Evaluate initial proximity state as "distance" value where zero means
that the sensor is covered.
Also use the initial value to setup the cached previously seen value
instead of blindly assuming that sensor is not covered.
As suggested in sensorfwd documentation: Switch from deprecated
dataAvailable() signal to reflectanceDataAvailable() signal.
Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
Change-Id: I49e5607134848dc3c72e79733321df6251b7df52
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/sensors/sensorfw/sensorfwproximitysensor.cpp | 27 | ||||
-rw-r--r-- | src/plugins/sensors/sensorfw/sensorfwproximitysensor.h | 2 |
2 files changed, 21 insertions, 8 deletions
diff --git a/src/plugins/sensors/sensorfw/sensorfwproximitysensor.cpp b/src/plugins/sensors/sensorfw/sensorfwproximitysensor.cpp index cdfe7bd..8eb2870 100644 --- a/src/plugins/sensors/sensorfw/sensorfwproximitysensor.cpp +++ b/src/plugins/sensors/sensorfw/sensorfwproximitysensor.cpp @@ -58,13 +58,25 @@ void SensorfwProximitySensor::start() if (reinitIsNeeded) init(); SensorfwSensorBase::start(); + if (m_sensorInterface) { + Unsigned data(((ProximitySensorChannelInterface*)m_sensorInterface)->proximity()); + // Note: Unlike reflectanceDataAvailable() signal, the query + // above returns only integer reflectance without the + // boolean withinProximity value. + bool close = (data.x() == 0); + m_exClose = close; + m_reading.setClose(close); + m_reading.setTimestamp(data.UnsignedData().timestamp_); + m_exClose = (int)m_reading.close(); + newReadingAvailable(); + } } - -void SensorfwProximitySensor::slotDataAvailable(const Unsigned& data) +void SensorfwProximitySensor::slotReflectanceDataAvailable(const Proximity& data) { - bool close = data.x()? true: false; - if (!firstRun && close == m_exClose) return; + bool close = data.x() ? true : false; + if (!firstRun && close == m_exClose) + return; m_reading.setClose(close); m_reading.setTimestamp(data.UnsignedData().timestamp_); newReadingAvailable(); @@ -75,9 +87,10 @@ void SensorfwProximitySensor::slotDataAvailable(const Unsigned& data) bool SensorfwProximitySensor::doConnect() { - Q_ASSERT(m_sensorInterface); - return (QObject::connect(m_sensorInterface, SIGNAL(dataAvailable(Unsigned)), - this, SLOT(slotDataAvailable(Unsigned)))); + Q_ASSERT(qobject_cast<ProximitySensorChannelInterface*>(m_sensorInterface)); + return QObject::connect(qobject_cast<ProximitySensorChannelInterface*>(m_sensorInterface), + &ProximitySensorChannelInterface::reflectanceDataAvailable, + this, &SensorfwProximitySensor::slotReflectanceDataAvailable); } diff --git a/src/plugins/sensors/sensorfw/sensorfwproximitysensor.h b/src/plugins/sensors/sensorfw/sensorfwproximitysensor.h index d8b9664..992db84 100644 --- a/src/plugins/sensors/sensorfw/sensorfwproximitysensor.h +++ b/src/plugins/sensors/sensorfw/sensorfwproximitysensor.h @@ -67,7 +67,7 @@ private: bool firstRun; private slots: - void slotDataAvailable(const Unsigned& data); + void slotReflectanceDataAvailable(const Proximity& data); }; #endif |