Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[sensorfw] Fix initial proximity sensor state evaluation. Fixes JB#38675
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>
  • Loading branch information
spiiroin authored and rainemak committed Jun 16, 2017
1 parent d297393 commit 68b8c97
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions src/plugins/sensors/sensorfw/sensorfwproximitysensor.cpp
Expand Up @@ -61,16 +61,21 @@ void SensorfwProximitySensor::start()
SensorfwSensorBase::start();
if (m_sensorInterface) {
Unsigned data(((ProximitySensorChannelInterface*)m_sensorInterface)->proximity());
m_reading.setClose(data.x()? true: false);
// 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;
bool close = (data.reflectance() == 0);
if (close == m_exClose) return;
m_reading.setClose(close);
m_reading.setTimestamp(data.UnsignedData().timestamp_);
Expand All @@ -81,8 +86,8 @@ 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))));
return QObject::connect(m_sensorInterface, SIGNAL(reflectanceDataAvailable(const Proximity&)),
this, SLOT(slotReflectanceDataAvailable(const Proximity&)));
}


Expand Down
2 changes: 1 addition & 1 deletion src/plugins/sensors/sensorfw/sensorfwproximitysensor.h
Expand Up @@ -68,7 +68,7 @@ class SensorfwProximitySensor : public SensorfwSensorBase
int m_exClose;

private slots:
void slotDataAvailable(const Unsigned& data);
void slotReflectanceDataAvailable(const Proximity& data);
};

#endif

0 comments on commit 68b8c97

Please sign in to comment.