summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@digia.com>2014-08-12 16:31:30 +0200
committerFrederik Gladhorn <frederik.gladhorn@digia.com>2014-08-12 16:32:04 +0200
commit15e924486a410780fefbc5a95fae8886e3190925 (patch)
treec6d784f1c528a0fe75367db415240fc4dfe5c73a
parentea7af7f00886f77941b81262e597c3b7f3477f48 (diff)
parent4c29e9149a583b48e563ad44b59666a9d45f9347 (diff)
downloadqtsensors-15e924486a410780fefbc5a95fae8886e3190925.tar.gz
qtsensors-15e924486a410780fefbc5a95fae8886e3190925.tar.bz2
qtsensors-15e924486a410780fefbc5a95fae8886e3190925.zip
Merge remote-tracking branch 'origin/5.3' into 5.4
Conflicts: src/plugins/sensors/sensorfw/sensorfwproximitysensor.cpp src/sensors/qcompass.cpp Change-Id: Idfcbbfe1757a4b827663453abc27f4026cd3d752
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwaccelerometer.cpp8
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwaccelerometer.h1
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwals.cpp3
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwcompass.cpp8
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwcompass.h1
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwgyroscope.cpp8
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwgyroscope.h1
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwirproximitysensor.cpp8
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwirproximitysensor.h1
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwlightsensor.cpp8
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwlightsensor.h1
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwmagnetometer.cpp3
-rw-r--r--src/plugins/sensors/sensorfw/sensorfworientationsensor.cpp3
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwproximitysensor.cpp5
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwrotationsensor.cpp8
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwrotationsensor.h1
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwsensorbase.cpp73
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwsensorbase.h74
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwtapsensor.cpp17
-rw-r--r--src/sensors/qcompass.cpp2
-rw-r--r--src/sensors/qsensormanager.cpp28
21 files changed, 184 insertions, 78 deletions
diff --git a/src/plugins/sensors/sensorfw/sensorfwaccelerometer.cpp b/src/plugins/sensors/sensorfw/sensorfwaccelerometer.cpp
index d38f1a0..0ac4e90 100644
--- a/src/plugins/sensors/sensorfw/sensorfwaccelerometer.cpp
+++ b/src/plugins/sensors/sensorfw/sensorfwaccelerometer.cpp
@@ -74,6 +74,7 @@ void sensorfwaccelerometer::slotFrameAvailable(const QVector<XYZ>& frame)
bool sensorfwaccelerometer::doConnect()
{
+ Q_ASSERT(m_sensorInterface);
if (m_bufferSize==1)
return QObject::connect(m_sensorInterface, SIGNAL(dataAvailable(XYZ)), this, SLOT(slotDataAvailable(XYZ)));
return QObject::connect(m_sensorInterface, SIGNAL(frameAvailable(QVector<XYZ>)),this, SLOT(slotFrameAvailable(QVector<XYZ>)));
@@ -96,3 +97,10 @@ void sensorfwaccelerometer::init()
m_initDone = false;
initSensor<AccelerometerSensorChannelInterface>(m_initDone);
}
+
+void sensorfwaccelerometer::start()
+{
+ if (reinitIsNeeded)
+ init();
+ SensorfwSensorBase::start();
+}
diff --git a/src/plugins/sensors/sensorfw/sensorfwaccelerometer.h b/src/plugins/sensors/sensorfw/sensorfwaccelerometer.h
index e0e84cc..e3ded24 100644
--- a/src/plugins/sensors/sensorfw/sensorfwaccelerometer.h
+++ b/src/plugins/sensors/sensorfw/sensorfwaccelerometer.h
@@ -60,6 +60,7 @@ protected:
bool doConnect() Q_DECL_OVERRIDE;
QString sensorName() const Q_DECL_OVERRIDE;
qreal correctionFactor() const Q_DECL_OVERRIDE;
+ void start() Q_DECL_OVERRIDE;
virtual void init();
private:
diff --git a/src/plugins/sensors/sensorfw/sensorfwals.cpp b/src/plugins/sensors/sensorfw/sensorfwals.cpp
index 0de7e71..a061f14 100644
--- a/src/plugins/sensors/sensorfw/sensorfwals.cpp
+++ b/src/plugins/sensors/sensorfw/sensorfwals.cpp
@@ -59,6 +59,8 @@ Sensorfwals::Sensorfwals(QSensor *sensor)
void Sensorfwals::start()
{
+ if (reinitIsNeeded)
+ init();
if (m_sensorInterface) {
Unsigned data(((ALSSensorChannelInterface*)m_sensorInterface)->lux());
m_reading.setLightLevel(getLightLevel(data.x()));
@@ -81,6 +83,7 @@ void Sensorfwals::slotDataAvailable(const Unsigned& data)
bool Sensorfwals::doConnect()
{
+ Q_ASSERT(m_sensorInterface);
return QObject::connect(m_sensorInterface, SIGNAL(ALSChanged(Unsigned)),
this, SLOT(slotDataAvailable(Unsigned)));
}
diff --git a/src/plugins/sensors/sensorfw/sensorfwcompass.cpp b/src/plugins/sensors/sensorfw/sensorfwcompass.cpp
index ad41cfe..d2f0288 100644
--- a/src/plugins/sensors/sensorfw/sensorfwcompass.cpp
+++ b/src/plugins/sensors/sensorfw/sensorfwcompass.cpp
@@ -70,6 +70,7 @@ void SensorfwCompass::slotDataAvailable(const Compass& data)
bool SensorfwCompass::doConnect()
{
+ Q_ASSERT(m_sensorInterface);
return QObject::connect(m_sensorInterface, SIGNAL(dataAvailable(Compass)),
this, SLOT(slotDataAvailable(Compass)));
}
@@ -84,3 +85,10 @@ void SensorfwCompass::init()
m_initDone = false;
initSensor<CompassSensorChannelInterface>(m_initDone);
}
+
+void SensorfwCompass::start()
+{
+ if (reinitIsNeeded)
+ init();
+ SensorfwSensorBase::start();
+}
diff --git a/src/plugins/sensors/sensorfw/sensorfwcompass.h b/src/plugins/sensors/sensorfw/sensorfwcompass.h
index 951435c..aa8e3bd 100644
--- a/src/plugins/sensors/sensorfw/sensorfwcompass.h
+++ b/src/plugins/sensors/sensorfw/sensorfwcompass.h
@@ -59,6 +59,7 @@ public:
protected:
bool doConnect() Q_DECL_OVERRIDE;
QString sensorName() const Q_DECL_OVERRIDE;
+ void start() Q_DECL_OVERRIDE;
virtual void init();
private:
QCompassReading m_reading;
diff --git a/src/plugins/sensors/sensorfw/sensorfwgyroscope.cpp b/src/plugins/sensors/sensorfw/sensorfwgyroscope.cpp
index deca190..f802d0d 100644
--- a/src/plugins/sensors/sensorfw/sensorfwgyroscope.cpp
+++ b/src/plugins/sensors/sensorfw/sensorfwgyroscope.cpp
@@ -75,6 +75,7 @@ void SensorfwGyroscope::slotFrameAvailable(const QVector<XYZ>& frame)
bool SensorfwGyroscope::doConnect()
{
+ Q_ASSERT(m_sensorInterface);
if (m_bufferSize==1)
return QObject::connect(m_sensorInterface, SIGNAL(dataAvailable(XYZ)), this, SLOT(slotDataAvailable(XYZ)));
return QObject::connect(m_sensorInterface, SIGNAL(frameAvailable(QVector<XYZ>)),this, SLOT(slotFrameAvailable(QVector<XYZ>)));
@@ -95,3 +96,10 @@ void SensorfwGyroscope::init()
m_initDone = false;
initSensor<GyroscopeSensorChannelInterface>(m_initDone);
}
+
+void SensorfwGyroscope::start()
+{
+ if (reinitIsNeeded)
+ init();
+ SensorfwSensorBase::start();
+}
diff --git a/src/plugins/sensors/sensorfw/sensorfwgyroscope.h b/src/plugins/sensors/sensorfw/sensorfwgyroscope.h
index f489bf6..bfbad62 100644
--- a/src/plugins/sensors/sensorfw/sensorfwgyroscope.h
+++ b/src/plugins/sensors/sensorfw/sensorfwgyroscope.h
@@ -62,6 +62,7 @@ protected:
bool doConnect() Q_DECL_OVERRIDE;
QString sensorName() const Q_DECL_OVERRIDE;
qreal correctionFactor() const Q_DECL_OVERRIDE;
+ void start() Q_DECL_OVERRIDE;
virtual void init();
private:
diff --git a/src/plugins/sensors/sensorfw/sensorfwirproximitysensor.cpp b/src/plugins/sensors/sensorfw/sensorfwirproximitysensor.cpp
index 4207735..145276e 100644
--- a/src/plugins/sensors/sensorfw/sensorfwirproximitysensor.cpp
+++ b/src/plugins/sensors/sensorfw/sensorfwirproximitysensor.cpp
@@ -67,6 +67,7 @@ void SensorfwIrProximitySensor::slotDataAvailable(const Proximity& proximity)
bool SensorfwIrProximitySensor::doConnect()
{
+ Q_ASSERT(m_sensorInterface);
return QObject::connect(m_sensorInterface, SIGNAL(reflectanceDataAvailable(Proximity)),
this, SLOT(slotDataAvailable(Proximity)));
}
@@ -83,3 +84,10 @@ void SensorfwIrProximitySensor::init()
m_initDone = false;
initSensor<ProximitySensorChannelInterface>(m_initDone);
}
+
+void SensorfwIrProximitySensor::start()
+{
+ if (reinitIsNeeded)
+ init();
+ SensorfwSensorBase::start();
+}
diff --git a/src/plugins/sensors/sensorfw/sensorfwirproximitysensor.h b/src/plugins/sensors/sensorfw/sensorfwirproximitysensor.h
index 642570d..3c176ff 100644
--- a/src/plugins/sensors/sensorfw/sensorfwirproximitysensor.h
+++ b/src/plugins/sensors/sensorfw/sensorfwirproximitysensor.h
@@ -58,6 +58,7 @@ public:
protected:
bool doConnect() Q_DECL_OVERRIDE;
QString sensorName() const Q_DECL_OVERRIDE;
+ void start() Q_DECL_OVERRIDE;
virtual void init();
private:
QIRProximityReading m_reading;
diff --git a/src/plugins/sensors/sensorfw/sensorfwlightsensor.cpp b/src/plugins/sensors/sensorfw/sensorfwlightsensor.cpp
index 6607433..dda87ea 100644
--- a/src/plugins/sensors/sensorfw/sensorfwlightsensor.cpp
+++ b/src/plugins/sensors/sensorfw/sensorfwlightsensor.cpp
@@ -61,6 +61,7 @@ void SensorfwLightSensor::slotDataAvailable(const Unsigned& data)
bool SensorfwLightSensor::doConnect()
{
+ Q_ASSERT(m_sensorInterface);
return QObject::connect(m_sensorInterface, SIGNAL(ALSChanged(Unsigned)),
this, SLOT(slotDataAvailable(Unsigned)));
}
@@ -75,3 +76,10 @@ void SensorfwLightSensor::init()
m_initDone = false;
initSensor<ALSSensorChannelInterface>(m_initDone);
}
+
+void SensorfwLightSensor::start()
+{
+ if (reinitIsNeeded)
+ init();
+ SensorfwSensorBase::start();
+}
diff --git a/src/plugins/sensors/sensorfw/sensorfwlightsensor.h b/src/plugins/sensors/sensorfw/sensorfwlightsensor.h
index 244f795..911ec55 100644
--- a/src/plugins/sensors/sensorfw/sensorfwlightsensor.h
+++ b/src/plugins/sensors/sensorfw/sensorfwlightsensor.h
@@ -59,6 +59,7 @@ public:
protected:
bool doConnect() Q_DECL_OVERRIDE;
QString sensorName() const Q_DECL_OVERRIDE;
+ void start() Q_DECL_OVERRIDE;
virtual void init();
private:
QLightReading m_reading;
diff --git a/src/plugins/sensors/sensorfw/sensorfwmagnetometer.cpp b/src/plugins/sensors/sensorfw/sensorfwmagnetometer.cpp
index 10b1afe..913d301 100644
--- a/src/plugins/sensors/sensorfw/sensorfwmagnetometer.cpp
+++ b/src/plugins/sensors/sensorfw/sensorfwmagnetometer.cpp
@@ -59,6 +59,8 @@ SensorfwMagnetometer::SensorfwMagnetometer(QSensor *sensor)
void SensorfwMagnetometer::start()
{
+ if (reinitIsNeeded)
+ init();
QMagnetometer *const magnetometer = qobject_cast<QMagnetometer *>(sensor());
if (magnetometer)
m_isGeoMagnetometer = magnetometer->returnGeoValues();
@@ -86,6 +88,7 @@ void SensorfwMagnetometer::slotFrameAvailable(const QVector<MagneticField>& fram
bool SensorfwMagnetometer::doConnect()
{
+ Q_ASSERT(m_sensorInterface);
if (m_bufferSize==1)
return QObject::connect(m_sensorInterface, SIGNAL(dataAvailable(MagneticField)),
this, SLOT(slotDataAvailable(MagneticField)));
diff --git a/src/plugins/sensors/sensorfw/sensorfworientationsensor.cpp b/src/plugins/sensors/sensorfw/sensorfworientationsensor.cpp
index b45b731..722d61b 100644
--- a/src/plugins/sensors/sensorfw/sensorfworientationsensor.cpp
+++ b/src/plugins/sensors/sensorfw/sensorfworientationsensor.cpp
@@ -57,6 +57,8 @@ SensorfwOrientationSensor::SensorfwOrientationSensor(QSensor *sensor)
void SensorfwOrientationSensor::start()
{
+ if (reinitIsNeeded)
+ init();
if (m_sensorInterface) {
Unsigned data(((OrientationSensorChannelInterface*)m_sensorInterface)->orientation());
m_reading.setOrientation(SensorfwOrientationSensor::getOrientation(data.x()));
@@ -76,6 +78,7 @@ void SensorfwOrientationSensor::slotDataAvailable(const Unsigned& data)
bool SensorfwOrientationSensor::doConnect()
{
+ Q_ASSERT(m_sensorInterface);
return QObject::connect(m_sensorInterface, SIGNAL(orientationChanged(Unsigned)),
this, SLOT(slotDataAvailable(Unsigned)));
}
diff --git a/src/plugins/sensors/sensorfw/sensorfwproximitysensor.cpp b/src/plugins/sensors/sensorfw/sensorfwproximitysensor.cpp
index 76ce38d..8f949ff 100644
--- a/src/plugins/sensors/sensorfw/sensorfwproximitysensor.cpp
+++ b/src/plugins/sensors/sensorfw/sensorfwproximitysensor.cpp
@@ -45,8 +45,8 @@ char const * const SensorfwProximitySensor::id("sensorfw.proximitysensor");
SensorfwProximitySensor::SensorfwProximitySensor(QSensor *sensor)
: SensorfwSensorBase(sensor),
- m_exClose(false),
m_initDone(false),
+ m_exClose(false),
firstRun(true)
{
init();
@@ -57,6 +57,8 @@ SensorfwProximitySensor::SensorfwProximitySensor(QSensor *sensor)
void SensorfwProximitySensor::start()
{
+ if (reinitIsNeeded)
+ init();
SensorfwSensorBase::start();
}
@@ -75,6 +77,7 @@ 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))));
}
diff --git a/src/plugins/sensors/sensorfw/sensorfwrotationsensor.cpp b/src/plugins/sensors/sensorfw/sensorfwrotationsensor.cpp
index c0ba069..87d547c 100644
--- a/src/plugins/sensors/sensorfw/sensorfwrotationsensor.cpp
+++ b/src/plugins/sensors/sensorfw/sensorfwrotationsensor.cpp
@@ -71,6 +71,7 @@ void SensorfwRotationSensor::slotFrameAvailable(const QVector<XYZ>& frame)
bool SensorfwRotationSensor::doConnect()
{
+ Q_ASSERT(m_sensorInterface);
if (m_bufferSize==1)
return QObject::connect(m_sensorInterface, SIGNAL(dataAvailable(XYZ)), this, SLOT(slotDataAvailable(XYZ)));
return QObject::connect(m_sensorInterface, SIGNAL(frameAvailable(QVector<XYZ>)),this, SLOT(slotFrameAvailable(QVector<XYZ>)));
@@ -86,3 +87,10 @@ void SensorfwRotationSensor::init()
m_initDone = false;
initSensor<RotationSensorChannelInterface>(m_initDone);
}
+
+void SensorfwRotationSensor::start()
+{
+ if (reinitIsNeeded)
+ init();
+ SensorfwSensorBase::start();
+}
diff --git a/src/plugins/sensors/sensorfw/sensorfwrotationsensor.h b/src/plugins/sensors/sensorfw/sensorfwrotationsensor.h
index dd41520..944d2c1 100644
--- a/src/plugins/sensors/sensorfw/sensorfwrotationsensor.h
+++ b/src/plugins/sensors/sensorfw/sensorfwrotationsensor.h
@@ -61,6 +61,7 @@ public:
protected:
bool doConnect() Q_DECL_OVERRIDE;
QString sensorName() const Q_DECL_OVERRIDE;
+ void start() Q_DECL_OVERRIDE;
virtual void init();
private:
QRotationReading m_reading;
diff --git a/src/plugins/sensors/sensorfw/sensorfwsensorbase.cpp b/src/plugins/sensors/sensorfw/sensorfwsensorbase.cpp
index 299c20e..b8e4077 100644
--- a/src/plugins/sensors/sensorfw/sensorfwsensorbase.cpp
+++ b/src/plugins/sensors/sensorfw/sensorfwsensorbase.cpp
@@ -56,6 +56,7 @@ SensorfwSensorBase::SensorfwSensorBase(QSensor *sensor)
: QSensorBackend(sensor),
m_sensorInterface(0),
m_bufferSize(-1),
+ reinitIsNeeded(false),
m_prevOutputRange(0),
m_efficientBufferSize(1),
m_maxBufferSize(1),
@@ -214,9 +215,16 @@ qreal SensorfwSensorBase::correctionFactor() const
void SensorfwSensorBase::connectToSensord()
{
m_remoteSensorManager = &SensorManagerInterface::instance();
+ if (!m_remoteSensorManager->isValid()) {
+ qWarning() << "SensorManagerInterface is invalid";
+ m_remoteSensorManager = 0;
+ return;
+ }
if (running) {
stop();
+ reinitIsNeeded = true;
start();
+ reinitIsNeeded = false;
}
}
@@ -225,3 +233,68 @@ void SensorfwSensorBase::sensordUnregistered()
m_bufferSize = -1;
}
+bool SensorfwSensorBase::initSensorInterface(QString const &name)
+{
+ if (!m_sensorInterface) {
+ sensorError(KErrNotFound);
+ return false;
+ }
+
+ //metadata
+ const QList<DataRange> intervals = m_sensorInterface->getAvailableIntervals();
+
+ for (int i = 0, l = intervals.size(); i < l; i++) {
+ qreal intervalMax = intervals.at(i).max;
+ qreal intervalMin = intervals.at(i).min;
+
+ if (intervalMin == 0 && intervalMax == 0) {
+ // 0 interval has different meanings in e.g. magge/acce
+ // magge -> best-effort
+ // acce -> lowest possible
+ // in Qt API setting 0 means default
+ continue;
+ }
+
+ qreal rateMin = intervalMax < 1 ? 1 : 1 / intervalMax * 1000;
+ rateMin = rateMin < 1 ? 1 : rateMin;
+
+ intervalMin = intervalMin < 1 ? 10: intervalMin; // do not divide with 0
+ qreal rateMax = 1 / intervalMin * 1000;
+ addDataRate(rateMin, rateMax);
+ }
+
+ //bufferSizes
+ if (m_bufferingSensors.contains(sensor()->identifier())) {
+
+ IntegerRangeList sizes = m_sensorInterface->getAvailableBufferSizes();
+ for (int i = 0; i < sizes.size(); i++) {
+ int second = sizes.at(i).second;
+ m_maxBufferSize = second > m_bufferSize ? second : m_maxBufferSize;
+ }
+ m_maxBufferSize = m_maxBufferSize < 0 ? 1 : m_maxBufferSize;
+ //SensorFW guarantees to provide the most efficient size first
+ //TODO: remove from comments
+ //m_efficientBufferSize = m_sensorInterface->hwBuffering()? (l>0?sizes.at(0).first:1) : 1;
+ } else {
+ m_maxBufferSize = 1;
+ }
+
+ sensor()->setMaxBufferSize(m_maxBufferSize);
+ sensor()->setEfficientBufferSize(m_efficientBufferSize);
+
+ // TODO deztructor: Leaking abstraction detected. Just copied code
+ // from initSensor<>() here, need to
+ QByteArray type = sensor()->type();
+ if ((type == QAmbientLightSensor::type) // SensorFW returns lux values, plugin enumerated values
+ || (type == QIRProximitySensor::type) // SensorFW returns raw reflectance values, plugin % of max reflectance
+ || (name == "accelerometersensor") // SensorFW returns milliGs, plugin m/s^2
+ || (name == "magnetometersensor") // SensorFW returns nanoTeslas, plugin Teslas
+ || (name == "gyroscopesensor")) // SensorFW returns DSPs, plugin milliDSPs
+ return true;
+
+ setDescription(m_sensorInterface->description());
+
+ if (name == "tapsensor") return true;
+ setRanges();
+ return true;
+}
diff --git a/src/plugins/sensors/sensorfw/sensorfwsensorbase.h b/src/plugins/sensors/sensorfw/sensorfwsensorbase.h
index 769a8cb..39e4147 100644
--- a/src/plugins/sensors/sensorfw/sensorfwsensorbase.h
+++ b/src/plugins/sensors/sensorfw/sensorfwsensorbase.h
@@ -77,10 +77,13 @@ protected:
template<typename T>
void initSensor(bool &initDone)
{
-
const QString name = sensorName();
if (!initDone) {
+ if (!m_remoteSensorManager) {
+ qDebug() << "There is no sensor manager yet, do not initialize" << name;
+ return;
+ }
if (!m_remoteSensorManager->loadPlugin(name)) {
sensorError(KErrNotFound);
return;
@@ -91,71 +94,7 @@ protected:
if (!m_sensorInterface) {
m_sensorInterface = const_cast<T*>(T::listenInterface(name));
}
- if (!m_sensorInterface) {
- sensorError(KErrNotFound);
- return;
- }
- if (!m_sensorInterface) {
- sensorError(KErrNotFound);
- return;
- }
-
- initDone = true;
-
- //metadata
- QList<DataRange> intervals = m_sensorInterface->getAvailableIntervals();
-
- for (int i = 0, l = intervals.size(); i < l; i++) {
- qreal intervalMax = ((DataRange)(intervals.at(i))).max;
- qreal intervalMin =((DataRange)(intervals.at(i))).min;
-
- if (intervalMin == 0 && intervalMax == 0) {
- // 0 interval has different meanings in e.g. magge/acce
- // magge -> best-effort
- // acce -> lowest possible
- // in Qt API setting 0 means default
- continue;
- }
-
- qreal rateMin = intervalMax < 1 ? 1 : 1 / intervalMax * 1000;
- rateMin = rateMin < 1 ? 1 : rateMin;
-
- intervalMin = intervalMin < 1 ? 10: intervalMin; // do not divide with 0
- qreal rateMax = 1 / intervalMin * 1000;
- addDataRate(rateMin, rateMax);
- }
-
- //bufferSizes
- if (m_bufferingSensors.contains(sensor()->identifier())) {
-
- IntegerRangeList sizes = m_sensorInterface->getAvailableBufferSizes();
- int l = sizes.size();
- for (int i = 0; i < l; i++) {
- int second = sizes.at(i).second;
- m_maxBufferSize = second > m_bufferSize ? second : m_maxBufferSize;
- }
- m_maxBufferSize = m_maxBufferSize < 0 ? 1 : m_maxBufferSize;
- //SensorFW guarantees to provide the most efficient size first
- //TODO: remove from comments
- //m_efficientBufferSize = m_sensorInterface->hwBuffering()? (l>0?sizes.at(0).first:1) : 1;
- }
- else
- m_maxBufferSize = 1;
-
- sensor()->setMaxBufferSize(m_maxBufferSize);
- sensor()->setEfficientBufferSize(m_efficientBufferSize);
-
- QByteArray type = sensor()->type();
- if (type == QAmbientLightSensor::type) return; // SensorFW returns lux values, plugin enumerated values
- if (type == QIRProximitySensor::type) return; // SensorFW returns raw reflectance values, plugin % of max reflectance
- if (name == "accelerometersensor") return; // SensorFW returns milliGs, plugin m/s^2
- if (name == "magnetometersensor") return; // SensorFW returns nanoTeslas, plugin Teslas
- if (name == "gyroscopesensor") return; // SensorFW returns DSPs, plugin milliDSPs
-
- setDescription(m_sensorInterface->description());
-
- if (name == "tapsensor") return;
- setRanges();
+ initDone = initSensorInterface(name);
};
@@ -163,9 +102,10 @@ protected:
int m_bufferSize;
int bufferSize() const;
virtual qreal correctionFactor() const;
+ bool reinitIsNeeded;
private:
-
+ bool initSensorInterface(QString const &);
static SensorManagerInterface* m_remoteSensorManager;
int m_prevOutputRange;
bool doConnectAfterCheck();
diff --git a/src/plugins/sensors/sensorfw/sensorfwtapsensor.cpp b/src/plugins/sensors/sensorfw/sensorfwtapsensor.cpp
index 1d7e950..01ee778 100644
--- a/src/plugins/sensors/sensorfw/sensorfwtapsensor.cpp
+++ b/src/plugins/sensors/sensorfw/sensorfwtapsensor.cpp
@@ -45,8 +45,8 @@ char const * const SensorfwTapSensor::id("sensorfw.tapsensor");
SensorfwTapSensor::SensorfwTapSensor(QSensor *sensor)
: SensorfwSensorBase(sensor),
+ m_initDone(false),
m_isOnceStarted(false)
- , m_initDone(false)
{
init();
setReading<QTapReading>(&m_reading);
@@ -58,6 +58,9 @@ SensorfwTapSensor::SensorfwTapSensor(QSensor *sensor)
void SensorfwTapSensor::start()
{
+ if (reinitIsNeeded)
+ init();
+
QTapSensor * const tapSensor = qobject_cast<QTapSensor *>(sensor());
bool b = tapSensor->returnDoubleTapEvents();
@@ -68,9 +71,14 @@ void SensorfwTapSensor::start()
}
else m_isDoubleTapSensor = b;
- if (!m_isOnceStarted || (m_isOnceStarted && isDoubleTapSensor != m_isDoubleTapSensor))
- ((TapSensorChannelInterface*)m_sensorInterface)->
- setTapType(m_isDoubleTapSensor?TapSensorChannelInterface::Double:TapSensorChannelInterface::Single);
+ if (!m_isOnceStarted || (m_isOnceStarted && isDoubleTapSensor != m_isDoubleTapSensor)) {
+ TapSensorChannelInterface *iface = static_cast<TapSensorChannelInterface *>(m_sensorInterface);
+ if (!iface) {
+ qWarning() << "Sensor interface is not initialized";
+ return;
+ }
+ iface->setTapType(m_isDoubleTapSensor?TapSensorChannelInterface::Double:TapSensorChannelInterface::Single);
+ }
SensorfwSensorBase::start();
// Set tap type (single/double)
@@ -103,6 +111,7 @@ void SensorfwTapSensor::slotDataAvailable(const Tap& data)
bool SensorfwTapSensor::doConnect()
{
+ Q_ASSERT(m_sensorInterface);
return QObject::connect(m_sensorInterface, SIGNAL(dataAvailable(Tap)),
this, SLOT(slotDataAvailable(Tap)));
}
diff --git a/src/sensors/qcompass.cpp b/src/sensors/qcompass.cpp
index 6564d36..468668f 100644
--- a/src/sensors/qcompass.cpp
+++ b/src/sensors/qcompass.cpp
@@ -75,7 +75,7 @@ IMPLEMENT_READING(QCompassReading)
\property QCompassReading::azimuth
\brief the azimuth of the device.
- Measured in degrees from magnetic north in a clockwise direction based
+ Measured in degrees from magnetic north in a clockwise direction based on
the top of the device, as defined by QPlatformScreen::nativeOrientation.
\sa {QCompassReading Units}
*/
diff --git a/src/sensors/qsensormanager.cpp b/src/sensors/qsensormanager.cpp
index 29bd4b5..abe5f85 100644
--- a/src/sensors/qsensormanager.cpp
+++ b/src/sensors/qsensormanager.cpp
@@ -48,12 +48,15 @@
#include "sensorlog_p.h"
#include <QTimer>
#include <QFile>
+#include <QLoggingCategory>
QT_BEGIN_NAMESPACE
typedef QHash<QByteArray,QSensorBackendFactory*> FactoryForIdentifierMap;
typedef QHash<QByteArray,FactoryForIdentifierMap> BackendIdentifiersForTypeMap;
+static QLoggingCategory sensorsCategory("qt.sensors");
+
class QSensorManagerPrivate : public QObject
{
friend class QSensorManager;
@@ -77,7 +80,6 @@ public:
loadExternalPlugins = false;
}
}
-
bool loadExternalPlugins;
PluginLoadingState pluginLoadingState;
QFactoryLoader *loader;
@@ -101,9 +103,16 @@ public:
if (config.isEmpty()) return; // QStandardPaths is broken?
config += QLatin1String("/QtProject/Sensors.conf");
#endif
- if (!QFile::exists(config)) return;
+ qCDebug(sensorsCategory) << "Loading config from" << config;
+ if (!QFile::exists(config)) {
+ qCWarning(sensorsCategory) << "There is no config file" << config;
+ return;
+ }
QFile cfgfile(config);
- if (!cfgfile.open(QFile::ReadOnly)) return;
+ if (!cfgfile.open(QFile::ReadOnly)) {
+ qCWarning(sensorsCategory) << "Can't open config file" << config;
+ return;
+ }
QTextStream stream(&cfgfile);
QString line;
@@ -169,13 +178,19 @@ Q_GLOBAL_STATIC(QSensorManagerPrivate, sensorManagerPrivate)
static void initPlugin(QObject *o)
{
- if (!o) return;
+ qCDebug(sensorsCategory) << "Init plugin" << o;
+ if (!o) {
+ qCWarning(sensorsCategory) << "Null plugin" << o;
+ return;
+ }
QSensorManagerPrivate *d = sensorManagerPrivate();
if (!d) return; // hardly likely but just in case...
- if (d->seenPlugins.contains(o))
+ if (d->seenPlugins.contains(o)) {
+ qCDebug(sensorsCategory) << "Plugin is seen" << o;
return;
+ }
QSensorChangesInterface *changes = qobject_cast<QSensorChangesInterface*>(o);
if (changes)
@@ -184,8 +199,11 @@ static void initPlugin(QObject *o)
QSensorPluginInterface *plugin = qobject_cast<QSensorPluginInterface*>(o);
if (plugin) {
+ qCDebug(sensorsCategory) << "Register sensors for " << plugin;
d->seenPlugins.insert(o);
plugin->registerSensors();
+ } else {
+ qCWarning(sensorsCategory) << "Can't cast to plugin" << o;
}
}