summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThomas McGuire <thomas.mcguire@kdab.com>2012-04-02 14:52:45 +0200
committerQt by Nokia <qt-info@nokia.com>2012-04-10 10:27:16 +0200
commitfbbd77647d0e9ab764b21203b8ad7de91dc57e02 (patch)
tree21c503ae61339c1c385532c3271fe411a91769a3 /src
parent74a2c5d2414be2f69df5e11761e889dce8887443 (diff)
Add blackberry backend
sensor.h is a temporary copy until this file is available in the Blackberry NDK. Change-Id: I6a47ee4c8ccc0cc3603ea2df3c9fd61259e8ffac Reviewed-by: Lincoln Ramsay <lincoln.ramsay@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/sensors/blackberry/bbaccelerometer.cpp60
-rw-r--r--src/plugins/sensors/blackberry/bbaccelerometer.h60
-rw-r--r--src/plugins/sensors/blackberry/bbaltimeter.cpp81
-rw-r--r--src/plugins/sensors/blackberry/bbaltimeter.h71
-rw-r--r--src/plugins/sensors/blackberry/bbgyroscope.cpp69
-rw-r--r--src/plugins/sensors/blackberry/bbgyroscope.h61
-rw-r--r--src/plugins/sensors/blackberry/bblightsensor.cpp58
-rw-r--r--src/plugins/sensors/blackberry/bblightsensor.h60
-rw-r--r--src/plugins/sensors/blackberry/bbmagnetometer.cpp86
-rw-r--r--src/plugins/sensors/blackberry/bbmagnetometer.h61
-rw-r--r--src/plugins/sensors/blackberry/bborientationsensor.cpp134
-rw-r--r--src/plugins/sensors/blackberry/bborientationsensor.h84
-rw-r--r--src/plugins/sensors/blackberry/bbproximitysensor.cpp117
-rw-r--r--src/plugins/sensors/blackberry/bbproximitysensor.h86
-rw-r--r--src/plugins/sensors/blackberry/bbrotationsensor.cpp114
-rw-r--r--src/plugins/sensors/blackberry/bbrotationsensor.h64
-rw-r--r--src/plugins/sensors/blackberry/bbsensorbackend.cpp175
-rw-r--r--src/plugins/sensors/blackberry/bbsensorbackend.h122
-rw-r--r--src/plugins/sensors/blackberry/bbtemperaturesensor.cpp83
-rw-r--r--src/plugins/sensors/blackberry/bbtemperaturesensor.h71
-rw-r--r--src/plugins/sensors/blackberry/bbutil.h54
-rw-r--r--src/plugins/sensors/blackberry/blackberry.pro38
-rw-r--r--src/plugins/sensors/blackberry/main.cpp125
-rw-r--r--src/plugins/sensors/blackberry/plugin.json1
-rw-r--r--src/plugins/sensors/blackberry/sensor.h364
-rw-r--r--src/plugins/sensors/sensors.pro1
26 files changed, 2300 insertions, 0 deletions
diff --git a/src/plugins/sensors/blackberry/bbaccelerometer.cpp b/src/plugins/sensors/blackberry/bbaccelerometer.cpp
new file mode 100644
index 00000000..ed4f51f6
--- /dev/null
+++ b/src/plugins/sensors/blackberry/bbaccelerometer.cpp
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Research In Motion
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtSensors module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "bbaccelerometer.h"
+
+BbAccelerometer::BbAccelerometer(QSensor *sensor)
+ : BbSensorBackend<QAccelerometerReading>(devicePath(), SENSOR_TYPE_ACCELEROMETER, sensor)
+{
+ setDescription(QLatin1String("X, Y, and Z axes accelerations in m/s^2"));
+}
+
+bool BbAccelerometer::updateReadingFromEvent(const sensor_event_t &event, QAccelerometerReading *reading)
+{
+ reading->setX(event.motion.dsp.x);
+ reading->setY(event.motion.dsp.y);
+ reading->setZ(event.motion.dsp.z);
+ return true;
+}
+
+QString BbAccelerometer::devicePath()
+{
+ return QLatin1String("/dev/sensor/accel");
+}
diff --git a/src/plugins/sensors/blackberry/bbaccelerometer.h b/src/plugins/sensors/blackberry/bbaccelerometer.h
new file mode 100644
index 00000000..7442dd42
--- /dev/null
+++ b/src/plugins/sensors/blackberry/bbaccelerometer.h
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Research In Motion
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtSensors module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef BBACCELEROMETER_H
+#define BBACCELEROMETER_H
+
+#include "bbsensorbackend.h"
+#include <qaccelerometer.h>
+
+class BbAccelerometer : public BbSensorBackend<QAccelerometerReading>
+{
+ Q_OBJECT
+
+public:
+ explicit BbAccelerometer(QSensor *sensor);
+
+ static QString devicePath();
+
+protected:
+ bool updateReadingFromEvent(const sensor_event_t &event, QAccelerometerReading *reading);
+};
+
+#endif
diff --git a/src/plugins/sensors/blackberry/bbaltimeter.cpp b/src/plugins/sensors/blackberry/bbaltimeter.cpp
new file mode 100644
index 00000000..a242099d
--- /dev/null
+++ b/src/plugins/sensors/blackberry/bbaltimeter.cpp
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Research In Motion
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtSensors module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#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)
+{
+ setDescription(QLatin1String("Altitude in meters relative to mean sea level"));
+}
+
+bool BbAltimeter::updateReadingFromEvent(const sensor_event_t &event, BbAltimeterReading *reading)
+{
+ reading->setAltitude(event.altitude_s.altitude);
+ return true;
+}
+
+QString BbAltimeter::devicePath()
+{
+ return QLatin1String("/dev/sensor/alt");
+}
diff --git a/src/plugins/sensors/blackberry/bbaltimeter.h b/src/plugins/sensors/blackberry/bbaltimeter.h
new file mode 100644
index 00000000..ea283d4e
--- /dev/null
+++ b/src/plugins/sensors/blackberry/bbaltimeter.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Research In Motion
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtSensors module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef BBALTIMETER_H
+#define BBALTIMETER_H
+
+#include "bbsensorbackend.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>
+{
+ Q_OBJECT
+
+public:
+ explicit BbAltimeter(QSensor *sensor);
+
+ static QString devicePath();
+
+protected:
+ bool updateReadingFromEvent(const sensor_event_t &event, BbAltimeterReading *reading);
+};
+
+#endif
diff --git a/src/plugins/sensors/blackberry/bbgyroscope.cpp b/src/plugins/sensors/blackberry/bbgyroscope.cpp
new file mode 100644
index 00000000..5372b55d
--- /dev/null
+++ b/src/plugins/sensors/blackberry/bbgyroscope.cpp
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Research In Motion
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtSensors module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "bbgyroscope.h"
+
+#include "bbutil.h"
+#include <QtCore/qmath.h>
+
+BbGyroscope::BbGyroscope(QSensor *sensor)
+ : BbSensorBackend<QGyroscopeReading>(devicePath(), SENSOR_TYPE_GYROSCOPE, sensor)
+{
+ setDescription(QLatin1String("Angular velocities around x, y, and z axis in degrees per second"));
+}
+
+bool BbGyroscope::updateReadingFromEvent(const sensor_event_t &event, QGyroscopeReading *reading)
+{
+ reading->setX(radiansToDegrees(event.motion.dsp.x));
+ reading->setY(radiansToDegrees(event.motion.dsp.y));
+ reading->setZ(radiansToDegrees(event.motion.dsp.z));
+
+ return true;
+}
+
+QString BbGyroscope::devicePath()
+{
+ return QLatin1String("/dev/sensor/gyro");
+}
+
+qreal BbGyroscope::convertValue(float valueInRadiansPerSecond)
+{
+ return radiansToDegrees(valueInRadiansPerSecond);
+}
diff --git a/src/plugins/sensors/blackberry/bbgyroscope.h b/src/plugins/sensors/blackberry/bbgyroscope.h
new file mode 100644
index 00000000..5e2465eb
--- /dev/null
+++ b/src/plugins/sensors/blackberry/bbgyroscope.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Research In Motion
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtSensors module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef BBGYROSCOPE_H
+#define BBGYROSCOPE_H
+
+#include "bbsensorbackend.h"
+#include <qgyroscope.h>
+
+class BbGyroscope : public BbSensorBackend<QGyroscopeReading>
+{
+ Q_OBJECT
+
+public:
+ explicit BbGyroscope(QSensor *sensor);
+
+ static QString devicePath();
+
+protected:
+ qreal convertValue(float bbValue);
+ bool updateReadingFromEvent(const sensor_event_t &event, QGyroscopeReading *reading);
+};
+
+#endif
diff --git a/src/plugins/sensors/blackberry/bblightsensor.cpp b/src/plugins/sensors/blackberry/bblightsensor.cpp
new file mode 100644
index 00000000..fc0ce524
--- /dev/null
+++ b/src/plugins/sensors/blackberry/bblightsensor.cpp
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Research In Motion
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtSensors module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "bblightsensor.h"
+
+BbLightSensor::BbLightSensor(QSensor *sensor)
+ : BbSensorBackend<QLightReading>(devicePath(), SENSOR_TYPE_LIGHT, sensor)
+{
+ setDescription(QLatin1String("Light intensity in lux"));
+}
+
+bool BbLightSensor::updateReadingFromEvent(const sensor_event_t &event, QLightReading *reading)
+{
+ reading->setLux(event.light_s.illuminance);
+ return true;
+}
+
+QString BbLightSensor::devicePath()
+{
+ return QLatin1String("/dev/sensor/light");
+}
diff --git a/src/plugins/sensors/blackberry/bblightsensor.h b/src/plugins/sensors/blackberry/bblightsensor.h
new file mode 100644
index 00000000..210ea098
--- /dev/null
+++ b/src/plugins/sensors/blackberry/bblightsensor.h
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Research In Motion
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtSensors module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef BBLIGHTSENSOR_H
+#define BBLIGHTSENSOR_H
+
+#include "bbsensorbackend.h"
+#include <qlightsensor.h>
+
+class BbLightSensor : public BbSensorBackend<QLightReading>
+{
+ Q_OBJECT
+
+public:
+ explicit BbLightSensor(QSensor *sensor);
+
+ static QString devicePath();
+
+protected:
+ bool updateReadingFromEvent(const sensor_event_t &event, QLightReading *reading);
+};
+
+#endif
diff --git a/src/plugins/sensors/blackberry/bbmagnetometer.cpp b/src/plugins/sensors/blackberry/bbmagnetometer.cpp
new file mode 100644
index 00000000..eed1497c
--- /dev/null
+++ b/src/plugins/sensors/blackberry/bbmagnetometer.cpp
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Research In Motion
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtSensors module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "bbmagnetometer.h"
+
+BbMagnetometer::BbMagnetometer(QSensor *sensor)
+ : BbSensorBackend<QMagnetometerReading>(devicePath(), SENSOR_TYPE_MAGNETOMETER, sensor)
+{
+ setDescription(QLatin1String("Magnetic flux density in Teslas (T)"));
+}
+
+QString BbMagnetometer::devicePath()
+{
+ return QLatin1String("/dev/sensor/mag");
+}
+
+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.
+ reading->setX(convertValue(event.motion.dsp.x));
+ reading->setY(convertValue(event.motion.dsp.y));
+ reading->setZ(convertValue(event.motion.dsp.z));
+
+ const bool returnGeoValues = sensor()->property("returnGeoValues").toBool();
+ if (returnGeoValues) {
+ switch (event.accuracy) {
+ case SENSOR_ACCURACY_UNRELIABLE: reading->setCalibrationLevel(0.0f); break;
+ case SENSOR_ACCURACY_LOW: reading->setCalibrationLevel(0.1f); break;
+
+ // We determined that MEDIUM should map to 1.0, because existing code samples
+ // show users should pop a calibration screen when seeing < 1.0. The MEDIUM accuracy
+ // is actually good enough not to require calibration, so we don't want to make it seem
+ // like it is required artificially.
+ case SENSOR_ACCURACY_MEDIUM: reading->setCalibrationLevel(1.0f); break;
+ case SENSOR_ACCURACY_HIGH: reading->setCalibrationLevel(1.0f); break;
+ }
+ } else {
+ reading->setCalibrationLevel(1.0f);
+ }
+
+ return true;
+}
+
+qreal BbMagnetometer::convertValue(float bbValueInMicroTesla)
+{
+ // Convert from microtesla to tesla
+ return bbValueInMicroTesla * 1.0e-6;
+}
diff --git a/src/plugins/sensors/blackberry/bbmagnetometer.h b/src/plugins/sensors/blackberry/bbmagnetometer.h
new file mode 100644
index 00000000..4ab482a2
--- /dev/null
+++ b/src/plugins/sensors/blackberry/bbmagnetometer.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Research In Motion
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtSensors module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef BBMAGNETOMETER_H
+#define BBMAGNETOMETER_H
+
+#include "bbsensorbackend.h"
+#include <qmagnetometer.h>
+
+class BbMagnetometer : public BbSensorBackend<QMagnetometerReading>
+{
+ Q_OBJECT
+
+public:
+ explicit BbMagnetometer(QSensor *sensor);
+
+ static QString devicePath();
+
+protected:
+ qreal convertValue(float bbValue);
+ bool updateReadingFromEvent(const sensor_event_t &event, QMagnetometerReading *reading);
+};
+
+#endif
diff --git a/src/plugins/sensors/blackberry/bborientationsensor.cpp b/src/plugins/sensors/blackberry/bborientationsensor.cpp
new file mode 100644
index 00000000..3f592f9b
--- /dev/null
+++ b/src/plugins/sensors/blackberry/bborientationsensor.cpp
@@ -0,0 +1,134 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Research In Motion
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtSensors module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "bborientationsensor.h"
+
+class BbOrientationReadingPrivate
+{
+public:
+ BbOrientationReadingPrivate()
+ : rotation(0)
+ {
+ }
+
+ int rotation;
+};
+
+BbOrientationReading::BbOrientationReading(QObject *parent)
+ : QOrientationReading(parent),
+ d(new BbOrientationReadingPrivate)
+{
+}
+
+BbOrientationReading::~BbOrientationReading()
+{
+}
+
+void BbOrientationReading::copyValuesFrom(QSensorReading *other)
+{
+ QOrientationReading::copyValuesFrom(other);
+ const BbOrientationReading * const reading = qobject_cast<const BbOrientationReading *>(other);
+ if (reading)
+ d->rotation = reading->rotation();
+}
+
+int BbOrientationReading::rotation() const
+{
+ return d->rotation;
+}
+
+void BbOrientationReading::setRotation(int rotation)
+{
+ d->rotation = rotation;
+}
+
+BbOrientationSensor::BbOrientationSensor(QSensor *sensor)
+ : BbSensorBackend<BbOrientationReading>(devicePath(), SENSOR_TYPE_ORIENTATION, sensor)
+{
+ setDescription(QLatin1String("Device orientation"));
+}
+
+QString BbOrientationSensor::devicePath()
+{
+ return QLatin1String("/dev/sensor/orientation");
+}
+
+void BbOrientationSensor::start()
+{
+ BbSensorBackend<BbOrientationReading>::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.
+ // So set the possible enum values of QOrientationReading::Orientation as the output range here.
+ // By returning false in addDefaultRange(), we skip setting the range from the OS service in the
+ // base class.
+ addOutputRange(0, 6, 1);
+}
+
+bool BbOrientationSensor::addDefaultRange()
+{
+ return false;
+}
+
+bool BbOrientationSensor::updateReadingFromEvent(const sensor_event_t &event, BbOrientationReading *reading)
+{
+ QOrientationReading::Orientation qtOrientation = QOrientationReading::Undefined;
+ const QByteArray face(event.orientation.face);
+ if (face == "FACE_UP") qtOrientation = QOrientationReading::FaceUp;
+ else if (face == "TOP_UP") qtOrientation = QOrientationReading::TopUp;
+ else if (face == "RIGHT_UP") qtOrientation = QOrientationReading::RightUp;
+ else if (face == "LEFT_UP") qtOrientation = QOrientationReading::LeftUp;
+ else if (face == "BOTTOM_UP") qtOrientation = QOrientationReading::TopDown;
+ else if (face == "FACE_DOWN") qtOrientation = QOrientationReading::FaceDown;
+
+ reading->setOrientation(qtOrientation);
+ reading->setRotation(event.orientation.screen);
+ return true;
+}
diff --git a/src/plugins/sensors/blackberry/bborientationsensor.h b/src/plugins/sensors/blackberry/bborientationsensor.h
new file mode 100644
index 00000000..44793093
--- /dev/null
+++ b/src/plugins/sensors/blackberry/bborientationsensor.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Research In Motion
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtSensors module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef BBORIENTATIONSENSOR_H
+#define BBORIENTATIONSENSOR_H
+
+#include "bbsensorbackend.h"
+#include <qorientationsensor.h>
+
+class BbOrientationReadingPrivate;
+
+// We extend QOrientationReading with the "rotation" property
+class BbOrientationReading : public QOrientationReading
+{
+ Q_OBJECT
+
+ // Screen Rotation in degrees - 0, 90, 180 or 270
+ Q_PROPERTY(int rotation READ rotation)
+public:
+ explicit BbOrientationReading(QObject *parent = 0);
+ ~BbOrientationReading();
+ void copyValuesFrom(QSensorReading *other);
+ int rotation() const;
+ void setRotation(int rotation);
+
+private:
+ QScopedPointer<BbOrientationReadingPrivate> d;
+};
+
+class BbOrientationSensor : public BbSensorBackend<BbOrientationReading>
+{
+ Q_OBJECT
+
+public:
+ explicit BbOrientationSensor(QSensor *sensor);
+
+ static QString devicePath();
+
+ void start();
+ void additionalDeviceInit();
+ bool addDefaultRange();
+
+protected:
+ bool updateReadingFromEvent(const sensor_event_t &event, BbOrientationReading *reading);
+};
+
+#endif
diff --git a/src/plugins/sensors/blackberry/bbproximitysensor.cpp b/src/plugins/sensors/blackberry/bbproximitysensor.cpp
new file mode 100644
index 00000000..8781c6f6
--- /dev/null
+++ b/src/plugins/sensors/blackberry/bbproximitysensor.cpp
@@ -0,0 +1,117 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Research In Motion
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtSensors module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "bbproximitysensor.h"
+
+class BbProximityReadingPrivate
+{
+public:
+ BbProximityReadingPrivate()
+ : distance(0),
+ reflectance(0)
+ {
+ }
+
+ qreal distance;
+ qreal reflectance;
+};
+
+BbProximityReading::BbProximityReading(QObject *parent)
+ : QProximityReading(parent),
+ d(new BbProximityReadingPrivate)
+{
+}
+
+BbProximityReading::~BbProximityReading()
+{
+}
+
+void BbProximityReading::copyValuesFrom(QSensorReading *other)
+{
+ QProximityReading::copyValuesFrom(other);
+ const BbProximityReading * const reading = qobject_cast<const BbProximityReading *>(other);
+ if (reading) {
+ d->distance = reading->distance();
+ d->reflectance = reading->reflectance();
+ }
+}
+
+qreal BbProximityReading::distance() const
+{
+ return d->distance;
+}
+
+void BbProximityReading::setDistance(qreal distance)
+{
+ d->distance = distance;
+}
+
+qreal BbProximityReading::reflectance() const
+{
+ return d->reflectance;
+}
+
+void BbProximityReading::setReflectance(qreal reflectance)
+{
+ d->reflectance = reflectance;
+}
+
+BbProximitySensor::BbProximitySensor(QSensor *sensor)
+ : BbSensorBackend<BbProximityReading>(devicePath(), SENSOR_TYPE_PROXIMITY, sensor)
+{
+ setDescription(QLatin1String("Proximity"));
+}
+
+QString BbProximitySensor::devicePath()
+{
+ return QLatin1String("/dev/sensor/prox");
+}
+
+bool BbProximitySensor::updateReadingFromEvent(const sensor_event_t &event, BbProximityReading *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);
+ reading->setDistance(event.proximity_s.distance);
+ reading->setReflectance(1.0f - event.proximity_s.normalized);
+ return true;
+}
diff --git a/src/plugins/sensors/blackberry/bbproximitysensor.h b/src/plugins/sensors/blackberry/bbproximitysensor.h
new file mode 100644
index 00000000..0cbdb8fb
--- /dev/null
+++ b/src/plugins/sensors/blackberry/bbproximitysensor.h
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Research In Motion
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtSensors module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef BBPROXIMITYSENSOR_H
+#define BBPROXIMITYSENSOR_H
+
+#include "bbsensorbackend.h"
+#include <qproximitysensor.h>
+
+class BbProximityReadingPrivate;
+
+// We extend QProximityReading with two new properties
+class BbProximityReading : public QProximityReading
+{
+ Q_OBJECT
+
+ // Distance in cm
+ Q_PROPERTY(qreal distance READ distance)
+
+ // Same as in QIRProximityReading
+ Q_PROPERTY(qreal reflectance READ reflectance)
+
+public:
+ explicit BbProximityReading(QObject *parent = 0);
+ ~BbProximityReading();
+ void copyValuesFrom(QSensorReading *other);
+ qreal distance() const;
+ void setDistance(qreal distance);
+ qreal reflectance() const;
+ void setReflectance(qreal reflectance);
+
+private:
+ QScopedPointer<BbProximityReadingPrivate> d;
+};
+
+class BbProximitySensor : public BbSensorBackend<BbProximityReading>
+{
+ Q_OBJECT
+
+public:
+ explicit BbProximitySensor(QSensor *sensor);
+
+ static QString devicePath();
+
+protected:
+ bool updateReadingFromEvent(const sensor_event_t &event, BbProximityReading *reading);
+};
+
+#endif
diff --git a/src/plugins/sensors/blackberry/bbrotationsensor.cpp b/src/plugins/sensors/blackberry/bbrotationsensor.cpp
new file mode 100644
index 00000000..fe34ea4e
--- /dev/null
+++ b/src/plugins/sensors/blackberry/bbrotationsensor.cpp
@@ -0,0 +1,114 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Research In Motion
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtSensors module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "bbrotationsensor.h"
+
+#include "bbutil.h"
+#include <QtCore/qmath.h>
+
+BbRotationSensor::BbRotationSensor(QSensor *sensor)
+ : BbSensorBackend<QRotationReading>(devicePath(), SENSOR_TYPE_ROTATION_MATRIX, sensor)
+{
+ setDescription(QLatin1String("Device rotation in degrees"));
+}
+
+QString BbRotationSensor::devicePath()
+{
+ return QLatin1String("/dev/sensor/rotMatrix");
+}
+
+void BbRotationSensor::additionalDeviceInit()
+{
+ addOutputRange(-180, 180, 0 /* ? */);
+}
+
+bool BbRotationSensor::addDefaultRange()
+{
+ // The range we get from the OS service is only -1 to 1, which are the values of the matrix.
+ // We need the values of the axes in degrees.
+ return false;
+}
+
+static float getMatrixElement(const float matrix[3*3], int index0, int index1)
+{
+ return matrix[index0 * 3 + index1];
+}
+
+static void matrixToEulerZXY(const float matrix[3*3],
+ float &thetaX, float &thetaY, float& thetaZ)
+{
+ thetaX = asin( getMatrixElement(matrix, 2, 1));
+ if ( thetaX < M_PI_2 ) {
+ if ( thetaX > -M_PI_2 ) {
+ thetaZ = atan2( -getMatrixElement(matrix, 0, 1),
+ getMatrixElement(matrix, 1, 1) );
+ thetaY = atan2( -getMatrixElement(matrix, 2, 0),
+ getMatrixElement(matrix, 2, 2) );
+ } else {
+ // Not a unique solution
+ thetaZ = -atan2( getMatrixElement(matrix, 0, 2),
+ getMatrixElement(matrix, 0, 0) );
+ thetaY = 0.0;
+ }
+ } else {
+ // Not a unique solution
+ thetaZ = atan2( getMatrixElement(matrix, 0, 2),
+ getMatrixElement(matrix, 0, 0) );
+ thetaY = 0.0;
+ }
+}
+
+bool BbRotationSensor::updateReadingFromEvent(const sensor_event_t &event, QRotationReading *reading)
+{
+ // sensor_event_t has euler angles for a Z-Y'-X'' system, but the QtMobility API
+ // uses Z-X'-Y''.
+ // So extract the euler angles using the Z-X'-Y'' system from the matrix.
+ float xRad, yRad, zRad;
+ matrixToEulerZXY(event.rotation_matrix, xRad, yRad, zRad);
+ reading->setX(radiansToDegrees(xRad));
+ reading->setY(radiansToDegrees(yRad));
+ reading->setZ(radiansToDegrees(zRad));
+ return true;
+}
+
+qreal BbRotationSensor::convertValue(float bbValueInRad)
+{
+ return radiansToDegrees(bbValueInRad);
+}
diff --git a/src/plugins/sensors/blackberry/bbrotationsensor.h b/src/plugins/sensors/blackberry/bbrotationsensor.h
new file mode 100644
index 00000000..475ad223
--- /dev/null
+++ b/src/plugins/sensors/blackberry/bbrotationsensor.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Research In Motion
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtSensors module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef BBROTATIONSENSOR_H
+#define BBROTATIONSENSOR_H
+
+#include "bbsensorbackend.h"
+#include <qrotationsensor.h>
+
+class BbRotationSensor : public BbSensorBackend<QRotationReading>
+{
+ Q_OBJECT
+
+public:
+ explicit BbRotationSensor(QSensor *sensor);
+
+ static QString devicePath();
+
+protected:
+ void additionalDeviceInit();
+ bool addDefaultRange();
+ qreal convertValue(float bbValue);
+ bool updateReadingFromEvent(const sensor_event_t &event, QRotationReading *reading);
+
+};
+
+#endif
diff --git a/src/plugins/sensors/blackberry/bbsensorbackend.cpp b/src/plugins/sensors/blackberry/bbsensorbackend.cpp
new file mode 100644
index 00000000..e659ee87
--- /dev/null
+++ b/src/plugins/sensors/blackberry/bbsensorbackend.cpp
@@ -0,0 +1,175 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Research In Motion
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtSensors module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "bbsensorbackend.h"
+
+#include <QtCore/QDebug>
+#include <fcntl.h>
+
+static const int microSecondsPerSecond = 1000 * 1000;
+
+static int microSecondsToHertz(uint microSeconds)
+{
+ return microSecondsPerSecond / microSeconds;
+}
+
+static uint hertzToMicroSeconds(int hertz)
+{
+ return microSecondsPerSecond / hertz;
+}
+
+BbSensorBackendBase::BbSensorBackendBase(const QString &devicePath, sensor_type_e sensorType,
+ QSensor *sensor)
+ : QSensorBackend(sensor), m_deviceFile(devicePath), m_sensorType(sensorType)
+{
+}
+
+QFile &BbSensorBackendBase::deviceFile()
+{
+ return m_deviceFile;
+}
+
+sensor_type_e BbSensorBackendBase::sensorType() const
+{
+ return m_sensorType;
+}
+
+void BbSensorBackendBase::initSensorInfo()
+{
+ if (!m_deviceFile.open(QFile::ReadOnly)) {
+ qDebug() << "initSensorInfo(): Failed to open" << m_deviceFile.fileName()
+ << ":" << m_deviceFile.errorString();
+ } else {
+ sensor_devctl_info_u deviceInfo;
+ const int result = devctl(m_deviceFile.handle(), DCMD_SENSOR_INFO, &deviceInfo,
+ sizeof(deviceInfo), NULL);
+ if (result != EOK) {
+ perror(QString::fromLatin1("Querying sensor info for %1 failed")
+ .arg(m_deviceFile.fileName()).toLocal8Bit());
+ } else {
+ if (addDefaultRange()) {
+ addOutputRange(convertValue(deviceInfo.rx.info.range_min),
+ convertValue(deviceInfo.rx.info.range_max),
+ convertValue(deviceInfo.rx.info.resolution));
+ }
+
+ // Min and max intentionally swapped here, as the minimum delay is the maximum rate
+ addDataRate(microSecondsToHertz(deviceInfo.rx.info.delay_max),
+ microSecondsToHertz(deviceInfo.rx.info.delay_min));
+ }
+ additionalDeviceInit();
+ m_deviceFile.close();
+ }
+}
+
+void BbSensorBackendBase::additionalDeviceInit()
+{
+}
+
+bool BbSensorBackendBase::addDefaultRange()
+{
+ return true;
+}
+
+qreal BbSensorBackendBase::convertValue(float bbValue)
+{
+ return bbValue;
+}
+
+void BbSensorBackendBase::start()
+{
+ if (!m_deviceFile.open(QFile::ReadOnly | QFile::Unbuffered)) {
+ qDebug() << "Starting sensor" << m_deviceFile.fileName()
+ << "failed:" << m_deviceFile.errorString();
+ sensorError(m_deviceFile.error());
+ return;
+ }
+
+ const int rateInHertz = sensor()->dataRate();
+ if (rateInHertz != 0) {
+ const uint rateInMicroseconds = hertzToMicroSeconds(rateInHertz);
+ sensor_devctl_rate_u deviceRate;
+ deviceRate.tx.rate = rateInMicroseconds;
+ const int result = devctl(m_deviceFile.handle(), DCMD_SENSOR_RATE, &deviceRate,
+ sizeof(deviceRate), NULL);
+ if (result != EOK) {
+ perror(QString::fromLatin1("Setting sensor rate for %1 failed")
+ .arg(m_deviceFile.fileName()).toLocal8Bit());
+ }
+ }
+
+ // 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;
+ }
+
+ m_socketNotifier.reset(new QSocketNotifier(m_deviceFile.handle(), QSocketNotifier::Read));
+ connect(m_socketNotifier.data(), SIGNAL(activated(int)), this, SLOT(dataAvailable()));
+}
+
+void BbSensorBackendBase::stop()
+{
+ m_socketNotifier.reset();
+ m_deviceFile.close();
+}
+
+void BbSensorBackendBase::dataAvailable()
+{
+ Q_FOREVER {
+ sensor_event_t event;
+ const qint64 numBytes = m_deviceFile.read(reinterpret_cast<char *>(&event),
+ sizeof(sensor_event_t));
+ if (numBytes == -1) {
+ break;
+ } else if (numBytes == sizeof(sensor_event_t)) {
+ processEvent(event);
+ } else {
+ qDebug() << "Reading sensor event data for" << m_deviceFile.fileName()
+ << "failed (unexpected data size):" << m_deviceFile.errorString();
+ }
+ }
+}
diff --git a/src/plugins/sensors/blackberry/bbsensorbackend.h b/src/plugins/sensors/blackberry/bbsensorbackend.h
new file mode 100644
index 00000000..254ad90f
--- /dev/null
+++ b/src/plugins/sensors/blackberry/bbsensorbackend.h
@@ -0,0 +1,122 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Research In Motion
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtSensors module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef BBSENSORBACKEND_H
+#define BBSENSORBACKEND_H
+
+#include <qsensorbackend.h>
+#include <QtCore/QFile>
+#include <QtCore/QSocketNotifier>
+#include "sensor.h"
+
+class BbSensorBackendBase : public QSensorBackend
+{
+ Q_OBJECT
+
+public:
+ BbSensorBackendBase(const QString &devicePath, sensor_type_e sensorType, QSensor *sensor);
+
+ void initSensorInfo();
+
+ void start();
+ void stop();
+
+protected:
+ QFile& deviceFile();
+ sensor_type_e sensorType() const;
+
+ // This is called while the device file is open during initalization and gives a subclass
+ // an opportunity to do additional initalization.
+ virtual void additionalDeviceInit();
+
+ // If true is returned here, initSensorInfo() will read the output range from the OS sensor
+ // service and pass it to the QtSensor API.
+ virtual bool addDefaultRange();
+
+ // Converts a value from units of the OS sensor service to units needed by the QtSensors API.
+ // This is used in initSensorInfo(), where the output range is read from the backend and passed
+ // on to the QtSensors side.
+ // One example is the magnetometer: The OS sensor service returns units in microtesla, whereas
+ // QtSensors expects tesla. This function would therefore convert from microtesla to tesla.
+ virtual qreal convertValue(float bbValue);
+
+ virtual void processEvent(const sensor_event_t &sensorEvent) = 0;
+
+private slots:
+ void dataAvailable();
+
+private:
+ QFile m_deviceFile;
+ QScopedPointer<QSocketNotifier> m_socketNotifier;
+ sensor_type_e m_sensorType;
+};
+
+template<class SensorReading>
+class BbSensorBackend : public BbSensorBackendBase
+{
+public:
+ BbSensorBackend(const QString &devicePath, sensor_type_e sensorType, QSensor *sensor)
+ : BbSensorBackendBase(devicePath, sensorType, sensor)
+ {
+ setReading(&m_reading);
+ }
+
+protected:
+ virtual bool updateReadingFromEvent(const sensor_event_t &sensorEvent, SensorReading *reading) = 0;
+
+private:
+ void processEvent(const sensor_event_t &sensorEvent)
+ {
+ // There may be "non-sensor" event types added later for housekeeping, so we have to check
+ // if the senor type matches the expected value
+ if (sensorEvent.type != sensorType())
+ return;
+
+ if (updateReadingFromEvent(sensorEvent, &m_reading)) {
+ // The OS timestamp is in nanoseconds, QtMobility expects microseconds
+ m_reading.setTimestamp(sensorEvent.timestamp / 1000);
+ newReadingAvailable();
+ }
+ }
+
+ SensorReading m_reading;
+};
+
+#endif
diff --git a/src/plugins/sensors/blackberry/bbtemperaturesensor.cpp b/src/plugins/sensors/blackberry/bbtemperaturesensor.cpp
new file mode 100644
index 00000000..582c37ba
--- /dev/null
+++ b/src/plugins/sensors/blackberry/bbtemperaturesensor.cpp
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Research In Motion
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtSensors module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#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)
+{
+ setDescription(QLatin1String("Temperature in degrees Celsius"));
+}
+
+QString BbTemperatureSensor::devicePath()
+{
+ return QLatin1String("/dev/sensor/temp");
+}
+
+bool BbTemperatureSensor::updateReadingFromEvent(const sensor_event_t &event, BbTemperatureReading *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.
+ reading->setTemperature(event.temperature_s.temperature);
+ return true;
+}
diff --git a/src/plugins/sensors/blackberry/bbtemperaturesensor.h b/src/plugins/sensors/blackberry/bbtemperaturesensor.h
new file mode 100644
index 00000000..48ae342b
--- /dev/null
+++ b/src/plugins/sensors/blackberry/bbtemperaturesensor.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Research In Motion
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtSensors module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef BBTEMPERATURESENSOR_H
+#define BBTEMPERATURESENSOR_H
+
+#include "bbsensorbackend.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>
+{
+ Q_OBJECT
+
+public:
+ explicit BbTemperatureSensor(QSensor *sensor);
+
+ static QString devicePath();
+
+protected:
+ bool updateReadingFromEvent(const sensor_event_t &event, BbTemperatureReading *reading);
+};
+
+#endif
diff --git a/src/plugins/sensors/blackberry/bbutil.h b/src/plugins/sensors/blackberry/bbutil.h
new file mode 100644
index 00000000..f360776f
--- /dev/null
+++ b/src/plugins/sensors/blackberry/bbutil.h
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Research In Motion
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtSensors module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef BBUTIL_H
+#define BBUTIL_H
+
+#include <QtCore/qmath.h>
+
+namespace {
+qreal radiansToDegrees(qreal radians)
+{
+ static const qreal radToDeg = 180.0f / M_PI;
+ return radians * radToDeg;
+}
+}
+
+#endif
diff --git a/src/plugins/sensors/blackberry/blackberry.pro b/src/plugins/sensors/blackberry/blackberry.pro
new file mode 100644
index 00000000..b5c339c4
--- /dev/null
+++ b/src/plugins/sensors/blackberry/blackberry.pro
@@ -0,0 +1,38 @@
+load(qt_module)
+
+TARGET = qtsensors_blackberry
+QT = sensors core
+DEFINES += QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII
+
+load(qt_plugin)
+
+DESTDIR = $$QT.sensors.plugins/sensors
+
+HEADERS += bbsensorbackend.h \
+ bbaccelerometer.h \
+ bbaltimeter.h \
+ bbgyroscope.h \
+ bblightsensor.h \
+ bbmagnetometer.h \
+ bborientationsensor.h \
+ bbproximitysensor.h \
+ bbrotationsensor.h \
+ bbtemperaturesensor.h \
+ bbutil.h
+
+SOURCES += bbsensorbackend.cpp \
+ bbaccelerometer.cpp \
+ bbaltimeter.cpp \
+ bbgyroscope.cpp \
+ bblightsensor.cpp \
+ bbmagnetometer.cpp \
+ bborientationsensor.cpp \
+ bbproximitysensor.cpp \
+ bbrotationsensor.cpp \
+ bbtemperaturesensor.cpp \
+ main.cpp
+
+OTHER_FILES = plugin.json
+
+target.path += $$[QT_INSTALL_PLUGINS]/sensors
+INSTALLS += target
diff --git a/src/plugins/sensors/blackberry/main.cpp b/src/plugins/sensors/blackberry/main.cpp
new file mode 100644
index 00000000..abe5972c
--- /dev/null
+++ b/src/plugins/sensors/blackberry/main.cpp
@@ -0,0 +1,125 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Research In Motion
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtSensors module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "bbaccelerometer.h"
+#include "bbaltimeter.h"
+#include "bbgyroscope.h"
+#include "bblightsensor.h"
+#include "bbmagnetometer.h"
+#include "bborientationsensor.h"
+#include "bbproximitysensor.h"
+#include "bbrotationsensor.h"
+#include "bbtemperaturesensor.h"
+
+#include <qsensormanager.h>
+#include <qsensorplugin.h>
+
+static const char *bbAccelerometerId = "bbAccelerometer";
+static const char *bbAltitmeterId = "bbAltimeter";
+static const char *bbGyroscopeId = "bbGyroscope";
+static const char *bbLightSensorId = "bbLightSensor";
+static const char *bbMagnetometerId = "bbMagnetometer";
+static const char *bbOrientationSensorId = "bbOrientationSensor";
+static const char *bbProximitySensorId = "bbProximitySensor";
+static const char *bbRotationSensorId = "bbRotationSensor";
+static const char *bbTemperatureSensorId = "bbTemperatureSensorId";
+
+class BbSensorPlugin : public QObject, public QSensorPluginInterface, public QSensorBackendFactory
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID "com.nokia.Qt.QSensorPluginInterface/1.0" FILE "plugin.json")
+ Q_INTERFACES(QSensorPluginInterface)
+
+public:
+ void registerSensors()
+ {
+ if (sensorSupported(BbAccelerometer::devicePath()))
+ QSensorManager::registerBackend("QAccelerometer", bbAccelerometerId, this);
+ if (sensorSupported(BbAltimeter::devicePath()))
+ QSensorManager::registerBackend("BbAltimeter", bbAltitmeterId, this);
+ if (sensorSupported(BbGyroscope::devicePath()))
+ QSensorManager::registerBackend("QGyroscope", bbGyroscopeId, this);
+ if (sensorSupported(BbLightSensor::devicePath()))
+ QSensorManager::registerBackend("QLightSensor", bbLightSensorId, this);
+ if (sensorSupported(BbMagnetometer::devicePath()))
+ QSensorManager::registerBackend("QMagnetometer", bbMagnetometerId, this);
+ if (sensorSupported(BbOrientationSensor::devicePath()))
+ QSensorManager::registerBackend("QOrientationSensor", bbOrientationSensorId, this);
+ if (sensorSupported(BbProximitySensor::devicePath()))
+ QSensorManager::registerBackend("QProximitySensor", bbProximitySensorId, this);
+ if (sensorSupported(BbRotationSensor::devicePath()))
+ QSensorManager::registerBackend("QRotationSensor", bbRotationSensorId, this);
+ if (sensorSupported(BbTemperatureSensor::devicePath()))
+ QSensorManager::registerBackend("BbTemperatureSensor", bbTemperatureSensorId, this);
+ }
+
+ QSensorBackend *createBackend(QSensor *sensor)
+ {
+ BbSensorBackendBase *backend = 0;
+ if (sensor->identifier() == bbAccelerometerId)
+ backend = new BbAccelerometer(sensor);
+ if (sensor->identifier() == bbAltitmeterId)
+ backend = new BbAltimeter(sensor);
+ if (sensor->identifier() == bbGyroscopeId)
+ backend = new BbGyroscope(sensor);
+ if (sensor->identifier() == bbLightSensorId)
+ backend = new BbLightSensor(sensor);
+ if (sensor->identifier() == bbMagnetometerId)
+ backend = new BbMagnetometer(sensor);
+ if (sensor->identifier() == bbOrientationSensorId)
+ backend = new BbOrientationSensor(sensor);
+ if (sensor->identifier() == bbProximitySensorId)
+ backend = new BbProximitySensor(sensor);
+ if (sensor->identifier() == bbRotationSensorId)
+ backend = new BbRotationSensor(sensor);
+ if (sensor->identifier() == bbTemperatureSensorId)
+ backend = new BbTemperatureSensor(sensor);
+ backend->initSensorInfo();
+ return backend;
+ }
+
+private:
+ bool sensorSupported(const QString &devicePath)
+ {
+ return QFile::exists(devicePath);
+ }
+};
+
+#include "main.moc"
diff --git a/src/plugins/sensors/blackberry/plugin.json b/src/plugins/sensors/blackberry/plugin.json
new file mode 100644
index 00000000..8a55b3ae
--- /dev/null
+++ b/src/plugins/sensors/blackberry/plugin.json
@@ -0,0 +1 @@
+{ "Keys": [ "notused" ] }
diff --git a/src/plugins/sensors/blackberry/sensor.h b/src/plugins/sensors/blackberry/sensor.h
new file mode 100644
index 00000000..6b4290a3
--- /dev/null
+++ b/src/plugins/sensors/blackberry/sensor.h
@@ -0,0 +1,364 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Research In Motion
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtSensors module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// This file is a temporary copy until it becomes available in the Blackberry NDK.
+//
+
+#ifndef SENSOR_H_
+#define SENSOR_H_
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include <devctl.h>
+#include <errno.h>
+
+typedef enum {
+ //Raw
+ SENSOR_TYPE_ACCELEROMETER = 0,
+ SENSOR_TYPE_MAGNETOMETER = 1,
+ SENSOR_TYPE_GYROSCOPE = 2,
+ SENSOR_TYPE_ALTIMETER = 3,
+ SENSOR_TYPE_TEMPERATURE = 4,
+ SENSOR_TYPE_PROXIMITY = 5,
+ SENSOR_TYPE_LIGHT = 6,
+ SENSOR_TYPE_GRAVITY = 7,
+ SENSOR_TYPE_LINEAR_ACCEL = 8,
+ SENSOR_TYPE_ROTATION_VECTOR = 9,
+ SENSOR_TYPE_ORIENTATION = 10,
+ SENSOR_TYPE_ACCEL_LEGACY = 11,
+ SENSOR_TYPE_ROTATION_MATRIX = 12,
+ SENSOR_TYPE_ROTATION_MATRIX_MAG = 13,
+ SENSOR_TYPE_AZIMUTH_PITCH_ROLL = 14,
+ SENSOR_TYPE_FACE_DETECT = 15,
+ SENSOR_TYPE_PRESSURE = 16,
+} sensor_type_e;
+
+typedef enum {
+ SENSOR_ACCURACY_UNRELIABLE,
+ SENSOR_ACCURACY_LOW,
+ SENSOR_ACCURACY_MEDIUM,
+ SENSOR_ACCURACY_HIGH,
+} sensor_accuracy_e;
+
+typedef struct {
+ float resolution;
+ float range_min;
+ float range_max;
+ uint32_t delay_min;
+ uint32_t delay_max;
+ uint32_t delay_default;
+ float power;
+} sensor_info_t;
+
+typedef struct {
+ size_t size; // The size of this structure, can be used for version
+ sensor_type_e type; // The sensor type, used to index into appropriate payload
+ uint32_t flags; // Flags
+ sensor_accuracy_e accuracy; // The accuracy associated with this sample
+ uint64_t timestamp; // Time stamp of data acquisition, value in nano-seconds
+ union {
+ struct {
+ struct {
+ /* Accelerometer, Linear Acceleration, Gravity -> m/s/s (meters/second/second)
+ * Magnetometer -> uT (micro Tesla)
+ * Gyroscope -> r/s (radian's/second)
+ */
+ float x, y, z; // data of sensor for x,y and z axis
+ } dsp, raw; // dsp values are signal processed/calibrated, raw is not
+ union {
+ struct {
+ float temperature;// temperature of gyro sensor in degrees Celcius
+ } gyro;
+ };
+ } motion; // Used by motion sensors like Accel, Mag, Gyro, Linear Accel and Gravity
+ float raw_data[18]; // Misc bucket for data payload
+ float rotation_matrix[3*3]; // Rotation Matrix
+ struct {
+ int screen; // Screen Rotation in degrees - 0, 90, 180 or 270
+ char face[64]; // String based representation of device face
+ } orientation;
+ struct {
+ float azimuth; // 0 to 359 degrees
+ float pitch; // -180 t0 180 degrees
+ float roll; // -90 to 90 degrees
+ } apr;
+ struct {
+ float distance; // range_min -> range_max, discrete steps of distance or actual value in cm
+ float normalized; // 0.0 -> 1.0 (close -> far), normalized unit-less signal from raw sensor
+ } proximity_s;
+ struct {
+ float pressure; // Pressure in Pascal's
+ float temperature; // Temperature in degrees Celcius
+ } pressure_s;
+ struct {
+ float altitude; // Altitude in meters relative to mean sea level
+ } altitude_s;
+ struct {
+ float illuminance; // Illuminance in lux
+ } light_s;
+ struct {
+ int face_detect; // 0 -> 1, bool value indicating if an object is close to or touching the screen
+ float probability; // 0 -> 1, probability indicating if an object is close to or touching the screen
+ } face_detect_s;
+ struct {
+ float temperature; // Temperature in degree Celcius
+ } temperature_s;
+
+ // Deprecated
+ float proximity; // see proximity_s.distance
+ float pressure; // see pressure_s.pressure
+ float altitude; // see altitude_s.altitude
+ float illuminance; // see light_s.illuminance
+ int face_detect; // see face_detect_s.face_detect
+ float temperature; // see temperature_s.temperature
+ struct {
+ float x,y,z;
+ struct {
+ float x,y,z;
+ } raw;
+ } axis_s; // see motion
+ };
+} sensor_event_t;
+
+
+/* ****************************************************************************
+ * devctl() common to all sensors
+ *
+ * Paths:
+ * dev/sensor/accel
+ * dev/sensor/mag
+ * dev/sensor/gyro
+ * dev/sensor/alt
+ * dev/sensor/temp
+ * dev/sensor/prox
+ * dev/sensor/light
+ * dev/sensor/gravity
+ * dev/sensor/linAccel
+ * dev/sensor/rotVect
+ * dev/sensor/orientation
+ * dev/sensor/rotMatrix
+ * dev/sensor/apr
+ * dev/sensor/faceDetect
+ * dev/sensor/pressure
+ *
+ * Example usage:
+ * fd = open( "/dev/sensor/???", O_RDONLY); // ??? = sensor file name
+ *
+ */
+
+typedef struct { // re-used for all the "enable" type controls
+ unsigned int enable;
+} sensor_devctl_enable_tx_t;
+
+/* DCMD_SENSOR_RATE
+ * Set Sensor Update Period Rate.
+ *
+ * Example usage:
+ * sensor_devctl_rate_u rateSet;
+ * rateSet.tx.rate = myValue;
+ * result = devctl(fd, DCMD_SENSOR_RATE, &rateSet, sizeof(rateSet), NULL);
+ * where
+ * rateSet.tx.rate = Update Event Period in micro-seconds
+ *
+ * rateSet.rx.rate = The period in microseconds the system granted.
+ * result = EOK - success, or see errno return code descriptions
+ * = EINVAL - invalid rate parameter, sensor will use default rate
+ */
+typedef union {
+ struct {
+ unsigned int rate;
+ } tx, rx;
+} sensor_devctl_rate_u;
+
+
+/* DCMD_SENSOR_ENABLE
+ * Enable/Disable Sensor.
+ *
+ * Example usage:
+ * sensor_devctl_enable_u enSensor;
+ * enSensor.tx.enable = 1; // 1 = enable, 0 = disable
+ * result = devctl(fd, DCMD_SENSOR_ENABLE, &enSensor, sizeof(enSensor), NULL);
+ * where
+ * result = EOK - success, or see errno return code descriptions
+ */
+typedef union {
+ sensor_devctl_enable_tx_t tx;
+} sensor_devctl_enable_u;
+
+
+/* DCMD_SENSOR_NAME
+ * Get Sensor name.
+ *
+ * Example usage:
+ * sensor_devctl_name_u sensorName;
+ * result = devctl(fd, DCMD_SENSOR_NAME, &sensorName, sizeof(sensorName), NULL);
+ * printf("My name is %s", sensorName.rx.name);
+ * where
+ * result = EOK - success, or see errno return code descriptions
+ */
+#define SENSOR_MAX_NAME_SIZE 20
+typedef union {
+ struct {
+ char name[SENSOR_MAX_NAME_SIZE];
+ } rx;
+} sensor_devctl_name_u;
+
+
+/* DCMD_SENSOR_CALIBRATE
+ * Request Sensor Calibrate.
+ *
+ * Example usage:
+ * sensor_devctl_calibrate_u sensorCal;
+ * sensorCal.tx.enable = 1; // 1 = start cal, 0 = stop cal
+ * result = devctl(fd, DCMD_SENSOR_CALIBRATE, &sensorCal, sizeof(sensorCal), NULL);
+ * where
+ * result = EOK - success, or see errno return code descriptions
+ */
+typedef union {
+ sensor_devctl_enable_tx_t tx;
+} sensor_devctl_calibrate_u;
+
+
+/* DCMD_SENSOR_QUEUE
+ * Enable/Disable Sensor Event Queuing. Sensor Services by default queues only
+ * one event. If a new event comes in before the client reads the last event, the
+ * previous event is overwritten. When queue is enabled, up to X events will be queued
+ * by the system. Client can set their read buffers up to X * sizeof(sensor_data_t)
+ * to be able to read all events queued.
+ *
+ * Example usage:
+ * sensor_devctl_queue_u sensorQue;
+ * sensorQue.tx.enable = 1; // 1 = enable, 0 = disable
+ * result = devctl(fd, DCMD_SENSOR_QUEUE, &sensorQue, sizeof(sensorQue), NULL);
+ * where
+ * sensorQue.rx.size - number of events that will be queued
+ * result = EOK - success, or see errno return code descriptions
+ */
+typedef union {
+ sensor_devctl_enable_tx_t tx;
+ struct {
+ unsigned int size;
+ } rx;
+} sensor_devctl_queue_u;
+
+
+/* DCMD_SENSOR_INFO
+ * Get Sensor Information.
+ *
+ * Example usage:
+ * sensor_devctl_info_u sensorInfo;
+ * result = devctl(fd, DCMD_SENSOR_INFO, &sensorInfo, sizeof(sensorInfo), NULL);
+ * where
+ * result = EOK - success, or see errno return code descriptions
+ * sensorInfo.rx.info = sensor info, see sensor_info_t
+ */
+typedef union {
+ struct {
+ sensor_info_t info;
+ } rx;
+} sensor_devctl_info_u;
+
+
+/* DCMD_SENSOR_SKIPDUPEVENT
+ * Enable/Disable Sensor Event duplicate event filtering. When enabled, exactly
+ * duplicate events from the sensor will be filtered. Some sensor hardware supports reduced
+ * reporting which will filter events that are the same within a certain threshold.
+ *
+ * Example usage:
+ * sensor_devctl_skipdupevent_u sensorSkipDup;
+ * sensorSkipDup.tx.enable = 1; // 1 = enable, 0 = disable
+ * result = devctl(fd, DCMD_SENSOR_SKIPDUPEVENT, &sensorSkipDup, sizeof(sensorSkipDup), NULL);
+ * where
+ * result = EOK - success, or see errno return code descriptions
+ */
+typedef union {
+ sensor_devctl_enable_tx_t tx;
+} sensor_devctl_skipdupevent_u;
+
+
+/* DCMD_SENSOR_BKGRND
+ * Request Sensor work when system is in user standby mode. By default, when the system
+ * is put in standby, all sensors are turned off and no events are sent to clients.
+ * By enabling background mode, the sensor will stay active when the system is in standby.
+ * This will reduce battery life.
+ *
+ * Example usage:
+ * sensor_devctl_bkgrnd_u sensorBkgrnd;
+ * sensorBkgrnd.tx.enable = 1; // 1 = enable, 0 = disable
+ * result = devctl(fd, DCMD_SENSOR_BKGRND, &sensorBkgrnd, sizeof(sensorBkgrnd), NULL);
+ * where
+ * result = EOK - success, or see errno return code descriptions
+ */
+typedef union {
+ sensor_devctl_enable_tx_t tx;
+} sensor_devctl_bkgrnd_u;
+
+/* DCMD_SENSOR_UNBLOCK
+ * UNBLOCK a blocked read
+ *
+ * Example usage:
+ * sensor_devctl_unblock_u sensorUnblock;
+ * sensorUnblock.tx.option = 0; // unblock client read with EINTR, zero bytes returned
+ * sensorUnblock.tx.option = reserved; // for future use
+ * result = devctl(fd, DCMD_SENSOR_UNBLOCK, &sensorUnblock, sizeof(sensorUnblock), NULL);
+ * where
+ * result = EOK - success, or see errno return code descriptions
+ */
+typedef union {
+ struct {
+ int option;
+ } tx;
+} sensor_devctl_unblock_u;
+
+
+#define DCMD_SENSOR_ENABLE __DIOT(_DCMD_INPUT, 1, sensor_devctl_enable_u )
+#define DCMD_SENSOR_RATE __DIOTF(_DCMD_INPUT, 2, sensor_devctl_rate_u )
+#define DCMD_SENSOR_INFO __DIOF(_DCMD_INPUT, 3, sensor_devctl_info_u )
+#define DCMD_SENSOR_SKIPDUPEVENT __DIOT(_DCMD_INPUT, 4, sensor_devctl_skipdupevent_u )
+#define DCMD_SENSOR_BKGRND __DIOT(_DCMD_INPUT, 5, sensor_devctl_bkgrnd_u )
+#define DCMD_SENSOR_QUEUE __DIOTF(_DCMD_INPUT, 6, sensor_devctl_queue_u )
+#define DCMD_SENSOR_CALIBRATE __DIOT(_DCMD_INPUT, 7, sensor_devctl_calibrate_u )
+#define DCMD_SENSOR_NAME __DIOF(_DCMD_INPUT, 9, sensor_devctl_name_u )
+#define DCMD_SENSOR_UNBLOCK __DIOT(_DCMD_INPUT, 10, sensor_devctl_unblock_u )
+
+#endif
diff --git a/src/plugins/sensors/sensors.pro b/src/plugins/sensors/sensors.pro
index d1adbf48..4f8fe034 100644
--- a/src/plugins/sensors/sensors.pro
+++ b/src/plugins/sensors/sensors.pro
@@ -3,3 +3,4 @@ TEMPLATE = subdirs
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