summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@digia.com>2014-08-18 15:25:35 +0200
committerFrederik Gladhorn <frederik.gladhorn@digia.com>2014-08-18 15:25:35 +0200
commit556d900877811c985bcd671d407bb50ccc7a3858 (patch)
tree4cbb1797c00918aa6fa1e71edb2335da039c960d
parent96efb156c0b0af3d2b2a549165245182073f2b05 (diff)
parent15e924486a410780fefbc5a95fae8886e3190925 (diff)
downloadqtsensors-556d900877811c985bcd671d407bb50ccc7a3858.tar.gz
Merge remote-tracking branch 'origin/5.4' into dev
Change-Id: I4a589c2f9005f6bfd9242e335387ec690e97210a
-rw-r--r--src/plugins/sensors/android/jar/src/org/qtproject/qt5/android/sensors/QtSensors.java19
-rw-r--r--src/plugins/sensors/android/src/androidcompass.cpp173
-rw-r--r--src/plugins/sensors/android/src/androidcompass.h76
-rw-r--r--src/plugins/sensors/android/src/androidjnisensors.cpp16
-rw-r--r--src/plugins/sensors/android/src/androidjnisensors.h1
-rw-r--r--src/plugins/sensors/android/src/main.cpp11
-rw-r--r--src/plugins/sensors/android/src/src.pro2
-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.cpp7
-rw-r--r--src/sensors/qsensormanager.cpp28
28 files changed, 485 insertions, 80 deletions
diff --git a/src/plugins/sensors/android/jar/src/org/qtproject/qt5/android/sensors/QtSensors.java b/src/plugins/sensors/android/jar/src/org/qtproject/qt5/android/sensors/QtSensors.java
index efd1ff6..e7e309e 100644
--- a/src/plugins/sensors/android/jar/src/org/qtproject/qt5/android/sensors/QtSensors.java
+++ b/src/plugins/sensors/android/jar/src/org/qtproject/qt5/android/sensors/QtSensors.java
@@ -153,6 +153,25 @@ public class QtSensors implements SensorEventListener
return angles;
}
+ private static float[] mRotation = new float[9];
+ private static float[] mOrientation = new float[3];
+ private static float[] mAcc = new float[3];
+ private static float[] mMag = new float[3];
+
+ private static float getCompassAzimuth(float a0, float a1, float a2, float m0, float m1, float m2)
+ {
+ mAcc[0] = a0;
+ mAcc[1] = a1;
+ mAcc[2] = a2;
+ mMag[0] = m0;
+ mMag[1] = m1;
+ mMag[2] = m2;
+
+ SensorManager.getRotationMatrix(mRotation, null, mAcc, mMag);
+ SensorManager.getOrientation(mRotation, mOrientation);
+ return mOrientation[0];
+ }
+
public static native void accuracyChanged(int sensorType, int accuracy);
public static native void sensorChanged(int sensorType, long timestamp, float[] values);
diff --git a/src/plugins/sensors/android/src/androidcompass.cpp b/src/plugins/sensors/android/src/androidcompass.cpp
new file mode 100644
index 0000000..f2b4bd2
--- /dev/null
+++ b/src/plugins/sensors/android/src/androidcompass.cpp
@@ -0,0 +1,173 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtSensors module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "androidcompass.h"
+
+#include <QDebug>
+#include <qmath.h>
+#include "androidjnisensors.h"
+
+
+class AndroidAccelerometerListener : public AndroidSensors::AndroidSensorsListenerInterface
+{
+public:
+
+ AndroidAccelerometerListener(AndroidCompass *parent)
+ : m_compass(parent)
+ {
+ }
+
+ void start(int dataRate)
+ {
+ AndroidSensors::registerListener(AndroidSensors::TYPE_ACCELEROMETER, this, dataRate);
+ }
+
+ void stop()
+ {
+ AndroidSensors::unregisterListener(AndroidSensors::TYPE_ACCELEROMETER, this);
+ }
+
+ void onAccuracyChanged(jint accuracy) Q_DECL_OVERRIDE
+ {
+ Q_UNUSED(accuracy);
+ }
+
+ void onSensorChanged(jlong /*timestamp*/, const jfloat *values, uint size) Q_DECL_OVERRIDE
+ {
+ if (size < 3)
+ return;
+ reading[0] = values[0];
+ reading[1] = values[1];
+ reading[2] = values[2];
+ m_compass->testStuff();
+ }
+
+ jfloat reading[3];
+
+private:
+ AndroidCompass *m_compass;
+};
+
+class AndroidMagnetometerListener : public AndroidSensors::AndroidSensorsListenerInterface
+{
+public:
+ AndroidMagnetometerListener(AndroidCompass *parent)
+ :m_compass(parent)
+ {
+
+ }
+
+ void start(int dataRate)
+ {
+ AndroidSensors::registerListener(AndroidSensors::TYPE_MAGNETIC_FIELD, this, dataRate);
+ }
+
+ void stop()
+ {
+ AndroidSensors::unregisterListener(AndroidSensors::TYPE_MAGNETIC_FIELD, this);
+ }
+
+ void onAccuracyChanged(jint accuracy) Q_DECL_OVERRIDE
+ {
+ Q_UNUSED(accuracy);
+ }
+
+ void onSensorChanged(jlong /*timestamp*/, const jfloat *values, uint size) Q_DECL_OVERRIDE
+ {
+ if (size < 3)
+ return;
+ reading[0] = values[0];
+ reading[1] = values[1];
+ reading[2] = values[2];
+ m_compass->testStuff();
+ }
+
+ jfloat reading[3];
+private:
+ AndroidCompass *m_compass;
+};
+
+char const * const AndroidCompass::id("android.synthetic.compass");
+
+AndroidCompass::AndroidCompass(QSensor *sensor)
+ : QSensorBackend(sensor), m_accelerometerListener(0), m_magnetometerListener(0), m_isStarted(false)
+{
+ setReading<QCompassReading>(&m_reading);
+ m_isStarted = false;
+}
+
+AndroidCompass::~AndroidCompass()
+{
+ if (m_isStarted)
+ stop();
+ delete m_accelerometerListener;
+ delete m_magnetometerListener;
+}
+
+void AndroidCompass::start()
+{
+ if (!m_accelerometerListener)
+ m_accelerometerListener = new AndroidAccelerometerListener(this);
+ m_accelerometerListener->start(sensor()->dataRate());
+ if (!m_magnetometerListener)
+ m_magnetometerListener = new AndroidMagnetometerListener(this);
+ m_magnetometerListener->start(sensor()->dataRate());
+
+ m_isStarted = true;
+}
+
+void AndroidCompass::stop()
+{
+ if (m_isStarted) {
+ m_isStarted = false;
+ m_accelerometerListener->stop();
+ m_magnetometerListener->stop();
+ }
+}
+
+void AndroidCompass::testStuff()
+{
+ qreal azimuth = AndroidSensors::getCompassAzimuth(m_accelerometerListener->reading, m_magnetometerListener->reading);
+
+ azimuth = azimuth * 180.0 / M_PI;
+ m_reading.setAzimuth(azimuth);
+ newReadingAvailable();
+}
diff --git a/src/plugins/sensors/android/src/androidcompass.h b/src/plugins/sensors/android/src/androidcompass.h
new file mode 100644
index 0000000..897dd46
--- /dev/null
+++ b/src/plugins/sensors/android/src/androidcompass.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtSensors module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ANDROIDCOMPASS_H
+#define ANDROIDCOMPASS_H
+#include <qcompass.h>
+
+#include "androidcommonsensor.h"
+
+class AndroidAccelerometerListener;
+class AndroidMagnetometerListener;
+
+class AndroidCompass : public QSensorBackend
+{
+ Q_OBJECT
+
+public:
+ static char const * const id;
+
+ AndroidCompass(QSensor *sensor);
+ ~AndroidCompass();
+
+ void start() Q_DECL_OVERRIDE;
+ void stop() Q_DECL_OVERRIDE;
+
+private:
+ AndroidAccelerometerListener *m_accelerometerListener;
+ AndroidMagnetometerListener *m_magnetometerListener;
+
+ QCompassReading m_reading;
+ bool m_isStarted;
+
+public Q_SLOTS:
+ void testStuff();
+
+};
+
+#endif // ANDROIDCOMPASS_H
diff --git a/src/plugins/sensors/android/src/androidjnisensors.cpp b/src/plugins/sensors/android/src/androidjnisensors.cpp
index 87889a8..9a7b671 100644
--- a/src/plugins/sensors/android/src/androidjnisensors.cpp
+++ b/src/plugins/sensors/android/src/androidjnisensors.cpp
@@ -54,6 +54,7 @@ static jmethodID registerSensorMethodId;
static jmethodID unregisterSensorMethodId;
static jmethodID getSensorDescriptionMethodId;
static jmethodID getSensorMaximumRangeMethodId;
+static jmethodID getCompassAzimuthId;
static QHash<int, QList<AndroidSensors::AndroidSensorsListenerInterface *> > listenersHash;
QReadWriteLock listenersLocker;
@@ -166,6 +167,20 @@ namespace AndroidSensors
}
return true;
}
+
+ qreal getCompassAzimuth(jfloat *accelerometerReading, jfloat *magnetometerReading)
+ {
+ AttachedJNIEnv aenv;
+ if (!aenv.jniEnv)
+ return 0.0;
+ return aenv.jniEnv->CallStaticFloatMethod(sensorsClass, getCompassAzimuthId,
+ accelerometerReading[0],
+ accelerometerReading[1],
+ accelerometerReading[2],
+ magnetometerReading[0],
+ magnetometerReading[1],
+ magnetometerReading[2]);
+ }
}
static const char logTag[] = "Qt";
@@ -227,6 +242,7 @@ static bool registerNatives(JNIEnv *env)
GET_AND_CHECK_STATIC_METHOD(unregisterSensorMethodId, sensorsClass, "unregisterSensor", "(I)Z");
GET_AND_CHECK_STATIC_METHOD(getSensorDescriptionMethodId, sensorsClass, "getSensorDescription", "(I)Ljava/lang/String;");
GET_AND_CHECK_STATIC_METHOD(getSensorMaximumRangeMethodId, sensorsClass, "getSensorMaximumRange", "(I)F");
+ GET_AND_CHECK_STATIC_METHOD(getCompassAzimuthId, sensorsClass, "getCompassAzimuth", "(FFFFFF)F");
return true;
}
diff --git a/src/plugins/sensors/android/src/androidjnisensors.h b/src/plugins/sensors/android/src/androidjnisensors.h
index 30aab6c..9d2ccf5 100644
--- a/src/plugins/sensors/android/src/androidjnisensors.h
+++ b/src/plugins/sensors/android/src/androidjnisensors.h
@@ -83,6 +83,7 @@ namespace AndroidSensors
qreal sensorMaximumRange(AndroidSensorType sensor);
bool registerListener(AndroidSensorType sensor, AndroidSensorsListenerInterface *listener, int dataRate = 0);
bool unregisterListener(AndroidSensorType sensor, AndroidSensorsListenerInterface *listener);
+ qreal getCompassAzimuth(jfloat *accelerometerReading, jfloat *magnetometerReading);
}
#endif // ANDROIDJNISENSORS_H
diff --git a/src/plugins/sensors/android/src/main.cpp b/src/plugins/sensors/android/src/main.cpp
index 3d8604f..b8d1496 100644
--- a/src/plugins/sensors/android/src/main.cpp
+++ b/src/plugins/sensors/android/src/main.cpp
@@ -44,7 +44,9 @@
#include <qsensorbackend.h>
#include <qsensormanager.h>
#include <qaccelerometer.h>
+#include <qcompass.h>
#include "androidaccelerometer.h"
+#include "androidcompass.h"
#include "androidgyroscope.h"
#include "androidlight.h"
#include "androidmagnetometer.h"
@@ -63,10 +65,13 @@ class AndroidSensorPlugin : public QObject, public QSensorPluginInterface, publi
public:
void registerSensors()
{
+ bool accelerometer = false;
+ bool magnetometer = false;
foreach (AndroidSensorType sensor, availableSensors()) {
switch (sensor) {
case TYPE_ACCELEROMETER:
QSensorManager::registerBackend(QAccelerometer::type, QByteArray::number(sensor), this);
+ accelerometer = true;
break;
case TYPE_AMBIENT_TEMPERATURE:
case TYPE_TEMPERATURE:
@@ -84,6 +89,7 @@ public:
break; // add the linear acceleration sensor backend
case TYPE_MAGNETIC_FIELD:
QSensorManager::registerBackend(QMagnetometer::type, QByteArray::number(sensor), this);
+ magnetometer = true;
break;
case TYPE_ORIENTATION:
break; // add the orientation sensor backend
@@ -106,10 +112,15 @@ public:
break; // add backends for API level 18 sensors
}
}
+ if (accelerometer && magnetometer)
+ QSensorManager::registerBackend(QCompass::type, AndroidCompass::id, this);
}
QSensorBackend *createBackend(QSensor *sensor)
{
+ if (sensor->identifier() == AndroidCompass::id)
+ return new AndroidCompass(sensor);
+
AndroidSensorType type = static_cast<AndroidSensorType>(sensor->identifier().toInt());
switch (type) {
case TYPE_ACCELEROMETER: {
diff --git a/src/plugins/sensors/android/src/src.pro b/src/plugins/sensors/android/src/src.pro
index 21423ef..23a6bea 100644
--- a/src/plugins/sensors/android/src/src.pro
+++ b/src/plugins/sensors/android/src/src.pro
@@ -12,6 +12,7 @@ DEFINES += QT_STATICPLUGIN
HEADERS = \
androidjnisensors.h \
androidaccelerometer.h \
+ androidcompass.h \
androidcommonsensor.h \
androidgyroscope.h \
androidmagnetometer.h \
@@ -25,6 +26,7 @@ SOURCES = \
main.cpp \
androidjnisensors.cpp \
androidaccelerometer.cpp \
+ androidcompass.cpp \
androidgyroscope.cpp \
androidmagnetometer.cpp \
androidpressure.cpp \
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 8bfca07..468668f 100644
--- a/src/sensors/qcompass.cpp
+++ b/src/sensors/qcompass.cpp
@@ -56,7 +56,8 @@ IMPLEMENT_READING(QCompassReading)
\section2 QCompassReading Units
The compass returns the azimuth of the device as degrees from
- magnetic north in a clockwise direction based on the top of the UI.
+ magnetic north in a clockwise direction based on the top of the device,
+ as defined by QPlatformScreen::nativeOrientation.
There is also a value to indicate the calibration status of the device.
If the device is not calibrated the azimuth may not be accurate.
@@ -74,8 +75,8 @@ IMPLEMENT_READING(QCompassReading)
\property QCompassReading::azimuth
\brief the azimuth of the device.
- Measured in degrees from magnetic north in a clockwise direction based
- the top of the UI.
+ 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;
}
}