From 267b5ad15fa2ec74756693196f503e05056cf617 Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Mon, 26 Nov 2012 01:29:29 +0000 Subject: Introducing sensors for blackberry. Change-Id: Id19ba9aa43e4701a8caea3782e948e77cec48fc6 Reviewed-by: Thomas McGuire Reviewed-by: Lorn Potter --- plugins/sensors/blackberry/bbaccelerometer.cpp | 102 ++++++ plugins/sensors/blackberry/bbaccelerometer.h | 66 ++++ plugins/sensors/blackberry/bbaltimeter.cpp | 81 +++++ plugins/sensors/blackberry/bbaltimeter.h | 73 ++++ .../sensors/blackberry/bbambientlightsensor.cpp | 69 ++++ plugins/sensors/blackberry/bbambientlightsensor.h | 60 +++ plugins/sensors/blackberry/bbcompass.cpp | 109 ++++++ plugins/sensors/blackberry/bbcompass.h | 62 ++++ plugins/sensors/blackberry/bbguihelper.cpp | 152 ++++++++ plugins/sensors/blackberry/bbguihelper.h | 78 ++++ plugins/sensors/blackberry/bbgyroscope.cpp | 75 ++++ plugins/sensors/blackberry/bbgyroscope.h | 63 ++++ plugins/sensors/blackberry/bbholstersensor.cpp | 58 +++ plugins/sensors/blackberry/bbholstersensor.h | 62 ++++ plugins/sensors/blackberry/bbirproximitysensor.cpp | 58 +++ plugins/sensors/blackberry/bbirproximitysensor.h | 62 ++++ plugins/sensors/blackberry/bblightsensor.cpp | 58 +++ plugins/sensors/blackberry/bblightsensor.h | 62 ++++ plugins/sensors/blackberry/bbmagnetometer.cpp | 90 +++++ plugins/sensors/blackberry/bbmagnetometer.h | 63 ++++ plugins/sensors/blackberry/bborientationsensor.cpp | 85 +++++ plugins/sensors/blackberry/bborientationsensor.h | 65 ++++ plugins/sensors/blackberry/bbpressuresensor.cpp | 60 +++ plugins/sensors/blackberry/bbpressuresensor.h | 62 ++++ plugins/sensors/blackberry/bbproximitysensor.cpp | 62 ++++ plugins/sensors/blackberry/bbproximitysensor.h | 62 ++++ plugins/sensors/blackberry/bbrotationsensor.cpp | 91 +++++ plugins/sensors/blackberry/bbrotationsensor.h | 65 ++++ plugins/sensors/blackberry/bbsensorbackend.cpp | 401 +++++++++++++++++++++ plugins/sensors/blackberry/bbsensorbackend.h | 155 ++++++++ plugins/sensors/blackberry/bbtemperaturesensor.cpp | 83 +++++ plugins/sensors/blackberry/bbtemperaturesensor.h | 73 ++++ plugins/sensors/blackberry/bbutil.cpp | 82 +++++ plugins/sensors/blackberry/bbutil.h | 53 +++ plugins/sensors/blackberry/blackberry.pri | 39 ++ plugins/sensors/blackberry/blackberry.pro | 19 + plugins/sensors/blackberry/main.cpp | 169 +++++++++ plugins/sensors/blackberry/sensor.h | 365 +++++++++++++++++++ 38 files changed, 3494 insertions(+) create mode 100644 plugins/sensors/blackberry/bbaccelerometer.cpp create mode 100644 plugins/sensors/blackberry/bbaccelerometer.h create mode 100644 plugins/sensors/blackberry/bbaltimeter.cpp create mode 100644 plugins/sensors/blackberry/bbaltimeter.h create mode 100644 plugins/sensors/blackberry/bbambientlightsensor.cpp create mode 100644 plugins/sensors/blackberry/bbambientlightsensor.h create mode 100644 plugins/sensors/blackberry/bbcompass.cpp create mode 100644 plugins/sensors/blackberry/bbcompass.h create mode 100644 plugins/sensors/blackberry/bbguihelper.cpp create mode 100644 plugins/sensors/blackberry/bbguihelper.h create mode 100644 plugins/sensors/blackberry/bbgyroscope.cpp create mode 100644 plugins/sensors/blackberry/bbgyroscope.h create mode 100644 plugins/sensors/blackberry/bbholstersensor.cpp create mode 100644 plugins/sensors/blackberry/bbholstersensor.h create mode 100644 plugins/sensors/blackberry/bbirproximitysensor.cpp create mode 100644 plugins/sensors/blackberry/bbirproximitysensor.h create mode 100644 plugins/sensors/blackberry/bblightsensor.cpp create mode 100644 plugins/sensors/blackberry/bblightsensor.h create mode 100644 plugins/sensors/blackberry/bbmagnetometer.cpp create mode 100644 plugins/sensors/blackberry/bbmagnetometer.h create mode 100644 plugins/sensors/blackberry/bborientationsensor.cpp create mode 100644 plugins/sensors/blackberry/bborientationsensor.h create mode 100644 plugins/sensors/blackberry/bbpressuresensor.cpp create mode 100644 plugins/sensors/blackberry/bbpressuresensor.h create mode 100644 plugins/sensors/blackberry/bbproximitysensor.cpp create mode 100644 plugins/sensors/blackberry/bbproximitysensor.h create mode 100644 plugins/sensors/blackberry/bbrotationsensor.cpp create mode 100644 plugins/sensors/blackberry/bbrotationsensor.h create mode 100644 plugins/sensors/blackberry/bbsensorbackend.cpp create mode 100644 plugins/sensors/blackberry/bbsensorbackend.h create mode 100644 plugins/sensors/blackberry/bbtemperaturesensor.cpp create mode 100644 plugins/sensors/blackberry/bbtemperaturesensor.h create mode 100644 plugins/sensors/blackberry/bbutil.cpp create mode 100644 plugins/sensors/blackberry/bbutil.h create mode 100644 plugins/sensors/blackberry/blackberry.pri create mode 100644 plugins/sensors/blackberry/blackberry.pro create mode 100644 plugins/sensors/blackberry/main.cpp create mode 100644 plugins/sensors/blackberry/sensor.h diff --git a/plugins/sensors/blackberry/bbaccelerometer.cpp b/plugins/sensors/blackberry/bbaccelerometer.cpp new file mode 100644 index 0000000000..5d4683421c --- /dev/null +++ b/plugins/sensors/blackberry/bbaccelerometer.cpp @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 "bbaccelerometer.h" + +BbAccelerometer::BbAccelerometer(QSensor *sensor) + : BbSensorBackend(devicePath(), SENSOR_TYPE_ACCELEROMETER, sensor) +{ + setDescription(QLatin1String("X, Y, and Z axes accelerations in m/s^2")); + + QAccelerometer * const accelerometer = qobject_cast(sensor); + if (accelerometer) { + connect(accelerometer, SIGNAL(accelerationModeChanged(AccelerationMode)), + this, SLOT(applyAccelerationMode())); + } +} + +bool BbAccelerometer::updateReadingFromEvent(const sensor_event_t &event, QAccelerometerReading *reading) +{ + float x = event.motion.dsp.x; + float y = event.motion.dsp.y; + float z = event.motion.dsp.z; + remapAxes(&x, &y, &z); + reading->setX(x); + reading->setY(y); + reading->setZ(z); + return true; +} + +void BbAccelerometer::start() +{ + applyAccelerationMode(); + BbSensorBackend::start(); +} + +QString BbAccelerometer::devicePath() +{ + return QLatin1String("/dev/sensor/accel"); +} + +void BbAccelerometer::applyAccelerationMode() +{ + const QAccelerometer * const accelerometer = qobject_cast(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/plugins/sensors/blackberry/bbaccelerometer.h b/plugins/sensors/blackberry/bbaccelerometer.h new file mode 100644 index 0000000000..aaa7416a04 --- /dev/null +++ b/plugins/sensors/blackberry/bbaccelerometer.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 BBACCELEROMETER_H +#define BBACCELEROMETER_H + +#include "bbsensorbackend.h" +#include + +QTM_USE_NAMESPACE + +class BbAccelerometer : public BbSensorBackend +{ + Q_OBJECT + +public: + explicit BbAccelerometer(QSensor *sensor); + + void start(); + static QString devicePath(); + +protected: + bool updateReadingFromEvent(const sensor_event_t &event, QAccelerometerReading *reading); + +private slots: + void applyAccelerationMode(); +}; + +#endif diff --git a/plugins/sensors/blackberry/bbaltimeter.cpp b/plugins/sensors/blackberry/bbaltimeter.cpp new file mode 100644 index 0000000000..3193cc4cdb --- /dev/null +++ b/plugins/sensors/blackberry/bbaltimeter.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 "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(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/plugins/sensors/blackberry/bbaltimeter.h b/plugins/sensors/blackberry/bbaltimeter.h new file mode 100644 index 0000000000..c18543941b --- /dev/null +++ b/plugins/sensors/blackberry/bbaltimeter.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 BBALTIMETER_H +#define BBALTIMETER_H + +#include "bbsensorbackend.h" + +QTM_USE_NAMESPACE + +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 +{ + Q_OBJECT + +public: + explicit BbAltimeter(QSensor *sensor); + + static QString devicePath(); + +protected: + bool updateReadingFromEvent(const sensor_event_t &event, BbAltimeterReading *reading); +}; + +#endif diff --git a/plugins/sensors/blackberry/bbambientlightsensor.cpp b/plugins/sensors/blackberry/bbambientlightsensor.cpp new file mode 100644 index 0000000000..933513ea2d --- /dev/null +++ b/plugins/sensors/blackberry/bbambientlightsensor.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 "bbambientlightsensor.h" + +BbAmbientLightSensor::BbAmbientLightSensor(QSensor *sensor) + : BbSensorBackend(devicePath(), SENSOR_TYPE_LIGHT, sensor) +{ + setDescription(QLatin1String("Ambient light brightness")); +} + +bool BbAmbientLightSensor::updateReadingFromEvent(const sensor_event_t &event, QAmbientLightReading *reading) +{ + const int lightLevelLux = event.light_s.illuminance; + if (lightLevelLux < 10) + reading->setLightLevel(QAmbientLightReading::Dark); + else if (lightLevelLux < 80) + reading->setLightLevel(QAmbientLightReading::Twilight); + else if (lightLevelLux < 400) + reading->setLightLevel(QAmbientLightReading::Light); + else if (lightLevelLux < 2500) + reading->setLightLevel(QAmbientLightReading::Bright); + else + reading->setLightLevel(QAmbientLightReading::Sunny); + + return true; +} + +QString BbAmbientLightSensor::devicePath() +{ + return QLatin1String("/dev/sensor/light"); +} diff --git a/plugins/sensors/blackberry/bbambientlightsensor.h b/plugins/sensors/blackberry/bbambientlightsensor.h new file mode 100644 index 0000000000..0da835a39c --- /dev/null +++ b/plugins/sensors/blackberry/bbambientlightsensor.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 BBAMBIENTLIGHTSENSOR_H +#define BBAMBIENTLIGHTSENSOR_H + +#include "bbsensorbackend.h" +#include + +class BbAmbientLightSensor : public BbSensorBackend +{ + Q_OBJECT + +public: + explicit BbAmbientLightSensor(QSensor *sensor); + + static QString devicePath(); + +protected: + bool updateReadingFromEvent(const sensor_event_t &event, QAmbientLightReading *reading); +}; + +#endif diff --git a/plugins/sensors/blackberry/bbcompass.cpp b/plugins/sensors/blackberry/bbcompass.cpp new file mode 100644 index 0000000000..b07b7fe949 --- /dev/null +++ b/plugins/sensors/blackberry/bbcompass.cpp @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 "bbcompass.h" +#include "bbutil.h" + +using namespace BbUtil; + +BbCompass::BbCompass(QSensor *sensor) +#ifdef HAVE_COMPASS_SENSOR + : BbSensorBackend(devicePath(), SENSOR_TYPE_COMPASS, sensor) +#else + : BbSensorBackend(devicePath(), SENSOR_TYPE_ROTATION_MATRIX, sensor) +#endif +{ + setDescription(QLatin1String("Azimuth in degrees from magnetic north")); +} + +bool BbCompass::updateReadingFromEvent(const sensor_event_t &event, QCompassReading *reading) +{ + float azimuth; +#ifdef HAVE_COMPASS_SENSOR + azimuth = event.compass_s.azimuth; +#else + float xRad, yRad, zRad; + matrixToEulerZXY(event.rotation_matrix, xRad, yRad, zRad); + azimuth = radiansToDegrees(zRad); + if (azimuth < 0) + azimuth = -azimuth; + else + azimuth = 360.0f - 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); + 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; + } + + return true; +} + +QString BbCompass::devicePath() +{ +#ifdef HAVE_COMPASS_SENSOR + return QLatin1String("/dev/sensor/compass"); +#else + return QLatin1String("/dev/sensor/rotMatrix"); +#endif +} diff --git a/plugins/sensors/blackberry/bbcompass.h b/plugins/sensors/blackberry/bbcompass.h new file mode 100644 index 0000000000..fc3e015968 --- /dev/null +++ b/plugins/sensors/blackberry/bbcompass.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 BBCOMPASS_H +#define BBCOMPASS_H + +#include "bbsensorbackend.h" +#include + +QTM_USE_NAMESPACE + +class BbCompass : public BbSensorBackend +{ + Q_OBJECT + +public: + explicit BbCompass(QSensor *sensor); + + static QString devicePath(); + +protected: + bool updateReadingFromEvent(const sensor_event_t &event, QCompassReading *reading); +}; + +#endif diff --git a/plugins/sensors/blackberry/bbguihelper.cpp b/plugins/sensors/blackberry/bbguihelper.cpp new file mode 100644 index 0000000000..1484135ee5 --- /dev/null +++ b/plugins/sensors/blackberry/bbguihelper.cpp @@ -0,0 +1,152 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 "bbguihelper.h" + +#include +#include +#include +#include +#include + +QAbstractEventDispatcher::EventFilter s_previousEventFilter = 0; +static BbGuiHelper *s_guiHelper = 0; + +static bool s_eventFilter(void *message) +{ + if (s_guiHelper) { + bps_event_t * const event = static_cast(message); + s_guiHelper->handleBpsEvent(event); + } + return s_previousEventFilter && s_previousEventFilter(message); +} + +BbGuiHelper::BbGuiHelper(QObject *parent) + : QObject(parent), + m_currentOrientation(0), + m_applicationActive(true) +{ + Q_ASSERT(!s_guiHelper); + Q_ASSERT(s_previousEventFilter == 0); + s_guiHelper = this; + + readApplicationActiveState(); + readOrientation(); + + s_previousEventFilter = QAbstractEventDispatcher::instance()->setEventFilter(s_eventFilter); +} + +BbGuiHelper::~BbGuiHelper() +{ + s_guiHelper = 0; +} + +int BbGuiHelper::currentOrientation() const +{ + return m_currentOrientation; +} + +bool BbGuiHelper::applicationActive() const +{ + return m_applicationActive; +} + +void BbGuiHelper::handleBpsEvent(bps_event_t *event) +{ + if (event && bps_event_get_domain(event) == navigator_get_domain()) { + const int code = bps_event_get_code(event); + if (code == NAVIGATOR_ORIENTATION) { + const int newOrientation = navigator_event_get_orientation_angle(event); + if (newOrientation != m_currentOrientation) { + m_currentOrientation = newOrientation; + emit orientationChanged(); + } + } else if (code == NAVIGATOR_WINDOW_STATE) { + const bool appActive = + (navigator_event_get_window_state(event) == NAVIGATOR_WINDOW_FULLSCREEN); + if (m_applicationActive != appActive) { + m_applicationActive = appActive; + emit applicationActiveChanged(); + } + } + } +} + +void BbGuiHelper::readApplicationActiveState() +{ + const QLatin1String fileName("/pps/services/navigator/state"); + QFile navigatorState(fileName); + if (!navigatorState.open(QFile::ReadOnly)) + return; + + const QString separator(QLatin1String("::")); + QTextStream stream(&navigatorState); + Q_FOREVER { + const QString line = stream.readLine(); + if (line.isNull()) + break; + + const int separatorPos = line.indexOf(separator); + if (separatorPos != -1) { + const QString key = line.left(separatorPos); + const QString value = line.mid(separatorPos + separator.length()); + + if (key.endsWith(QLatin1String("fullscreen"))) { + bool ok = false; + const int fullscreenPid = value.toInt(&ok); + if (ok) + m_applicationActive = (fullscreenPid == QCoreApplication::applicationPid()); + break; + } + } + } +} + +void BbGuiHelper::readOrientation() +{ + // There is no API to get the current orientation at the moment. + // Therefore, we assume that the inital orientation that is set in the environment variable + // hasn't changed yet. + // This assumptions don't always hold, but it is the best we got so far. + // The navigator will at least inform us about updates. + const QByteArray orientationText = qgetenv("ORIENTATION"); + if (!orientationText.isEmpty()) + m_currentOrientation = orientationText.toInt(); +} diff --git a/plugins/sensors/blackberry/bbguihelper.h b/plugins/sensors/blackberry/bbguihelper.h new file mode 100644 index 0000000000..7d045d80f3 --- /dev/null +++ b/plugins/sensors/blackberry/bbguihelper.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 BBGUIHELPER_H +#define BBGUIHELPER_H + +#include + +struct bps_event_t; + +// We can't depend on QtGui in this plugin, only on BPS. +// This class provides replacements for some QtGui functions, implemented using BPS. +class BbGuiHelper : public QObject +{ + Q_OBJECT +public: + explicit BbGuiHelper(QObject *parent = 0); + ~BbGuiHelper(); + + // Orientation 0 is device held in normal position (Blackberry logo readable), then orientation + // increases in 90 degrees steps counter-clockwise, i.e. rotating the device to the left. + // Therefore the range is 0 to 270 degrees. + int currentOrientation() const; + + bool applicationActive() const; + + void handleBpsEvent(bps_event_t *event); + +signals: + void orientationChanged(); + void applicationActiveChanged(); + +private: + void readOrientation(); + void readApplicationActiveState(); + + int m_currentOrientation; + bool m_applicationActive; +}; + +#endif diff --git a/plugins/sensors/blackberry/bbgyroscope.cpp b/plugins/sensors/blackberry/bbgyroscope.cpp new file mode 100644 index 0000000000..f480d21c64 --- /dev/null +++ b/plugins/sensors/blackberry/bbgyroscope.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 "bbgyroscope.h" + +#include "bbutil.h" +#include + +using namespace BbUtil; + +BbGyroscope::BbGyroscope(QSensor *sensor) + : BbSensorBackend(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) +{ + float x = radiansToDegrees(event.motion.dsp.x); + float y = radiansToDegrees(event.motion.dsp.y); + float z = radiansToDegrees(event.motion.dsp.z); + remapAxes(&x, &y, &z); + reading->setX(x); + reading->setY(y); + reading->setZ(z); + + return true; +} + +QString BbGyroscope::devicePath() +{ + return QLatin1String("/dev/sensor/gyro"); +} + +qreal BbGyroscope::convertValue(float valueInRadiansPerSecond) +{ + return radiansToDegrees(valueInRadiansPerSecond); +} diff --git a/plugins/sensors/blackberry/bbgyroscope.h b/plugins/sensors/blackberry/bbgyroscope.h new file mode 100644 index 0000000000..cffb7a0d31 --- /dev/null +++ b/plugins/sensors/blackberry/bbgyroscope.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 BBGYROSCOPE_H +#define BBGYROSCOPE_H + +#include "bbsensorbackend.h" +#include + +QTM_USE_NAMESPACE + +class BbGyroscope : public BbSensorBackend +{ + 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/plugins/sensors/blackberry/bbholstersensor.cpp b/plugins/sensors/blackberry/bbholstersensor.cpp new file mode 100644 index 0000000000..0e2c3ff2fa --- /dev/null +++ b/plugins/sensors/blackberry/bbholstersensor.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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(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/plugins/sensors/blackberry/bbholstersensor.h b/plugins/sensors/blackberry/bbholstersensor.h new file mode 100644 index 0000000000..943dcd7c79 --- /dev/null +++ b/plugins/sensors/blackberry/bbholstersensor.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 + +QTM_USE_NAMESPACE + +class BbHolsterSensor : public BbSensorBackend +{ + Q_OBJECT + +public: + explicit BbHolsterSensor(QSensor *sensor); + + static QString devicePath(); + +protected: + bool updateReadingFromEvent(const sensor_event_t &event, QHolsterReading *reading); +}; + +#endif diff --git a/plugins/sensors/blackberry/bbirproximitysensor.cpp b/plugins/sensors/blackberry/bbirproximitysensor.cpp new file mode 100644 index 0000000000..86063f8b7f --- /dev/null +++ b/plugins/sensors/blackberry/bbirproximitysensor.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 "bbirproximitysensor.h" + +BbIRProximitySensor::BbIRProximitySensor(QSensor *sensor) + : BbSensorBackend(devicePath(), SENSOR_TYPE_PROXIMITY, sensor) +{ + setDescription(QLatin1String("IR Proximity")); +} + +bool BbIRProximitySensor::updateReadingFromEvent(const sensor_event_t &event, QIRProximityReading *reading) +{ + reading->setReflectance(1.0f - event.proximity_s.normalized); + return true; +} + +QString BbIRProximitySensor::devicePath() +{ + return QLatin1String("/dev/sensor/prox"); +} diff --git a/plugins/sensors/blackberry/bbirproximitysensor.h b/plugins/sensors/blackberry/bbirproximitysensor.h new file mode 100644 index 0000000000..53cb8807d1 --- /dev/null +++ b/plugins/sensors/blackberry/bbirproximitysensor.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 BBIRPROXIMITYSENSOR_H +#define BBIRPROXIMITYSENSOR_H + +#include "bbsensorbackend.h" +#include + +QTM_USE_NAMESPACE + +class BbIRProximitySensor : public BbSensorBackend +{ + Q_OBJECT + +public: + explicit BbIRProximitySensor(QSensor *sensor); + + static QString devicePath(); + +protected: + bool updateReadingFromEvent(const sensor_event_t &event, QIRProximityReading *reading); +}; + +#endif diff --git a/plugins/sensors/blackberry/bblightsensor.cpp b/plugins/sensors/blackberry/bblightsensor.cpp new file mode 100644 index 0000000000..4149c07a1e --- /dev/null +++ b/plugins/sensors/blackberry/bblightsensor.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 "bblightsensor.h" + +BbLightSensor::BbLightSensor(QSensor *sensor) + : BbSensorBackend(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/plugins/sensors/blackberry/bblightsensor.h b/plugins/sensors/blackberry/bblightsensor.h new file mode 100644 index 0000000000..1468fb5555 --- /dev/null +++ b/plugins/sensors/blackberry/bblightsensor.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 BBLIGHTSENSOR_H +#define BBLIGHTSENSOR_H + +#include "bbsensorbackend.h" +#include + +QTM_USE_NAMESPACE + +class BbLightSensor : public BbSensorBackend +{ + Q_OBJECT + +public: + explicit BbLightSensor(QSensor *sensor); + + static QString devicePath(); + +protected: + bool updateReadingFromEvent(const sensor_event_t &event, QLightReading *reading); +}; + +#endif diff --git a/plugins/sensors/blackberry/bbmagnetometer.cpp b/plugins/sensors/blackberry/bbmagnetometer.cpp new file mode 100644 index 0000000000..d6d952ba8f --- /dev/null +++ b/plugins/sensors/blackberry/bbmagnetometer.cpp @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 "bbmagnetometer.h" + +BbMagnetometer::BbMagnetometer(QSensor *sensor) + : BbSensorBackend(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. + 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); + + 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/plugins/sensors/blackberry/bbmagnetometer.h b/plugins/sensors/blackberry/bbmagnetometer.h new file mode 100644 index 0000000000..687f541b00 --- /dev/null +++ b/plugins/sensors/blackberry/bbmagnetometer.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 BBMAGNETOMETER_H +#define BBMAGNETOMETER_H + +#include "bbsensorbackend.h" +#include + +QTM_USE_NAMESPACE + +class BbMagnetometer : public BbSensorBackend +{ + 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/plugins/sensors/blackberry/bborientationsensor.cpp b/plugins/sensors/blackberry/bborientationsensor.cpp new file mode 100644 index 0000000000..7e18598339 --- /dev/null +++ b/plugins/sensors/blackberry/bborientationsensor.cpp @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 "bborientationsensor.h" + +BbOrientationSensor::BbOrientationSensor(QSensor *sensor) + : BbSensorBackend(devicePath(), SENSOR_TYPE_ORIENTATION, sensor) +{ + setDescription(QLatin1String("Device orientation")); + + // Orientation rarely changes, so enable skiping of duplicates by default + sensor->setSkipDuplicates(true); + +} + +QString BbOrientationSensor::devicePath() +{ + return QLatin1String("/dev/sensor/orientation"); +} + +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, QOrientationReading *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); + return true; +} diff --git a/plugins/sensors/blackberry/bborientationsensor.h b/plugins/sensors/blackberry/bborientationsensor.h new file mode 100644 index 0000000000..7f4ec38bab --- /dev/null +++ b/plugins/sensors/blackberry/bborientationsensor.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 BBORIENTATIONSENSOR_H +#define BBORIENTATIONSENSOR_H + +#include "bbsensorbackend.h" +#include + +QTM_USE_NAMESPACE + +class BbOrientationSensor : public BbSensorBackend +{ + Q_OBJECT + +public: + explicit BbOrientationSensor(QSensor *sensor); + + static QString devicePath(); + + void additionalDeviceInit(); + bool addDefaultRange(); + +protected: + bool updateReadingFromEvent(const sensor_event_t &event, QOrientationReading *reading); +}; + +#endif diff --git a/plugins/sensors/blackberry/bbpressuresensor.cpp b/plugins/sensors/blackberry/bbpressuresensor.cpp new file mode 100644 index 0000000000..e9d97709ba --- /dev/null +++ b/plugins/sensors/blackberry/bbpressuresensor.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 "bbpressuresensor.h" + +BbPressureSensor::BbPressureSensor(QSensor *sensor) + : BbSensorBackend(devicePath(), SENSOR_TYPE_PRESSURE, sensor) +{ + setDescription(QLatin1String("Pressure in Pascals")); +} + +QString BbPressureSensor::devicePath() +{ + return QLatin1String("/dev/sensor/pressure"); +} + +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. + reading->setPressure(event.pressure_s.pressure); + return true; +} diff --git a/plugins/sensors/blackberry/bbpressuresensor.h b/plugins/sensors/blackberry/bbpressuresensor.h new file mode 100644 index 0000000000..272ec016ba --- /dev/null +++ b/plugins/sensors/blackberry/bbpressuresensor.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 BBPRESSURESENSOR_H +#define BBPRESSURESENSOR_H + +#include "bbsensorbackend.h" +#include + +QTM_USE_NAMESPACE + +class BbPressureSensor : public BbSensorBackend +{ + Q_OBJECT + +public: + explicit BbPressureSensor(QSensor *sensor); + + static QString devicePath(); + +protected: + bool updateReadingFromEvent(const sensor_event_t &event, QPressureReading *reading); +}; + +#endif diff --git a/plugins/sensors/blackberry/bbproximitysensor.cpp b/plugins/sensors/blackberry/bbproximitysensor.cpp new file mode 100644 index 0000000000..1e6e541c98 --- /dev/null +++ b/plugins/sensors/blackberry/bbproximitysensor.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 "bbproximitysensor.h" + +BbProximitySensor::BbProximitySensor(QSensor *sensor) + : BbSensorBackend(devicePath(), SENSOR_TYPE_PROXIMITY, sensor) +{ + setDescription(QLatin1String("Proximity")); +} + +QString BbProximitySensor::devicePath() +{ + return QLatin1String("/dev/sensor/prox"); +} + +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/plugins/sensors/blackberry/bbproximitysensor.h b/plugins/sensors/blackberry/bbproximitysensor.h new file mode 100644 index 0000000000..f7c305d311 --- /dev/null +++ b/plugins/sensors/blackberry/bbproximitysensor.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 BBPROXIMITYSENSOR_H +#define BBPROXIMITYSENSOR_H + +#include "bbsensorbackend.h" +#include + +QTM_USE_NAMESPACE + +class BbProximitySensor : public BbSensorBackend +{ + Q_OBJECT + +public: + explicit BbProximitySensor(QSensor *sensor); + + static QString devicePath(); + +protected: + bool updateReadingFromEvent(const sensor_event_t &event, QProximityReading *reading); +}; + +#endif diff --git a/plugins/sensors/blackberry/bbrotationsensor.cpp b/plugins/sensors/blackberry/bbrotationsensor.cpp new file mode 100644 index 0000000000..a2522c981c --- /dev/null +++ b/plugins/sensors/blackberry/bbrotationsensor.cpp @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 "bbrotationsensor.h" + +#include "bbguihelper.h" +#include "bbutil.h" + +using namespace BbUtil; + +BbRotationSensor::BbRotationSensor(QSensor *sensor) + : BbSensorBackend(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; +} + +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; + float mappedRotationMatrix[3*3]; + remapMatrix(event.rotation_matrix, mappedRotationMatrix); + matrixToEulerZXY(mappedRotationMatrix, 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/plugins/sensors/blackberry/bbrotationsensor.h b/plugins/sensors/blackberry/bbrotationsensor.h new file mode 100644 index 0000000000..7eaf7cb63b --- /dev/null +++ b/plugins/sensors/blackberry/bbrotationsensor.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 BBROTATIONSENSOR_H +#define BBROTATIONSENSOR_H + +#include "bbsensorbackend.h" +#include + +QTM_USE_NAMESPACE + +class BbRotationSensor : public BbSensorBackend +{ + 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/plugins/sensors/blackberry/bbsensorbackend.cpp b/plugins/sensors/blackberry/bbsensorbackend.cpp new file mode 100644 index 0000000000..3b6b581096 --- /dev/null +++ b/plugins/sensors/blackberry/bbsensorbackend.cpp @@ -0,0 +1,401 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 "bbsensorbackend.h" + +#include "bbguihelper.h" +#include +#include +#include +#include + +static const int microSecondsPerSecond = 1000 * 1000; +static const int defaultBufferSize = 10; + +static int microSecondsToHertz(uint microSeconds) +{ + return microSecondsPerSecond / microSeconds; +} + +static uint hertzToMicroSeconds(int hertz) +{ + return microSecondsPerSecond / hertz; +} + +static void remapMatrix(const float inputMatrix[3*3], + const float mappingMatrix[4], + float outputMatrix[3*3]) +{ + int i,j,k; + + for (i = 0; i < 3; i++) { + for (j = 0; j < 2; j++) { //only goto 2 because last column stays unchanged + + outputMatrix[i*3+j] = 0; + + for (k = 0; k < 2; k++) { //only goto 2 because we know rotation matrix is zero in bottom row + outputMatrix[i*3+j] += inputMatrix[i*3+k] * mappingMatrix[k*2+j]; + } + } + + outputMatrix[i*3+2] = inputMatrix[i*3+2]; + } +} + +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_mappingMatrix[0] = m_mappingMatrix[3] = 1; + m_mappingMatrix[1] = m_mappingMatrix[2] = 0; + connect(sensor, SIGNAL(alwaysOnChanged()), this, SLOT(applyAlwaysOnProperty())); + QOrientableSensorBase * const base = dynamic_cast(sensor); + if (base) + connect(sensor, SIGNAL(userOrientationChanged(int)), this, SLOT(updateOrientation())); + + // Set some sensible default values + sensor->setProperty("efficientBufferSize", defaultBufferSize); + sensor->setProperty("maxBufferSize", defaultBufferSize); +} + +BbGuiHelper *BbSensorBackendBase::guiHelper() const +{ + return m_guiHelper; +} + +QFile &BbSensorBackendBase::deviceFile() +{ + return m_deviceFile; +} + +sensor_type_e BbSensorBackendBase::sensorType() const +{ + return m_sensorType; +} + +void BbSensorBackendBase::setDevice(const QString &deviceFile, sensor_type_e sensorType) +{ + const bool isActive = m_deviceFile.isOpen(); + if (isActive) + stop(); + + m_sensorType = sensorType; + m_deviceFile.setFileName(deviceFile); + + if (isActive) + start(); +} + +void BbSensorBackendBase::initSensorInfo() +{ + if (!m_deviceFile.open(QFile::ReadOnly | QFile::Unbuffered)) { + qDebug() << "Failed to open sensor" << 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 + if (deviceInfo.rx.info.delay_max > 0 && deviceInfo.rx.info.delay_min > 0) { + addDataRate(microSecondsToHertz(deviceInfo.rx.info.delay_max), + microSecondsToHertz(deviceInfo.rx.info.delay_min)); + } + } + additionalDeviceInit(); + + // Instead of closing the device here and opening it again in start(), just pause the sensor. + // This avoids an expensive close() and open() call. + setPaused(true); + + m_socketNotifier.reset(new QSocketNotifier(m_deviceFile.handle(), QSocketNotifier::Read)); + connect(m_socketNotifier.data(), SIGNAL(activated(int)), this, SLOT(dataAvailable())); + } +} + +void BbSensorBackendBase::setGuiHelper(BbGuiHelper *guiHelper) +{ + Q_ASSERT(!m_guiHelper); + m_guiHelper = guiHelper; + connect(m_guiHelper, SIGNAL(applicationActiveChanged()), this, SLOT(updatePauseState())); + connect(m_guiHelper, SIGNAL(orientationChanged()), this, SLOT(updateOrientation())); + updateOrientation(); +} + +void BbSensorBackendBase::additionalDeviceInit() +{ +} + +bool BbSensorBackendBase::addDefaultRange() +{ + return true; +} + +qreal BbSensorBackendBase::convertValue(float bbValue) +{ + return bbValue; +} + +bool BbSensorBackendBase::isAutoAxisRemappingEnabled() const +{ + const QOrientableSensorBase * const base = dynamic_cast(sensor()); + return base && base->axesOrientationMode() != QOrientableSensorBase::FixedOrientation; +} + +void BbSensorBackendBase::remapMatrix(const float inputMatrix[], float outputMatrix[]) +{ + if (!isAutoAxisRemappingEnabled() || orientationForRemapping() == 0) { + memcpy(outputMatrix, inputMatrix, sizeof(float) * 9); + return; + } + + ::remapMatrix(inputMatrix, m_mappingMatrix, outputMatrix); +} + +void BbSensorBackendBase::remapAxes(float *x, float *y, float *z) +{ + Q_ASSERT(x && y && z); + if (!isAutoAxisRemappingEnabled() || orientationForRemapping() == 0) + return; + + const int angle = orientationForRemapping(); + + const float oldX = *x; + const float oldY = *y; + + switch (angle) { + case 90: + *x = -oldY; + *y = oldX; + break; + case 180: + *x = -oldX; + *y = -oldY; + break; + case 270: + *x = oldY; + *y = -oldX; + break; + } +} + +void BbSensorBackendBase::start() +{ + Q_ASSERT(m_guiHelper); + + if (!m_deviceFile.isOpen() || !setPaused(false)) { + qDebug() << "Starting sensor" << m_deviceFile.fileName() + << "failed:" << m_deviceFile.errorString(); + sensorError(m_deviceFile.error()); + return; + } + m_started = true; + + 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) { + sensor()->setDataRate(0); + perror(QString::fromLatin1("Setting sensor rate for %1 failed") + .arg(m_deviceFile.fileName()).toLocal8Bit()); + } else { + if (deviceRate.rx.rate > 0) + sensor()->setDataRate(microSecondsToHertz(deviceRate.rx.rate)); + else + sensor()->setDataRate(0); + } + } + + // Enable/disable duplicate skipping + sensor_devctl_skipdupevent_u deviceSkip; + deviceSkip.tx.enable = sensor()->skipDuplicates() ? 1 : 0; + 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()); + } + + // 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); + } + + applyAlwaysOnProperty(); +} + +void BbSensorBackendBase::stop() +{ + setPaused(true); + m_started = false; +} + +void BbSensorBackendBase::dataAvailable() +{ + if (!m_started) + return; + + Q_FOREVER { + sensor_event_t event; + const qint64 numBytes = m_deviceFile.read(reinterpret_cast(&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(); + } + } +} + +void BbSensorBackendBase::applyAlwaysOnProperty() +{ + if (!m_deviceFile.isOpen() || !m_started) + return; + + sensor_devctl_bkgrnd_u bgState; + bgState.tx.enable = sensor()->isAlwaysOn() ? 1 : 0; + + const int result = devctl(m_deviceFile.handle(), DCMD_SENSOR_BKGRND, &bgState, sizeof(bgState), NULL); + if (result != EOK) { + perror(QString::fromLatin1("Setting sensor always on for %1 failed") + .arg(m_deviceFile.fileName()).toLocal8Bit()); + } + + // We might need to pause now + updatePauseState(); +} + +bool BbSensorBackendBase::setPaused(bool paused) +{ + if (!m_deviceFile.isOpen()) + return false; + + sensor_devctl_enable_u enableState; + enableState.tx.enable = paused ? 0 : 1; + + 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") + .arg(paused) + .arg(m_deviceFile.fileName()).toLocal8Bit()); + return false; + } + + return true; +} + +void BbSensorBackendBase::updatePauseState() +{ + if (!m_started) + return; + + setPaused(!sensor()->isAlwaysOn() && !m_guiHelper->applicationActive()); +} + +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 = 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); + + QOrientableSensorBase * const base = dynamic_cast(sensor()); + if (base) + base->setCurrentOrientation(rotationAngle); +} + +int BbSensorBackendBase::orientationForRemapping() const +{ + const QOrientableSensorBase * const base = dynamic_cast(sensor()); + if (!base) + return 0; + + switch (base->axesOrientationMode()) { + case QOrientableSensorBase::FixedOrientation: return 0; + case QOrientableSensorBase::AutomaticOrientation: return guiHelper()->currentOrientation(); + case QOrientableSensorBase::UserOrientation: return base->userOrientation(); + } +} diff --git a/plugins/sensors/blackberry/bbsensorbackend.h b/plugins/sensors/blackberry/bbsensorbackend.h new file mode 100644 index 0000000000..abc50f76ae --- /dev/null +++ b/plugins/sensors/blackberry/bbsensorbackend.h @@ -0,0 +1,155 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 BBSENSORBACKEND_H +#define BBSENSORBACKEND_H + +#include +#include +#include + +// Earlier NDK versions did not ship sensor.h, that is why we have our own copy in +// here. +// We prefer the NDK version if that exists, as that is more up-to-date. +#ifdef HAVE_NDK_SENSOR_H +#include +#include +#include +#else +#include "sensor.h" +#endif + +QTM_USE_NAMESPACE + +class BbGuiHelper; + +class BbSensorBackendBase : public QSensorBackend +{ + Q_OBJECT + +public: + BbSensorBackendBase(const QString &devicePath, sensor_type_e sensorType, QSensor *sensor); + + void initSensorInfo(); + void setGuiHelper(BbGuiHelper *guiHelper); + + void start(); + void stop(); + +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. + 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); + + bool isAutoAxisRemappingEnabled() const; + + // These functions will automatically remap the matrix or the axes if auto axes remapping is + // enabled + void remapMatrix(const float inputMatrix[3*3], float outputMatrix[3*3]); + void remapAxes(float *x, float *y, float *z); + + virtual void processEvent(const sensor_event_t &sensorEvent) = 0; + +private slots: + void dataAvailable(); + void applyAlwaysOnProperty(); + bool setPaused(bool paused); + void updatePauseState(); + void updateOrientation(); + +private: + QFile m_deviceFile; + QScopedPointer m_socketNotifier; + sensor_type_e m_sensorType; + BbGuiHelper *m_guiHelper; + float m_mappingMatrix[4]; + bool m_started; +}; + +template +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/plugins/sensors/blackberry/bbtemperaturesensor.cpp b/plugins/sensors/blackberry/bbtemperaturesensor.cpp new file mode 100644 index 0000000000..b23b735e90 --- /dev/null +++ b/plugins/sensors/blackberry/bbtemperaturesensor.cpp @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 "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(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/plugins/sensors/blackberry/bbtemperaturesensor.h b/plugins/sensors/blackberry/bbtemperaturesensor.h new file mode 100644 index 0000000000..eef19cbd34 --- /dev/null +++ b/plugins/sensors/blackberry/bbtemperaturesensor.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 BBTEMPERATURESENSOR_H +#define BBTEMPERATURESENSOR_H + +#include "bbsensorbackend.h" + +QTM_USE_NAMESPACE + +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 +{ + Q_OBJECT + +public: + explicit BbTemperatureSensor(QSensor *sensor); + + static QString devicePath(); + +protected: + bool updateReadingFromEvent(const sensor_event_t &event, BbTemperatureReading *reading); +}; + +#endif diff --git a/plugins/sensors/blackberry/bbutil.cpp b/plugins/sensors/blackberry/bbutil.cpp new file mode 100644 index 0000000000..9c06b2dfe8 --- /dev/null +++ b/plugins/sensors/blackberry/bbutil.cpp @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 "bbutil.h" + +#include + +namespace BbUtil { + +static float getMatrixElement(const float matrix[3*3], int index0, int index1) +{ + return matrix[index0 * 3 + index1]; +} + +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; + } +} + +qreal radiansToDegrees(qreal radians) +{ + static const qreal radToDeg = 180.0f / M_PI; + return radians * radToDeg; +} + +} diff --git a/plugins/sensors/blackberry/bbutil.h b/plugins/sensors/blackberry/bbutil.h new file mode 100644 index 0000000000..c5158dfe67 --- /dev/null +++ b/plugins/sensors/blackberry/bbutil.h @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 BBUTIL_H +#define BBUTIL_H + +#include + +namespace BbUtil { + +void matrixToEulerZXY(const float matrix[3*3], float &thetaX, float &thetaY, float& thetaZ); +qreal radiansToDegrees(qreal radians); + +} + +#endif diff --git a/plugins/sensors/blackberry/blackberry.pri b/plugins/sensors/blackberry/blackberry.pri new file mode 100644 index 0000000000..484f5dc4f9 --- /dev/null +++ b/plugins/sensors/blackberry/blackberry.pri @@ -0,0 +1,39 @@ +HEADERS += bbsensorbackend.h \ + bbaccelerometer.h \ + bbaltimeter.h \ + bbambientlightsensor.h \ + bbcompass.h \ + bbgyroscope.h \ + bbirproximitysensor.h \ + bblightsensor.h \ + bbmagnetometer.h \ + bborientationsensor.h \ + bbpressuresensor.h \ + bbproximitysensor.h \ + bbrotationsensor.h \ + bbtemperaturesensor.h \ + bbguihelper.h \ + bbutil.h + +SOURCES += bbsensorbackend.cpp \ + bbaccelerometer.cpp \ + bbaltimeter.cpp \ + bbambientlightsensor.cpp \ + bbcompass.cpp \ + bbgyroscope.cpp \ + bbirproximitysensor.cpp \ + bblightsensor.cpp \ + bbmagnetometer.cpp \ + bborientationsensor.cpp \ + bbpressuresensor.cpp \ + bbproximitysensor.cpp \ + bbrotationsensor.cpp \ + bbtemperaturesensor.cpp \ + bbguihelper.cpp \ + bbutil.cpp \ + main.cpp + +contains(bbsensor_holster_enabled, yes) { + HEADERS += bbholstersensor.h + SOURCES += bbholstersensor.cpp +} diff --git a/plugins/sensors/blackberry/blackberry.pro b/plugins/sensors/blackberry/blackberry.pro new file mode 100644 index 0000000000..026f286fbc --- /dev/null +++ b/plugins/sensors/blackberry/blackberry.pro @@ -0,0 +1,19 @@ +INCLUDEPATH+=../../../src/sensors + +PLUGIN_TYPE = sensors + +TEMPLATE = lib +CONFIG += plugin +TARGET = $$qtLibraryTarget(qtsensors_blackberry) + +include(../../../common.pri) +include(blackberry.pri) + +QT = core +CONFIG += mobility +MOBILITY += sensors +DEFINES += QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII + +contains(bbsensor_header_enabled, yes):DEFINES += HAVE_NDK_SENSOR_H +contains(bbsensor_holster_enabled, yes):DEFINES += HAVE_HOLSTER_SENSOR +contains(bbsensor_compass_enabled, yes):DEFINES += HAVE_COMPASS_SENSOR diff --git a/plugins/sensors/blackberry/main.cpp b/plugins/sensors/blackberry/main.cpp new file mode 100644 index 0000000000..8ae622d95c --- /dev/null +++ b/plugins/sensors/blackberry/main.cpp @@ -0,0 +1,169 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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 "bbaccelerometer.h" +#include "bbaltimeter.h" +#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" +#include "bborientationsensor.h" +#include "bbpressuresensor.h" +#include "bbproximitysensor.h" +#include "bbrotationsensor.h" +#include "bbtemperaturesensor.h" +#include "bbguihelper.h" + +#include +#include + +QTM_USE_NAMESPACE + +static const char *bbAccelerometerId = "bbAccelerometer"; +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"; +static const char *bbOrientationSensorId = "bbOrientationSensor"; +static const char *bbPressureSensorId = "bbPressureSensor"; +static const char *bbProximitySensorId = "bbProximitySensor"; +static const char *bbRotationSensorId = "bbRotationSensor"; +static const char *bbTemperatureSensorId = "bbTemperatureSensor"; + +class BbSensorPlugin : public QObject, public QSensorPluginInterface, public QSensorBackendFactory +{ + Q_OBJECT + Q_INTERFACES(QtMobility::QSensorPluginInterface) +public: + void registerSensors() + { + if (sensorSupported(BbAccelerometer::devicePath())) + QSensorManager::registerBackend(QAccelerometer::type, bbAccelerometerId, this); + if (sensorSupported(BbAltimeter::devicePath())) + QSensorManager::registerBackend("BbAltimeter", 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())) + QSensorManager::registerBackend(QLightSensor::type, bbLightSensorId, this); + if (sensorSupported(BbMagnetometer::devicePath())) + QSensorManager::registerBackend(QMagnetometer::type, bbMagnetometerId, this); + if (sensorSupported(BbOrientationSensor::devicePath())) + QSensorManager::registerBackend(QOrientationSensor::type, bbOrientationSensorId, this); + if (sensorSupported(BbPressureSensor::devicePath())) + 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); + } + + 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() == bbAmbientLightSensorId) + backend = new BbAmbientLightSensor(sensor); + if (sensor->identifier() == bbCompassId) + 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) + backend = new BbLightSensor(sensor); + if (sensor->identifier() == bbMagnetometerId) + backend = new BbMagnetometer(sensor); + if (sensor->identifier() == bbOrientationSensorId) + backend = new BbOrientationSensor(sensor); + if (sensor->identifier() == bbPressureSensorId) + backend = new BbPressureSensor(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(); + backend->setGuiHelper(&m_guiHelper); + return backend; + } + +private: + bool sensorSupported(const QString &devicePath) + { + return QFile::exists(devicePath); + } + + BbGuiHelper m_guiHelper; +}; + +Q_EXPORT_PLUGIN2(libsensors_blackberry, BbSensorPlugin) + +#include "main.moc" diff --git a/plugins/sensors/blackberry/sensor.h b/plugins/sensors/blackberry/sensor.h new file mode 100644 index 0000000000..3f4261709b --- /dev/null +++ b/plugins/sensors/blackberry/sensor.h @@ -0,0 +1,365 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $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$ +** +****************************************************************************/ + + +// +// This file is a temporary copy until it becomes available in the Blackberry NDK. +// + +#ifndef SENSOR_H_ +#define SENSOR_H_ + +#include +#include + +#include +#include + +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 -- cgit v1.2.3