From 0cadbe2057f47e6bb4c72441b8f62ef574125e6b Mon Sep 17 00:00:00 2001 From: Kevin Ottens Date: Thu, 3 May 2012 10:54:41 +0200 Subject: Add support for the IR proximity sensor Change-Id: I04e1c1eb7702626f4ce5e19b301f8774e604b930 Reviewed-by: Tennessee Carmel-Veilleux Reviewed-by: Lincoln Ramsay --- .../sensors/blackberry/bbirproximitysensor.cpp | 58 +++++++++++++++++++++ .../sensors/blackberry/bbirproximitysensor.h | 60 ++++++++++++++++++++++ src/plugins/sensors/blackberry/blackberry.pro | 2 + src/plugins/sensors/blackberry/main.cpp | 6 +++ 4 files changed, 126 insertions(+) create mode 100644 src/plugins/sensors/blackberry/bbirproximitysensor.cpp create mode 100644 src/plugins/sensors/blackberry/bbirproximitysensor.h diff --git a/src/plugins/sensors/blackberry/bbirproximitysensor.cpp b/src/plugins/sensors/blackberry/bbirproximitysensor.cpp new file mode 100644 index 00000000..7790688d --- /dev/null +++ b/src/plugins/sensors/blackberry/bbirproximitysensor.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "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/src/plugins/sensors/blackberry/bbirproximitysensor.h b/src/plugins/sensors/blackberry/bbirproximitysensor.h new file mode 100644 index 00000000..534b8901 --- /dev/null +++ b/src/plugins/sensors/blackberry/bbirproximitysensor.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef BBIRPROXIMITYSENSOR_H +#define BBIRPROXIMITYSENSOR_H + +#include "bbsensorbackend.h" +#include + +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/src/plugins/sensors/blackberry/blackberry.pro b/src/plugins/sensors/blackberry/blackberry.pro index 15c6626d..2b849e51 100644 --- a/src/plugins/sensors/blackberry/blackberry.pro +++ b/src/plugins/sensors/blackberry/blackberry.pro @@ -12,6 +12,7 @@ HEADERS += bbsensorbackend.h \ bbaccelerometer.h \ bbaltimeter.h \ bbgyroscope.h \ + bbirproximitysensor.h \ bblightsensor.h \ bbmagnetometer.h \ bborientationsensor.h \ @@ -24,6 +25,7 @@ SOURCES += bbsensorbackend.cpp \ bbaccelerometer.cpp \ bbaltimeter.cpp \ bbgyroscope.cpp \ + bbirproximitysensor.cpp \ bblightsensor.cpp \ bbmagnetometer.cpp \ bborientationsensor.cpp \ diff --git a/src/plugins/sensors/blackberry/main.cpp b/src/plugins/sensors/blackberry/main.cpp index abe5972c..61ec0cd4 100644 --- a/src/plugins/sensors/blackberry/main.cpp +++ b/src/plugins/sensors/blackberry/main.cpp @@ -41,6 +41,7 @@ #include "bbaccelerometer.h" #include "bbaltimeter.h" #include "bbgyroscope.h" +#include "bbirproximitysensor.h" #include "bblightsensor.h" #include "bbmagnetometer.h" #include "bborientationsensor.h" @@ -54,6 +55,7 @@ static const char *bbAccelerometerId = "bbAccelerometer"; static const char *bbAltitmeterId = "bbAltimeter"; static const char *bbGyroscopeId = "bbGyroscope"; +static const char *bbIRProximitySensorId = "bbIRProximitySensor"; static const char *bbLightSensorId = "bbLightSensor"; static const char *bbMagnetometerId = "bbMagnetometer"; static const char *bbOrientationSensorId = "bbOrientationSensor"; @@ -76,6 +78,8 @@ public: QSensorManager::registerBackend("BbAltimeter", bbAltitmeterId, this); if (sensorSupported(BbGyroscope::devicePath())) QSensorManager::registerBackend("QGyroscope", bbGyroscopeId, this); + if (sensorSupported(BbIRProximitySensor::devicePath())) + QSensorManager::registerBackend("QIRProximitySensor", bbIRProximitySensorId, this); if (sensorSupported(BbLightSensor::devicePath())) QSensorManager::registerBackend("QLightSensor", bbLightSensorId, this); if (sensorSupported(BbMagnetometer::devicePath())) @@ -99,6 +103,8 @@ public: backend = new BbAltimeter(sensor); if (sensor->identifier() == bbGyroscopeId) backend = new BbGyroscope(sensor); + if (sensor->identifier() == bbIRProximitySensorId) + backend = new BbIRProximitySensor(sensor); if (sensor->identifier() == bbLightSensorId) backend = new BbLightSensor(sensor); if (sensor->identifier() == bbMagnetometerId) -- cgit v1.2.3