summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorSergio Ahumada <sergio.ahumada@digia.com>2013-03-19 11:05:55 +0100
committerSergio Ahumada <sergio.ahumada@digia.com>2013-03-19 11:06:33 +0100
commit50c16eab20a6d9884ab3149ef59137a10de63e6d (patch)
tree2684617d911514147283516ddd15803a4049da61 /src/plugins
parentd2cafb8506b798bad7fa56f19557dd6e1cb25cd7 (diff)
parent879e5536b033302b2ad976750cd2351674e161d6 (diff)
Merge branch 'dev' into stable
This starts Qt 5.1 release cycle Change-Id: Idce0f9b94f9e585abfb6903f554500a06f4f8aaa
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/sensors/android/android.pro2
-rw-r--r--src/plugins/sensors/android/jar/AndroidManifest.xml6
-rw-r--r--src/plugins/sensors/android/jar/jar.pro10
-rw-r--r--src/plugins/sensors/android/jar/src/org/qtproject/qt5/android/sensors/QtSensors.java161
-rw-r--r--src/plugins/sensors/android/src/androidaccelerometer.cpp63
-rw-r--r--src/plugins/sensors/android/src/androidaccelerometer.h59
-rw-r--r--src/plugins/sensors/android/src/androidcommonsensor.h88
-rw-r--r--src/plugins/sensors/android/src/androidgyroscope.cpp64
-rw-r--r--src/plugins/sensors/android/src/androidgyroscope.h57
-rw-r--r--src/plugins/sensors/android/src/androidjnisensors.cpp245
-rw-r--r--src/plugins/sensors/android/src/androidjnisensors.h83
-rw-r--r--src/plugins/sensors/android/src/androidlight.cpp62
-rw-r--r--src/plugins/sensors/android/src/androidlight.h57
-rw-r--r--src/plugins/sensors/android/src/androidmagnetometer.cpp63
-rw-r--r--src/plugins/sensors/android/src/androidmagnetometer.h57
-rw-r--r--src/plugins/sensors/android/src/androidrotation.cpp65
-rw-r--r--src/plugins/sensors/android/src/androidrotation.h56
-rw-r--r--src/plugins/sensors/android/src/main.cpp135
-rw-r--r--src/plugins/sensors/android/src/plugin.json1
-rw-r--r--src/plugins/sensors/android/src/src.pro29
-rw-r--r--src/plugins/sensors/blackberry/bbaccelerometer.cpp38
-rw-r--r--src/plugins/sensors/blackberry/bbaccelerometer.h4
-rw-r--r--src/plugins/sensors/blackberry/bbaltimeter.cpp27
-rw-r--r--src/plugins/sensors/blackberry/bbaltimeter.h17
-rw-r--r--src/plugins/sensors/blackberry/bbcompass.cpp15
-rw-r--r--src/plugins/sensors/blackberry/bbholstersensor.cpp58
-rw-r--r--src/plugins/sensors/blackberry/bbholstersensor.h60
-rw-r--r--src/plugins/sensors/blackberry/bbmagnetometer.cpp34
-rw-r--r--src/plugins/sensors/blackberry/bborientationsensor.cpp16
-rw-r--r--src/plugins/sensors/blackberry/bborientationsensor.h1
-rw-r--r--src/plugins/sensors/blackberry/bbpressuresensor.cpp29
-rw-r--r--src/plugins/sensors/blackberry/bbpressuresensor.h19
-rw-r--r--src/plugins/sensors/blackberry/bbproximitysensor.cpp3
-rw-r--r--src/plugins/sensors/blackberry/bbsensorbackend.cpp166
-rw-r--r--src/plugins/sensors/blackberry/bbsensorbackend.h5
-rw-r--r--src/plugins/sensors/blackberry/bbtemperaturesensor.cpp27
-rw-r--r--src/plugins/sensors/blackberry/bbtemperaturesensor.h17
-rw-r--r--src/plugins/sensors/blackberry/blackberry.pro9
-rw-r--r--src/plugins/sensors/blackberry/main.cpp20
-rw-r--r--src/plugins/sensors/dummy/dummy.pro2
-rw-r--r--src/plugins/sensors/generic/generic.pro30
-rw-r--r--src/plugins/sensors/generic/genericrotationsensor.cpp4
-rw-r--r--src/plugins/sensors/generic/genericrotationsensor.h1
-rw-r--r--src/plugins/sensors/generic/generictiltsensor.cpp47
-rw-r--r--src/plugins/sensors/generic/generictiltsensor.h4
-rw-r--r--src/plugins/sensors/generic/main.cpp44
-rw-r--r--src/plugins/sensors/ios/ios.pro17
-rw-r--r--src/plugins/sensors/ios/iosaccelerometer.h71
-rw-r--r--src/plugins/sensors/ios/iosaccelerometer.mm143
-rw-r--r--src/plugins/sensors/ios/iosmotionmanager.h55
-rw-r--r--src/plugins/sensors/ios/iosmotionmanager.mm57
-rw-r--r--src/plugins/sensors/ios/main.mm70
-rw-r--r--src/plugins/sensors/ios/plugin.json1
-rw-r--r--src/plugins/sensors/linux/linux.pro2
-rw-r--r--src/plugins/sensors/sensorfw/Sensors.conf11
-rw-r--r--src/plugins/sensors/sensorfw/main.cpp109
-rw-r--r--src/plugins/sensors/sensorfw/plugin.json1
-rw-r--r--src/plugins/sensors/sensorfw/sensorfw.pri26
-rw-r--r--src/plugins/sensors/sensorfw/sensorfw.pro17
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwaccelerometer.cpp91
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwaccelerometer.h74
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwals.cpp111
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwals.h75
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwcompass.cpp80
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwcompass.h70
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwgyroscope.cpp90
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwgyroscope.h78
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwirproximitysensor.cpp81
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwirproximitysensor.h71
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwlightsensor.cpp71
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwlightsensor.h72
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwmagnetometer.cpp98
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwmagnetometer.h79
-rw-r--r--src/plugins/sensors/sensorfw/sensorfworientationsensor.cpp98
-rw-r--r--src/plugins/sensors/sensorfw/sensorfworientationsensor.h74
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwproximitysensor.cpp87
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwproximitysensor.h75
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwrotationsensor.cpp79
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwrotationsensor.h75
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwsensorbase.cpp189
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwsensorbase.h170
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwtapsensor.cpp110
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwtapsensor.h73
-rw-r--r--src/plugins/sensors/sensors.pro16
84 files changed, 4595 insertions, 232 deletions
diff --git a/src/plugins/sensors/android/android.pro b/src/plugins/sensors/android/android.pro
new file mode 100644
index 00000000..0dc6a3fc
--- /dev/null
+++ b/src/plugins/sensors/android/android.pro
@@ -0,0 +1,2 @@
+TEMPLATE = subdirs
+SUBDIRS += jar src
diff --git a/src/plugins/sensors/android/jar/AndroidManifest.xml b/src/plugins/sensors/android/jar/AndroidManifest.xml
new file mode 100644
index 00000000..5d15cab2
--- /dev/null
+++ b/src/plugins/sensors/android/jar/AndroidManifest.xml
@@ -0,0 +1,6 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="org.qtproject.qt5.android.sensors"
+ android:versionCode="1"
+ android:versionName="1.0" >
+ <supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/>
+</manifest>
diff --git a/src/plugins/sensors/android/jar/jar.pro b/src/plugins/sensors/android/jar/jar.pro
new file mode 100644
index 00000000..a9350743
--- /dev/null
+++ b/src/plugins/sensors/android/jar/jar.pro
@@ -0,0 +1,10 @@
+load(qt_build_paths)
+
+CONFIG += java
+TARGET = QtSensors
+DESTDIR = $$MODULE_BASE_OUTDIR/jar
+
+JAVACLASSPATH += $$PWD/src
+
+JAVASOURCES += \
+ $$PWD/src/org/qtproject/qt5/android/sensors/QtSensors.java
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
new file mode 100644
index 00000000..c7956d2d
--- /dev/null
+++ b/src/plugins/sensors/android/jar/src/org/qtproject/qt5/android/sensors/QtSensors.java
@@ -0,0 +1,161 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 BogDan Vatra <bogdan@kde.org>
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtSensor 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$
+**
+****************************************************************************/
+
+package org.qtproject.qt5.android.sensors;
+
+import java.util.HashSet;
+import java.util.List;
+
+import android.app.Activity;
+import android.hardware.Sensor;
+import android.hardware.SensorEvent;
+import android.hardware.SensorEventListener;
+import android.hardware.SensorManager;
+import android.os.Build;
+import android.util.SparseArray;
+
+import android.util.Log;
+
+public class QtSensors implements SensorEventListener
+{
+ static final QtSensors m_sensorsListener = new QtSensors();
+ static SensorManager m_sensorManager = null;
+ static SparseArray<Sensor> m_registeredSensors = new SparseArray<Sensor>();
+ static Object m_syncObject = new Object();
+ static public void setActivity(Activity activity, Object acitvityDelegate)
+ {
+ try {
+ m_sensorManager = (SensorManager)activity.getSystemService(Activity.SENSOR_SERVICE);
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private static String getSensorDescription(int sensorType)
+ {
+ try {
+ Sensor s = m_sensorManager.getDefaultSensor(sensorType);
+ return s.getName() + " " + s.getVendor() + " v" + s.getVersion();
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ private static int[] getSensorList()
+ {
+ try {
+ List<Sensor> list = m_sensorManager.getSensorList(Sensor.TYPE_ALL);
+ HashSet<Integer> filteredList = new HashSet<Integer>();
+ for (Sensor s : list)
+ filteredList.add(s.getType());
+ int retList[] = new int[filteredList.size()];
+ int pos = 0;
+ for (int type : filteredList)
+ retList[pos++] = type;
+ return retList;
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ private static boolean registerSensor(int sensorType, int rate)
+ {
+ synchronized (m_syncObject) {
+ try {
+ Sensor s = m_sensorManager.getDefaultSensor(sensorType);
+ m_sensorManager.registerListener(m_sensorsListener, s, rate);
+ m_registeredSensors.put(sensorType, s);
+ } catch(Exception e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private static boolean unregisterSensor(int sensorType)
+ {
+ synchronized (m_syncObject) {
+ try {
+ Sensor s = m_registeredSensors.get(sensorType);
+ if (s != null) {
+ m_sensorManager.unregisterListener(m_sensorsListener, m_registeredSensors.get(sensorType));
+ m_registeredSensors.remove(sensorType);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private static float[] convertQuaternionToEuler(float[] rotationVector)
+ {
+ float matrix[] = new float[9];
+ SensorManager.getRotationMatrixFromVector (matrix, rotationVector);
+ float angles[] = new float[3];
+ SensorManager.getOrientation (matrix, angles);
+ return angles;
+ }
+
+ public static native void accuracyChanged(int sensorType, int accuracy);
+ public static native void sensorChanged(int sensorType, long timestamp, float[] values);
+
+ @Override
+ public void onAccuracyChanged(Sensor sensor, int accuracy)
+ {
+ accuracyChanged(sensor.getType(), accuracy);
+ }
+
+ @Override
+ public void onSensorChanged(SensorEvent sensorEvent)
+ {
+ if (sensorEvent.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) {
+ //#### hacky, but much easier than exposing the convert function and converting the arrays back and forth...
+ sensorChanged(sensorEvent.sensor.getType(), sensorEvent.timestamp, convertQuaternionToEuler(sensorEvent.values));
+ } else {
+ sensorChanged(sensorEvent.sensor.getType(), sensorEvent.timestamp, sensorEvent.values);
+ }
+ }
+}
diff --git a/src/plugins/sensors/android/src/androidaccelerometer.cpp b/src/plugins/sensors/android/src/androidaccelerometer.cpp
new file mode 100644
index 00000000..b64536ef
--- /dev/null
+++ b/src/plugins/sensors/android/src/androidaccelerometer.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 BogDan Vatra <bogdan@kde.org>
+** 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 "androidaccelerometer.h"
+
+AndroidAccelerometer::AndroidAccelerometer(AndroidSensors::AndroidSensorType type, QSensor *sensor)
+ : AndroidCommonSensor<QAccelerometerReading>(type, sensor)
+{}
+
+void AndroidAccelerometer::onSensorChanged(jlong timestamp, const jfloat *values, uint size)
+{
+ if (size < 3)
+ return;
+ m_reader.setTimestamp(timestamp);
+ // check https://developer.android.com/reference/android/hardware/SensorEvent.html#values
+ m_reader.setX(values[0]);
+ m_reader.setY(values[1]);
+ m_reader.setZ(values[2]);
+ newReadingAvailable();
+}
+
+void AndroidAccelerometer::onAccuracyChanged(jint accuracy)
+{
+ Q_UNUSED(accuracy)
+}
diff --git a/src/plugins/sensors/android/src/androidaccelerometer.h b/src/plugins/sensors/android/src/androidaccelerometer.h
new file mode 100644
index 00000000..6c95fdb3
--- /dev/null
+++ b/src/plugins/sensors/android/src/androidaccelerometer.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 BogDan Vatra <bogdan@kde.org>
+** 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 ANDROIDACCELEROMETER_H
+#define ANDROIDACCELEROMETER_H
+#include <qaccelerometer.h>
+
+#include "androidcommonsensor.h"
+
+class AndroidAccelerometer : public AndroidCommonSensor<QAccelerometerReading>
+{
+public:
+ AndroidAccelerometer(AndroidSensors::AndroidSensorType type, QSensor *sensor);
+
+private:
+ virtual void onAccuracyChanged(jint accuracy);
+ virtual void onSensorChanged(jlong timestamp, const jfloat *values, uint size);
+
+};
+
+#endif // ANDROIDACCELEROMETER_H
diff --git a/src/plugins/sensors/android/src/androidcommonsensor.h b/src/plugins/sensors/android/src/androidcommonsensor.h
new file mode 100644
index 00000000..40f118ed
--- /dev/null
+++ b/src/plugins/sensors/android/src/androidcommonsensor.h
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 BogDan Vatra <bogdan@kde.org>
+** 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 ANDROIDCOMMONSENSOR_H
+#define ANDROIDCOMMONSENSOR_H
+
+#include <qsensorbackend.h>
+#include <qsensor.h>
+#include "androidjnisensors.h"
+
+template <typename ReaderType>
+class AndroidCommonSensor : public QSensorBackend, protected AndroidSensors::AndroidSensorsListenerInterface
+{
+public:
+ AndroidCommonSensor(AndroidSensors::AndroidSensorType type, QSensor *sensor) : QSensorBackend(sensor)
+ {
+ setDescription(AndroidSensors::sensorDescription(type));
+ setReading<ReaderType>(&m_reader);
+ m_type = type;
+ m_isStarted = false;
+ }
+
+ virtual ~AndroidCommonSensor()
+ {
+ if (m_isStarted)
+ stop();
+ }
+ virtual void start()
+ {
+ if (AndroidSensors::registerListener(m_type, this, sensor()->dataRate()))
+ m_isStarted = true;
+ }
+
+ virtual void stop()
+ {
+ if (m_isStarted) {
+ m_isStarted = false;
+ AndroidSensors::unregisterListener(m_type, this);
+ }
+ }
+
+protected:
+ ReaderType m_reader;
+
+private:
+ AndroidSensors::AndroidSensorType m_type;
+ bool m_isStarted;
+};
+
+#endif // ANDROIDCOMMONSENSOR_H
diff --git a/src/plugins/sensors/android/src/androidgyroscope.cpp b/src/plugins/sensors/android/src/androidgyroscope.cpp
new file mode 100644
index 00000000..69a05c18
--- /dev/null
+++ b/src/plugins/sensors/android/src/androidgyroscope.cpp
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 BogDan Vatra <bogdan@kde.org>
+** 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 "androidgyroscope.h"
+#include <math.h>
+
+AndroidGyroscope::AndroidGyroscope(AndroidSensors::AndroidSensorType type, QSensor *sensor)
+ : AndroidCommonSensor<QGyroscopeReading>(type, sensor)
+{}
+
+void AndroidGyroscope::onSensorChanged(jlong timestamp, const jfloat *values, uint size)
+{
+ if (size < 3)
+ return;
+ m_reader.setTimestamp(timestamp);
+ // check https://developer.android.com/reference/android/hardware/SensorEvent.html#values
+ m_reader.setX(values[0]*180/M_PI);
+ m_reader.setY(values[1]*180/M_PI);
+ m_reader.setZ(values[2]*180/M_PI);
+ newReadingAvailable();
+}
+
+void AndroidGyroscope::onAccuracyChanged(jint accuracy)
+{
+ Q_UNUSED(accuracy)
+}
diff --git a/src/plugins/sensors/android/src/androidgyroscope.h b/src/plugins/sensors/android/src/androidgyroscope.h
new file mode 100644
index 00000000..3b633b7c
--- /dev/null
+++ b/src/plugins/sensors/android/src/androidgyroscope.h
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 BogDan Vatra <bogdan@kde.org>
+** 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 ANDROIDGYROSCOPE_H
+#define ANDROIDGYROSCOPE_H
+#include <qgyroscope.h>
+
+#include "androidcommonsensor.h"
+
+class AndroidGyroscope : public AndroidCommonSensor<QGyroscopeReading>
+{
+public:
+ AndroidGyroscope(AndroidSensors::AndroidSensorType type, QSensor *sensor);
+private:
+ virtual void onAccuracyChanged(jint accuracy);
+ virtual void onSensorChanged(jlong timestamp, const jfloat *values, uint size);
+};
+
+#endif // ANDROIDGYROSCOPE_H
diff --git a/src/plugins/sensors/android/src/androidjnisensors.cpp b/src/plugins/sensors/android/src/androidjnisensors.cpp
new file mode 100644
index 00000000..6365433c
--- /dev/null
+++ b/src/plugins/sensors/android/src/androidjnisensors.cpp
@@ -0,0 +1,245 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 BogDan Vatra <bogdan@kde.org>
+** 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 <qglobal.h>
+#include <android/log.h>
+#include <QtCore/QReadWriteLock>
+#include <QtCore/QHash>
+
+#include "androidjnisensors.h"
+
+static JavaVM *javaVM = 0;
+jclass sensorsClass;
+
+static jmethodID getSensorListMethodId;
+static jmethodID registerSensorMethodId;
+static jmethodID unregisterSensorMethodId;
+static jmethodID getSensorDescriptionMethodId;
+
+static QHash<int, QList<AndroidSensors::AndroidSensorsListenerInterface *> > listenersHash;
+QReadWriteLock listenersLocker;
+enum {
+ SENSOR_DELAY_FASTEST = 0,
+ SENSOR_DELAY_GAME = 1,
+ SENSOR_DELAY_NORMAL = 3,
+ SENSOR_DELAY_UI =2
+};
+namespace AndroidSensors
+{
+ struct AttachedJNIEnv
+ {
+ AttachedJNIEnv()
+ {
+ attached = false;
+ if (javaVM->GetEnv((void**)&jniEnv, JNI_VERSION_1_6) < 0) {
+ if (javaVM->AttachCurrentThread(&jniEnv, NULL) < 0) {
+ __android_log_print(ANDROID_LOG_ERROR, "Qt", "AttachCurrentThread failed");
+ jniEnv = 0;
+ return;
+ }
+ attached = true;
+ }
+ }
+
+ ~AttachedJNIEnv()
+ {
+ if (attached)
+ javaVM->DetachCurrentThread();
+ }
+ bool attached;
+ JNIEnv *jniEnv;
+ };
+
+ QVector<AndroidSensorType> availableSensors()
+ {
+ QVector<AndroidSensorType> ret;
+ AttachedJNIEnv aenv;
+ if (!aenv.jniEnv)
+ return ret;
+ jintArray jsensors = static_cast<jintArray>(aenv.jniEnv->CallStaticObjectMethod(sensorsClass,
+ getSensorListMethodId));
+ jint *sensors = aenv.jniEnv->GetIntArrayElements(jsensors, 0);
+ const uint sz = aenv.jniEnv->GetArrayLength(jsensors);
+ for (uint i = 0; i < sz; i++)
+ ret.push_back(AndroidSensorType(sensors[i]));
+ aenv.jniEnv->ReleaseIntArrayElements(jsensors, sensors, 0);
+ return ret;
+ }
+
+ QString sensorDescription(AndroidSensorType sensor)
+ {
+ AttachedJNIEnv aenv;
+ if (!aenv.jniEnv)
+ return QString();
+ jstring jstr = static_cast<jstring>(aenv.jniEnv->CallStaticObjectMethod(sensorsClass,
+ getSensorDescriptionMethodId,
+ jint(sensor)));
+ const jchar *pstr = aenv.jniEnv->GetStringChars(jstr, 0);
+ QString ret(reinterpret_cast<const QChar *>(pstr), aenv.jniEnv->GetStringLength(jstr));
+ aenv.jniEnv->ReleaseStringChars(jstr, pstr);
+ aenv.jniEnv->DeleteLocalRef(jstr);
+ return ret;
+ }
+
+ bool registerListener(AndroidSensorType sensor, AndroidSensorsListenerInterface *listener, int dataRate)
+ {
+ listenersLocker.lockForWrite();
+ bool startService = listenersHash[sensor].empty();
+ listenersHash[sensor].push_back(listener);
+ listenersLocker.unlock();
+ if (startService) {
+ AttachedJNIEnv aenv;
+ if (!aenv.jniEnv)
+ return false;
+ int rate = dataRate > 0 ? 1000000/dataRate : SENSOR_DELAY_GAME;
+ return aenv.jniEnv->CallStaticBooleanMethod(sensorsClass,
+ registerSensorMethodId,
+ jint(sensor),
+ jint(rate));
+ }
+ return true;
+ }
+
+ bool unregisterListener(AndroidSensorType sensor, AndroidSensorsListenerInterface *listener)
+ {
+ listenersLocker.lockForWrite();
+ listenersHash[sensor].removeOne(listener);
+ bool stopService = listenersHash[sensor].empty();
+ if (stopService)
+ listenersHash.remove(sensor);
+ listenersLocker.unlock();
+ if (stopService) {
+ AttachedJNIEnv aenv;
+ if (!aenv.jniEnv)
+ return false;
+ return aenv.jniEnv->CallStaticBooleanMethod(sensorsClass, unregisterSensorMethodId, jint(sensor));
+ }
+ return true;
+ }
+}
+
+static const char logTag[] = "Qt";
+static const char classErrorMsg[] = "Can't find class \"%s\"";
+static const char methodErrorMsg[] = "Can't find method \"%s%s\"";
+
+static void accuracyChanged(JNIEnv * /*env*/, jobject /*thiz*/, jint sensor, jint accuracy)
+{
+ listenersLocker.lockForRead();
+ foreach (AndroidSensors::AndroidSensorsListenerInterface *listener, listenersHash[sensor])
+ listener->onAccuracyChanged(accuracy);
+ listenersLocker.unlock();
+}
+
+static void sensorChanged(JNIEnv *env, jobject /*thiz*/, jint sensor, jlong timeStamp, jfloatArray array)
+{
+ uint size = env->GetArrayLength(array);
+ jfloat *values = env->GetFloatArrayElements(array, 0);
+ listenersLocker.lockForRead();
+ foreach (AndroidSensors::AndroidSensorsListenerInterface *listener, listenersHash[sensor])
+ listener->onSensorChanged(timeStamp, values, size);
+ listenersLocker.unlock();
+ env->ReleaseFloatArrayElements(array, values, JNI_ABORT); // don't copy back the elements
+
+}
+
+static JNINativeMethod methods[] = {
+ {"accuracyChanged", "(II)V", (void *)accuracyChanged},
+ {"sensorChanged", "(IJ[F)V", (void *)sensorChanged}
+};
+
+#define FIND_AND_CHECK_CLASS(CLASS_NAME) \
+clazz = env->FindClass(CLASS_NAME); \
+if (!clazz) { \
+ __android_log_print(ANDROID_LOG_FATAL, logTag, classErrorMsg, CLASS_NAME); \
+ return JNI_FALSE; \
+}
+
+#define GET_AND_CHECK_STATIC_METHOD(VAR, CLASS, METHOD_NAME, METHOD_SIGNATURE) \
+VAR = env->GetStaticMethodID(CLASS, METHOD_NAME, METHOD_SIGNATURE); \
+if (!VAR) { \
+ __android_log_print(ANDROID_LOG_FATAL, logTag, methodErrorMsg, METHOD_NAME, METHOD_SIGNATURE); \
+ return JNI_FALSE; \
+}
+
+static bool registerNatives(JNIEnv *env)
+{
+ jclass clazz;
+ FIND_AND_CHECK_CLASS("org/qtproject/qt5/android/sensors/QtSensors");
+ sensorsClass = static_cast<jclass>(env->NewGlobalRef(clazz));
+
+ if (env->RegisterNatives(sensorsClass, methods, sizeof(methods) / sizeof(methods[0])) < 0) {
+ __android_log_print(ANDROID_LOG_FATAL, logTag, "RegisterNatives failed");
+ return JNI_FALSE;
+ }
+
+ GET_AND_CHECK_STATIC_METHOD(getSensorListMethodId, sensorsClass, "getSensorList", "()[I");
+ GET_AND_CHECK_STATIC_METHOD(registerSensorMethodId, sensorsClass, "registerSensor", "(II)Z");
+ GET_AND_CHECK_STATIC_METHOD(unregisterSensorMethodId, sensorsClass, "unregisterSensor", "(I)Z");
+ GET_AND_CHECK_STATIC_METHOD(getSensorDescriptionMethodId, sensorsClass, "getSensorDescription", "(I)Ljava/lang/String;");
+
+ return true;
+}
+
+Q_DECL_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void * /*reserved*/)
+{
+ typedef union {
+ JNIEnv *nativeEnvironment;
+ void *venv;
+ } UnionJNIEnvToVoid;
+
+ __android_log_print(ANDROID_LOG_INFO, logTag, "Sensors start");
+ UnionJNIEnvToVoid uenv;
+ uenv.venv = NULL;
+ javaVM = 0;
+
+ if (vm->GetEnv(&uenv.venv, JNI_VERSION_1_4) != JNI_OK) {
+ __android_log_print(ANDROID_LOG_FATAL, logTag, "GetEnv failed");
+ return -1;
+ }
+ JNIEnv *env = uenv.nativeEnvironment;
+ if (!registerNatives(env)) {
+ __android_log_print(ANDROID_LOG_FATAL, logTag, "registerNatives failed");
+ return -1;
+ }
+
+ javaVM = vm;
+ return JNI_VERSION_1_4;
+}
diff --git a/src/plugins/sensors/android/src/androidjnisensors.h b/src/plugins/sensors/android/src/androidjnisensors.h
new file mode 100644
index 00000000..53ca58d0
--- /dev/null
+++ b/src/plugins/sensors/android/src/androidjnisensors.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 BogDan Vatra <bogdan@kde.org>
+** 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 ANDROIDJNISENSORS_H
+#define ANDROIDJNISENSORS_H
+
+#include <jni.h>
+
+#include <QtCore/QVector>
+#include <QtCore/QString>
+
+namespace AndroidSensors
+{
+ // must be in sync with https://developer.android.com/reference/android/hardware/Sensor.html#TYPE_ACCELEROMETER
+ enum AndroidSensorType
+ {
+ TYPE_ACCELEROMETER = 1,
+ TYPE_AMBIENT_TEMPERATURE = 13,
+ TYPE_GRAVITY = 9,
+ TYPE_GYROSCOPE = 4,
+ TYPE_LIGHT = 5,
+ TYPE_LINEAR_ACCELERATION = 10,
+ TYPE_MAGNETIC_FIELD = 2,
+ TYPE_ORIENTATION = 3, //This constant was deprecated in API level 8. use SensorManager.getOrientation() instead.
+ TYPE_PRESSURE = 6,
+ TYPE_PROXIMITY = 8,
+ TYPE_RELATIVE_HUMIDITY = 12,
+ TYPE_ROTATION_VECTOR = 11,
+ TYPE_TEMPERATURE = 7 //This constant was deprecated in API level 14. use Sensor.TYPE_AMBIENT_TEMPERATURE instead.
+ };
+
+ struct AndroidSensorsListenerInterface
+ {
+ virtual ~AndroidSensorsListenerInterface() {}
+ virtual void onAccuracyChanged(jint accuracy) = 0;
+ virtual void onSensorChanged(jlong timestamp, const jfloat *values, uint size) = 0;
+ };
+
+ QVector<AndroidSensorType> availableSensors();
+ QString sensorDescription(AndroidSensorType sensor);
+ bool registerListener(AndroidSensorType sensor, AndroidSensorsListenerInterface *listener, int dataRate = 0);
+ bool unregisterListener(AndroidSensorType sensor, AndroidSensorsListenerInterface *listener);
+}
+
+#endif // ANDROIDJNISENSORS_H
diff --git a/src/plugins/sensors/android/src/androidlight.cpp b/src/plugins/sensors/android/src/androidlight.cpp
new file mode 100644
index 00000000..42295e54
--- /dev/null
+++ b/src/plugins/sensors/android/src/androidlight.cpp
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 BogDan Vatra <bogdan@kde.org>
+** 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 "androidlight.h"
+
+AndroidLight::AndroidLight(AndroidSensors::AndroidSensorType type, QSensor *sensor)
+ : AndroidCommonSensor<QLightReading>(type, sensor)
+{}
+
+
+void AndroidLight::onAccuracyChanged(jint accuracy)
+{
+ Q_UNUSED(accuracy)
+}
+
+void AndroidLight::onSensorChanged(jlong timestamp, const jfloat *values, uint size)
+{
+ if (size < 1)
+ return;
+ m_reader.setTimestamp(timestamp);
+ // check https://developer.android.com/reference/android/hardware/SensorEvent.html#values
+ m_reader.setLux(values[0]);
+ newReadingAvailable();
+}
diff --git a/src/plugins/sensors/android/src/androidlight.h b/src/plugins/sensors/android/src/androidlight.h
new file mode 100644
index 00000000..fdea3edb
--- /dev/null
+++ b/src/plugins/sensors/android/src/androidlight.h
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 BogDan Vatra <bogdan@kde.org>
+** 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 ANDROIDLIGHT_H
+#define ANDROIDLIGHT_H
+#include <qlightsensor.h>
+
+#include "androidcommonsensor.h"
+
+class AndroidLight : public AndroidCommonSensor<QLightReading>
+{
+public:
+ AndroidLight(AndroidSensors::AndroidSensorType type, QSensor *sensor);
+private:
+ virtual void onAccuracyChanged(jint accuracy);
+ virtual void onSensorChanged(jlong timestamp, const jfloat *values, uint size);
+};
+
+#endif // ANDROIDLIGHT_H
diff --git a/src/plugins/sensors/android/src/androidmagnetometer.cpp b/src/plugins/sensors/android/src/androidmagnetometer.cpp
new file mode 100644
index 00000000..9175f584
--- /dev/null
+++ b/src/plugins/sensors/android/src/androidmagnetometer.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 BogDan Vatra <bogdan@kde.org>
+** 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 "androidmagnetometer.h"
+
+AndroidMagnetometer::AndroidMagnetometer(AndroidSensors::AndroidSensorType type, QSensor *sensor)
+ :AndroidCommonSensor<QMagnetometerReading>(type, sensor)
+{}
+
+void AndroidMagnetometer::onAccuracyChanged(jint accuracy)
+{
+ m_reader.setCalibrationLevel(accuracy);
+}
+
+void AndroidMagnetometer::onSensorChanged(jlong timestamp, const jfloat *values, uint size)
+{
+ if (size<3)
+ return;
+ m_reader.setTimestamp(timestamp);
+ // check https://developer.android.com/reference/android/hardware/SensorEvent.html#values
+ m_reader.setX(values[0]/1e6);
+ m_reader.setY(values[1]/1e6);
+ m_reader.setZ(values[2]/1e6);
+ newReadingAvailable();
+}
diff --git a/src/plugins/sensors/android/src/androidmagnetometer.h b/src/plugins/sensors/android/src/androidmagnetometer.h
new file mode 100644
index 00000000..57d9f36d
--- /dev/null
+++ b/src/plugins/sensors/android/src/androidmagnetometer.h
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 BogDan Vatra <bogdan@kde.org>
+** 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 ANDROIDMAGNETOMETER_H
+#define ANDROIDMAGNETOMETER_H
+#include <qmagnetometer.h>
+
+#include "androidcommonsensor.h"
+
+class AndroidMagnetometer : public AndroidCommonSensor<QMagnetometerReading>
+{
+public:
+ AndroidMagnetometer(AndroidSensors::AndroidSensorType type, QSensor *sensor);
+private:
+ virtual void onAccuracyChanged(jint accuracy);
+ virtual void onSensorChanged(jlong timestamp, const jfloat *values, uint size);
+};
+
+#endif // ANDROIDMAGNETOMETER_H
diff --git a/src/plugins/sensors/android/src/androidrotation.cpp b/src/plugins/sensors/android/src/androidrotation.cpp
new file mode 100644
index 00000000..602575fe
--- /dev/null
+++ b/src/plugins/sensors/android/src/androidrotation.cpp
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 BogDan Vatra <bogdan@kde.org>
+** 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 "androidrotation.h"
+#include <math.h>
+
+AndroidRotation::AndroidRotation(AndroidSensors::AndroidSensorType type, QSensor *sensor)
+ : AndroidCommonSensor<QRotationReading>(type, sensor)
+{}
+
+void AndroidRotation::onAccuracyChanged(jint accuracy)
+{
+ Q_UNUSED(accuracy)
+}
+
+void AndroidRotation::onSensorChanged(jlong timestamp, const jfloat *values, uint size)
+{
+ if (size < 3)
+ return;
+ m_reader.setTimestamp(timestamp);
+
+ float rz = -values[0]*180/M_PI;
+ float rx = -values[1]*180/M_PI;
+ float ry = values[2]*180/M_PI;
+ m_reader.setFromEuler(rx, ry, rz);
+ newReadingAvailable();
+}
diff --git a/src/plugins/sensors/android/src/androidrotation.h b/src/plugins/sensors/android/src/androidrotation.h
new file mode 100644
index 00000000..cd2c4d65
--- /dev/null
+++ b/src/plugins/sensors/android/src/androidrotation.h
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 BogDan Vatra <bogdan@kde.org>
+** 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 ANDROIDROTATION_H
+#define ANDROIDROTATION_H
+#include <qrotationsensor.h>
+
+#include "androidcommonsensor.h"
+class AndroidRotation : public AndroidCommonSensor<QRotationReading>
+{
+public:
+ AndroidRotation(AndroidSensors::AndroidSensorType type, QSensor *sensor);
+private:
+ virtual void onAccuracyChanged(jint accuracy);
+ virtual void onSensorChanged(jlong timestamp, const jfloat *values, uint size);
+};
+
+#endif // ANDROIDROTATION_H
diff --git a/src/plugins/sensors/android/src/main.cpp b/src/plugins/sensors/android/src/main.cpp
new file mode 100644
index 00000000..0cb4de49
--- /dev/null
+++ b/src/plugins/sensors/android/src/main.cpp
@@ -0,0 +1,135 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 BogDan Vatra <bogdan@kde.org>
+** 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 <qplugin.h>
+#include <qsensorplugin.h>
+#include <qsensorbackend.h>
+#include <qsensormanager.h>
+#include "androidaccelerometer.h"
+#include "androidgyroscope.h"
+#include "androidlight.h"
+#include "androidmagnetometer.h"
+#include "androidrotation.h"
+
+using namespace AndroidSensors;
+
+class AndroidSensorPlugin : public QObject, public QSensorPluginInterface, public QSensorBackendFactory
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QSensorPluginInterface/1.0" FILE "plugin.json")
+ Q_INTERFACES(QSensorPluginInterface)
+public:
+ void registerSensors()
+ {
+ foreach (AndroidSensorType sensor, availableSensors()) {
+ switch (sensor) {
+ case TYPE_ACCELEROMETER:
+ QSensorManager::registerBackend(QAccelerometer::type, QByteArray::number(sensor), this);
+ break;
+ case TYPE_AMBIENT_TEMPERATURE:
+ case TYPE_TEMPERATURE:
+ break; // add the temperature sensor backend
+ case TYPE_GRAVITY:
+ break; // add the gravity sensor backend
+ case TYPE_GYROSCOPE:
+ QSensorManager::registerBackend(QGyroscope::type, QByteArray::number(sensor), this);
+ break;
+ case TYPE_LIGHT:
+ QSensorManager::registerBackend(QLightSensor::type, QByteArray::number(sensor), this);
+ break; // add the light sensor backend
+ case TYPE_LINEAR_ACCELERATION:
+ break; // add the linear acceleration sensor backend
+ case TYPE_MAGNETIC_FIELD:
+ QSensorManager::registerBackend(QMagnetometer::type, QByteArray::number(sensor), this);
+ break;
+ case TYPE_ORIENTATION:
+ break; // add the orientation sensor backend
+ case TYPE_PRESSURE:
+ break; // add the pressure sensor backend
+ case TYPE_PROXIMITY:
+ break; // add the proximity sensor backend
+ case TYPE_RELATIVE_HUMIDITY:
+ break; // add the relative humidity sensor backend
+ case TYPE_ROTATION_VECTOR:
+ QSensorManager::registerBackend(QRotationSensor::type, QByteArray::number(sensor), this);
+ break;
+ }
+ }
+ }
+
+ QSensorBackend *createBackend(QSensor *sensor)
+ {
+ AndroidSensorType type = static_cast<AndroidSensorType>(sensor->identifier().toInt());
+ switch (type) {
+ case TYPE_ACCELEROMETER:
+ return new AndroidAccelerometer(type, sensor);
+ case TYPE_AMBIENT_TEMPERATURE:
+ case TYPE_TEMPERATURE:
+ break; // add the temperature sensor backend
+ case TYPE_GRAVITY:
+ break; // add the gravity sensor backend
+ case TYPE_GYROSCOPE:
+ return new AndroidGyroscope(type, sensor);
+ case TYPE_LIGHT:
+ return new AndroidLight(type, sensor);
+ case TYPE_LINEAR_ACCELERATION:
+ break; // add the linear acceleration sensor backend
+ case TYPE_MAGNETIC_FIELD:
+ return new AndroidMagnetometer(type, sensor);
+ case TYPE_ORIENTATION:
+ break; // add the orientation sensor backend
+ case TYPE_PRESSURE:
+ break; // add the pressure sensor backend
+ case TYPE_PROXIMITY:
+ break; // add the proximity sensor backend
+ case TYPE_RELATIVE_HUMIDITY:
+ break; // add the relative humidity sensor backend
+ case TYPE_ROTATION_VECTOR:
+ return new AndroidRotation(type, sensor);
+ }
+ return 0;
+ }
+};
+
+Q_IMPORT_PLUGIN (AndroidSensorPlugin) // automatically register the plugin
+
+#include "main.moc"
+
diff --git a/src/plugins/sensors/android/src/plugin.json b/src/plugins/sensors/android/src/plugin.json
new file mode 100644
index 00000000..8a55b3ae
--- /dev/null
+++ b/src/plugins/sensors/android/src/plugin.json
@@ -0,0 +1 @@
+{ "Keys": [ "notused" ] }
diff --git a/src/plugins/sensors/android/src/src.pro b/src/plugins/sensors/android/src/src.pro
new file mode 100644
index 00000000..715a0111
--- /dev/null
+++ b/src/plugins/sensors/android/src/src.pro
@@ -0,0 +1,29 @@
+TARGET = qtsensors_android
+QT = sensors core
+
+PLUGIN_TYPE = sensors
+load(qt_plugin)
+
+# STATICPLUGIN needed because there's a Q_IMPORT_PLUGIN in main.cpp
+# Yes, the plugin imports itself statically
+DEFINES += QT_STATICPLUGIN
+
+HEADERS = \
+ androidjnisensors.h \
+ androidaccelerometer.h \
+ androidcommonsensor.h \
+ androidgyroscope.h \
+ androidmagnetometer.h \
+ androidrotation.h \
+ androidlight.h
+
+SOURCES = \
+ main.cpp \
+ androidjnisensors.cpp \
+ androidaccelerometer.cpp \
+ androidgyroscope.cpp \
+ androidmagnetometer.cpp \
+ androidrotation.cpp \
+ androidlight.cpp
+
+OTHER_FILES = plugin.json
diff --git a/src/plugins/sensors/blackberry/bbaccelerometer.cpp b/src/plugins/sensors/blackberry/bbaccelerometer.cpp
index dcbd7fcc..0826cf7a 100644
--- a/src/plugins/sensors/blackberry/bbaccelerometer.cpp
+++ b/src/plugins/sensors/blackberry/bbaccelerometer.cpp
@@ -44,6 +44,12 @@ BbAccelerometer::BbAccelerometer(QSensor *sensor)
: BbSensorBackend<QAccelerometerReading>(devicePath(), SENSOR_TYPE_ACCELEROMETER, sensor)
{
setDescription(QLatin1String("X, Y, and Z axes accelerations in m/s^2"));
+
+ QAccelerometer * const accelerometer = qobject_cast<QAccelerometer *>(sensor);
+ if (accelerometer) {
+ connect(accelerometer, SIGNAL(accelerationModeChanged(AccelerationMode)),
+ this, SLOT(applyAccelerationMode()));
+ }
}
bool BbAccelerometer::updateReadingFromEvent(const sensor_event_t &event, QAccelerometerReading *reading)
@@ -58,7 +64,39 @@ bool BbAccelerometer::updateReadingFromEvent(const sensor_event_t &event, QAccel
return true;
}
+void BbAccelerometer::start()
+{
+ applyAccelerationMode();
+ BbSensorBackend<QAccelerometerReading>::start();
+}
+
QString BbAccelerometer::devicePath()
{
return QLatin1String("/dev/sensor/accel");
}
+
+void BbAccelerometer::applyAccelerationMode()
+{
+ const QAccelerometer * const accelerometer = qobject_cast<QAccelerometer *>(sensor());
+ if (accelerometer) {
+ QString fileName;
+ sensor_type_e sensorType;
+ switch (accelerometer->accelerationMode()) {
+ case QAccelerometer::Gravity:
+ fileName = QLatin1String("/dev/sensor/gravity");
+ sensorType = SENSOR_TYPE_GRAVITY;
+ break;
+ case QAccelerometer::User:
+ fileName = QLatin1String("/dev/sensor/linAccel");
+ sensorType = SENSOR_TYPE_LINEAR_ACCEL;
+ break;
+ default:
+ case QAccelerometer::Combined:
+ fileName = devicePath();
+ sensorType = SENSOR_TYPE_ACCELEROMETER;
+ break;
+ }
+
+ setDevice(fileName, sensorType);
+ }
+}
diff --git a/src/plugins/sensors/blackberry/bbaccelerometer.h b/src/plugins/sensors/blackberry/bbaccelerometer.h
index aa47873c..3071c801 100644
--- a/src/plugins/sensors/blackberry/bbaccelerometer.h
+++ b/src/plugins/sensors/blackberry/bbaccelerometer.h
@@ -51,10 +51,14 @@ class BbAccelerometer : public BbSensorBackend<QAccelerometerReading>
public:
explicit BbAccelerometer(QSensor *sensor);
+ void start() Q_DECL_OVERRIDE;
static QString devicePath();
protected:
bool updateReadingFromEvent(const sensor_event_t &event, QAccelerometerReading *reading) Q_DECL_OVERRIDE;
+
+private Q_SLOTS:
+ void applyAccelerationMode();
};
#endif
diff --git a/src/plugins/sensors/blackberry/bbaltimeter.cpp b/src/plugins/sensors/blackberry/bbaltimeter.cpp
index 07aa2646..3d21ef32 100644
--- a/src/plugins/sensors/blackberry/bbaltimeter.cpp
+++ b/src/plugins/sensors/blackberry/bbaltimeter.cpp
@@ -40,36 +40,13 @@
****************************************************************************/
#include "bbaltimeter.h"
-class BbAltimeterReadingPrivate
-{
-public:
- BbAltimeterReadingPrivate()
- : altitude(0)
- {
- }
-
- qreal altitude;
-};
-
-IMPLEMENT_READING(BbAltimeterReading)
-
-qreal BbAltimeterReading::altitude() const
-{
- return d->altitude;
-}
-
-void BbAltimeterReading::setAltitude(qreal altitude)
-{
- d->altitude = altitude;
-}
-
BbAltimeter::BbAltimeter(QSensor *sensor)
- : BbSensorBackend<BbAltimeterReading>(devicePath(), SENSOR_TYPE_ALTIMETER, sensor)
+ : BbSensorBackend<QAltimeterReading>(devicePath(), SENSOR_TYPE_ALTIMETER, sensor)
{
setDescription(QLatin1String("Altitude in meters relative to mean sea level"));
}
-bool BbAltimeter::updateReadingFromEvent(const sensor_event_t &event, BbAltimeterReading *reading)
+bool BbAltimeter::updateReadingFromEvent(const sensor_event_t &event, QAltimeterReading *reading)
{
reading->setAltitude(event.altitude_s.altitude);
return true;
diff --git a/src/plugins/sensors/blackberry/bbaltimeter.h b/src/plugins/sensors/blackberry/bbaltimeter.h
index 4744a3ff..b369c6cb 100644
--- a/src/plugins/sensors/blackberry/bbaltimeter.h
+++ b/src/plugins/sensors/blackberry/bbaltimeter.h
@@ -42,20 +42,9 @@
#define BBALTIMETER_H
#include "bbsensorbackend.h"
+#include <qaltimeter.h>
-class BbAltimeterReadingPrivate;
-
-class BbAltimeterReading : public QSensorReading
-{
- Q_OBJECT
- Q_PROPERTY(qreal altitude READ altitude)
- DECLARE_READING(BbAltimeterReading)
-public:
- qreal altitude() const;
- void setAltitude(qreal altitude);
-};
-
-class BbAltimeter : public BbSensorBackend<BbAltimeterReading>
+class BbAltimeter : public BbSensorBackend<QAltimeterReading>
{
Q_OBJECT
@@ -65,7 +54,7 @@ public:
static QString devicePath();
protected:
- bool updateReadingFromEvent(const sensor_event_t &event, BbAltimeterReading *reading) Q_DECL_OVERRIDE;
+ bool updateReadingFromEvent(const sensor_event_t &event, QAltimeterReading *reading) Q_DECL_OVERRIDE;
};
#endif
diff --git a/src/plugins/sensors/blackberry/bbcompass.cpp b/src/plugins/sensors/blackberry/bbcompass.cpp
index 6e33d1a3..df8cc2e1 100644
--- a/src/plugins/sensors/blackberry/bbcompass.cpp
+++ b/src/plugins/sensors/blackberry/bbcompass.cpp
@@ -55,19 +55,28 @@ BbCompass::BbCompass(QSensor *sensor)
bool BbCompass::updateReadingFromEvent(const sensor_event_t &event, QCompassReading *reading)
{
+ float azimuth;
#ifdef HAVE_COMPASS_SENSOR
- reading->setAzimuth(event.compass_s.azimuth);
+ azimuth = event.compass_s.azimuth;
#else
float xRad, yRad, zRad;
matrixToEulerZXY(event.rotation_matrix, xRad, yRad, zRad);
- float azimuth = radiansToDegrees(zRad);
+ azimuth = radiansToDegrees(zRad);
if (azimuth < 0)
azimuth = -azimuth;
else
azimuth = 360.0f - azimuth;
- reading->setAzimuth(azimuth);
#endif
+ if (isAutoAxisRemappingEnabled()) {
+ azimuth += orientationForRemapping();
+ if (azimuth >= 360.0f)
+ azimuth -= 360.0f;
+ }
+
+ reading->setAzimuth(azimuth);
+
+
switch (event.accuracy) {
case SENSOR_ACCURACY_UNRELIABLE:
reading->setCalibrationLevel(0.0f);
diff --git a/src/plugins/sensors/blackberry/bbholstersensor.cpp b/src/plugins/sensors/blackberry/bbholstersensor.cpp
new file mode 100644
index 00000000..53888f58
--- /dev/null
+++ b/src/plugins/sensors/blackberry/bbholstersensor.cpp
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Research In Motion
+** 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 "bbholstersensor.h"
+
+BbHolsterSensor::BbHolsterSensor(QSensor *sensor)
+ : BbSensorBackend<QHolsterReading>(devicePath(), SENSOR_TYPE_HOLSTER, sensor)
+{
+ setDescription(QLatin1String("Whether the device is holstered or not"));
+}
+
+bool BbHolsterSensor::updateReadingFromEvent(const sensor_event_t &event, QHolsterReading *reading)
+{
+ reading->setHolstered(event.holster_s.holstered == 1);
+ return true;
+}
+
+QString BbHolsterSensor::devicePath()
+{
+ return QLatin1String("/dev/sensor/holster");
+}
diff --git a/src/plugins/sensors/blackberry/bbholstersensor.h b/src/plugins/sensors/blackberry/bbholstersensor.h
new file mode 100644
index 00000000..b33b391d
--- /dev/null
+++ b/src/plugins/sensors/blackberry/bbholstersensor.h
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Research In Motion
+** 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 BBHOLSTERSENSOR_H
+#define BBHOLSTERSENSOR_H
+
+#include "bbsensorbackend.h"
+#include <qholstersensor.h>
+
+class BbHolsterSensor : public BbSensorBackend<QHolsterReading>
+{
+ Q_OBJECT
+
+public:
+ explicit BbHolsterSensor(QSensor *sensor);
+
+ static QString devicePath();
+
+protected:
+ bool updateReadingFromEvent(const sensor_event_t &event, QHolsterReading *reading) Q_DECL_OVERRIDE;
+};
+
+#endif
diff --git a/src/plugins/sensors/blackberry/bbmagnetometer.cpp b/src/plugins/sensors/blackberry/bbmagnetometer.cpp
index 489a0481..45fd49b3 100644
--- a/src/plugins/sensors/blackberry/bbmagnetometer.cpp
+++ b/src/plugins/sensors/blackberry/bbmagnetometer.cpp
@@ -53,17 +53,11 @@ QString BbMagnetometer::devicePath()
bool BbMagnetometer::updateReadingFromEvent(const sensor_event_t &event, QMagnetometerReading *reading)
{
- // TODO: In the future, support returnGeoValues here. Right now, /dev/sensors/mag has no
- // geomagnatic mode, but will gain it in the future.
- float x = convertValue(event.motion.dsp.x);
- float y = convertValue(event.motion.dsp.y);
- float z = convertValue(event.motion.dsp.z);
- remapAxes(&x, &y, &z);
- reading->setX(x);
- reading->setY(y);
- reading->setZ(z);
+ float x, y, z;
- const bool returnGeoValues = sensor()->property("returnGeoValues").toBool();
+ QMagnetometer * const magnetometer = qobject_cast<QMagnetometer *>(sensor());
+ Q_ASSERT(magnetometer);
+ const bool returnGeoValues = magnetometer->returnGeoValues();
if (returnGeoValues) {
switch (event.accuracy) {
case SENSOR_ACCURACY_UNRELIABLE: reading->setCalibrationLevel(0.0f); break;
@@ -76,10 +70,30 @@ bool BbMagnetometer::updateReadingFromEvent(const sensor_event_t &event, QMagnet
case SENSOR_ACCURACY_MEDIUM: reading->setCalibrationLevel(1.0f); break;
case SENSOR_ACCURACY_HIGH: reading->setCalibrationLevel(1.0f); break;
}
+
+ x = convertValue(event.motion.dsp.x);
+ y = convertValue(event.motion.dsp.y);
+ z = convertValue(event.motion.dsp.z);
+
} else {
reading->setCalibrationLevel(1.0f);
+
+#ifndef Q_OS_BLACKBERRY_TABLET
+ x = convertValue(event.motion.raw.x);
+ y = convertValue(event.motion.raw.y);
+ z = convertValue(event.motion.raw.z);
+#else
+ // Blackberry Tablet OS does not support raw reading values
+ x = convertValue(event.motion.dsp.x);
+ y = convertValue(event.motion.dsp.y);
+ z = convertValue(event.motion.dsp.z);
+#endif
}
+ remapAxes(&x, &y, &z);
+ reading->setX(x);
+ reading->setY(y);
+ reading->setZ(z);
return true;
}
diff --git a/src/plugins/sensors/blackberry/bborientationsensor.cpp b/src/plugins/sensors/blackberry/bborientationsensor.cpp
index 68ed735b..3d9d120c 100644
--- a/src/plugins/sensors/blackberry/bborientationsensor.cpp
+++ b/src/plugins/sensors/blackberry/bborientationsensor.cpp
@@ -44,6 +44,9 @@ BbOrientationSensor::BbOrientationSensor(QSensor *sensor)
: BbSensorBackend<QOrientationReading>(devicePath(), SENSOR_TYPE_ORIENTATION, sensor)
{
setDescription(QLatin1String("Device orientation"));
+
+ // Orientation rarely changes, so enable skipping of duplicates by default
+ sensor->setSkipDuplicates(true);
}
QString BbOrientationSensor::devicePath()
@@ -51,19 +54,6 @@ QString BbOrientationSensor::devicePath()
return QLatin1String("/dev/sensor/orientation");
}
-void BbOrientationSensor::start()
-{
- BbSensorBackend<QOrientationReading>::start();
-
- // Orientation rarely changes, so enable skiping of duplicates
- sensor_devctl_skipdupevent_u deviceSkip;
- deviceSkip.tx.enable = 1;
- const int result = devctl(deviceFile().handle(), DCMD_SENSOR_SKIPDUPEVENT, &deviceSkip,
- sizeof(deviceSkip), NULL);
- if (result != EOK)
- perror("Enabling duplicate skipping for orientation sensor failed");
-}
-
void BbOrientationSensor::additionalDeviceInit()
{
// When querying the OS service for the range, it gives us the angles, which we don't need.
diff --git a/src/plugins/sensors/blackberry/bborientationsensor.h b/src/plugins/sensors/blackberry/bborientationsensor.h
index 07dc3d0f..85c7bd67 100644
--- a/src/plugins/sensors/blackberry/bborientationsensor.h
+++ b/src/plugins/sensors/blackberry/bborientationsensor.h
@@ -53,7 +53,6 @@ public:
static QString devicePath();
- void start() Q_DECL_OVERRIDE;
void additionalDeviceInit() Q_DECL_OVERRIDE;
bool addDefaultRange() Q_DECL_OVERRIDE;
diff --git a/src/plugins/sensors/blackberry/bbpressuresensor.cpp b/src/plugins/sensors/blackberry/bbpressuresensor.cpp
index 01a2493b..8cb9b1ea 100644
--- a/src/plugins/sensors/blackberry/bbpressuresensor.cpp
+++ b/src/plugins/sensors/blackberry/bbpressuresensor.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2012 Research In Motion
+** Copyright (C) 2013 Research In Motion
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtSensors module of the Qt Toolkit.
@@ -40,31 +40,8 @@
****************************************************************************/
#include "bbpressuresensor.h"
-class BbPressureReadingPrivate
-{
-public:
- BbPressureReadingPrivate()
- : pressure(0)
- {
- }
-
- qreal pressure;
-};
-
-IMPLEMENT_READING(BbPressureReading)
-
-qreal BbPressureReading::pressure() const
-{
- return d->pressure;
-}
-
-void BbPressureReading::setPressure(qreal pressure)
-{
- d->pressure = pressure;
-}
-
BbPressureSensor::BbPressureSensor(QSensor *sensor)
- : BbSensorBackend<BbPressureReading>(devicePath(), SENSOR_TYPE_PRESSURE, sensor)
+ : BbSensorBackend<QPressureReading>(devicePath(), SENSOR_TYPE_PRESSURE, sensor)
{
setDescription(QLatin1String("Pressure in Pascals"));
}
@@ -74,7 +51,7 @@ QString BbPressureSensor::devicePath()
return QLatin1String("/dev/sensor/pressure");
}
-bool BbPressureSensor::updateReadingFromEvent(const sensor_event_t &event, BbPressureReading *reading)
+bool BbPressureSensor::updateReadingFromEvent(const sensor_event_t &event, QPressureReading *reading)
{
// TODO: I was unable to test this since the device I was testing this with did not have
// a pressure sensor. Verify that this works and check that the units are correct.
diff --git a/src/plugins/sensors/blackberry/bbpressuresensor.h b/src/plugins/sensors/blackberry/bbpressuresensor.h
index 833832c4..7531bd68 100644
--- a/src/plugins/sensors/blackberry/bbpressuresensor.h
+++ b/src/plugins/sensors/blackberry/bbpressuresensor.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2012 Research In Motion
+** Copyright (C) 2013 Research In Motion
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtSensors module of the Qt Toolkit.
@@ -42,20 +42,9 @@
#define BBPRESSURESENSOR_H
#include "bbsensorbackend.h"
+#include <qpressuresensor.h>
-class BbPressureReadingPrivate;
-
-class BbPressureReading : public QSensorReading
-{
- Q_OBJECT
- Q_PROPERTY(qreal pressure READ pressure)
- DECLARE_READING(BbPressureReading)
-public:
- qreal pressure() const;
- void setPressure(qreal pressure);
-};
-
-class BbPressureSensor : public BbSensorBackend<BbPressureReading>
+class BbPressureSensor : public BbSensorBackend<QPressureReading>
{
Q_OBJECT
@@ -65,7 +54,7 @@ public:
static QString devicePath();
protected:
- bool updateReadingFromEvent(const sensor_event_t &event, BbPressureReading *reading) Q_DECL_OVERRIDE;
+ bool updateReadingFromEvent(const sensor_event_t &event, QPressureReading *reading) Q_DECL_OVERRIDE;
};
#endif
diff --git a/src/plugins/sensors/blackberry/bbproximitysensor.cpp b/src/plugins/sensors/blackberry/bbproximitysensor.cpp
index 79f3834a..1177f744 100644
--- a/src/plugins/sensors/blackberry/bbproximitysensor.cpp
+++ b/src/plugins/sensors/blackberry/bbproximitysensor.cpp
@@ -53,9 +53,6 @@ QString BbProximitySensor::devicePath()
bool BbProximitySensor::updateReadingFromEvent(const sensor_event_t &event, QProximityReading *reading)
{
- // TODO: I was unable to test this since the device I was testing this with did not have
- // a proximity sensor. Verify that this works, check that the units are correct
- // and that the threshold makes sense.
const qreal minProximity = sensor()->outputRanges().first().minimum;
reading->setClose(event.proximity_s.distance <= minProximity);
return true;
diff --git a/src/plugins/sensors/blackberry/bbsensorbackend.cpp b/src/plugins/sensors/blackberry/bbsensorbackend.cpp
index fa8c89be..6b614a8a 100644
--- a/src/plugins/sensors/blackberry/bbsensorbackend.cpp
+++ b/src/plugins/sensors/blackberry/bbsensorbackend.cpp
@@ -81,15 +81,17 @@ static void remapMatrix(const float inputMatrix[3*3],
BbSensorBackendBase::BbSensorBackendBase(const QString &devicePath, sensor_type_e sensorType,
QSensor *sensor)
: QSensorBackend(sensor), m_deviceFile(devicePath), m_sensorType(sensorType), m_guiHelper(0),
- m_started(false)
+ m_started(false), m_applyingBufferSize(false)
{
m_mappingMatrix[0] = m_mappingMatrix[3] = 1;
m_mappingMatrix[1] = m_mappingMatrix[2] = 0;
connect(sensor, SIGNAL(alwaysOnChanged()), this, SLOT(applyAlwaysOnProperty()));
+ connect(sensor, SIGNAL(bufferSizeChanged(int)), this, SLOT(applyBuffering()));
+ connect(sensor, SIGNAL(userOrientationChanged(int)), this, SLOT(updateOrientation()));
// Set some sensible default values
- sensor->setProperty("efficientBufferSize", defaultBufferSize);
- sensor->setProperty("maxBufferSize", defaultBufferSize);
+ sensor->setEfficientBufferSize(defaultBufferSize);
+ sensor->setMaxBufferSize(defaultBufferSize);
}
BbGuiHelper *BbSensorBackendBase::guiHelper() const
@@ -107,12 +109,40 @@ sensor_type_e BbSensorBackendBase::sensorType() const
return m_sensorType;
}
+void BbSensorBackendBase::setDevice(const QString &deviceFile, sensor_type_e sensorType)
+{
+ if (deviceFile != m_deviceFile.fileName()) {
+ setPaused(true);
+ delete m_socketNotifier.take();
+ m_deviceFile.close();
+
+ m_sensorType = sensorType;
+ m_deviceFile.setFileName(deviceFile);
+ initSensorInfo();
+ if (m_started)
+ start(); // restart with new device file
+ }
+}
+
void BbSensorBackendBase::initSensorInfo()
{
if (!m_deviceFile.open(QFile::ReadOnly | QFile::Unbuffered)) {
qDebug() << "Failed to open sensor" << m_deviceFile.fileName()
<< ":" << m_deviceFile.errorString();
} else {
+
+ // Explicitly switch to non-blocking mode, otherwise read() will wait until new sensor
+ // data is available, and we have no way to check if there is more data or not (bytesAvailable()
+ // does not work for unbuffered mode)
+ const int oldFlags = fcntl(m_deviceFile.handle(), F_GETFL);
+ if (fcntl(m_deviceFile.handle(), F_SETFL, oldFlags | O_NONBLOCK) == -1) {
+ perror(QString::fromLatin1("Starting sensor %1 failed, fcntl() returned -1")
+ .arg(m_deviceFile.fileName()).toLocal8Bit());
+ sensorError(errno);
+ stop();
+ return;
+ }
+
sensor_devctl_info_u deviceInfo;
const int result = devctl(m_deviceFile.handle(), DCMD_SENSOR_INFO, &deviceInfo,
sizeof(deviceInfo), NULL);
@@ -139,6 +169,7 @@ void BbSensorBackendBase::initSensorInfo()
setPaused(true);
m_socketNotifier.reset(new QSocketNotifier(m_deviceFile.handle(), QSocketNotifier::Read));
+ m_socketNotifier->setEnabled(false);
connect(m_socketNotifier.data(), SIGNAL(activated(int)), this, SLOT(dataAvailable()));
}
}
@@ -168,12 +199,13 @@ qreal BbSensorBackendBase::convertValue(float bbValue)
bool BbSensorBackendBase::isAutoAxisRemappingEnabled() const
{
- return sensor()->property("automaticAxisRemapping").toBool();
+ return sensor()->isFeatureSupported(QSensor::AxesOrientation) &&
+ sensor()->axesOrientationMode() != QSensor::FixedOrientation;
}
void BbSensorBackendBase::remapMatrix(const float inputMatrix[], float outputMatrix[])
{
- if (!isAutoAxisRemappingEnabled() || m_guiHelper->currentOrientation() == 0) {
+ if (!isAutoAxisRemappingEnabled() || orientationForRemapping() == 0) {
memcpy(outputMatrix, inputMatrix, sizeof(float) * 9);
return;
}
@@ -184,10 +216,10 @@ void BbSensorBackendBase::remapMatrix(const float inputMatrix[], float outputMat
void BbSensorBackendBase::remapAxes(float *x, float *y, float *z)
{
Q_ASSERT(x && y && z);
- if (!isAutoAxisRemappingEnabled() || m_guiHelper->currentOrientation() == 0)
+ if (!isAutoAxisRemappingEnabled() || orientationForRemapping() == 0)
return;
- const int angle = m_guiHelper->currentOrientation();
+ const int angle = orientationForRemapping();
const float oldX = *x;
const float oldY = *y;
@@ -239,36 +271,17 @@ void BbSensorBackendBase::start()
}
}
- // Explicitly switch to non-blocking mode, otherwise read() will wait until new sensor
- // data is available, and we have no way to check if there is more data or not (bytesAvailable()
- // does not work for unbuffered mode)
- const int oldFlags = fcntl(m_deviceFile.handle(), F_GETFL);
- if (fcntl(m_deviceFile.handle(), F_SETFL, oldFlags | O_NONBLOCK) == -1) {
- perror(QString::fromLatin1("Starting sensor %1 failed, fcntl() returned -1")
- .arg(m_deviceFile.fileName()).toLocal8Bit());
- sensorError(errno);
- stop();
- return;
- }
-
- // Activate event queuing if needed
- bool ok = false;
- const int requestedBufferSize = sensor()->property("bufferSize").toInt(&ok);
- if (ok && requestedBufferSize > 1) {
- sensor_devctl_queue_u queueControl;
- queueControl.tx.enable = 1;
- const int result = devctl(m_deviceFile.handle(), DCMD_SENSOR_QUEUE, &queueControl, sizeof(queueControl), NULL);
- if (result != EOK) {
- perror(QString::fromLatin1("Enabling sensor queuing for %1 failed")
- .arg(m_deviceFile.fileName()).toLocal8Bit());
- }
-
- const int actualBufferSize = queueControl.rx.size;
- sensor()->setProperty("bufferSize", actualBufferSize);
- sensor()->setProperty("efficientBufferSize", actualBufferSize);
- sensor()->setProperty("maxBufferSize", actualBufferSize);
+ // Enable/disable duplicate skipping
+ sensor_devctl_skipdupevent_u deviceSkip;
+ deviceSkip.tx.enable = sensor()->skipDuplicates();
+ const int result = devctl(deviceFile().handle(), DCMD_SENSOR_SKIPDUPEVENT, &deviceSkip,
+ sizeof(deviceSkip), NULL);
+ if (result != EOK) {
+ perror(QString::fromLatin1("Setting duplicate skipping for %1 failed")
+ .arg(m_deviceFile.fileName()).toLocal8Bit());
}
+ applyBuffering();
applyAlwaysOnProperty();
}
@@ -281,11 +294,23 @@ void BbSensorBackendBase::stop()
bool BbSensorBackendBase::isFeatureSupported(QSensor::Feature feature) const
{
switch (feature) {
+ case QSensor::AxesOrientation:
+ return (sensorType() == SENSOR_TYPE_ACCELEROMETER || sensorType() == SENSOR_TYPE_MAGNETOMETER ||
+ sensorType() == SENSOR_TYPE_GYROSCOPE || sensorType() == SENSOR_TYPE_GRAVITY ||
+ sensorType() == SENSOR_TYPE_LINEAR_ACCEL || sensorType() == SENSOR_TYPE_ROTATION_VECTOR ||
+ sensorType() == SENSOR_TYPE_ROTATION_MATRIX || sensorType() == SENSOR_TYPE_AZIMUTH_PITCH_ROLL);
case QSensor::AlwaysOn:
case QSensor::Buffering:
+ case QSensor::AccelerationMode:
+ case QSensor::SkipDuplicates:
return true;
- case QSensor::Reserved:
case QSensor::GeoValues:
+#ifndef Q_OS_BLACKBERRY_TABLET
+ return (sensorType() == SENSOR_TYPE_MAGNETOMETER);
+#else
+ return false;
+#endif
+ case QSensor::Reserved:
case QSensor::FieldOfView:
break;
}
@@ -295,8 +320,12 @@ bool BbSensorBackendBase::isFeatureSupported(QSensor::Feature feature) const
void BbSensorBackendBase::dataAvailable()
{
- if (!m_started)
+ if (!m_started) {
+ // Spurious dataAvailable() call, drain the device file of data. We also disable
+ // the socket notifier for this, so this is just added safety here.
+ m_deviceFile.readAll();
return;
+ }
Q_FOREVER {
sensor_event_t event;
@@ -331,6 +360,46 @@ void BbSensorBackendBase::applyAlwaysOnProperty()
updatePauseState();
}
+void BbSensorBackendBase::applyBuffering()
+{
+ if (!m_deviceFile.isOpen() || !m_started || m_applyingBufferSize)
+ return;
+
+ // Flag to prevent recursion. We call setBufferSize() below, and because of the changed signal,
+ // we might end up in this slot again.
+ // The call to setBufferSize() is needed since the requested buffer size is most likely different
+ // from the actual buffer size that will be used.
+ m_applyingBufferSize = true;
+
+ const bool enableBuffering = sensor()->bufferSize() > 1;
+ sensor_devctl_queue_u queueControl;
+ queueControl.tx.enable = enableBuffering ? 1 : 0;
+ const int result = devctl(m_deviceFile.handle(), DCMD_SENSOR_QUEUE, &queueControl, sizeof(queueControl), NULL);
+ if (result != EOK) {
+ perror(QString::fromLatin1("Enabling sensor queuing for %1 failed")
+ .arg(m_deviceFile.fileName()).toLocal8Bit());
+ } else {
+ if (enableBuffering) {
+ int actualBufferSize = queueControl.rx.size;
+
+ // Some firmware versions don't report the buffer size correctly. Simply pretend the
+ // buffer size is the same as the requested buffer size, as setting the buffer size to
+ // 1 here would seem as if buffering were disabled.
+ if (actualBufferSize == 1)
+ actualBufferSize = sensor()->bufferSize();
+
+ sensor()->setBufferSize(actualBufferSize);
+ sensor()->setEfficientBufferSize(actualBufferSize);
+ sensor()->setMaxBufferSize(actualBufferSize);
+ } else {
+ sensor()->setBufferSize(1);
+ sensor()->setEfficientBufferSize(defaultBufferSize);
+ sensor()->setMaxBufferSize(defaultBufferSize);
+ }
+ }
+ m_applyingBufferSize = false;
+}
+
bool BbSensorBackendBase::setPaused(bool paused)
{
if (!m_deviceFile.isOpen())
@@ -339,6 +408,9 @@ bool BbSensorBackendBase::setPaused(bool paused)
sensor_devctl_enable_u enableState;
enableState.tx.enable = paused ? 0 : 1;
+ if (m_socketNotifier)
+ m_socketNotifier->setEnabled(!paused);
+
const int result = devctl(m_deviceFile.handle(), DCMD_SENSOR_ENABLE, &enableState, sizeof(enableState), NULL);
if (result != EOK) {
perror(QString::fromLatin1("Setting sensor enabled (%1) for %2 failed")
@@ -360,12 +432,26 @@ void BbSensorBackendBase::updatePauseState()
void BbSensorBackendBase::updateOrientation()
{
- // ### I can't really test this, the rotation matrix has too many glitches and drifts over time,
- // making any measurement quite hard
- const int rotationAngle = guiHelper()->currentOrientation();
+ const int rotationAngle = orientationForRemapping();
m_mappingMatrix[0] = cos(rotationAngle*M_PI/180);
m_mappingMatrix[1] = sin(rotationAngle*M_PI/180);
m_mappingMatrix[2] = -sin(rotationAngle*M_PI/180);
m_mappingMatrix[3] = cos(rotationAngle*M_PI/180);
+
+ if (sensor()->isFeatureSupported(QSensor::AxesOrientation))
+ sensor()->setCurrentOrientation(rotationAngle);
+}
+
+int BbSensorBackendBase::orientationForRemapping() const
+{
+ if (!sensor()->isFeatureSupported(QSensor::AxesOrientation))
+ return 0;
+
+ switch (sensor()->axesOrientationMode()) {
+ default:
+ case QSensor::FixedOrientation: return 0;
+ case QSensor::AutomaticOrientation: return guiHelper()->currentOrientation();
+ case QSensor::UserOrientation: return sensor()->userOrientation();
+ }
}
diff --git a/src/plugins/sensors/blackberry/bbsensorbackend.h b/src/plugins/sensors/blackberry/bbsensorbackend.h
index 7e2ad0ec..4e7b8101 100644
--- a/src/plugins/sensors/blackberry/bbsensorbackend.h
+++ b/src/plugins/sensors/blackberry/bbsensorbackend.h
@@ -76,6 +76,9 @@ protected:
BbGuiHelper *guiHelper() const;
QFile& deviceFile();
sensor_type_e sensorType() const;
+ int orientationForRemapping() const;
+
+ void setDevice(const QString &deviceFile, sensor_type_e sensorType);
// This is called while the device file is open during initalization and gives a subclass
// an opportunity to do additional initalization.
@@ -104,6 +107,7 @@ protected:
private slots:
void dataAvailable();
void applyAlwaysOnProperty();
+ void applyBuffering();
bool setPaused(bool paused);
void updatePauseState();
void updateOrientation();
@@ -115,6 +119,7 @@ private:
BbGuiHelper *m_guiHelper;
float m_mappingMatrix[4];
bool m_started;
+ bool m_applyingBufferSize;
};
template<class SensorReading>
diff --git a/src/plugins/sensors/blackberry/bbtemperaturesensor.cpp b/src/plugins/sensors/blackberry/bbtemperaturesensor.cpp
index f3ec6342..b38fba4d 100644
--- a/src/plugins/sensors/blackberry/bbtemperaturesensor.cpp
+++ b/src/plugins/sensors/blackberry/bbtemperaturesensor.cpp
@@ -40,31 +40,8 @@
****************************************************************************/
#include "bbtemperaturesensor.h"
-class BbTemperatureReadingPrivate
-{
-public:
- BbTemperatureReadingPrivate()
- : temperature(0)
- {
- }
-
- qreal temperature;
-};
-
-IMPLEMENT_READING(BbTemperatureReading)
-
-qreal BbTemperatureReading::temperature() const
-{
- return d->temperature;
-}
-
-void BbTemperatureReading::setTemperature(qreal temperature)
-{
- d->temperature = temperature;
-}
-
BbTemperatureSensor::BbTemperatureSensor(QSensor *sensor)
- : BbSensorBackend<BbTemperatureReading>(devicePath(), SENSOR_TYPE_TEMPERATURE, sensor)
+ : BbSensorBackend<QAmbientTemperatureReading>(devicePath(), SENSOR_TYPE_TEMPERATURE, sensor)
{
setDescription(QLatin1String("Temperature in degrees Celsius"));
}
@@ -74,7 +51,7 @@ QString BbTemperatureSensor::devicePath()
return QLatin1String("/dev/sensor/temp");
}
-bool BbTemperatureSensor::updateReadingFromEvent(const sensor_event_t &event, BbTemperatureReading *reading)
+bool BbTemperatureSensor::updateReadingFromEvent(const sensor_event_t &event, QAmbientTemperatureReading *reading)
{
// TODO: I was unable to test this since the device I was testing this with did not have
// a temperature sensor. Verify that this works and check that the units are correct.
diff --git a/src/plugins/sensors/blackberry/bbtemperaturesensor.h b/src/plugins/sensors/blackberry/bbtemperaturesensor.h
index 1b9ea1bf..a24c67e7 100644
--- a/src/plugins/sensors/blackberry/bbtemperaturesensor.h
+++ b/src/plugins/sensors/blackberry/bbtemperaturesensor.h
@@ -42,20 +42,9 @@
#define BBTEMPERATURESENSOR_H
#include "bbsensorbackend.h"
+#include <qambienttemperaturesensor.h>
-class BbTemperatureReadingPrivate;
-
-class BbTemperatureReading : public QSensorReading
-{
- Q_OBJECT
- Q_PROPERTY(qreal temperature READ temperature)
- DECLARE_READING(BbTemperatureReading)
-public:
- qreal temperature() const;
- void setTemperature(qreal temperature);
-};
-
-class BbTemperatureSensor : public BbSensorBackend<BbTemperatureReading>
+class BbTemperatureSensor : public BbSensorBackend<QAmbientTemperatureReading>
{
Q_OBJECT
@@ -65,7 +54,7 @@ public:
static QString devicePath();
protected:
- bool updateReadingFromEvent(const sensor_event_t &event, BbTemperatureReading *reading);
+ bool updateReadingFromEvent(const sensor_event_t &event, QAmbientTemperatureReading *reading);
};
#endif
diff --git a/src/plugins/sensors/blackberry/blackberry.pro b/src/plugins/sensors/blackberry/blackberry.pro
index 73027c20..902239c4 100644
--- a/src/plugins/sensors/blackberry/blackberry.pro
+++ b/src/plugins/sensors/blackberry/blackberry.pro
@@ -12,6 +12,10 @@ config_bbsensor_compass {
DEFINES += HAVE_COMPASS_SENSOR
}
+config_bbsensor_holster {
+ DEFINES += HAVE_HOLSTER_SENSOR
+}
+
HEADERS += bbsensorbackend.h \
bbaccelerometer.h \
bbaltimeter.h \
@@ -47,4 +51,9 @@ SOURCES += bbsensorbackend.cpp \
bbutil.cpp \
main.cpp
+config_bbsensor_holster {
+ HEADERS += bbholstersensor.h
+ SOURCES += bbholstersensor.cpp
+}
+
OTHER_FILES = plugin.json
diff --git a/src/plugins/sensors/blackberry/main.cpp b/src/plugins/sensors/blackberry/main.cpp
index 7c2d5dbc..61f9aa08 100644
--- a/src/plugins/sensors/blackberry/main.cpp
+++ b/src/plugins/sensors/blackberry/main.cpp
@@ -43,6 +43,9 @@
#include "bbambientlightsensor.h"
#include "bbcompass.h"
#include "bbgyroscope.h"
+#ifdef HAVE_HOLSTER_SENSOR
+#include "bbholstersensor.h"
+#endif
#include "bbirproximitysensor.h"
#include "bblightsensor.h"
#include "bbmagnetometer.h"
@@ -61,6 +64,9 @@ static const char *bbAltitmeterId = "bbAltimeter";
static const char *bbAmbientLightSensorId = "bbAmbientLightSensor";
static const char *bbCompassId = "bbCompass";
static const char *bbGyroscopeId = "bbGyroscope";
+#ifdef HAVE_HOLSTER_SENSOR
+static const char *bbHolsterSensorId = "bbHolsterSensor";
+#endif
static const char *bbIRProximitySensorId = "bbIRProximitySensor";
static const char *bbLightSensorId = "bbLightSensor";
static const char *bbMagnetometerId = "bbMagnetometer";
@@ -82,13 +88,17 @@ public:
if (sensorSupported(BbAccelerometer::devicePath()))
QSensorManager::registerBackend(QAccelerometer::type, bbAccelerometerId, this);
if (sensorSupported(BbAltimeter::devicePath()))
- QSensorManager::registerBackend("BbAltimeter", bbAltitmeterId, this);
+ QSensorManager::registerBackend(QAltimeter::type, bbAltitmeterId, this);
if (sensorSupported(BbAmbientLightSensor::devicePath()))
QSensorManager::registerBackend(QAmbientLightSensor::type, bbAmbientLightSensorId, this);
if (sensorSupported(BbCompass::devicePath()))
QSensorManager::registerBackend(QCompass::type, bbCompassId, this);
if (sensorSupported(BbGyroscope::devicePath()))
QSensorManager::registerBackend(QGyroscope::type, bbGyroscopeId, this);
+#ifdef HAVE_HOLSTER_SENSOR
+ if (sensorSupported(BbHolsterSensor::devicePath()))
+ QSensorManager::registerBackend(QHolsterSensor::type, bbHolsterSensorId, this);
+#endif
if (sensorSupported(BbIRProximitySensor::devicePath()))
QSensorManager::registerBackend(QIRProximitySensor::type, bbIRProximitySensorId, this);
if (sensorSupported(BbLightSensor::devicePath()))
@@ -98,13 +108,13 @@ public:
if (sensorSupported(BbOrientationSensor::devicePath()))
QSensorManager::registerBackend(QOrientationSensor::type, bbOrientationSensorId, this);
if (sensorSupported(BbPressureSensor::devicePath()))
- QSensorManager::registerBackend("BbPressureSensor", bbPressureSensorId, this);
+ QSensorManager::registerBackend(QPressureSensor::type, bbPressureSensorId, this);
if (sensorSupported(BbProximitySensor::devicePath()))
QSensorManager::registerBackend(QProximitySensor::type, bbProximitySensorId, this);
if (sensorSupported(BbRotationSensor::devicePath()))
QSensorManager::registerBackend(QRotationSensor::type, bbRotationSensorId, this);
if (sensorSupported(BbTemperatureSensor::devicePath()))
- QSensorManager::registerBackend("BbTemperatureSensor", bbTemperatureSensorId, this);
+ QSensorManager::registerBackend(QAmbientTemperatureSensor::type, bbTemperatureSensorId, this);
}
QSensorBackend *createBackend(QSensor *sensor) Q_DECL_OVERRIDE
@@ -120,6 +130,10 @@ public:
backend = new BbCompass(sensor);
if (sensor->identifier() == bbGyroscopeId)
backend = new BbGyroscope(sensor);
+#ifdef HAVE_HOLSTER_SENSOR
+ if (sensor->identifier() == bbHolsterSensorId)
+ backend = new BbHolsterSensor(sensor);
+#endif
if (sensor->identifier() == bbIRProximitySensorId)
backend = new BbIRProximitySensor(sensor);
if (sensor->identifier() == bbLightSensorId)
diff --git a/src/plugins/sensors/dummy/dummy.pro b/src/plugins/sensors/dummy/dummy.pro
index b97bd9ce..f54588af 100644
--- a/src/plugins/sensors/dummy/dummy.pro
+++ b/src/plugins/sensors/dummy/dummy.pro
@@ -15,4 +15,4 @@ SOURCES += dummycommon.cpp\
OTHER_FILES = plugin.json
-unix:!mac:!qnx:LIBS+=-lrt
+unix:!mac:!qnx:!android:LIBS+=-lrt
diff --git a/src/plugins/sensors/generic/generic.pro b/src/plugins/sensors/generic/generic.pro
index 2d4f9f9f..fcc1bfcd 100644
--- a/src/plugins/sensors/generic/generic.pro
+++ b/src/plugins/sensors/generic/generic.pro
@@ -4,15 +4,27 @@ QT = core sensors
PLUGIN_TYPE = sensors
load(qt_plugin)
-HEADERS += genericorientationsensor.h\
- genericrotationsensor.h\
- genericalssensor.h\
- generictiltsensor.h
-
-SOURCES += genericorientationsensor.cpp\
- main.cpp\
- genericrotationsensor.cpp\
- genericalssensor.cpp\
+HEADERS += generictiltsensor.h
+
+SOURCES += main.cpp\
generictiltsensor.cpp
+DEFINES += QTSENSORS_GENERICTILTSENSOR
+
+!blackberry {
+ HEADERS += genericorientationsensor.h\
+ genericalssensor.h
+
+ SOURCES += genericorientationsensor.cpp\
+ genericalssensor.cpp
+ DEFINES += QTSENSORS_GENERICORIENTATIONSENSOR QTSENSORS_GENERICALSSENSOR
+}
+
+!blackberry:!android {
+ HEADERS += genericrotationsensor.h
+
+ SOURCES += genericrotationsensor.cpp
+
+ DEFINES += QTSENSORS_GENERICROTATIONSENSOR
+}
OTHER_FILES = plugin.json
diff --git a/src/plugins/sensors/generic/genericrotationsensor.cpp b/src/plugins/sensors/generic/genericrotationsensor.cpp
index b5f80cb3..0548adc0 100644
--- a/src/plugins/sensors/generic/genericrotationsensor.cpp
+++ b/src/plugins/sensors/generic/genericrotationsensor.cpp
@@ -57,7 +57,9 @@ genericrotationsensor::genericrotationsensor(QSensor *sensor)
setReading<QRotationReading>(&m_reading);
setDataRates(accelerometer);
- sensor->setProperty("hasZ", false);
+ QRotationSensor * const rotationSensor = qobject_cast<QRotationSensor *>(sensor);
+ if (rotationSensor)
+ rotationSensor->setHasZ(false);
}
void genericrotationsensor::start()
diff --git a/src/plugins/sensors/generic/genericrotationsensor.h b/src/plugins/sensors/generic/genericrotationsensor.h
index 3475cafe..ffa48ea3 100644
--- a/src/plugins/sensors/generic/genericrotationsensor.h
+++ b/src/plugins/sensors/generic/genericrotationsensor.h
@@ -62,7 +62,6 @@ public:
private:
QRotationReading m_reading;
QAccelerometer *accelerometer;
- QMagnetometer *magnetometer;
};
#endif
diff --git a/src/plugins/sensors/generic/generictiltsensor.cpp b/src/plugins/sensors/generic/generictiltsensor.cpp
index 6aefb576..95c8525b 100644
--- a/src/plugins/sensors/generic/generictiltsensor.cpp
+++ b/src/plugins/sensors/generic/generictiltsensor.cpp
@@ -53,6 +53,8 @@ GenericTiltSensor::GenericTiltSensor(QSensor *sensor)
, roll(0)
, calibratedPitch(0)
, calibratedRoll(0)
+ , xRotation(0)
+ , yRotation(0)
{
accelerometer = new QAccelerometer(this);
accelerometer->addFilter(this);
@@ -106,6 +108,11 @@ void GenericTiltSensor::calibrate()
calibratedRoll = roll;
}
+static qreal rad2deg(qreal rad)
+{
+ return rad / (2 * M_PI) * 360;
+}
+
bool GenericTiltSensor::filter(QAccelerometerReading *reading)
{
/*
@@ -119,16 +126,16 @@ bool GenericTiltSensor::filter(QAccelerometerReading *reading)
qreal az = reading->z();
#ifdef LOGCALIBRATION
qDebug() << "------------ new value -----------";
- qDebug() << "old _pitch: " << _pitch;
- qDebug() << "old _roll: " << _roll;
- qDebug() << "_calibratedPitch: " << _calibratedPitch;
- qDebug() << "_calibratedRoll: " << _calibratedRoll;
+ qDebug() << "old _pitch: " << pitch;
+ qDebug() << "old _roll: " << roll;
+ qDebug() << "_calibratedPitch: " << calibratedPitch;
+ qDebug() << "_calibratedRoll: " << calibratedRoll;
#endif
pitch = calcPitch(ax, ay, az);
roll = calcRoll (ax, ay, az);
#ifdef LOGCALIBRATION
- qDebug() << "_pitch: " << _pitch;
- qDebug() << "_roll: " << _roll;
+ qDebug() << "_pitch: " << pitch;
+ qDebug() << "_roll: " << roll;
#endif
qreal xrot = roll - calibratedRoll;
qreal yrot = pitch - calibratedPitch;
@@ -154,23 +161,22 @@ bool GenericTiltSensor::filter(QAccelerometerReading *reading)
qDebug() << "new yrot: " << yrot;
qDebug() << "----------------------------------";
#endif
- qreal dxrot = xrot - xRotation;
- qreal dyrot = yrot - yRotation;
+ qreal dxrot = rad2deg(xrot) - xRotation;
+ qreal dyrot = rad2deg(yrot) - yRotation;
if (dxrot < 0) dxrot = -dxrot;
if (dyrot < 0) dyrot = -dyrot;
- bool change = false;
- if (dxrot >= radAccuracy) {
- xRotation = xrot;
- change = true;
+ bool setNewReading = false;
+ if (dxrot >= rad2deg(radAccuracy) || !sensor()->skipDuplicates()) {
+ xRotation = rad2deg(xrot);
+ setNewReading = true;
}
- if (dyrot >= radAccuracy) {
- yRotation = yrot;
- change = true;
+ if (dyrot >= rad2deg(radAccuracy) || !sensor()->skipDuplicates()) {
+ yRotation = rad2deg(yrot);
+ setNewReading = true;
}
- if (xRotation != m_reading.xRotation()
- || yRotation != m_reading.yRotation()
- || m_reading.timestamp() == 0) {
+
+ if (setNewReading || m_reading.timestamp() == 0) {
m_reading.setTimestamp(reading->timestamp());
m_reading.setXRotation(xRotation);
m_reading.setYRotation(yRotation);
@@ -179,3 +185,8 @@ bool GenericTiltSensor::filter(QAccelerometerReading *reading)
return false;
}
+
+bool GenericTiltSensor::isFeatureSupported(QSensor::Feature feature) const
+{
+ return (feature == QSensor::SkipDuplicates);
+}
diff --git a/src/plugins/sensors/generic/generictiltsensor.h b/src/plugins/sensors/generic/generictiltsensor.h
index 0633662c..0f84ca6f 100644
--- a/src/plugins/sensors/generic/generictiltsensor.h
+++ b/src/plugins/sensors/generic/generictiltsensor.h
@@ -46,7 +46,6 @@
#include <qtiltsensor.h>
#include <qaccelerometer.h>
-QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
class GenericTiltSensor : public QSensorBackend, public QAccelerometerFilter
@@ -64,6 +63,8 @@ public:
bool filter(QAccelerometerReading *reading);
+ bool isFeatureSupported(QSensor::Feature feature) const Q_DECL_OVERRIDE;
+
private:
QTiltReading m_reading;
QAccelerometer *accelerometer;
@@ -77,7 +78,6 @@ private:
};
QT_END_NAMESPACE
-QT_END_HEADER
#endif
diff --git a/src/plugins/sensors/generic/main.cpp b/src/plugins/sensors/generic/main.cpp
index 15507b63..aa9f58c2 100644
--- a/src/plugins/sensors/generic/main.cpp
+++ b/src/plugins/sensors/generic/main.cpp
@@ -39,9 +39,18 @@
**
****************************************************************************/
+#ifdef QTSENSORS_GENERICORIENTATIONSENSOR
#include "genericorientationsensor.h"
+#endif
+#ifdef QTSENSORS_GENERICROTATIONSENSOR
#include "genericrotationsensor.h"
+#endif
+#ifdef QTSENSORS_GENERICALSSENSOR
#include "genericalssensor.h"
+#endif
+#ifdef QTSENSORS_GENERICTILTSENSOR
+#include "generictiltsensor.h"
+#endif
#include <qsensorplugin.h>
#include <qsensorbackend.h>
#include <qsensormanager.h>
@@ -56,7 +65,6 @@ class genericSensorPlugin : public QObject, public QSensorPluginInterface, publi
public:
void registerSensors()
{
- qDebug() << "loaded the Generic plugin";
// Nothing to register here
}
@@ -64,34 +72,60 @@ public:
{
if (!QSensor::defaultSensorForType(QAccelerometer::type).isEmpty()) {
// There is an accelerometer available. Register the backends
+#ifdef QTSENSORS_GENERICORIENTATIONSENSOR
if (!QSensorManager::isBackendRegistered(QOrientationSensor::type, genericorientationsensor::id))
QSensorManager::registerBackend(QOrientationSensor::type, genericorientationsensor::id, this);
+#endif
+#ifdef QTSENSORS_GENERICROTATIONSENSOR
if (!QSensorManager::isBackendRegistered(QRotationSensor::type, genericrotationsensor::id))
QSensorManager::registerBackend(QRotationSensor::type, genericrotationsensor::id, this);
+#endif
+#ifdef QTSENSORS_GENERICALSSENSOR
if (!QSensorManager::isBackendRegistered(QAmbientLightSensor::type, genericalssensor::id))
QSensorManager::registerBackend(QAmbientLightSensor::type, genericalssensor::id, this);
- if (!QSensorManager::isBackendRegistered(QAmbientLightSensor::type, genericalssensor::id))
- QSensorManager::registerBackend(QAmbientLightSensor::type, genericalssensor::id, this);
+#endif
+#ifdef QTSENSORS_GENERICTILTSENSOR
+ if (!QSensorManager::isBackendRegistered(QTiltSensor::type, GenericTiltSensor::id))
+ QSensorManager::registerBackend(QTiltSensor::type, GenericTiltSensor::id, this);
+#endif
} else {
+#ifdef QTSENSORS_GENERICORIENTATIONSENSOR
if (QSensorManager::isBackendRegistered(QOrientationSensor::type, genericorientationsensor::id))
QSensorManager::unregisterBackend(QOrientationSensor::type, genericorientationsensor::id);
+#endif
+#ifdef QTSENSORS_GENERICROTATIONSENSOR
if (QSensorManager::isBackendRegistered(QRotationSensor::type, genericrotationsensor::id))
QSensorManager::unregisterBackend(QRotationSensor::type, genericrotationsensor::id);
+#endif
+#ifdef QTSENSORS_GENERICALSSENSOR
if (QSensorManager::isBackendRegistered(QAmbientLightSensor::type, genericalssensor::id))
QSensorManager::unregisterBackend(QAmbientLightSensor::type, genericalssensor::id);
+#endif
+#ifdef QTSENSORS_GENERICTILTSENSOR
+ if (QSensorManager::isBackendRegistered(QTiltSensor::type, GenericTiltSensor::id))
+ QSensorManager::unregisterBackend(QTiltSensor::type, GenericTiltSensor::id);
+#endif
}
}
QSensorBackend *createBackend(QSensor *sensor)
{
+#ifdef QTSENSORS_GENERICORIENTATIONSENSOR
if (sensor->identifier() == genericorientationsensor::id)
return new genericorientationsensor(sensor);
-
+#endif
+#ifdef QTSENSORS_GENERICROTATIONSENSOR
if (sensor->identifier() == genericrotationsensor::id)
return new genericrotationsensor(sensor);
-
+#endif
+#ifdef QTSENSORS_GENERICALSSENSOR
if (sensor->identifier() == genericalssensor::id)
return new genericalssensor(sensor);
+#endif
+#ifdef QTSENSORS_GENERICTILTSENSOR
+ if (sensor->identifier() == GenericTiltSensor::id)
+ return new GenericTiltSensor(sensor);
+#endif
return 0;
}
diff --git a/src/plugins/sensors/ios/ios.pro b/src/plugins/sensors/ios/ios.pro
new file mode 100644
index 00000000..4242cfca
--- /dev/null
+++ b/src/plugins/sensors/ios/ios.pro
@@ -0,0 +1,17 @@
+TARGET = qtsensors_ios
+QT = core sensors
+
+PLUGIN_TYPE = sensors
+PLUGIN_CLASS_NAME = IOSSensorPlugin
+load(qt_plugin)
+
+OTHER_FILES = plugin.json
+
+HEADERS += iosaccelerometer.h \
+ iosmotionmanager.h
+
+OBJECTIVE_SOURCES += main.mm \
+ iosaccelerometer.mm \
+ iosmotionmanager.mm
+
+LIBS += -framework UIKit -framework CoreMotion
diff --git a/src/plugins/sensors/ios/iosaccelerometer.h b/src/plugins/sensors/ios/iosaccelerometer.h
new file mode 100644
index 00000000..34cc3ebd
--- /dev/null
+++ b/src/plugins/sensors/ios/iosaccelerometer.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Lorn Potter
+** 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 IOSACCELEROMETER_H
+#define IOSACCELEROMETER_H
+
+#include <qsensorbackend.h>
+#include <qaccelerometer.h>
+
+QT_BEGIN_NAMESPACE
+
+@class QtIoAccelListener;
+
+class IOSAccelerometer : public QSensorBackend
+{
+public:
+ static char const * const id;
+
+ explicit IOSAccelerometer(QSensor *sensor);
+ ~IOSAccelerometer();
+
+ void start();
+ void stop();
+ void readingsChanged(quint64,qreal,qreal,qreal);
+
+private:
+ QtIoAccelListener *m_listener;
+ QAccelerometerReading m_reading;
+};
+QT_END_NAMESPACE
+
+#endif // IOSACCELEROMETER_H
+
diff --git a/src/plugins/sensors/ios/iosaccelerometer.mm b/src/plugins/sensors/ios/iosaccelerometer.mm
new file mode 100644
index 00000000..ef7d2a6d
--- /dev/null
+++ b/src/plugins/sensors/ios/iosaccelerometer.mm
@@ -0,0 +1,143 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Lorn Potter
+** 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 "iosaccelerometer.h"
+#include "iosmotionmanager.h"
+
+#include <UIKit/UIAccelerometer.h>
+#include <CoreMotion/CMMotionManager.h>
+
+char const * const IOSAccelerometer::id("ios.accelerometer");
+
+@interface QtIoAccelListener : NSObject
+{
+ IOSAccelerometer *m_qiosAccelerometer;
+ NSOperationQueue *m_updateQueue;
+}
+@end
+
+@implementation QtIoAccelListener
+
+-(id)initWithQIOSAccelerometer:(IOSAccelerometer *) qiosAccelerometer
+{
+ self = [super init];
+ if (self) {
+ m_qiosAccelerometer = qiosAccelerometer;
+ m_updateQueue = [[NSOperationQueue alloc] init];
+ }
+ return self;
+}
+
+-(void)dealloc
+{
+ [m_updateQueue release];
+ [super dealloc];
+}
+
+-(void)startAccelerometer
+{
+ CMMotionManager *motionManager = [QIOSMotionManager sharedManager];
+
+ if (motionManager.deviceMotionAvailable) {
+ [motionManager startAccelerometerUpdatesToQueue:m_updateQueue withHandler:^(CMAccelerometerData *data, NSError *error) {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ Q_UNUSED(error);
+ CMAcceleration acc = data.acceleration;
+ // Convert from G to m/s2, and flip axes:
+ const qreal G = 9.8066;
+ qreal x = qreal(acc.x) * G * -1;
+ qreal y = qreal(acc.y) * G * -1;
+ qreal z = qreal(acc.z) * G * -1;
+ m_qiosAccelerometer->readingsChanged(quint64(data.timestamp), x, y, z);
+ });
+ }];
+ }
+}
+
+-(void)stopAccelerometer
+{
+ [[QIOSMotionManager sharedManager] stopAccelerometerUpdates];
+}
+
+-(void)setInterval:(NSTimeInterval) interval
+{
+ [QIOSMotionManager sharedManager].accelerometerUpdateInterval = interval;
+}
+
+@end
+
+QT_BEGIN_NAMESPACE
+
+IOSAccelerometer::IOSAccelerometer(QSensor *sensor)
+ : QSensorBackend(sensor)
+ , m_listener([[QtIoAccelListener alloc] initWithQIOSAccelerometer:this])
+{
+ setReading<QAccelerometerReading>(&m_reading);
+ addDataRate(1, 100); // 100Hz
+ addOutputRange(-22.418, 22.418, 0.17651); // 2G
+}
+
+IOSAccelerometer::~IOSAccelerometer()
+{
+ [m_listener dealloc];
+}
+
+void IOSAccelerometer::start()
+{
+ [m_listener startAccelerometer];
+}
+
+void IOSAccelerometer::stop()
+{
+ [m_listener stopAccelerometer];
+}
+
+void IOSAccelerometer::readingsChanged(quint64 ts, qreal x, qreal y, qreal z)
+{
+ m_reading.setTimestamp(ts);
+ m_reading.setX(x);
+ m_reading.setY(y);
+ m_reading.setZ(z);
+
+ newReadingAvailable();
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/sensors/ios/iosmotionmanager.h b/src/plugins/sensors/ios/iosmotionmanager.h
new file mode 100644
index 00000000..7babfc36
--- /dev/null
+++ b/src/plugins/sensors/ios/iosmotionmanager.h
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Lorn Potter
+** 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 IOSMOTIONMANAGER_H
+#define IOSMOTIONMANAGER_H
+
+#import <UIKit/UIKit.h>
+#import <CoreMotion/CoreMotion.h>
+
+@interface QIOSMotionManager : NSObject {
+}
+
++ (CMMotionManager *)sharedManager;
+@end
+
+#endif //IOSMOTIONMANAGER_H
+
diff --git a/src/plugins/sensors/ios/iosmotionmanager.mm b/src/plugins/sensors/ios/iosmotionmanager.mm
new file mode 100644
index 00000000..a367c49b
--- /dev/null
+++ b/src/plugins/sensors/ios/iosmotionmanager.mm
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Lorn Potter
+** 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 "iosmotionmanager.h"
+
+static CMMotionManager *sharedManager = nil;
+
+@implementation QIOSMotionManager
+
++ (CMMotionManager *)sharedManager
+{
+ static dispatch_once_t staticToken;
+ dispatch_once(&staticToken, ^{
+ sharedManager = [[CMMotionManager alloc] init];
+ });
+ return sharedManager;
+}
+
+@end
diff --git a/src/plugins/sensors/ios/main.mm b/src/plugins/sensors/ios/main.mm
new file mode 100644
index 00000000..3c739393
--- /dev/null
+++ b/src/plugins/sensors/ios/main.mm
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 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 <qsensorplugin.h>
+#include <qsensorbackend.h>
+#include <qsensormanager.h>
+
+#include "iosaccelerometer.h"
+
+class IOSSensorPlugin : public QObject, public QSensorPluginInterface, public QSensorBackendFactory
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID "com.qt-project.Qt.QSensorPluginInterface/1.0" FILE "plugin.json")
+ Q_INTERFACES(QSensorPluginInterface)
+public:
+ void registerSensors()
+ {
+ if (!QSensorManager::isBackendRegistered(QAccelerometer::type, IOSAccelerometer::id))
+ QSensorManager::registerBackend(QAccelerometer::type, IOSAccelerometer::id, this);
+ }
+
+ QSensorBackend *createBackend(QSensor *sensor)
+ {
+ if (sensor->identifier() == IOSAccelerometer::id)
+ return new IOSAccelerometer(sensor);
+
+ return 0;
+ }
+};
+
+#include "main.moc"
+
diff --git a/src/plugins/sensors/ios/plugin.json b/src/plugins/sensors/ios/plugin.json
new file mode 100644
index 00000000..8a55b3ae
--- /dev/null
+++ b/src/plugins/sensors/ios/plugin.json
@@ -0,0 +1 @@
+{ "Keys": [ "notused" ] }
diff --git a/src/plugins/sensors/linux/linux.pro b/src/plugins/sensors/linux/linux.pro
index 7546728f..25c4f2d9 100644
--- a/src/plugins/sensors/linux/linux.pro
+++ b/src/plugins/sensors/linux/linux.pro
@@ -6,7 +6,7 @@ load(qt_plugin)
OTHER_FILES = plugin.json
-LIBS += -lrt
+!android:LIBS += -lrt
HEADERS += linuxsysaccelerometer.h
SOURCES += linuxsysaccelerometer.cpp \
main.cpp
diff --git a/src/plugins/sensors/sensorfw/Sensors.conf b/src/plugins/sensors/sensorfw/Sensors.conf
new file mode 100644
index 00000000..a003f12c
--- /dev/null
+++ b/src/plugins/sensors/sensorfw/Sensors.conf
@@ -0,0 +1,11 @@
+[Default]
+QAccelerometer=sensorfw.accelerometer
+QAmbientLightSensor=sensorfw.als
+QCompass=sensorfw.compass
+QMagnetometer=sensorfw.magnetometer
+QOrientationSensor=sensorfw.orientationsensor
+QProximitySensor=sensorfw.proximitysensor
+QRotationSensor=sensorfw.rotationsensor
+QTapSensor=sensorfw.tapsensor
+QLightSensor=sensorfw.lightsensor
+QIRProximitySensor=sensorfw.irproximitysensor
diff --git a/src/plugins/sensors/sensorfw/main.cpp b/src/plugins/sensors/sensorfw/main.cpp
new file mode 100644
index 00000000..f12a193e
--- /dev/null
+++ b/src/plugins/sensors/sensorfw/main.cpp
@@ -0,0 +1,109 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 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 "sensorfwaccelerometer.h"
+#include "sensorfwals.h"
+#include "sensorfwcompass.h"
+#include "sensorfwmagnetometer.h"
+#include "sensorfworientationsensor.h"
+#include "sensorfwproximitysensor.h"
+#include "sensorfwirproximitysensor.h"
+#include "sensorfwrotationsensor.h"
+#include "sensorfwtapsensor.h"
+#include "sensorfwgyroscope.h"
+#include "sensorfwlightsensor.h"
+
+#include <qsensorplugin.h>
+#include <qsensorbackend.h>
+#include <qsensormanager.h>
+#include <QDebug>
+#include <QSettings>
+
+class sensorfwSensorPlugin : public QObject, public QSensorPluginInterface, public QSensorBackendFactory
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID "com.qt-project.Qt.QSensorPluginInterface/1.0" FILE "plugin.json")
+ Q_INTERFACES(QSensorPluginInterface)
+
+public:
+
+ void registerSensors()
+ {
+ // if no default - no support either, uses Sensors.conf
+ QSettings settings(QSettings::SystemScope, QLatin1String("QtProject"), QLatin1String("Sensors"));
+ settings.beginGroup(QLatin1String("Default"));
+ QStringList keys = settings.allKeys();
+ for (int i=0,l=keys.size(); i<l; i++) {
+ QString type = keys.at(i);
+ QSensorManager::registerBackend(type.toLocal8Bit(), settings.value(type).toByteArray(), this);
+ }
+ }
+
+
+ QSensorBackend *createBackend(QSensor *sensor)
+ {
+ if (sensor->identifier() == sensorfwaccelerometer::id)
+ return new sensorfwaccelerometer(sensor);
+ if (sensor->identifier() == Sensorfwals::id)
+ return new Sensorfwals(sensor);
+ if (sensor->identifier() == SensorfwCompass::id)
+ return new SensorfwCompass(sensor);
+ if (sensor->identifier() == SensorfwMagnetometer::id)
+ return new SensorfwMagnetometer(sensor);
+ if (sensor->identifier() == SensorfwOrientationSensor::id)
+ return new SensorfwOrientationSensor(sensor);
+ if (sensor->identifier() == SensorfwProximitySensor::id)
+ return new SensorfwProximitySensor(sensor);
+ if (sensor->identifier() == SensorfwRotationSensor::id)
+ return new SensorfwRotationSensor(sensor);
+ if (sensor->identifier() == SensorfwTapSensor::id)
+ return new SensorfwTapSensor(sensor);
+ if (sensor->identifier() == SensorfwGyroscope::id)
+ return new SensorfwGyroscope(sensor);
+ if (sensor->identifier() == SensorfwLightSensor::id)
+ return new SensorfwLightSensor(sensor);
+ if (sensor->identifier() == SensorfwIrProximitySensor::id)
+ return new SensorfwIrProximitySensor(sensor);
+ return 0;
+ }
+};
+
+#include "main.moc"
diff --git a/src/plugins/sensors/sensorfw/plugin.json b/src/plugins/sensors/sensorfw/plugin.json
new file mode 100644
index 00000000..8a55b3ae
--- /dev/null
+++ b/src/plugins/sensors/sensorfw/plugin.json
@@ -0,0 +1 @@
+{ "Keys": [ "notused" ] }
diff --git a/src/plugins/sensors/sensorfw/sensorfw.pri b/src/plugins/sensors/sensorfw/sensorfw.pri
new file mode 100644
index 00000000..31d7254c
--- /dev/null
+++ b/src/plugins/sensors/sensorfw/sensorfw.pri
@@ -0,0 +1,26 @@
+HEADERS += sensorfwsensorbase.h \
+ sensorfwaccelerometer.h \
+ sensorfwals.h \
+ sensorfwcompass.h \
+ sensorfwgyroscope.h \
+ sensorfwmagnetometer.h \
+ sensorfworientationsensor.h \
+ sensorfwproximitysensor.h \
+ sensorfwrotationsensor.h \
+ sensorfwtapsensor.h \
+ sensorfwlightsensor.h \
+ sensorfwirproximitysensor.h
+
+SOURCES += sensorfwsensorbase.cpp \
+ sensorfwaccelerometer.cpp \
+ sensorfwals.cpp \
+ sensorfwcompass.cpp \
+ sensorfwgyroscope.cpp \
+ sensorfwmagnetometer.cpp \
+ sensorfworientationsensor.cpp \
+ sensorfwproximitysensor.cpp \
+ sensorfwirproximitysensor.cpp \
+ sensorfwrotationsensor.cpp \
+ sensorfwtapsensor.cpp \
+ sensorfwlightsensor.cpp \
+ main.cpp
diff --git a/src/plugins/sensors/sensorfw/sensorfw.pro b/src/plugins/sensors/sensorfw/sensorfw.pro
new file mode 100644
index 00000000..8d67c81f
--- /dev/null
+++ b/src/plugins/sensors/sensorfw/sensorfw.pro
@@ -0,0 +1,17 @@
+TARGET = qtsensors_sensorfw
+QT = core sensors network
+
+PLUGIN_TYPE = sensors
+load(qt_plugin)
+
+include(sensorfw.pri)
+
+
+CONFIG += link_pkgconfig
+PKGCONFIG += sensord
+
+CONFIGFILES.files = Sensors.conf
+CONFIGFILES.path = /etc/xdg/QtProject/
+INSTALLS += CONFIGFILES
+
+OTHER_FILES = plugin.json
diff --git a/src/plugins/sensors/sensorfw/sensorfwaccelerometer.cpp b/src/plugins/sensors/sensorfw/sensorfwaccelerometer.cpp
new file mode 100644
index 00000000..ddbaa9c6
--- /dev/null
+++ b/src/plugins/sensors/sensorfw/sensorfwaccelerometer.cpp
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 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 "sensorfwaccelerometer.h"
+
+char const * const sensorfwaccelerometer::id("sensorfw.accelerometer");
+bool sensorfwaccelerometer::m_initDone = false;
+
+sensorfwaccelerometer::sensorfwaccelerometer(QSensor *sensor)
+ : SensorfwSensorBase(sensor)
+{
+ initSensor<AccelerometerSensorChannelInterface>(m_initDone);
+ setDescription(QLatin1String("x, y, and z axes accelerations in m/s^2"));
+ setRanges(GRAVITY_EARTH_THOUSANDTH);
+ setReading<QAccelerometerReading>(&m_reading);
+}
+
+void sensorfwaccelerometer::slotDataAvailable(const XYZ& data)
+{
+ // Convert from milli-Gs to meters per second per second
+ // Using 1 G = 9.80665 m/s^2
+ m_reading.setX(-data.x() * GRAVITY_EARTH_THOUSANDTH);
+ m_reading.setY(-data.y() * GRAVITY_EARTH_THOUSANDTH);
+ m_reading.setZ(-data.z() * GRAVITY_EARTH_THOUSANDTH);
+ m_reading.setTimestamp(data.XYZData().timestamp_);
+ newReadingAvailable();
+}
+
+void sensorfwaccelerometer::slotFrameAvailable(const QVector<XYZ>& frame)
+{
+ for (int i=0, l=frame.size(); i<l; i++) {
+ slotDataAvailable(frame.at(i));
+ }
+}
+
+bool sensorfwaccelerometer::doConnect()
+{
+ if (m_bufferSize==1)
+ return QObject::connect(m_sensorInterface, SIGNAL(dataAvailable(const XYZ&)), this, SLOT(slotDataAvailable(const XYZ&)));
+ return QObject::connect(m_sensorInterface, SIGNAL(frameAvailable(const QVector<XYZ>& )),this, SLOT(slotFrameAvailable(const QVector<XYZ>& )));
+}
+
+
+QString sensorfwaccelerometer::sensorName() const
+{
+ return "accelerometersensor";
+}
+
+
+qreal sensorfwaccelerometer::correctionFactor() const
+{
+ return GRAVITY_EARTH_THOUSANDTH;
+}
diff --git a/src/plugins/sensors/sensorfw/sensorfwaccelerometer.h b/src/plugins/sensors/sensorfw/sensorfwaccelerometer.h
new file mode 100644
index 00000000..1c94aae3
--- /dev/null
+++ b/src/plugins/sensors/sensorfw/sensorfwaccelerometer.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 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 SENSORFWACCELEROMETER_H
+#define SENSORFWACCELEROMETER_H
+
+#include "sensorfwsensorbase.h"
+#include <qaccelerometer.h>
+
+#include <accelerometersensor_i.h>
+#include <datatypes/xyz.h>
+
+
+
+class sensorfwaccelerometer : public SensorfwSensorBase
+{
+ Q_OBJECT
+
+public:
+ static char const * const id;
+ sensorfwaccelerometer(QSensor *sensor);
+protected:
+ virtual bool doConnect();
+ virtual QString sensorName() const;
+ virtual qreal correctionFactor() const;
+
+
+private:
+ QAccelerometerReading m_reading;
+ static bool m_initDone;
+
+private slots:
+ void slotDataAvailable(const XYZ& data);
+ void slotFrameAvailable(const QVector<XYZ>&);
+};
+
+#endif
diff --git a/src/plugins/sensors/sensorfw/sensorfwals.cpp b/src/plugins/sensors/sensorfw/sensorfwals.cpp
new file mode 100644
index 00000000..811da77f
--- /dev/null
+++ b/src/plugins/sensors/sensorfw/sensorfwals.cpp
@@ -0,0 +1,111 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 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 "sensorfwals.h"
+
+char const * const Sensorfwals::id("sensorfw.als");
+bool Sensorfwals::m_initDone = false;
+
+Sensorfwals::Sensorfwals(QSensor *sensor)
+ : SensorfwSensorBase(sensor)
+{
+ initSensor<ALSSensorChannelInterface>(m_initDone);
+ setReading<QAmbientLightReading>(&m_reading);
+ // metadata
+ setDescription(QLatin1String("ambient light intensity given as 5 pre-defined levels"));
+ addOutputRange(0, 5, 1);
+ addDataRate(10,10);
+}
+
+void Sensorfwals::start()
+{
+ if (m_sensorInterface) {
+ Unsigned data(((ALSSensorChannelInterface*)m_sensorInterface)->lux());
+ m_reading.setLightLevel(getLightLevel(data.x()));
+ m_reading.setTimestamp(data.UnsignedData().timestamp_);
+ newReadingAvailable();
+ }
+ SensorfwSensorBase::start();
+}
+
+
+void Sensorfwals::slotDataAvailable(const Unsigned& data)
+{
+ QAmbientLightReading::LightLevel level = getLightLevel(data.x());
+ if (level != m_reading.lightLevel()) {
+ m_reading.setLightLevel(level);
+ m_reading.setTimestamp(data.UnsignedData().timestamp_);
+ newReadingAvailable();
+ }
+}
+
+bool Sensorfwals::doConnect()
+{
+ return QObject::connect(m_sensorInterface, SIGNAL(ALSChanged(const Unsigned&)),
+ this, SLOT(slotDataAvailable(const Unsigned&)));
+}
+
+
+QString Sensorfwals::sensorName() const
+{
+ return "alssensor";
+}
+
+
+QAmbientLightReading::LightLevel Sensorfwals::getLightLevel(int lux)
+{
+ // Convert from integer to fixed levels
+ if (lux < 0) {
+ return QAmbientLightReading::Undefined;
+ } else if (lux < 10) {
+ return QAmbientLightReading::Dark;
+ } else if (lux < 50) {
+ return QAmbientLightReading::Twilight;
+ } else if (lux < 100) {
+ return QAmbientLightReading::Light;
+ } else if (lux < 150) {
+ return QAmbientLightReading::Bright;
+ } else {
+ return QAmbientLightReading::Sunny;
+ }
+
+}
diff --git a/src/plugins/sensors/sensorfw/sensorfwals.h b/src/plugins/sensors/sensorfw/sensorfwals.h
new file mode 100644
index 00000000..ba7c9af1
--- /dev/null
+++ b/src/plugins/sensors/sensorfw/sensorfwals.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 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 SENSORFWALS_H
+#define SENSORFWALS_H
+
+#include "sensorfwsensorbase.h"
+#include <qambientlightsensor.h>
+
+#include <alssensor_i.h>
+#include <unsigned.h>
+
+
+
+class Sensorfwals : public SensorfwSensorBase
+{
+ Q_OBJECT
+
+public:
+ static char const * const id;
+ Sensorfwals(QSensor *sensor);
+protected:
+ virtual bool doConnect();
+ virtual QString sensorName() const;
+ virtual void start();
+
+
+private:
+ QAmbientLightReading m_reading;
+ static bool m_initDone;
+private slots:
+ void slotDataAvailable(const Unsigned& data);
+ static QAmbientLightReading::LightLevel getLightLevel(int lux);
+
+};
+
+#endif
diff --git a/src/plugins/sensors/sensorfw/sensorfwcompass.cpp b/src/plugins/sensors/sensorfw/sensorfwcompass.cpp
new file mode 100644
index 00000000..00741a1f
--- /dev/null
+++ b/src/plugins/sensors/sensorfw/sensorfwcompass.cpp
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 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 "sensorfwcompass.h"
+
+char const * const SensorfwCompass::id("sensorfw.compass");
+bool SensorfwCompass::m_initDone = false;
+
+SensorfwCompass::SensorfwCompass(QSensor *sensor)
+ : SensorfwSensorBase(sensor)
+{
+ initSensor<CompassSensorChannelInterface>(m_initDone);
+ setReading<QCompassReading>(&m_reading);
+}
+
+void SensorfwCompass::slotDataAvailable(const Compass& data)
+{
+ // The scale for level is [0,3], where 3 is the best
+ // Qt: Measured as a value from 0 to 1 with higher values being better.
+ m_reading.setCalibrationLevel(((float) data.level()) / 3.0);
+
+ // The scale for degrees from sensord is [0,359]
+ // Value can be directly used as azimuth
+ m_reading.setAzimuth(data.degrees());
+
+ m_reading.setTimestamp(data.data().timestamp_);
+ newReadingAvailable();
+}
+
+
+bool SensorfwCompass::doConnect()
+{
+ return QObject::connect(m_sensorInterface, SIGNAL(dataAvailable(const Compass&)),
+ this, SLOT(slotDataAvailable(const Compass&)));
+}
+
+QString SensorfwCompass::sensorName() const
+{
+ return "compasssensor";
+}
+
diff --git a/src/plugins/sensors/sensorfw/sensorfwcompass.h b/src/plugins/sensors/sensorfw/sensorfwcompass.h
new file mode 100644
index 00000000..e54c348e
--- /dev/null
+++ b/src/plugins/sensors/sensorfw/sensorfwcompass.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 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 SENSORFWCOMPASS_H
+#define SENSORFWCOMPASS_H
+
+#include "sensorfwsensorbase.h"
+#include <qcompass.h>
+
+#include <compasssensor_i.h>
+#include <compass.h>
+
+
+
+class SensorfwCompass : public SensorfwSensorBase
+{
+ Q_OBJECT
+
+public:
+ static char const * const id;
+ SensorfwCompass(QSensor *sensor);
+protected:
+ virtual bool doConnect();
+ virtual QString sensorName() const;
+
+private:
+ QCompassReading m_reading;
+ static bool m_initDone;
+private slots:
+ void slotDataAvailable(const Compass& data);
+};
+
+#endif
diff --git a/src/plugins/sensors/sensorfw/sensorfwgyroscope.cpp b/src/plugins/sensors/sensorfw/sensorfwgyroscope.cpp
new file mode 100644
index 00000000..238993ac
--- /dev/null
+++ b/src/plugins/sensors/sensorfw/sensorfwgyroscope.cpp
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 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 "sensorfwgyroscope.h"
+
+char const * const SensorfwGyroscope::id("sensorfw.gyroscope");
+const float SensorfwGyroscope::MILLI = 0.001;
+bool SensorfwGyroscope::m_initDone = false;
+
+SensorfwGyroscope::SensorfwGyroscope(QSensor *sensor)
+ : SensorfwSensorBase(sensor)
+{
+ initSensor<GyroscopeSensorChannelInterface>(m_initDone);
+ setDescription(QLatin1String("angular velocities around x, y, and z axis in degrees per second"));
+ setRanges(MILLI);
+ setReading<QGyroscopeReading>(&m_reading);
+ addDataRate(10, 10);
+ addDataRate(50, 50);
+}
+
+void SensorfwGyroscope::slotDataAvailable(const XYZ& data)
+{
+ m_reading.setX((qreal)(data.x()*MILLI));
+ m_reading.setY((qreal)(data.y()*MILLI));
+ m_reading.setZ((qreal)(data.z()*MILLI));
+ m_reading.setTimestamp(data.XYZData().timestamp_);
+ newReadingAvailable();
+}
+
+void SensorfwGyroscope::slotFrameAvailable(const QVector<XYZ>& frame)
+{
+ for (int i=0, l=frame.size(); i<l; i++) {
+ slotDataAvailable(frame.at(i));
+ }
+}
+
+bool SensorfwGyroscope::doConnect()
+{
+ if (m_bufferSize==1)
+ return QObject::connect(m_sensorInterface, SIGNAL(dataAvailable(const XYZ&)), this, SLOT(slotDataAvailable(const XYZ&)));
+ return QObject::connect(m_sensorInterface, SIGNAL(frameAvailable(const QVector<XYZ>& )),this, SLOT(slotFrameAvailable(const QVector<XYZ>& )));
+}
+
+QString SensorfwGyroscope::sensorName() const
+{
+ return "gyroscopesensor";
+}
+
+qreal SensorfwGyroscope::correctionFactor() const
+{
+ return MILLI;
+}
diff --git a/src/plugins/sensors/sensorfw/sensorfwgyroscope.h b/src/plugins/sensors/sensorfw/sensorfwgyroscope.h
new file mode 100644
index 00000000..e982c809
--- /dev/null
+++ b/src/plugins/sensors/sensorfw/sensorfwgyroscope.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 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 SENSORFWGYROSCOPE_H
+#define SENSORFWGYROSCOPE_H
+
+#include "sensorfwsensorbase.h"
+#include <qgyroscope.h>
+#include <datatypes/xyz.h>
+#include <gyroscopesensor_i.h>
+
+
+
+
+class SensorfwGyroscope : public SensorfwSensorBase
+{
+ Q_OBJECT
+
+public:
+ static char const * const id;
+ SensorfwGyroscope(QSensor *sensor);
+protected:
+ virtual bool doConnect();
+ virtual QString sensorName() const;
+ virtual qreal correctionFactor() const;
+
+
+private:
+ QGyroscopeReading m_reading;
+ static bool m_initDone;
+ static const float MILLI;
+private slots:
+ void slotDataAvailable(const XYZ& data);
+ void slotFrameAvailable(const QVector<XYZ>&);
+
+};
+
+
+#endif // sensorfwGYROSCOPE_H
diff --git a/src/plugins/sensors/sensorfw/sensorfwirproximitysensor.cpp b/src/plugins/sensors/sensorfw/sensorfwirproximitysensor.cpp
new file mode 100644
index 00000000..865d3760
--- /dev/null
+++ b/src/plugins/sensors/sensorfw/sensorfwirproximitysensor.cpp
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 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 "sensorfwirproximitysensor.h"
+#define RM680_PS "/dev/bh1770glc_ps"
+
+char const * const SensorfwIrProximitySensor::id("sensorfw.irproximitysensor");
+bool SensorfwIrProximitySensor::m_initDone = false;
+
+
+
+SensorfwIrProximitySensor::SensorfwIrProximitySensor(QSensor *sensor)
+ : SensorfwSensorBase(sensor)
+{
+ initSensor<ProximitySensorChannelInterface>(m_initDone);
+ setReading<QIRProximityReading>(&m_reading);
+ setDescription(QLatin1String("reflectance as percentage (%) of maximum"));
+ addOutputRange(0, 100, 1);
+ addDataRate(10,10);
+ rangeMax = QFile::exists(RM680_PS)?255:1023;
+}
+
+void SensorfwIrProximitySensor::slotDataAvailable(const Proximity& proximity)
+{
+ m_reading.setReflectance((float)proximity.reflectance()*100 / rangeMax);
+ m_reading.setTimestamp(proximity.UnsignedData().timestamp_);
+ newReadingAvailable();
+}
+
+
+bool SensorfwIrProximitySensor::doConnect()
+{
+ return QObject::connect(m_sensorInterface, SIGNAL(reflectanceDataAvailable(const Proximity&)),
+ this, SLOT(slotDataAvailable(const Proximity&)));
+}
+
+
+QString SensorfwIrProximitySensor::sensorName() const
+{
+ return "proximitysensor";
+}
+
+
diff --git a/src/plugins/sensors/sensorfw/sensorfwirproximitysensor.h b/src/plugins/sensors/sensorfw/sensorfwirproximitysensor.h
new file mode 100644
index 00000000..c729f595
--- /dev/null
+++ b/src/plugins/sensors/sensorfw/sensorfwirproximitysensor.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 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 SENSORFWIRPROXIMITYSENSOR_H
+#define SENSORFWIRPROXIMITYSENSOR_H
+
+#include "sensorfwsensorbase.h"
+#include <qirproximitysensor.h>
+#include <proximitysensor_i.h>
+
+
+class SensorfwIrProximitySensor : public SensorfwSensorBase
+{
+ Q_OBJECT
+
+public:
+ static char const * const id;
+
+ SensorfwIrProximitySensor(QSensor *sensor);
+protected:
+ virtual bool doConnect();
+ virtual QString sensorName() const;
+
+private:
+ QIRProximityReading m_reading;
+ static bool m_initDone;
+ int rangeMax;
+
+private slots:
+ void slotDataAvailable(const Proximity& proximity);
+};
+
+#endif
diff --git a/src/plugins/sensors/sensorfw/sensorfwlightsensor.cpp b/src/plugins/sensors/sensorfw/sensorfwlightsensor.cpp
new file mode 100644
index 00000000..b49e7b2d
--- /dev/null
+++ b/src/plugins/sensors/sensorfw/sensorfwlightsensor.cpp
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 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 "sensorfwlightsensor.h"
+
+char const * const SensorfwLightSensor::id("sensorfw.lightsensor");
+bool SensorfwLightSensor::m_initDone = false;
+
+SensorfwLightSensor::SensorfwLightSensor(QSensor *sensor)
+ : SensorfwSensorBase(sensor)
+{
+ initSensor<ALSSensorChannelInterface>(m_initDone);
+ setReading<QLightReading>(&m_reading);
+}
+
+void SensorfwLightSensor::slotDataAvailable(const Unsigned& data)
+{
+ m_reading.setLux(data.x());
+ m_reading.setTimestamp(data.UnsignedData().timestamp_);
+ newReadingAvailable();
+}
+
+bool SensorfwLightSensor::doConnect()
+{
+ return QObject::connect(m_sensorInterface, SIGNAL(ALSChanged(const Unsigned&)),
+ this, SLOT(slotDataAvailable(const Unsigned&)));
+}
+
+
+QString SensorfwLightSensor::sensorName() const
+{
+ return "alssensor";
+}
diff --git a/src/plugins/sensors/sensorfw/sensorfwlightsensor.h b/src/plugins/sensors/sensorfw/sensorfwlightsensor.h
new file mode 100644
index 00000000..83591fae
--- /dev/null
+++ b/src/plugins/sensors/sensorfw/sensorfwlightsensor.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 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 SENSORFWLIGHTSENSOR_H
+#define SENSORFWLIGHTSENSOR_H
+
+#include "sensorfwsensorbase.h"
+#include <qlightsensor.h>
+
+#include <alssensor_i.h>
+#include <unsigned.h>
+
+
+
+class SensorfwLightSensor : public SensorfwSensorBase
+{
+ Q_OBJECT
+
+public:
+ static char const * const id;
+ SensorfwLightSensor(QSensor *sensor);
+protected:
+ virtual bool doConnect();
+ virtual QString sensorName() const;
+
+private:
+ QLightReading m_reading;
+ static bool m_initDone;
+private slots:
+ void slotDataAvailable(const Unsigned& data);
+};
+
+#endif
diff --git a/src/plugins/sensors/sensorfw/sensorfwmagnetometer.cpp b/src/plugins/sensors/sensorfw/sensorfwmagnetometer.cpp
new file mode 100644
index 00000000..9778b95c
--- /dev/null
+++ b/src/plugins/sensors/sensorfw/sensorfwmagnetometer.cpp
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 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 "sensorfwmagnetometer.h"
+
+char const * const SensorfwMagnetometer::id("sensorfw.magnetometer");
+bool SensorfwMagnetometer::m_initDone = false;
+const float SensorfwMagnetometer::NANO = 0.000000001;
+
+
+SensorfwMagnetometer::SensorfwMagnetometer(QSensor *sensor)
+ : SensorfwSensorBase(sensor)
+{
+ initSensor<MagnetometerSensorChannelInterface>(m_initDone);
+ setDescription(QLatin1String("magnetic flux density in teslas (T)"));
+ setRanges(NANO);
+ setReading<QMagnetometerReading>(&m_reading);
+}
+
+void SensorfwMagnetometer::start()
+{
+ m_isGeoMagnetometer = sensor()->returnGeoValues();
+ SensorfwSensorBase::start();
+}
+
+void SensorfwMagnetometer::slotDataAvailable(const MagneticField& data)
+{
+ //nanoTeslas given, divide with 10^9 to get Teslas
+ m_reading.setX( NANO * (m_isGeoMagnetometer?data.x():data.rx()));
+ m_reading.setY( NANO * (m_isGeoMagnetometer?data.y():data.ry()));
+ m_reading.setZ( NANO * (m_isGeoMagnetometer?data.z():data.rz()));
+ m_reading.setCalibrationLevel( m_isGeoMagnetometer?((float) data.level()) / 3.0 :1);
+ m_reading.setTimestamp(data.timestamp());
+ newReadingAvailable();
+}
+
+
+void SensorfwMagnetometer::slotFrameAvailable(const QVector<MagneticField>& frame)
+{
+ for (int i=0, l=frame.size(); i<l; i++) {
+ slotDataAvailable(frame.at(i));
+ }
+}
+
+bool SensorfwMagnetometer::doConnect()
+{
+ if (m_bufferSize==1)
+ return QObject::connect(m_sensorInterface, SIGNAL(dataAvailable(const MagneticField&)), this, SLOT(slotDataAvailable(const MagneticField&)));
+ return QObject::connect(m_sensorInterface, SIGNAL(frameAvailable(const QVector<MagneticField>& )),this, SLOT(slotFrameAvailable(const QVector<MagneticField>& )));
+}
+
+QString SensorfwMagnetometer::sensorName() const
+{
+ return "magnetometersensor";
+}
+
+qreal SensorfwMagnetometer::correctionFactor() const
+{
+ return SensorfwMagnetometer::NANO;
+}
diff --git a/src/plugins/sensors/sensorfw/sensorfwmagnetometer.h b/src/plugins/sensors/sensorfw/sensorfwmagnetometer.h
new file mode 100644
index 00000000..dff70c09
--- /dev/null
+++ b/src/plugins/sensors/sensorfw/sensorfwmagnetometer.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 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 SENSORFWMAGNETOMETER_H
+#define SENSORFWMAGNETOMETER_H
+
+#include "sensorfwsensorbase.h"
+#include <qmagnetometer.h>
+
+#include <magnetometersensor_i.h>
+#include <magneticfield.h>
+
+
+
+class SensorfwMagnetometer : public SensorfwSensorBase
+{
+ Q_OBJECT
+
+public:
+ static char const * const id;
+ SensorfwMagnetometer(QSensor *sensor);
+protected:
+ virtual bool doConnect();
+ virtual void start();
+ virtual QString sensorName() const;
+ virtual qreal correctionFactor() const;
+
+
+private:
+ static const float NANO;
+ QMagnetometerReading m_reading;
+ static bool m_initDone;
+ bool m_isGeoMagnetometer;
+
+private slots:
+ void slotDataAvailable(const MagneticField& data);
+ void slotFrameAvailable(const QVector<MagneticField>&);
+
+};
+
+#endif
diff --git a/src/plugins/sensors/sensorfw/sensorfworientationsensor.cpp b/src/plugins/sensors/sensorfw/sensorfworientationsensor.cpp
new file mode 100644
index 00000000..09dfb0eb
--- /dev/null
+++ b/src/plugins/sensors/sensorfw/sensorfworientationsensor.cpp
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 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 "sensorfworientationsensor.h"
+
+#include <posedata.h>
+
+char const * const SensorfwOrientationSensor::id("sensorfw.orientationsensor");
+bool SensorfwOrientationSensor::m_initDone = false;
+
+SensorfwOrientationSensor::SensorfwOrientationSensor(QSensor *sensor)
+ : SensorfwSensorBase(sensor)
+{
+ initSensor<OrientationSensorChannelInterface>(m_initDone);
+ setReading<QOrientationReading>(&m_reading);
+}
+
+
+void SensorfwOrientationSensor::start()
+{
+ if (m_sensorInterface) {
+ Unsigned data(((OrientationSensorChannelInterface*)m_sensorInterface)->orientation());
+ m_reading.setOrientation(SensorfwOrientationSensor::getOrientation(data.x()));
+ m_reading.setTimestamp(data.UnsignedData().timestamp_);
+ newReadingAvailable();
+ }
+ SensorfwSensorBase::start();
+}
+
+
+void SensorfwOrientationSensor::slotDataAvailable(const Unsigned& data)
+{
+ m_reading.setOrientation(SensorfwOrientationSensor::getOrientation(data.x()));
+ m_reading.setTimestamp(data.UnsignedData().timestamp_);
+ newReadingAvailable();
+}
+
+bool SensorfwOrientationSensor::doConnect()
+{
+ return QObject::connect(m_sensorInterface, SIGNAL(orientationChanged(const Unsigned&)),
+ this, SLOT(slotDataAvailable(const Unsigned&)));
+}
+
+QString SensorfwOrientationSensor::sensorName() const
+{
+ return "orientationsensor";
+}
+
+QOrientationReading::Orientation SensorfwOrientationSensor::getOrientation(int orientation)
+{
+ switch (orientation) {
+ case PoseData::BottomDown: return QOrientationReading::TopUp;
+ case PoseData::BottomUp: return QOrientationReading::TopDown;
+ case PoseData::LeftUp: return QOrientationReading::LeftUp;
+ case PoseData::RightUp: return QOrientationReading::RightUp;
+ case PoseData::FaceUp: return QOrientationReading::FaceUp;
+ case PoseData::FaceDown: return QOrientationReading::FaceDown;
+ }
+ return QOrientationReading::Undefined;
+}
diff --git a/src/plugins/sensors/sensorfw/sensorfworientationsensor.h b/src/plugins/sensors/sensorfw/sensorfworientationsensor.h
new file mode 100644
index 00000000..496939ce
--- /dev/null
+++ b/src/plugins/sensors/sensorfw/sensorfworientationsensor.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 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 SENSORFWORIENTATIONSENSOR_H
+#define SENSORFWORIENTATIONSENSOR_H
+
+#include "sensorfwsensorbase.h"
+#include <qorientationsensor.h>
+
+#include <orientationsensor_i.h>
+#include <unsigned.h>
+
+
+
+class SensorfwOrientationSensor : public SensorfwSensorBase
+{
+ Q_OBJECT
+
+public:
+ static char const * const id;
+ SensorfwOrientationSensor(QSensor *sensor);
+protected:
+ virtual bool doConnect();
+ virtual QString sensorName() const;
+ virtual void start();
+
+private:
+ QOrientationReading m_reading;
+ static QOrientationReading::Orientation getOrientation(int orientation);
+ static bool m_initDone;
+
+private slots:
+ void slotDataAvailable(const Unsigned& orientation);
+};
+
+#endif
diff --git a/src/plugins/sensors/sensorfw/sensorfwproximitysensor.cpp b/src/plugins/sensors/sensorfw/sensorfwproximitysensor.cpp
new file mode 100644
index 00000000..4602a9a1
--- /dev/null
+++ b/src/plugins/sensors/sensorfw/sensorfwproximitysensor.cpp
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 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 "sensorfwproximitysensor.h"
+
+char const * const SensorfwProximitySensor::id("sensorfw.proximitysensor");
+bool SensorfwProximitySensor::m_initDone = false;
+
+SensorfwProximitySensor::SensorfwProximitySensor(QSensor *sensor)
+ : SensorfwSensorBase(sensor), m_exClose(false)
+{
+ initSensor<ProximitySensorChannelInterface>(m_initDone);
+ setReading<QProximityReading>(&m_reading);
+ addDataRate(10,10); //TODO: fix this when we know better
+}
+
+void SensorfwProximitySensor::start()
+{
+ if (m_sensorInterface) {
+ Unsigned data(((ProximitySensorChannelInterface*)m_sensorInterface)->proximity());
+ m_reading.setClose(data.x()? true: false);
+ m_reading.setTimestamp(data.UnsignedData().timestamp_);
+ newReadingAvailable();
+ }
+ SensorfwSensorBase::start();
+}
+
+
+void SensorfwProximitySensor::slotDataAvailable(const Unsigned& data)
+{
+ bool close = data.x()? true: false;
+ if (close == m_exClose) return;
+ m_reading.setClose(close);
+ m_reading.setTimestamp(data.UnsignedData().timestamp_);
+ newReadingAvailable();
+ m_exClose = close;
+}
+
+bool SensorfwProximitySensor::doConnect()
+{
+ return (QObject::connect(m_sensorInterface, SIGNAL(dataAvailable(const Unsigned&)),
+ this, SLOT(slotDataAvailable(const Unsigned&))));
+}
+
+
+QString SensorfwProximitySensor::sensorName() const
+{
+ return "proximitysensor";
+}
diff --git a/src/plugins/sensors/sensorfw/sensorfwproximitysensor.h b/src/plugins/sensors/sensorfw/sensorfwproximitysensor.h
new file mode 100644
index 00000000..91800c2e
--- /dev/null
+++ b/src/plugins/sensors/sensorfw/sensorfwproximitysensor.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 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 SENSORFWPROXIMITYSENSOR_H
+#define SENSORFWPROXIMITYSENSOR_H
+
+#include "sensorfwsensorbase.h"
+#include <qproximitysensor.h>
+
+#include <proximitysensor_i.h>
+#include <unsigned.h>
+
+
+
+class SensorfwProximitySensor : public SensorfwSensorBase
+{
+ Q_OBJECT
+
+public:
+ static char const * const id;
+ SensorfwProximitySensor(QSensor *sensor);
+protected:
+ virtual bool doConnect();
+ virtual QString sensorName() const;
+ virtual void start();
+
+
+private:
+ QProximityReading m_reading;
+ static bool m_initDone;
+ bool m_exClose;
+
+private slots:
+ void slotDataAvailable(const Unsigned& data);
+};
+
+#endif
diff --git a/src/plugins/sensors/sensorfw/sensorfwrotationsensor.cpp b/src/plugins/sensors/sensorfw/sensorfwrotationsensor.cpp
new file mode 100644
index 00000000..d5774022
--- /dev/null
+++ b/src/plugins/sensors/sensorfw/sensorfwrotationsensor.cpp
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 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 "sensorfwrotationsensor.h"
+
+char const * const SensorfwRotationSensor::id("sensorfw.rotationsensor");
+bool SensorfwRotationSensor::m_initDone = false;
+
+SensorfwRotationSensor::SensorfwRotationSensor(QSensor *sensor)
+ : SensorfwSensorBase(sensor)
+{
+ initSensor<RotationSensorChannelInterface>(m_initDone);
+ setReading<QRotationReading>(&m_reading);
+ sensor()->setHasZ(true);
+}
+
+void SensorfwRotationSensor::slotDataAvailable(const XYZ& data)
+{
+ m_reading.setFromEuler(data.x(),data.y(),data.z());
+ m_reading.setTimestamp(data.XYZData().timestamp_);
+ newReadingAvailable();
+}
+
+void SensorfwRotationSensor::slotFrameAvailable(const QVector<XYZ>& frame)
+{
+ for (int i=0, l=frame.size(); i<l; i++) {
+ slotDataAvailable(frame.at(i));
+ }
+}
+
+bool SensorfwRotationSensor::doConnect()
+{
+ if (m_bufferSize==1)
+ return QObject::connect(m_sensorInterface, SIGNAL(dataAvailable(const XYZ&)), this, SLOT(slotDataAvailable(const XYZ&)));
+ return QObject::connect(m_sensorInterface, SIGNAL(frameAvailable(const QVector<XYZ>& )),this, SLOT(slotFrameAvailable(const QVector<XYZ>& )));
+}
+
+QString SensorfwRotationSensor::sensorName() const
+{
+ return "rotationsensor";
+}
diff --git a/src/plugins/sensors/sensorfw/sensorfwrotationsensor.h b/src/plugins/sensors/sensorfw/sensorfwrotationsensor.h
new file mode 100644
index 00000000..5b5556df
--- /dev/null
+++ b/src/plugins/sensors/sensorfw/sensorfwrotationsensor.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 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 SENSORFWROTATION_H
+#define SENSORFWROTATION_H
+
+#include "sensorfwsensorbase.h"
+#include <qrotationsensor.h>
+
+#include <rotationsensor_i.h>
+#include <xyz.h>
+
+
+
+class SensorfwRotationSensor : public SensorfwSensorBase
+{
+ Q_OBJECT
+
+public:
+ static char const * const id;
+ SensorfwRotationSensor(QSensor *sensor);
+protected:
+ virtual bool doConnect();
+ virtual QString sensorName() const;
+
+private:
+ QRotationReading m_reading;
+ static bool m_initDone;
+
+private slots:
+ void slotDataAvailable(const XYZ& data);
+ void slotFrameAvailable(const QVector<XYZ>&);
+
+};
+
+#endif
diff --git a/src/plugins/sensors/sensorfw/sensorfwsensorbase.cpp b/src/plugins/sensors/sensorfw/sensorfwsensorbase.cpp
new file mode 100644
index 00000000..85968e22
--- /dev/null
+++ b/src/plugins/sensors/sensorfw/sensorfwsensorbase.cpp
@@ -0,0 +1,189 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 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 "sensorfwsensorbase.h"
+
+
+SensorManagerInterface* SensorfwSensorBase::m_remoteSensorManager = 0;
+
+//According to wikipedia link http://en.wikipedia.org/wiki/Standard_gravity
+//const float sensorfwsensorbase::GRAVITY_EARTH = 9.812865328;
+const float SensorfwSensorBase::GRAVITY_EARTH_THOUSANDTH = 0.009812865328;
+const int SensorfwSensorBase::KErrNotFound=-1;
+const int SensorfwSensorBase::KErrInUse=-14;
+QStringList SensorfwSensorBase::m_bufferingSensors = QStringList()
+ <<"sensorfw.accelerometer"<<"sensorfw.magnetometer"
+ <<"sensorfw.gyroscope"<<"sensorfw.rotationsensor";
+
+SensorfwSensorBase::SensorfwSensorBase(QSensor *sensor)
+ : QSensorBackend(sensor), m_sensorInterface(0), m_bufferSize(-1), m_prevOutputRange(0), m_efficientBufferSize(1), m_maxBufferSize(1)
+{
+ if (!m_remoteSensorManager)
+ m_remoteSensorManager = &SensorManagerInterface::instance();
+}
+
+SensorfwSensorBase::~SensorfwSensorBase()
+{
+ if (m_sensorInterface) {
+ stop();
+ delete m_sensorInterface, m_sensorInterface = 0;
+ }
+}
+
+void SensorfwSensorBase::start()
+{
+ if (m_sensorInterface) {
+ // dataRate
+ QByteArray type = sensor()->type();
+ if (type != QTapSensor::type() && type != QProximitySensor::type()) {
+ int dataRate = sensor()->dataRate();
+ int interval = dataRate > 0 ? 1000 / dataRate : 0;
+ // for testing maximum speed
+ //interval = 1;
+ //dataRate = 1000;
+ m_sensorInterface->setInterval(interval);
+ }
+
+ // outputRange
+ int currentRange = sensor()->outputRange();
+ int l = sensor()->outputRanges().size();
+ if (l > 1) {
+ if (currentRange != m_prevOutputRange) {
+//#ifdef Q_WS_MAEMO_6
+ bool isOk = m_sensorInterface->setDataRangeIndex(currentRange); //NOTE THAT THE CHANGE MIGHT NOT SUCCEED, FIRST COME FIRST SERVED
+ if (!isOk) sensorError(KErrInUse);
+ else m_prevOutputRange = currentRange;
+//#else
+// // TODO: remove when sensord integrated, in sensorfw env there is a delay
+// qoutputrange range = sensor()->outputRanges().at(currentRange);
+// qreal correction = 1/correctionFactor();
+// DataRange range1(range.minimum*correction, range.maximum*correction, range.accuracy*correction);
+// m_sensorInterface->requestDataRange(range1);
+// m_prevOutputRange = currentRange;
+//#endif
+ }
+ }
+
+ // always on
+ bool alwaysOn = sensor()->isAlwaysOn();
+ m_sensorInterface->setStandbyOverride(alwaysOn);
+
+ // connects after buffering checks
+ doConnectAfterCheck();
+
+ int returnCode = m_sensorInterface->start().error().type();
+ if (returnCode == 0) return;
+ qWarning() << "m_sensorInterface did not start, error code:" << returnCode;
+ }
+ sensorStopped();
+}
+
+void SensorfwSensorBase::stop()
+{
+ if (m_sensorInterface) m_sensorInterface->stop();
+}
+
+void SensorfwSensorBase::setRanges(qreal correctionFactor)
+{
+ if (!m_sensorInterface) return;
+
+ QList<DataRange> ranges = m_sensorInterface->getAvailableDataRanges();
+
+ for (int i = 0, l = ranges.size(); i < l; i++) {
+ DataRange range = ranges.at(i);
+ qreal rangeMin = range.min * correctionFactor;
+ qreal rangeMax = range.max * correctionFactor;
+ qreal resolution = range.resolution * correctionFactor;
+ addOutputRange(rangeMin, rangeMax, resolution);
+ }
+}
+
+
+bool SensorfwSensorBase::doConnectAfterCheck()
+{
+ if (!m_sensorInterface) return false;
+
+ // buffer size
+ int size = bufferSize();
+ if (size == m_bufferSize) return true;
+
+ if (m_bufferingSensors.contains(sensor()->identifier()))
+ m_sensorInterface->setBufferSize(size);
+ else
+ size = 1;
+
+ // if multiple->single or single->multiple or if uninitialized
+ if ((m_bufferSize > 1 && size == 1) || (m_bufferSize == 1 && size > 1) || m_bufferSize == -1) {
+ m_bufferSize = size;
+ disconnect(this);
+ if (!doConnect()) {
+ qWarning() << "Unable to connect "<< sensorName();
+ return false;
+ }
+ return true;
+ }
+ m_bufferSize = size;
+ return true;
+}
+
+int SensorfwSensorBase::bufferSize() const
+{
+ int bufferSize = sensor()->bufferSize();
+ if (bufferSize == 1)
+ return 1;
+
+ // otherwise check validit
+ if (bufferSize < 1) {
+ qWarning() << "bufferSize cannot be " << bufferSize << ", must be a positive number >= 1";
+ return 1;
+ }
+ if (bufferSize > m_maxBufferSize) {
+ qWarning() << "bufferSize cannot be " << bufferSize << ", MAX value is " << m_maxBufferSize;
+ return m_maxBufferSize;
+ }
+ return bufferSize;
+}
+
+qreal SensorfwSensorBase::correctionFactor() const
+{
+ return 1;
+}
+
diff --git a/src/plugins/sensors/sensorfw/sensorfwsensorbase.h b/src/plugins/sensors/sensorfw/sensorfwsensorbase.h
new file mode 100644
index 00000000..78a6c14f
--- /dev/null
+++ b/src/plugins/sensors/sensorfw/sensorfwsensorbase.h
@@ -0,0 +1,170 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 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 SENSORFWSENSORBASE_H
+#define SENSORFWSENSORBASE_H
+
+#include <qsensorbackend.h>
+#include <sensormanagerinterface.h>
+#include <abstractsensor_i.h>
+
+class SensorfwSensorBase : public QSensorBackend
+{
+public:
+ SensorfwSensorBase(QSensor *sensor);
+ virtual ~SensorfwSensorBase();
+
+
+protected:
+ virtual bool doConnect()=0;
+ virtual void start();
+ virtual void stop();
+
+ static const float GRAVITY_EARTH;
+ static const float GRAVITY_EARTH_THOUSANDTH; //for speed
+ static const int KErrNotFound;
+ static const int KErrInUse;
+ static QStringList m_bufferingSensors;
+
+ void setRanges(qreal correctionFactor=1);
+ virtual QString sensorName() const=0;
+
+ template<typename T>
+ void initSensor(bool &initDone)
+ {
+
+ const QString name = sensorName();
+
+ if (!initDone) {
+ if (!m_remoteSensorManager->loadPlugin(name)) {
+ sensorError(KErrNotFound);
+ return;
+ }
+ m_remoteSensorManager->registerSensorInterface<T>(name);
+ }
+ m_sensorInterface = T::controlInterface(name);
+ 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()->efficientBufferSize(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();
+ };
+
+
+ AbstractSensorChannelInterface* m_sensorInterface;
+ int m_bufferSize;
+ int bufferSize() const;
+ virtual qreal correctionFactor() const;
+
+private:
+
+ static SensorManagerInterface* m_remoteSensorManager;
+ int m_prevOutputRange;
+ bool doConnectAfterCheck();
+ int m_efficientBufferSize, m_maxBufferSize;
+
+};
+
+#endif
diff --git a/src/plugins/sensors/sensorfw/sensorfwtapsensor.cpp b/src/plugins/sensors/sensorfw/sensorfwtapsensor.cpp
new file mode 100644
index 00000000..c945ac11
--- /dev/null
+++ b/src/plugins/sensors/sensorfw/sensorfwtapsensor.cpp
@@ -0,0 +1,110 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 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 "sensorfwtapsensor.h"
+
+char const * const SensorfwTapSensor::id("sensorfw.tapsensor");
+bool SensorfwTapSensor::m_initDone = false;
+
+SensorfwTapSensor::SensorfwTapSensor(QSensor *sensor)
+ : SensorfwSensorBase(sensor), m_isOnceStarted(false)
+{
+ initSensor<TapSensorChannelInterface>(m_initDone);
+ setReading<QTapReading>(&m_reading);
+ addOutputRange(QTapReading::Undefined, QTapReading::Z_Both, 1);
+ addDataRate(10,10); //TODO: fix this when we know better
+}
+
+
+void SensorfwTapSensor::start()
+{
+ bool b = sensor()->returnDoubleTapEvents();
+ bool isDoubleTapSensor = m_isDoubleTapSensor;
+ if (!b) {
+ sensor()->setReturnDoubleTapEvents(true); //by default doubles
+ m_isDoubleTapSensor = true;
+ }
+ else m_isDoubleTapSensor = b;
+
+ if (!m_isOnceStarted || (m_isOnceStarted && isDoubleTapSensor != m_isDoubleTapSensor))
+ ((TapSensorChannelInterface*)m_sensorInterface)->
+ setTapType(m_isDoubleTapSensor?TapSensorChannelInterface::Double:TapSensorChannelInterface::Single);
+
+ SensorfwSensorBase::start();
+ // Set tap type (single/double)
+ m_reading.setDoubleTap(m_isDoubleTapSensor);
+ m_isOnceStarted = true;
+}
+
+
+void SensorfwTapSensor::slotDataAvailable(const Tap& data)
+{
+ // Set tap direction
+ QTapReading::TapDirection o;
+ switch (data.direction()) {
+ case TapData::X: o = QTapReading::X_Both; break;
+ case TapData::Y: o = QTapReading::Y_Both; break;
+ case TapData::Z: o = QTapReading::Z_Both; break;
+ case TapData::LeftRight: o = QTapReading::X_Pos; break;
+ case TapData::RightLeft: o = QTapReading::X_Neg; break;
+ case TapData::TopBottom: o = QTapReading::Z_Neg; break;
+ case TapData::BottomTop: o = QTapReading::Z_Pos; break;
+ case TapData::FaceBack: o = QTapReading::Y_Pos; break;
+ case TapData::BackFace: o = QTapReading::Y_Neg; break;
+ default: o = QTapReading::Undefined;
+ }
+ m_reading.setTapDirection(o);
+ m_reading.setTimestamp(data.tapData().timestamp_);
+ newReadingAvailable();
+}
+
+
+bool SensorfwTapSensor::doConnect()
+{
+ return QObject::connect(m_sensorInterface, SIGNAL(dataAvailable(const Tap&)),
+ this, SLOT(slotDataAvailable(const Tap&)));
+}
+
+
+QString SensorfwTapSensor::sensorName() const
+{
+ return "tapsensor";
+}
diff --git a/src/plugins/sensors/sensorfw/sensorfwtapsensor.h b/src/plugins/sensors/sensorfw/sensorfwtapsensor.h
new file mode 100644
index 00000000..6df3bcfb
--- /dev/null
+++ b/src/plugins/sensors/sensorfw/sensorfwtapsensor.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 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 SENSORFWTAPSENSOR_H
+#define SENSORFWTAPSENSOR_H
+
+#include "sensorfwsensorbase.h"
+#include <qtapsensor.h>
+
+#include <tapsensor_i.h>
+#include <tap.h>
+
+
+
+class SensorfwTapSensor : public SensorfwSensorBase
+{
+ Q_OBJECT
+
+public:
+ static char const * const id;
+ SensorfwTapSensor(QSensor *sensor);
+protected:
+ virtual bool doConnect();
+ virtual void start();
+ virtual QString sensorName() const;
+
+private:
+ QTapReading m_reading;
+ static bool m_initDone;
+ bool m_isDoubleTapSensor;
+ bool m_isOnceStarted;
+private slots:
+ void slotDataAvailable(const Tap&);
+};
+
+#endif
diff --git a/src/plugins/sensors/sensors.pro b/src/plugins/sensors/sensors.pro
index df63f36d..73f42672 100644
--- a/src/plugins/sensors/sensors.pro
+++ b/src/plugins/sensors/sensors.pro
@@ -1,12 +1,24 @@
TEMPLATE = subdirs
-# Don't build dummy and generic plugins by default, the Blackberry backend has real implementations
+# Don't build dummy plugins, the Blackberry backend has real implementations
# of these. This reduces compile time and plugin loading time.
blackberry {
- isEmpty(SENSORS_PLUGINS): SENSORS_PLUGINS = blackberry
+ isEmpty(SENSORS_PLUGINS): SENSORS_PLUGINS = blackberry generic
}
+
+android {
+ isEmpty(SENSORS_PLUGINS): SENSORS_PLUGINS = android generic
+}
+
+sensorfw {
+ isEmpty(SENSORS_PLUGINS): SENSORS_PLUGINS = sensorfw generic
+}
+
isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, dummy):SUBDIRS += dummy
isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, generic):SUBDIRS += generic
isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, simulator):simulator:SUBDIRS += simulator
isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, blackberry):blackberry:SUBDIRS += blackberry
isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, linux):linux:SUBDIRS += linux
+isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, android):android:SUBDIRS += android
+isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, sensorfw):sensorfw:SUBDIRS += sensorfw
+isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, ios):ios:SUBDIRS += ios