From fb47cd561472bb1e83b6bc432334f3c0420717cc Mon Sep 17 00:00:00 2001 From: Sergio Ahumada Date: Tue, 15 Jan 2013 12:09:35 +0100 Subject: sync.profile: Point dependencies to 'refs/heads/dev' Change-Id: Ia62b896c75b5be345d0a078dd76b2a5634642b59 Reviewed-by: Oswald Buddenhagen --- sync.profile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sync.profile b/sync.profile index 36e545a..9e398bd 100644 --- a/sync.profile +++ b/sync.profile @@ -4,7 +4,7 @@ %moduleheaders = ( # restrict the module headers to those found in relative path ); %dependencies = ( - "qtbase" => "refs/heads/master", - "qtdeclarative" => "refs/heads/master", - "qtjsbackend" => "refs/heads/master", + "qtbase" => "refs/heads/dev", + "qtdeclarative" => "refs/heads/dev", + "qtjsbackend" => "refs/heads/dev", ); -- cgit v1.2.1 From 73705cc57ad9befc95de9508912a09139a112edd Mon Sep 17 00:00:00 2001 From: Rainer Keller Date: Mon, 14 Jan 2013 15:29:55 +0100 Subject: Do not link librt on Android platforms Android platform does not need to have librt linked separately. Change-Id: Iab35d5f44bde439ca83a1d4664a7e10bae6cb0da Reviewed-by: Thomas McGuire Reviewed-by: Lorn Potter --- src/plugins/sensors/dummy/dummy.pro | 2 +- src/plugins/sensors/linux/linux.pro | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/sensors/dummy/dummy.pro b/src/plugins/sensors/dummy/dummy.pro index b97bd9c..f54588a 100644 --- a/src/plugins/sensors/dummy/dummy.pro +++ b/src/plugins/sensors/dummy/dummy.pro @@ -15,4 +15,4 @@ SOURCES += dummycommon.cpp\ OTHER_FILES = plugin.json -unix:!mac:!qnx:LIBS+=-lrt +unix:!mac:!qnx:!android:LIBS+=-lrt diff --git a/src/plugins/sensors/linux/linux.pro b/src/plugins/sensors/linux/linux.pro index 7546728..25c4f2d 100644 --- a/src/plugins/sensors/linux/linux.pro +++ b/src/plugins/sensors/linux/linux.pro @@ -6,7 +6,7 @@ load(qt_plugin) OTHER_FILES = plugin.json -LIBS += -lrt +!android:LIBS += -lrt HEADERS += linuxsysaccelerometer.h SOURCES += linuxsysaccelerometer.cpp \ main.cpp -- cgit v1.2.1 From 91030f1ac36c5b4f6a5cd7333fd8965446f7a203 Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Thu, 10 Jan 2013 17:46:33 +0100 Subject: Generic Tilt sensor: Use degree rather than radians This is stated in the docs and it is also more consistent with all other sensors. Change-Id: I5d1d074630f9efa7371a42d10196984549769e24 Reviewed-by: Lorn Potter --- src/plugins/sensors/generic/generictiltsensor.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/plugins/sensors/generic/generictiltsensor.cpp b/src/plugins/sensors/generic/generictiltsensor.cpp index df07355..01281bd 100644 --- a/src/plugins/sensors/generic/generictiltsensor.cpp +++ b/src/plugins/sensors/generic/generictiltsensor.cpp @@ -106,6 +106,11 @@ void GenericTiltSensor::calibrate() calibratedRoll = roll; } +static qreal rad2deg(qreal rad) +{ + return rad / (2 * M_PI) * 360; +} + bool GenericTiltSensor::filter(QAccelerometerReading *reading) { /* @@ -168,6 +173,10 @@ bool GenericTiltSensor::filter(QAccelerometerReading *reading) yRotation = yrot; change = true; } + + xRotation = rad2deg(xRotation); + yRotation = rad2deg(yRotation); + if (xRotation != m_reading.xRotation() || yRotation != m_reading.yRotation() || m_reading.timestamp() == 0) { -- cgit v1.2.1 From 96d5cec1e18aad8335f165bca77b84235b0ebda1 Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Thu, 10 Jan 2013 17:37:33 +0100 Subject: Actually enable loading of the generic tilt sensor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also, disable loading of all other generic plugins on the BlackBerry platform. Change-Id: I7c969fdb224daf1016162ad597edac81e967105e Reviewed-by: Sérgio Martins Reviewed-by: Lorn Potter --- src/plugins/sensors/generic/generic.pro | 20 ++++++++++++-------- src/plugins/sensors/generic/main.cpp | 17 +++++++++++++++-- src/plugins/sensors/sensors.pro | 4 ++-- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/plugins/sensors/generic/generic.pro b/src/plugins/sensors/generic/generic.pro index 2d4f9f9..5bfeff6 100644 --- a/src/plugins/sensors/generic/generic.pro +++ b/src/plugins/sensors/generic/generic.pro @@ -4,15 +4,19 @@ QT = core sensors PLUGIN_TYPE = sensors load(qt_plugin) -HEADERS += genericorientationsensor.h\ - genericrotationsensor.h\ - genericalssensor.h\ - generictiltsensor.h +HEADERS += generictiltsensor.h -SOURCES += genericorientationsensor.cpp\ - main.cpp\ - genericrotationsensor.cpp\ - genericalssensor.cpp\ +SOURCES += main.cpp\ generictiltsensor.cpp +!blackberry { + HEADERS += genericorientationsensor.h\ + genericrotationsensor.h\ + genericalssensor.h + + SOURCES += genericorientationsensor.cpp\ + genericrotationsensor.cpp\ + genericalssensor.cpp +} + OTHER_FILES = plugin.json diff --git a/src/plugins/sensors/generic/main.cpp b/src/plugins/sensors/generic/main.cpp index c455489..a69c279 100644 --- a/src/plugins/sensors/generic/main.cpp +++ b/src/plugins/sensors/generic/main.cpp @@ -39,9 +39,12 @@ ** ****************************************************************************/ +#ifndef Q_OS_BLACKBERRY #include "genericorientationsensor.h" #include "genericrotationsensor.h" #include "genericalssensor.h" +#endif +#include "generictiltsensor.h" #include #include #include @@ -64,26 +67,33 @@ public: { if (!QSensor::defaultSensorForType(QAccelerometer::type).isEmpty()) { // There is an accelerometer available. Register the backends +#ifndef Q_OS_BLACKBERRY if (!QSensorManager::isBackendRegistered(QOrientationSensor::type, genericorientationsensor::id)) QSensorManager::registerBackend(QOrientationSensor::type, genericorientationsensor::id, this); if (!QSensorManager::isBackendRegistered(QRotationSensor::type, genericrotationsensor::id)) QSensorManager::registerBackend(QRotationSensor::type, genericrotationsensor::id, this); if (!QSensorManager::isBackendRegistered(QAmbientLightSensor::type, genericalssensor::id)) QSensorManager::registerBackend(QAmbientLightSensor::type, genericalssensor::id, this); - if (!QSensorManager::isBackendRegistered(QAmbientLightSensor::type, genericalssensor::id)) - QSensorManager::registerBackend(QAmbientLightSensor::type, genericalssensor::id, this); +#endif + if (!QSensorManager::isBackendRegistered(QTiltSensor::type, GenericTiltSensor::id)) + QSensorManager::registerBackend(QTiltSensor::type, GenericTiltSensor::id, this); } else { +#ifndef Q_OS_BLACKBERRY if (QSensorManager::isBackendRegistered(QOrientationSensor::type, genericorientationsensor::id)) QSensorManager::unregisterBackend(QOrientationSensor::type, genericorientationsensor::id); if (QSensorManager::isBackendRegistered(QRotationSensor::type, genericrotationsensor::id)) QSensorManager::unregisterBackend(QRotationSensor::type, genericrotationsensor::id); if (QSensorManager::isBackendRegistered(QAmbientLightSensor::type, genericalssensor::id)) QSensorManager::unregisterBackend(QAmbientLightSensor::type, genericalssensor::id); +#endif + if (QSensorManager::isBackendRegistered(QTiltSensor::type, GenericTiltSensor::id)) + QSensorManager::unregisterBackend(QTiltSensor::type, GenericTiltSensor::id); } } QSensorBackend *createBackend(QSensor *sensor) { +#ifndef Q_OS_BLACKBERRY if (sensor->identifier() == genericorientationsensor::id) return new genericorientationsensor(sensor); @@ -92,6 +102,9 @@ public: if (sensor->identifier() == genericalssensor::id) return new genericalssensor(sensor); +#endif + if (sensor->identifier() == GenericTiltSensor::id) + return new GenericTiltSensor(sensor); return 0; } diff --git a/src/plugins/sensors/sensors.pro b/src/plugins/sensors/sensors.pro index 41fc6fd..2edbb36 100644 --- a/src/plugins/sensors/sensors.pro +++ b/src/plugins/sensors/sensors.pro @@ -1,9 +1,9 @@ TEMPLATE = subdirs -# Don't build dummy and generic plugins by default, the Blackberry backend has real implementations +# Don't build dummy plugins, the Blackberry backend has real implementations # of these. This reduces compile time and plugin loading time. blackberry { - isEmpty(SENSORS_PLUGINS): SENSORS_PLUGINS = blackberry + isEmpty(SENSORS_PLUGINS): SENSORS_PLUGINS = blackberry generic } isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, dummy):SUBDIRS += dummy -- cgit v1.2.1 From a001511d8629c05de807f9927c3fa75f5d59a768 Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Thu, 10 Jan 2013 17:38:14 +0100 Subject: Generic plugin: Remove debug message noise. Change-Id: I33e43f0846197cbb47609af249e54769e17920b8 Reviewed-by: Lorn Potter --- src/plugins/sensors/generic/main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/plugins/sensors/generic/main.cpp b/src/plugins/sensors/generic/main.cpp index a69c279..ed33f58 100644 --- a/src/plugins/sensors/generic/main.cpp +++ b/src/plugins/sensors/generic/main.cpp @@ -59,7 +59,6 @@ class genericSensorPlugin : public QObject, public QSensorPluginInterface, publi public: void registerSensors() { - qDebug() << "loaded the Generic plugin"; // Nothing to register here } -- cgit v1.2.1 From acd094c6d795a597d3b899633e207d65f79ea746 Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Tue, 8 Jan 2013 11:55:10 +0100 Subject: QAccelerometer: Add AccelerationMode property MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a new property to be able to toggle effects of gravity on or off. Implement the Blackberry backend side of this as well. QTBUG-25842 Change-Id: I15c4cae72373f48b0153b83c6aa3d27b66538c87 Reviewed-by: Lorn Potter Reviewed-by: Sérgio Martins --- src/imports/sensors/plugins.qmltypes | 76 ++++++++++++--------- src/imports/sensors/qmlaccelerometer.cpp | 21 ++++++ src/imports/sensors/qmlaccelerometer.h | 15 +++++ src/imports/sensors/sensors.cpp | 35 ++++++++++ src/imports/sensors/sensors.pro | 2 +- src/plugins/sensors/blackberry/bbaccelerometer.cpp | 38 +++++++++++ src/plugins/sensors/blackberry/bbaccelerometer.h | 4 ++ src/plugins/sensors/blackberry/bbsensorbackend.cpp | 16 +++++ src/plugins/sensors/blackberry/bbsensorbackend.h | 3 + src/sensors/qaccelerometer.cpp | 78 +++++++++++++++++++++- src/sensors/qaccelerometer.h | 20 ++++++ src/sensors/qaccelerometer_p.h | 13 ++++ src/sensors/qsensor.cpp | 5 ++ src/sensors/qsensor.h | 1 + tests/auto/qsensor/tst_qsensor.cpp | 2 + 15 files changed, 295 insertions(+), 34 deletions(-) diff --git a/src/imports/sensors/plugins.qmltypes b/src/imports/sensors/plugins.qmltypes index 687a1f2..00d8c36 100644 --- a/src/imports/sensors/plugins.qmltypes +++ b/src/imports/sensors/plugins.qmltypes @@ -3,18 +3,32 @@ import QtQuick.tooling 1.1 // This file describes the plugin-supplied types contained in the library. // It is used for QML tooling purposes only. // -// This file was auto-generated with the command 'qmlplugindump QtSensors 5.0 /home/thomas/src/qtbase/imports/'. +// This file was auto-generated with the command 'qmlplugindump QtSensors 5.0 /home/thomas/src/qtbase/qml'. Module { Component { name: "QmlAccelerometer" prototype: "QmlSensor" - exports: ["Accelerometer 5.0"] + exports: ["Accelerometer 5.0", "Accelerometer 5.1"] + exportMetaObjectRevisions: [0, 1] + Enum { + name: "AccelerationMode" + values: { + "Combined": 0, + "Gravity": 1, + "User": 2 + } + } + Property { name: "accelerationMode"; revision: 1; type: "AccelerationMode" } + Signal { + name: "accelerationModeChanged" + Parameter { name: "accelerationMode"; type: "AccelerationMode" } + } } Component { name: "QmlAccelerometerReading" prototype: "QmlSensorReading" - exports: ["AccelerometerReading 5.0"] + exports: ["AccelerometerReading 5.0", "AccelerometerReading 5.1"] Property { name: "x"; type: "double"; isReadonly: true } Property { name: "y"; type: "double"; isReadonly: true } Property { name: "z"; type: "double"; isReadonly: true } @@ -22,35 +36,35 @@ Module { Component { name: "QmlAmbientLightSensor" prototype: "QmlSensor" - exports: ["AmbientLightSensor 5.0"] + exports: ["AmbientLightSensor 5.0", "AmbientLightSensor 5.1"] } Component { name: "QmlAmbientLightSensorReading" prototype: "QmlSensorReading" - exports: ["AmbientLightReading 5.0"] + exports: ["AmbientLightReading 5.0", "AmbientLightReading 5.1"] Property { name: "lightLevel"; type: "QAmbientLightReading::LightLevel"; isReadonly: true } } Component { name: "QmlCompass" prototype: "QmlSensor" - exports: ["Compass 5.0"] + exports: ["Compass 5.0", "Compass 5.1"] } Component { name: "QmlCompassReading" prototype: "QmlSensorReading" - exports: ["CompassReading 5.0"] + exports: ["CompassReading 5.0", "CompassReading 5.1"] Property { name: "azimuth"; type: "double"; isReadonly: true } Property { name: "calibrationLevel"; type: "double"; isReadonly: true } } Component { name: "QmlGyroscope" prototype: "QmlSensor" - exports: ["Gyroscope 5.0"] + exports: ["Gyroscope 5.0", "Gyroscope 5.1"] } Component { name: "QmlGyroscopeReading" prototype: "QmlSensorReading" - exports: ["GyroscopeReading 5.0"] + exports: ["GyroscopeReading 5.0", "GyroscopeReading 5.1"] Property { name: "x"; type: "double"; isReadonly: true } Property { name: "y"; type: "double"; isReadonly: true } Property { name: "z"; type: "double"; isReadonly: true } @@ -58,35 +72,35 @@ Module { Component { name: "QmlIRProximitySensor" prototype: "QmlSensor" - exports: ["IRProximitySensor 5.0"] + exports: ["IRProximitySensor 5.0", "IRProximitySensor 5.1"] } Component { name: "QmlIRProximitySensorReading" prototype: "QmlSensorReading" - exports: ["IRProximityReading 5.0"] + exports: ["IRProximityReading 5.0", "IRProximityReading 5.1"] Property { name: "reflectance"; type: "double"; isReadonly: true } } Component { name: "QmlLightSensor" prototype: "QmlSensor" - exports: ["LightSensor 5.0"] + exports: ["LightSensor 5.0", "LightSensor 5.1"] Property { name: "fieldOfView"; type: "double"; isReadonly: true } } Component { name: "QmlLightSensorReading" prototype: "QmlSensorReading" - exports: ["LightReading 5.0"] + exports: ["LightReading 5.0", "LightReading 5.1"] Property { name: "illuminance"; type: "double"; isReadonly: true } } Component { name: "QmlMagnetometer" prototype: "QmlSensor" - exports: ["Magnetometer 5.0"] + exports: ["Magnetometer 5.0", "Magnetometer 5.1"] } Component { name: "QmlMagnetometerReading" prototype: "QmlSensorReading" - exports: ["MagnetometerReading 5.0"] + exports: ["MagnetometerReading 5.0", "MagnetometerReading 5.1"] Property { name: "x"; type: "double"; isReadonly: true } Property { name: "y"; type: "double"; isReadonly: true } Property { name: "z"; type: "double"; isReadonly: true } @@ -95,35 +109,35 @@ Module { Component { name: "QmlOrientationSensor" prototype: "QmlSensor" - exports: ["OrientationSensor 5.0"] + exports: ["OrientationSensor 5.0", "OrientationSensor 5.1"] } Component { name: "QmlOrientationSensorReading" prototype: "QmlSensorReading" - exports: ["OrientationReading 5.0"] + exports: ["OrientationReading 5.0", "OrientationReading 5.1"] Property { name: "orientation"; type: "QOrientationReading::Orientation"; isReadonly: true } } Component { name: "QmlProximitySensor" prototype: "QmlSensor" - exports: ["ProximitySensor 5.0"] + exports: ["ProximitySensor 5.0", "ProximitySensor 5.1"] } Component { name: "QmlProximitySensorReading" prototype: "QmlSensorReading" - exports: ["ProximityReading 5.0"] + exports: ["ProximityReading 5.0", "ProximityReading 5.1"] Property { name: "near"; type: "bool"; isReadonly: true } } Component { name: "QmlRotationSensor" prototype: "QmlSensor" - exports: ["RotationSensor 5.0"] + exports: ["RotationSensor 5.0", "RotationSensor 5.1"] Property { name: "hasZ"; type: "bool"; isReadonly: true } } Component { name: "QmlRotationSensorReading" prototype: "QmlSensorReading" - exports: ["RotationReading 5.0"] + exports: ["RotationReading 5.0", "RotationReading 5.1"] Property { name: "x"; type: "double"; isReadonly: true } Property { name: "y"; type: "double"; isReadonly: true } Property { name: "z"; type: "double"; isReadonly: true } @@ -131,7 +145,7 @@ Module { Component { name: "QmlSensor" prototype: "QObject" - exports: ["Sensor 5.0"] + exports: ["Sensor 5.0", "Sensor 5.1"] Property { name: "identifier"; type: "string" } Property { name: "type"; type: "string"; isReadonly: true } Property { name: "connectedToBackend"; type: "bool"; isReadonly: true } @@ -151,7 +165,7 @@ Module { Component { name: "QmlSensorGesture" prototype: "QObject" - exports: ["SensorGesture 5.0"] + exports: ["SensorGesture 5.0", "SensorGesture 5.1"] Property { name: "availableGestures"; type: "QStringList"; isReadonly: true } Property { name: "gestures"; type: "QStringList" } Property { name: "validGestures"; type: "QStringList"; isReadonly: true } @@ -165,7 +179,7 @@ Module { Component { name: "QmlSensorGlobal" prototype: "QObject" - exports: ["QmlSensors 5.0"] + exports: ["QmlSensors 5.0", "QmlSensors 5.1"] Signal { name: "availableSensorsChanged" } Method { name: "sensorTypes"; type: "QStringList" } Method { @@ -182,7 +196,7 @@ Module { Component { name: "QmlSensorOutputRange" prototype: "QObject" - exports: ["OutputRange 5.0"] + exports: ["OutputRange 5.0", "OutputRange 5.1"] Property { name: "minimum"; type: "double"; isReadonly: true } Property { name: "maximum"; type: "double"; isReadonly: true } Property { name: "accuracy"; type: "double"; isReadonly: true } @@ -190,26 +204,26 @@ Module { Component { name: "QmlSensorRange" prototype: "QObject" - exports: ["Range 5.0"] + exports: ["Range 5.0", "Range 5.1"] Property { name: "minimum"; type: "int"; isReadonly: true } Property { name: "maximum"; type: "int"; isReadonly: true } } Component { name: "QmlSensorReading" prototype: "QObject" - exports: ["SensorReading 5.0"] + exports: ["SensorReading 5.0", "SensorReading 5.1"] Property { name: "timestamp"; type: "qulonglong"; isReadonly: true } } Component { name: "QmlTapSensor" prototype: "QmlSensor" - exports: ["TapSensor 5.0"] + exports: ["TapSensor 5.0", "TapSensor 5.1"] Property { name: "returnDoubleTapEvents"; type: "bool" } } Component { name: "QmlTapSensorReading" prototype: "QmlSensorReading" - exports: ["TapReading 5.0"] + exports: ["TapReading 5.0", "TapReading 5.1"] Property { name: "tapDirection"; type: "QTapReading::TapDirection"; isReadonly: true } Property { name: "doubleTap"; type: "bool"; isReadonly: true } Signal { name: "isDoubleTapChanged" } @@ -217,13 +231,13 @@ Module { Component { name: "QmlTiltSensor" prototype: "QmlSensor" - exports: ["TiltSensor 5.0"] + exports: ["TiltSensor 5.0", "TiltSensor 5.1"] Method { name: "calibrate" } } Component { name: "QmlTiltSensorReading" prototype: "QmlSensorReading" - exports: ["TiltReading 5.0"] + exports: ["TiltReading 5.0", "TiltReading 5.1"] Property { name: "yRotation"; type: "double"; isReadonly: true } Property { name: "xRotation"; type: "double"; isReadonly: true } } diff --git a/src/imports/sensors/qmlaccelerometer.cpp b/src/imports/sensors/qmlaccelerometer.cpp index 390f8be..6fc82ea 100644 --- a/src/imports/sensors/qmlaccelerometer.cpp +++ b/src/imports/sensors/qmlaccelerometer.cpp @@ -65,12 +65,33 @@ QmlAccelerometer::QmlAccelerometer(QObject *parent) : QmlSensor(parent) , m_sensor(new QAccelerometer(this)) { + connect(m_sensor, SIGNAL(accelerationModeChanged(AccelerationMode)), + this, SIGNAL(accelerationModeChanged(AccelerationMode))); } QmlAccelerometer::~QmlAccelerometer() { } +/*! + \qmlproperty AccelerationMode Accelerometer::accelerationMode + \since QtSensors 5.1 + + This property holds the current acceleration mode. + + Please see QAccelerometer::accelerationMode for information about this property. +*/ + +QmlAccelerometer::AccelerationMode QmlAccelerometer::accelerationMode() const +{ + return static_cast(m_sensor->accelerationMode()); +} + +void QmlAccelerometer::setAccelerationMode(QmlAccelerometer::AccelerationMode accelerationMode) +{ + m_sensor->setAccelerationMode(static_cast(accelerationMode)); +} + QmlSensorReading *QmlAccelerometer::createReading() const { return new QmlAccelerometerReading(m_sensor); diff --git a/src/imports/sensors/qmlaccelerometer.h b/src/imports/sensors/qmlaccelerometer.h index 95785ed..b2dc671 100644 --- a/src/imports/sensors/qmlaccelerometer.h +++ b/src/imports/sensors/qmlaccelerometer.h @@ -52,10 +52,25 @@ class QAccelerometer; class QmlAccelerometer : public QmlSensor { Q_OBJECT + Q_ENUMS(AccelerationMode) + Q_PROPERTY(AccelerationMode accelerationMode READ accelerationMode WRITE setAccelerationMode + NOTIFY accelerationModeChanged REVISION 1) public: explicit QmlAccelerometer(QObject *parent = 0); ~QmlAccelerometer(); + // Keep this enum in sync with QAccelerometer::AccelerationMode + enum AccelerationMode { + Combined, + Gravity, + User + }; + + AccelerationMode accelerationMode() const; + void setAccelerationMode(AccelerationMode accelerationMode); + +signals: + void accelerationModeChanged(AccelerationMode accelerationMode); private: QSensor *sensor() const Q_DECL_OVERRIDE; diff --git a/src/imports/sensors/sensors.cpp b/src/imports/sensors/sensors.cpp index 50ccdf9..95fc8cc 100644 --- a/src/imports/sensors/sensors.cpp +++ b/src/imports/sensors/sensors.cpp @@ -125,6 +125,41 @@ public: qmlRegisterUncreatableType(package, major, minor, "TiltReading", QLatin1String("Cannot create TiltReading")); qmlRegisterType (package, major, minor, "SensorGesture"); + + // Register the 5.1 interfaces + major = 5; + minor = 1; + qmlRegisterSingletonType (package, major, minor, "QmlSensors", global_object_50); + qmlRegisterUncreatableType(package, major, minor, "Range", QLatin1String("Cannot create Range")); + qmlRegisterUncreatableType(package, major, minor, "OutputRange", QLatin1String("Cannot create OutputRange")); + qmlRegisterUncreatableType(package, major, minor, "Sensor", QLatin1String("Cannot create Sensor")); + qmlRegisterUncreatableType(package, major, minor, "SensorReading", QLatin1String("Cannot create SensorReading")); + qmlRegisterType (package, major, minor, "Accelerometer"); + qmlRegisterUncreatableType(package, major, minor, "AccelerometerReading", QLatin1String("Cannot create AccelerometerReading")); + qmlRegisterType (package, major, minor, "AmbientLightSensor"); + qmlRegisterUncreatableType(package, major, minor, "AmbientLightReading", QLatin1String("Cannot create AmbientLightReading")); + qmlRegisterType (package, major, minor, "Compass"); + qmlRegisterUncreatableType(package, major, minor, "CompassReading", QLatin1String("Cannot create CompassReading")); + qmlRegisterType (package, major, minor, "Gyroscope"); + qmlRegisterUncreatableType(package, major, minor, "GyroscopeReading", QLatin1String("Cannot create GyroscopeReading")); + qmlRegisterType (package, major, minor, "IRProximitySensor"); + qmlRegisterUncreatableType(package, major, minor, "IRProximityReading", QLatin1String("Cannot create IRProximityReading")); + qmlRegisterType (package, major, minor, "LightSensor"); + qmlRegisterUncreatableType(package, major, minor, "LightReading", QLatin1String("Cannot create LightReading")); + qmlRegisterType (package, major, minor, "Magnetometer"); + qmlRegisterUncreatableType(package, major, minor, "MagnetometerReading", QLatin1String("Cannot create MagnetometerReading")); + qmlRegisterType (package, major, minor, "OrientationSensor"); + qmlRegisterUncreatableType(package, major, minor, "OrientationReading", QLatin1String("Cannot create OrientationReading")); + qmlRegisterType (package, major, minor, "ProximitySensor"); + qmlRegisterUncreatableType(package, major, minor, "ProximityReading", QLatin1String("Cannot create ProximityReading")); + qmlRegisterType (package, major, minor, "RotationSensor"); + qmlRegisterUncreatableType(package, major, minor, "RotationReading", QLatin1String("Cannot create RotationReading")); + qmlRegisterType (package, major, minor, "TapSensor"); + qmlRegisterUncreatableType(package, major, minor, "TapReading", QLatin1String("Cannot create TapReading")); + qmlRegisterType (package, major, minor, "TiltSensor"); + qmlRegisterUncreatableType(package, major, minor, "TiltReading", QLatin1String("Cannot create TiltReading")); + + qmlRegisterType (package, major, minor, "SensorGesture"); } }; diff --git a/src/imports/sensors/sensors.pro b/src/imports/sensors/sensors.pro index 210ceac..7636201 100644 --- a/src/imports/sensors/sensors.pro +++ b/src/imports/sensors/sensors.pro @@ -1,7 +1,7 @@ CXX_MODULE = sensors TARGET = declarative_sensors TARGETPATH = QtSensors -IMPORT_VERSION = 5.0 # Doesn't matter, as long as it's a valid version?! +IMPORT_VERSION = 5.1 # Doesn't matter, as long as it's a valid version?! QT += qml sensors sensors-private diff --git a/src/plugins/sensors/blackberry/bbaccelerometer.cpp b/src/plugins/sensors/blackberry/bbaccelerometer.cpp index dcbd7fc..0826cf7 100644 --- a/src/plugins/sensors/blackberry/bbaccelerometer.cpp +++ b/src/plugins/sensors/blackberry/bbaccelerometer.cpp @@ -44,6 +44,12 @@ 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) @@ -58,7 +64,39 @@ bool BbAccelerometer::updateReadingFromEvent(const sensor_event_t &event, QAccel 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/src/plugins/sensors/blackberry/bbaccelerometer.h b/src/plugins/sensors/blackberry/bbaccelerometer.h index aa47873..3071c80 100644 --- a/src/plugins/sensors/blackberry/bbaccelerometer.h +++ b/src/plugins/sensors/blackberry/bbaccelerometer.h @@ -51,10 +51,14 @@ class BbAccelerometer : public BbSensorBackend public: explicit BbAccelerometer(QSensor *sensor); + void start() Q_DECL_OVERRIDE; static QString devicePath(); protected: bool updateReadingFromEvent(const sensor_event_t &event, QAccelerometerReading *reading) Q_DECL_OVERRIDE; + +private Q_SLOTS: + void applyAccelerationMode(); }; #endif diff --git a/src/plugins/sensors/blackberry/bbsensorbackend.cpp b/src/plugins/sensors/blackberry/bbsensorbackend.cpp index fa8c89b..324929f 100644 --- a/src/plugins/sensors/blackberry/bbsensorbackend.cpp +++ b/src/plugins/sensors/blackberry/bbsensorbackend.cpp @@ -107,6 +107,21 @@ sensor_type_e BbSensorBackendBase::sensorType() const return m_sensorType; } +void BbSensorBackendBase::setDevice(const QString &deviceFile, sensor_type_e sensorType) +{ + if (deviceFile != m_deviceFile.fileName()) { + setPaused(true); + delete m_socketNotifier.take(); + m_deviceFile.close(); + + m_sensorType = sensorType; + m_deviceFile.setFileName(deviceFile); + initSensorInfo(); + if (m_started) + start(); // restart with new device file + } +} + void BbSensorBackendBase::initSensorInfo() { if (!m_deviceFile.open(QFile::ReadOnly | QFile::Unbuffered)) { @@ -283,6 +298,7 @@ bool BbSensorBackendBase::isFeatureSupported(QSensor::Feature feature) const switch (feature) { case QSensor::AlwaysOn: case QSensor::Buffering: + case QSensor::AccelerationMode: return true; case QSensor::Reserved: case QSensor::GeoValues: diff --git a/src/plugins/sensors/blackberry/bbsensorbackend.h b/src/plugins/sensors/blackberry/bbsensorbackend.h index 7e2ad0e..cd9a0e2 100644 --- a/src/plugins/sensors/blackberry/bbsensorbackend.h +++ b/src/plugins/sensors/blackberry/bbsensorbackend.h @@ -75,8 +75,11 @@ public: protected: BbGuiHelper *guiHelper() const; QFile& deviceFile(); + sensor_type_e sensorType() 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(); diff --git a/src/sensors/qaccelerometer.cpp b/src/sensors/qaccelerometer.cpp index 4aeedf4..9b9bd34 100644 --- a/src/sensors/qaccelerometer.cpp +++ b/src/sensors/qaccelerometer.cpp @@ -152,6 +152,29 @@ void QAccelerometerReading::setZ(qreal z) char const * const QAccelerometer::type("QAccelerometer"); +/*! + \enum QAccelerometer::AccelerationMode + + \brief This enum represents the acceleration mode of an acceleration sensor. + + The acceleration mode controls how the sensor reports acceleration. QAccelerometer::Combined + is the only mode in which the values can be directly physically measured, the others are an + approximation. + + \value Combined Both the acceleration caused by gravity and the acceleration caused by the + user moving the device is reported combined. + \value Gravity Only the acceleration caused by gravity is reported. Movements of the device + caused by the user have no effect other than changing the direction when the + device is rotated. + \value User Only the acceleration caused by the user moving the device is reported, the + effect of gravity is canceled out. A device at rest therefore should report + values of, or close to, zero. + In other APIs, this mode might be known as \e {linear acceleration}. + + \sa QAccelerometer::accelerationMode + \since 5.1 +*/ + /*! \class QAccelerometer \ingroup sensors_type @@ -161,7 +184,11 @@ char const * const QAccelerometer::type("QAccelerometer"); The only behavioural difference is that this class sets the type properly. - This class also features a reading() function that returns a QAccelerometerReading instead of a QSensorReading. + It also supports changing the acceleration mode, which controls whether the force of gravity + is included in the accelerometer values or not. + + Furthermore, this class features a reading() function that returns a QAccelerometerReading + instead of a QSensorReading. For details about how the sensor works, see \l QAccelerometerReading. @@ -172,7 +199,7 @@ char const * const QAccelerometer::type("QAccelerometer"); Construct the sensor as a child of \a parent. */ QAccelerometer::QAccelerometer(QObject *parent) - : QSensor(QAccelerometer::type, parent) + : QSensor(QAccelerometer::type, *new QAccelerometerPrivate, parent) { } @@ -183,6 +210,45 @@ QAccelerometer::~QAccelerometer() { } +/*! + \property QAccelerometer::accelerationMode + \brief The acceleration mode controls how acceleration values are reported. + \since 5.1 + + The acceleration mode controls how the acceleration sensor reports its values. + The default mode is QAccelerometer::Combined, which means the acceleration caused + by gravity is included in the reported values. + + Acceleration caused by gravity and acceleration caused by the user moving the device + are physically impossible to distinguish because of general relativity. Most devices use + sensor fusion to figure out which parts of the acceleration is caused by gravity, for example + by using a rotation sensor to calculate the gravity direction and assuming a fixed magnitude + for gravity. Therefore the result is only an approximation and may be inaccurate. + The QAccelerometer::Combined mode is the most accurate one, as it does not involve approximating + the gravity. + + Not all backends and devices might support setting the acceleration mode. For those cases, the + default mode QAccelerometer::Combined is used, changing it has no effect. +*/ +QAccelerometer::AccelerationMode QAccelerometer::accelerationMode() const +{ + Q_D(const QAccelerometer); + return d->accelerationMode; +} + +/*! + Sets the acceleration mode to \a accelerationMode. + \since 5.1 +*/ +void QAccelerometer::setAccelerationMode(QAccelerometer::AccelerationMode accelerationMode) +{ + Q_D(QAccelerometer); + if (d->accelerationMode != accelerationMode) { + d->accelerationMode = accelerationMode; + emit accelerationModeChanged(d->accelerationMode); + } +} + /*! \fn QAccelerometer::reading() const @@ -191,6 +257,14 @@ QAccelerometer::~QAccelerometer() \sa QSensor::reading() */ +/*! + \fn QAccelerometer::accelerationModeChanged(AccelerationMode accelerationMode) + + Emitted when the acceleration mode was changed. + + \since 5.1 +*/ + #include "moc_qaccelerometer.cpp" QT_END_NAMESPACE diff --git a/src/sensors/qaccelerometer.h b/src/sensors/qaccelerometer.h index 734ce97..d230eb1 100644 --- a/src/sensors/qaccelerometer.h +++ b/src/sensors/qaccelerometer.h @@ -77,16 +77,36 @@ private: bool filter(QSensorReading *reading) { return filter(static_cast(reading)); } }; +class QAccelerometerPrivate; + class Q_SENSORS_EXPORT QAccelerometer : public QSensor { Q_OBJECT + Q_ENUMS(AccelerationMode) + Q_PROPERTY(AccelerationMode accelerationMode READ accelerationMode WRITE setAccelerationMode + NOTIFY accelerationModeChanged) public: explicit QAccelerometer(QObject *parent = 0); virtual ~QAccelerometer(); + + // Keep this enum in sync with QmlAccelerometer::AccelerationMode + enum AccelerationMode { + Combined, + Gravity, + User + }; + + AccelerationMode accelerationMode() const; + void setAccelerationMode(AccelerationMode accelerationMode); + QAccelerometerReading *reading() const { return static_cast(QSensor::reading()); } static char const * const type; +Q_SIGNALS: + void accelerationModeChanged(AccelerationMode accelerationMode); + private: + Q_DECLARE_PRIVATE(QAccelerometer) Q_DISABLE_COPY(QAccelerometer) }; diff --git a/src/sensors/qaccelerometer_p.h b/src/sensors/qaccelerometer_p.h index dd60fd1..371535b 100644 --- a/src/sensors/qaccelerometer_p.h +++ b/src/sensors/qaccelerometer_p.h @@ -53,6 +53,8 @@ // We mean it. // +#include "qsensor_p.h" + QT_BEGIN_HEADER QT_BEGIN_NAMESPACE @@ -71,6 +73,17 @@ public: qreal z; }; +class QAccelerometerPrivate : public QSensorPrivate +{ +public: + QAccelerometerPrivate() + : accelerationMode(QAccelerometer::Combined) + { + } + + QAccelerometer::AccelerationMode accelerationMode; +}; + QT_END_NAMESPACE QT_END_HEADER diff --git a/src/sensors/qsensor.cpp b/src/sensors/qsensor.cpp index 81cb653..4c3715c 100644 --- a/src/sensors/qsensor.cpp +++ b/src/sensors/qsensor.cpp @@ -200,6 +200,11 @@ void QSensorPrivate::init(const QByteArray &sensorType) \value FieldOfView The backend specifies its field of view, which can be read from the QLightSensor::fieldOfView property. + The features of QAccelerometer are: + + \value AccelerationMode The backend supports switching the acceleration mode + of the acceleromter with the QAccelerometer::accelerationMode property. + \omitvalue Reserved \sa QSensor::isFeatureSupported() diff --git a/src/sensors/qsensor.h b/src/sensors/qsensor.h index 46d011d..f142ca4 100644 --- a/src/sensors/qsensor.h +++ b/src/sensors/qsensor.h @@ -104,6 +104,7 @@ public: AlwaysOn, GeoValues, FieldOfView, + AccelerationMode, Reserved = 257 // Make sure at least 2 bytes are used for the enum to avoid breaking BC later }; diff --git a/tests/auto/qsensor/tst_qsensor.cpp b/tests/auto/qsensor/tst_qsensor.cpp index a4591aa..3852f7e 100644 --- a/tests/auto/qsensor/tst_qsensor.cpp +++ b/tests/auto/qsensor/tst_qsensor.cpp @@ -959,6 +959,7 @@ private slots: QVERIFY(!sensor.isFeatureSupported(QSensor::Buffering)); QVERIFY(!sensor.isFeatureSupported(QSensor::GeoValues)); QVERIFY(!sensor.isFeatureSupported(QSensor::FieldOfView)); + QVERIFY(!sensor.isFeatureSupported(QSensor::AccelerationMode)); // Connect to backend - according to the testsensorimpl implementation, AlwaysOn and // GeoValues should be supported afterwards @@ -968,6 +969,7 @@ private slots: QVERIFY(!sensor.isFeatureSupported(QSensor::Buffering)); QVERIFY(sensor.isFeatureSupported(QSensor::GeoValues)); QVERIFY(!sensor.isFeatureSupported(QSensor::FieldOfView)); + QVERIFY(!sensor.isFeatureSupported(QSensor::AccelerationMode)); } }; -- cgit v1.2.1 From 33edd92343082ab5d59e09fff049b6b74c40720e Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Tue, 8 Jan 2013 15:50:05 +0100 Subject: Fix since documentation tag in sensor template script Change-Id: Ia7d14a7d354fe95e038416e9883a507dd7ccba81 Reviewed-by: Lorn Potter --- src/sensors/make_sensor.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sensors/make_sensor.pl b/src/sensors/make_sensor.pl index 4d78a31..a2d5bf8 100755 --- a/src/sensors/make_sensor.pl +++ b/src/sensors/make_sensor.pl @@ -188,7 +188,7 @@ IMPLEMENT_READING('.$reading.') \class '.$reading.' \ingroup sensors_reading \inmodule QtSensors - \since QtSensors 5.[INSERT VERSION HERE] + \since 5.[INSERT VERSION HERE] \brief The '.$reading.' class holds readings from the [X] sensor. @@ -226,7 +226,7 @@ void '.$reading.'::setMyprop(qreal myprop) \class '.$filter.' \ingroup sensors_filter \inmodule QtSensors - \since QtSensors 5.[INSERT VERSION HERE] + \since 5.[INSERT VERSION HERE] \brief The '.$filter.' class is a convenience wrapper around QSensorFilter. @@ -248,7 +248,7 @@ char const * const '.$sensor.'::type("'.$sensor.'"); \class '.$sensor.' \ingroup sensors_type \inmodule QtSensors - \since QtSensors 5.[INSERT VERSION HERE] + \since 5.[INSERT VERSION HERE] \brief The '.$sensor.' class is a convenience wrapper around QSensor. -- cgit v1.2.1 From bbf9a9f61a18ccb478cbca414d85ed531f078966 Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Tue, 8 Jan 2013 16:38:36 +0100 Subject: Add the QML classes to the sensor template script Change-Id: I373a88ee3116d6ad9c389e762478742af38cb949 Reviewed-by: Lorn Potter --- src/sensors/make_sensor.pl | 174 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) diff --git a/src/sensors/make_sensor.pl b/src/sensors/make_sensor.pl index a2d5bf8..4d35739 100755 --- a/src/sensors/make_sensor.pl +++ b/src/sensors/make_sensor.pl @@ -52,6 +52,15 @@ $sensorbase =~ s/Sensor$//; my $reading = $sensorbase.'Reading'; my $reading_private = $reading.'Private'; my $filter = $sensorbase.'Filter'; +my $no_q_sensor = $sensor; +$no_q_sensor =~ s/^.//; +my $qmlsensor = "Qml".$no_q_sensor; +my $qmlsensorbase = $qmlsensor; +$qmlsensorbase =~ s/Sensor$//; +my $qmlreading = $qmlsensorbase."Reading"; +my $no_q_reading = $no_q_sensor; +$no_q_reading =~ s/Sensor$//; +$no_q_reading = $no_q_reading."Reading"; my $filebase; eval { @@ -61,9 +70,15 @@ if ($@) { $filebase = lc($sensor); } +my $qmlfilebase = $filebase; +$qmlfilebase =~ s/^.//; +$qmlfilebase = "qml".$qmlfilebase; + my $pheader = $filebase."_p.h"; my $header = $filebase.".h"; my $source = $filebase.".cpp"; +my $qmlsource = "../imports/sensors/".$qmlfilebase.".cpp"; +my $qmlheader = "../imports/sensors/".$qmlfilebase.".h"; my $pguard = uc($pheader); $pguard =~ s/\./_/g; @@ -71,6 +86,165 @@ $pguard =~ s/\./_/g; my $guard = uc($header); $guard =~ s/\./_/g; +my $qmlguard = "QML".uc($no_q_sensor)."_H"; + +if (! -e $qmlheader) { + print "Creating $qmlheader\n"; + open OUT, ">$qmlheader" or die $!; + print OUT ' +#ifndef '.$qmlguard.' +#define '.$qmlguard.' + +#include "qmlsensor.h" + +QT_BEGIN_HEADER +QT_BEGIN_NAMESPACE + +class '.$sensor.'; + +class '.$qmlsensor.' : public QmlSensor +{ + Q_OBJECT +public: + explicit '.$qmlsensor.'(QObject *parent = 0); + ~'.$qmlsensor.'(); + +private: + QSensor *sensor() const Q_DECL_OVERRIDE; + QmlSensorReading *createReading() const Q_DECL_OVERRIDE; + + '.$sensor.' *m_sensor; +}; + +class '.$qmlreading.' : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal prop1 READ prop1 NOTIFY prop1Changed) +public: + explicit '.$qmlreading.'('.$sensor.' *sensor); + ~'.$qmlreading.'(); + + qreal prop1() const; + +Q_SIGNALS: + void prop1Changed(); + +private: + QSensorReading *reading() const Q_DECL_OVERRIDE; + void readingUpdate() Q_DECL_OVERRIDE; + + '.$sensor.' *m_sensor; + qreal m_prop1; +}; + +QT_END_NAMESPACE +QT_END_HEADER +#endif +'; + close OUT; +} + +if (! -e $qmlsource) { + print "Creating $qmlsource\n"; + open OUT, ">$qmlsource" or die $!; + print OUT ' +#include "qml'.lc($no_q_sensor).'.h" +#include <'.$sensor.'> + +/*! + \qmltype '.$no_q_sensor.' + \instantiates '.$qmlsensor.' + \ingroup qml-sensors_type + \inqmlmodule QtSensors 5.0 + \since QtSensors 5.[INSERT VERSION HERE] + \inherits Sensor + \brief The '.$no_q_sensor.' element reports on fubbleness. + + The '.$no_q_sensor.' element reports on fubbleness. + + This element wraps the '.$sensor.' class. Please see the documentation for + '.$sensor.' for details. + + \sa '.$no_q_reading.' +*/ + +'.$qmlsensor.'::'.$qmlsensor.'(QObject *parent) + : QmlSensor(parent) + , m_sensor(new '.$sensor.'(this)) +{ +} + +'.$qmlsensor.'::~'.$qmlsensor.'() +{ +} + +QmlSensorReading *'.$qmlsensor.'::createReading() const +{ + return new '.$qmlreading.'(m_sensor); +} + +QSensor *'.$qmlsensor.'::sensor() const +{ + return m_sensor; +} + +/*! + \qmltype '.$no_q_reading.' + \instantiates '.$qmlreading.' + \ingroup qml-sensors_reading + \inqmlmodule QtSensors 5.0 + \since QtSensors 5.[INSERT VERSION HERE] + \inherits SensorReading + \brief The '.$no_q_reading.' element holds the most recent '.$no_q_sensor.' reading. + + The '.$no_q_reading.' element holds the most recent '.$no_q_sensor.' reading. + + This element wraps the '.$reading.' class. Please see the documentation for + '.$reading.' for details. + + This element cannot be directly created. +*/ + +'.$qmlreading.'::'.$qmlreading.'('.$sensor.' *sensor) + : QmlSensorReading(sensor) + , m_sensor(sensor) + , m_prop1(0) +{ +} + +'.$qmlreading.'::~'.$qmlreading.'() +{ +} + +/*! + \qmlproperty qreal '.$no_q_reading.'::prop1 + This property holds the fubble of the device. + + Please see '.$reading.'::prop1 for information about this property. +*/ + +qreal '.$qmlreading.'::prop1() const +{ + return m_prop1; +} + +QSensorReading *'.$qmlreading.'::reading() const +{ + return m_sensor->reading(); +} + +void '.$qmlreading.'::readingUpdate() +{ + qreal prop1 = m_sensor->reading()->prop1(); + if (m_prop1 != prop1) { + m_prop1 = prop1; + Q_EMIT prop1Changed(); + } +} +'; + close OUT; +} + if (! -e $pheader) { print "Creating $pheader\n"; open OUT, ">$pheader" or die $!; -- cgit v1.2.1 From 02285d735e7d3bd8ddfb61b7ea5e16da4ad522d1 Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Tue, 8 Jan 2013 16:55:38 +0100 Subject: Add QPressureSensor This adds a new QPressureSensor plus the assorted reading and filter classes, as well as a QML API. The Blackberry backend is ported to use the new reading class. Change-Id: Ifc86a2ae955a9337a67fd9a86ceabab908917cb3 Reviewed-by: Thomas McGuire --- src/imports/sensors/plugins.qmltypes | 11 ++ src/imports/sensors/qmlpressuresensor.cpp | 133 +++++++++++++++++++ src/imports/sensors/qmlpressuresensor.h | 88 ++++++++++++ src/imports/sensors/sensors.cpp | 3 + src/imports/sensors/sensors.pro | 2 + .../sensors/blackberry/bbpressuresensor.cpp | 29 +--- src/plugins/sensors/blackberry/bbpressuresensor.h | 19 +-- src/plugins/sensors/blackberry/main.cpp | 2 +- src/sensors/doc/src/compatmap.qdoc | 6 + src/sensors/qpressuresensor.cpp | 147 +++++++++++++++++++++ src/sensors/qpressuresensor.h | 88 ++++++++++++ src/sensors/qpressuresensor_p.h | 72 ++++++++++ src/sensors/sensors.pro | 1 + tests/auto/qsensor/test_backends.h | 4 + tests/auto/qsensor/tst_qsensor.cpp | 4 + 15 files changed, 567 insertions(+), 42 deletions(-) create mode 100644 src/imports/sensors/qmlpressuresensor.cpp create mode 100644 src/imports/sensors/qmlpressuresensor.h create mode 100644 src/sensors/qpressuresensor.cpp create mode 100644 src/sensors/qpressuresensor.h create mode 100644 src/sensors/qpressuresensor_p.h diff --git a/src/imports/sensors/plugins.qmltypes b/src/imports/sensors/plugins.qmltypes index 00d8c36..1429ae7 100644 --- a/src/imports/sensors/plugins.qmltypes +++ b/src/imports/sensors/plugins.qmltypes @@ -117,6 +117,17 @@ Module { exports: ["OrientationReading 5.0", "OrientationReading 5.1"] Property { name: "orientation"; type: "QOrientationReading::Orientation"; isReadonly: true } } + Component { + name: "QmlPressureReading" + prototype: "QmlSensorReading" + exports: ["PressureReading 5.1"] + Property { name: "pressure"; type: "double"; isReadonly: true } + } + Component { + name: "QmlPressureSensor" + prototype: "QmlSensor" + exports: ["PressureSensor 5.1"] + } Component { name: "QmlProximitySensor" prototype: "QmlSensor" diff --git a/src/imports/sensors/qmlpressuresensor.cpp b/src/imports/sensors/qmlpressuresensor.cpp new file mode 100644 index 0000000..a21f7c0 --- /dev/null +++ b/src/imports/sensors/qmlpressuresensor.cpp @@ -0,0 +1,133 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qmlpressuresensor.h" +#include + +/*! + \qmltype PressureSensor + \instantiates QmlPressureSensor + \ingroup qml-sensors_type + \inqmlmodule QtSensors 5.0 + \since QtSensors 5.1 + \inherits Sensor + \brief The PressureSensor element reports on atmospheric pressure values. + + The PressureSensor element reports on atmospheric pressure values. + + This element wraps the QPressureSensor class. Please see the documentation for + QPressureSensor for details. + + \sa PressureReading +*/ + +QmlPressureSensor::QmlPressureSensor(QObject *parent) + : QmlSensor(parent) + , m_sensor(new QPressureSensor(this)) +{ +} + +QmlPressureSensor::~QmlPressureSensor() +{ +} + +QmlSensorReading *QmlPressureSensor::createReading() const +{ + return new QmlPressureReading(m_sensor); +} + +QSensor *QmlPressureSensor::sensor() const +{ + return m_sensor; +} + +/*! + \qmltype PressureReading + \instantiates QmlPressureReading + \ingroup qml-sensors_reading + \inqmlmodule QtSensors 5.0 + \since QtSensors 5.1 + \inherits SensorReading + \brief The PressureReading element holds the most recent PressureSensor reading. + + The PressureReading element holds the most recent PressureSensor reading. + + This element wraps the QPressureReading class. Please see the documentation for + QPressureReading for details. + + This element cannot be directly created. +*/ + +QmlPressureReading::QmlPressureReading(QPressureSensor *sensor) + : QmlSensorReading(sensor) + , m_sensor(sensor) + , m_pressure(0) +{ +} + +QmlPressureReading::~QmlPressureReading() +{ +} + +/*! + \qmlproperty qreal PressureReading::pressure + This property holds the atmospheric pressure value in Pascals. + + Please see QPressureReading::pressure for information about this property. +*/ + +qreal QmlPressureReading::pressure() const +{ + return m_pressure; +} + +QSensorReading *QmlPressureReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlPressureReading::readingUpdate() +{ + qreal pressure = m_sensor->reading()->pressure(); + if (m_pressure != pressure) { + m_pressure = pressure; + Q_EMIT pressureChanged(); + } +} diff --git a/src/imports/sensors/qmlpressuresensor.h b/src/imports/sensors/qmlpressuresensor.h new file mode 100644 index 0000000..e150c7d --- /dev/null +++ b/src/imports/sensors/qmlpressuresensor.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QMLPRESSURESENSOR_H +#define QMLPRESSURESENSOR_H + +#include "qmlsensor.h" + +QT_BEGIN_HEADER +QT_BEGIN_NAMESPACE + +class QPressureSensor; + +class QmlPressureSensor : public QmlSensor +{ + Q_OBJECT +public: + explicit QmlPressureSensor(QObject *parent = 0); + ~QmlPressureSensor(); + +private: + QSensor *sensor() const Q_DECL_OVERRIDE; + QmlSensorReading *createReading() const Q_DECL_OVERRIDE; + + QPressureSensor *m_sensor; +}; + +class QmlPressureReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal pressure READ pressure NOTIFY pressureChanged) +public: + explicit QmlPressureReading(QPressureSensor *sensor); + ~QmlPressureReading(); + + qreal pressure() const; + +Q_SIGNALS: + void pressureChanged(); + +private: + QSensorReading *reading() const Q_DECL_OVERRIDE; + void readingUpdate() Q_DECL_OVERRIDE; + + QPressureSensor *m_sensor; + qreal m_pressure; +}; + +QT_END_NAMESPACE +QT_END_HEADER +#endif diff --git a/src/imports/sensors/sensors.cpp b/src/imports/sensors/sensors.cpp index 95fc8cc..9392baf 100644 --- a/src/imports/sensors/sensors.cpp +++ b/src/imports/sensors/sensors.cpp @@ -66,6 +66,7 @@ #include "qmllightsensor.h" #include "qmlmagnetometer.h" #include "qmlorientationsensor.h" +#include "qmlpressuresensor.h" #include "qmlproximitysensor.h" #include "qmlrotationsensor.h" #include "qmltapsensor.h" @@ -150,6 +151,8 @@ public: qmlRegisterUncreatableType(package, major, minor, "MagnetometerReading", QLatin1String("Cannot create MagnetometerReading")); qmlRegisterType (package, major, minor, "OrientationSensor"); qmlRegisterUncreatableType(package, major, minor, "OrientationReading", QLatin1String("Cannot create OrientationReading")); + qmlRegisterType (package, major, minor, "PressureSensor"); + qmlRegisterUncreatableType(package, major, minor, "PressureReading", QLatin1String("Cannot create PressureReading")); qmlRegisterType (package, major, minor, "ProximitySensor"); qmlRegisterUncreatableType(package, major, minor, "ProximityReading", QLatin1String("Cannot create ProximityReading")); qmlRegisterType (package, major, minor, "RotationSensor"); diff --git a/src/imports/sensors/sensors.pro b/src/imports/sensors/sensors.pro index 7636201..8224151 100644 --- a/src/imports/sensors/sensors.pro +++ b/src/imports/sensors/sensors.pro @@ -16,6 +16,7 @@ HEADERS += \ qmllightsensor.h \ qmlmagnetometer.h \ qmlorientationsensor.h \ + qmlpressuresensor.h\ qmlproximitysensor.h \ qmltapsensor.h \ qmlrotationsensor.h \ @@ -34,6 +35,7 @@ SOURCES += sensors.cpp \ qmllightsensor.cpp \ qmlmagnetometer.cpp \ qmlorientationsensor.cpp \ + qmlpressuresensor.cpp\ qmlproximitysensor.cpp \ qmltapsensor.cpp \ qmlrotationsensor.cpp \ diff --git a/src/plugins/sensors/blackberry/bbpressuresensor.cpp b/src/plugins/sensors/blackberry/bbpressuresensor.cpp index 01a2493..8cb9b1e 100644 --- a/src/plugins/sensors/blackberry/bbpressuresensor.cpp +++ b/src/plugins/sensors/blackberry/bbpressuresensor.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2012 Research In Motion +** Copyright (C) 2013 Research In Motion ** Contact: http://www.qt-project.org/legal ** ** This file is part of the QtSensors module of the Qt Toolkit. @@ -40,31 +40,8 @@ ****************************************************************************/ #include "bbpressuresensor.h" -class BbPressureReadingPrivate -{ -public: - BbPressureReadingPrivate() - : pressure(0) - { - } - - qreal pressure; -}; - -IMPLEMENT_READING(BbPressureReading) - -qreal BbPressureReading::pressure() const -{ - return d->pressure; -} - -void BbPressureReading::setPressure(qreal pressure) -{ - d->pressure = pressure; -} - BbPressureSensor::BbPressureSensor(QSensor *sensor) - : BbSensorBackend(devicePath(), SENSOR_TYPE_PRESSURE, sensor) + : BbSensorBackend(devicePath(), SENSOR_TYPE_PRESSURE, sensor) { setDescription(QLatin1String("Pressure in Pascals")); } @@ -74,7 +51,7 @@ QString BbPressureSensor::devicePath() return QLatin1String("/dev/sensor/pressure"); } -bool BbPressureSensor::updateReadingFromEvent(const sensor_event_t &event, BbPressureReading *reading) +bool BbPressureSensor::updateReadingFromEvent(const sensor_event_t &event, QPressureReading *reading) { // TODO: I was unable to test this since the device I was testing this with did not have // a pressure sensor. Verify that this works and check that the units are correct. diff --git a/src/plugins/sensors/blackberry/bbpressuresensor.h b/src/plugins/sensors/blackberry/bbpressuresensor.h index 833832c..7531bd6 100644 --- a/src/plugins/sensors/blackberry/bbpressuresensor.h +++ b/src/plugins/sensors/blackberry/bbpressuresensor.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2012 Research In Motion +** Copyright (C) 2013 Research In Motion ** Contact: http://www.qt-project.org/legal ** ** This file is part of the QtSensors module of the Qt Toolkit. @@ -42,20 +42,9 @@ #define BBPRESSURESENSOR_H #include "bbsensorbackend.h" +#include -class BbPressureReadingPrivate; - -class BbPressureReading : public QSensorReading -{ - Q_OBJECT - Q_PROPERTY(qreal pressure READ pressure) - DECLARE_READING(BbPressureReading) -public: - qreal pressure() const; - void setPressure(qreal pressure); -}; - -class BbPressureSensor : public BbSensorBackend +class BbPressureSensor : public BbSensorBackend { Q_OBJECT @@ -65,7 +54,7 @@ public: static QString devicePath(); protected: - bool updateReadingFromEvent(const sensor_event_t &event, BbPressureReading *reading) Q_DECL_OVERRIDE; + bool updateReadingFromEvent(const sensor_event_t &event, QPressureReading *reading) Q_DECL_OVERRIDE; }; #endif diff --git a/src/plugins/sensors/blackberry/main.cpp b/src/plugins/sensors/blackberry/main.cpp index 54e4163..7b4180a 100644 --- a/src/plugins/sensors/blackberry/main.cpp +++ b/src/plugins/sensors/blackberry/main.cpp @@ -98,7 +98,7 @@ public: if (sensorSupported(BbOrientationSensor::devicePath())) QSensorManager::registerBackend(QOrientationSensor::type, bbOrientationSensorId, this); if (sensorSupported(BbPressureSensor::devicePath())) - QSensorManager::registerBackend("BbPressureSensor", bbPressureSensorId, this); + QSensorManager::registerBackend(QPressureSensor::type, bbPressureSensorId, this); if (sensorSupported(BbProximitySensor::devicePath())) QSensorManager::registerBackend(QProximitySensor::type, bbProximitySensorId, this); if (sensorSupported(BbRotationSensor::devicePath())) diff --git a/src/sensors/doc/src/compatmap.qdoc b/src/sensors/doc/src/compatmap.qdoc index 0fd4951..065ff79 100644 --- a/src/sensors/doc/src/compatmap.qdoc +++ b/src/sensors/doc/src/compatmap.qdoc @@ -106,6 +106,12 @@ + Pressure Sensor + + + + + Proximity Sensor diff --git a/src/sensors/qpressuresensor.cpp b/src/sensors/qpressuresensor.cpp new file mode 100644 index 0000000..ea8a79b --- /dev/null +++ b/src/sensors/qpressuresensor.cpp @@ -0,0 +1,147 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include "qpressuresensor_p.h" + +QT_BEGIN_NAMESPACE + +IMPLEMENT_READING(QPressureReading) + +/*! + \class QPressureReading + \ingroup sensors_reading + \inmodule QtSensors + \since 5.1 + + \brief The QPressureReading class holds readings from the pressure sensor. + + \section2 QPressureReading Units + + The pressure sensor returns atmospheric pressure values in Pascals. +*/ + +/*! + \property QPressureReading::pressure + \brief The measured atmospheric pressure. + + Returned as Pascals. + \sa {QPressureReading Units} +*/ + +qreal QPressureReading::pressure() const +{ + return d->pressure; +} + +/*! + Sets the pressure to \a pressure. +*/ +void QPressureReading::setPressure(qreal pressure) +{ + d->pressure = pressure; +} + +// ===================================================================== + +/*! + \class QPressureFilter + \ingroup sensors_filter + \inmodule QtSensors + \since 5.1 + + \brief The QPressureFilter class is a convenience wrapper around QSensorFilter. + + The only difference is that the filter() method features a pointer to QPressureReading + instead of QSensorReading. +*/ + +/*! + \fn QPressureFilter::filter(QPressureReading *reading) + + Called when \a reading changes. Returns false to prevent the reading from propagating. + + \sa QSensorFilter::filter() +*/ + +char const * const QPressureSensor::type("QPressureSensor"); + +/*! + \class QPressureSensor + \ingroup sensors_type + \inmodule QtSensors + \since 5.1 + + \brief The QPressureSensor class is a convenience wrapper around QSensor. + + The only behavioural difference is that this class sets the type properly. + + This class also features a reading() function that returns a QPressureReading instead of a QSensorReading. + + For details about how the sensor works, see \l QPressureReading. + + \sa QPressureReading +*/ + +/*! + Construct the sensor as a child of \a parent. +*/ +QPressureSensor::QPressureSensor(QObject *parent) + : QSensor(QPressureSensor::type, parent) +{ +} + +/*! + Destroy the sensor. Stops the sensor if it has not already been stopped. +*/ +QPressureSensor::~QPressureSensor() +{ +} + +/*! + \fn QPressureSensor::reading() const + + Returns the reading class for this sensor. + + \sa QSensor::reading() +*/ + +#include "moc_qpressuresensor.cpp" +QT_END_NAMESPACE diff --git a/src/sensors/qpressuresensor.h b/src/sensors/qpressuresensor.h new file mode 100644 index 0000000..80c99f0 --- /dev/null +++ b/src/sensors/qpressuresensor.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QPRESSURESENSOR_H +#define QPRESSURESENSOR_H + +#include + +QT_BEGIN_HEADER +QT_BEGIN_NAMESPACE + +QT_MODULE(QtSensors) + +class QPressureReadingPrivate; + +class Q_SENSORS_EXPORT QPressureReading : public QSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal pressure READ pressure) + DECLARE_READING(QPressureReading) +public: + qreal pressure() const; + void setPressure(qreal pressure); +}; + +class Q_SENSORS_EXPORT QPressureFilter : public QSensorFilter +{ +public: + virtual bool filter(QPressureReading *reading) = 0; +private: + bool filter(QSensorReading *reading) Q_DECL_OVERRIDE + { return filter(static_cast(reading)); } +}; + +class Q_SENSORS_EXPORT QPressureSensor : public QSensor +{ + Q_OBJECT +public: + explicit QPressureSensor(QObject *parent = 0); + ~QPressureSensor(); + QPressureReading *reading() const { return static_cast(QSensor::reading()); } + static char const * const type; + +private: + Q_DISABLE_COPY(QPressureSensor) +}; + +QT_END_NAMESPACE +QT_END_HEADER + +#endif diff --git a/src/sensors/qpressuresensor_p.h b/src/sensors/qpressuresensor_p.h new file mode 100644 index 0000000..4067ccb --- /dev/null +++ b/src/sensors/qpressuresensor_p.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QPRESSURESENSOR_P_H +#define QPRESSURESENSOR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +QT_BEGIN_HEADER +QT_BEGIN_NAMESPACE + +class QPressureReadingPrivate +{ +public: + QPressureReadingPrivate() + : pressure(0) + { + } + + qreal pressure; +}; + +QT_END_NAMESPACE +QT_END_HEADER + +#endif diff --git a/src/sensors/sensors.pro b/src/sensors/sensors.pro index 2cb3346..6f943ab 100644 --- a/src/sensors/sensors.pro +++ b/src/sensors/sensors.pro @@ -62,6 +62,7 @@ SENSORS=\ qtapsensor\ qtiltsensor\ qgyroscope\ + qpressuresensor\ for(s,SENSORS) { # Client API diff --git a/tests/auto/qsensor/test_backends.h b/tests/auto/qsensor/test_backends.h index a36a858..e47cfd5 100644 --- a/tests/auto/qsensor/test_backends.h +++ b/tests/auto/qsensor/test_backends.h @@ -54,6 +54,7 @@ void unregister_test_backends(); #include #include #include +#include #include #include #include @@ -120,6 +121,9 @@ PREPARE_SENSORINTERFACE(QMagnetometer, QMagnetometerReading, QMagnetometerFilter PREPARE_SENSORINTERFACE(QOrientationSensor, QOrientationReading, QOrientationFilter, { reading->setOrientation(QOrientationReading::LeftUp); }) +PREPARE_SENSORINTERFACE(QPressureSensor, QPressureReading, QPressureFilter, { + reading->setPressure(1.0); +}) PREPARE_SENSORINTERFACE(QProximitySensor, QProximityReading, QProximityFilter, { reading->setClose(true); }) diff --git a/tests/auto/qsensor/tst_qsensor.cpp b/tests/auto/qsensor/tst_qsensor.cpp index 3852f7e..3dbcb68 100644 --- a/tests/auto/qsensor/tst_qsensor.cpp +++ b/tests/auto/qsensor/tst_qsensor.cpp @@ -877,6 +877,10 @@ private slots: QCOMPARE(reading->orientation(), QOrientationReading::LeftUp); }) + TEST_SENSORINTERFACE(QPressureSensor, QPressureReading, { + QCOMPARE(reading->pressure(), 1.0); + }) + TEST_SENSORINTERFACE(QProximitySensor, QProximityReading, { QCOMPARE(reading->close(), true); }) -- cgit v1.2.1 From 1831170d56f32530e64bbd5484a6c2cc9e1817ca Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Wed, 9 Jan 2013 13:57:16 +0100 Subject: Add API for duplicate skipping Duplicate skipping enables omitting reading values that are very similar to the previous one, thus saving processing power. Implement this for the Blackberry backend. Change-Id: Ic608d8ca795b5a2e0bca5a75a62e8005c283c620 Reviewed-by: Thomas McGuire --- src/imports/sensors/plugins.qmltypes | 6 +++ src/imports/sensors/qmlsensor.cpp | 20 +++++++++ src/imports/sensors/qmlsensor.h | 5 +++ src/imports/sensors/sensors.cpp | 2 +- .../sensors/blackberry/bborientationsensor.cpp | 16 ++----- .../sensors/blackberry/bborientationsensor.h | 1 - src/plugins/sensors/blackberry/bbsensorbackend.cpp | 11 +++++ src/sensors/qsensor.cpp | 51 ++++++++++++++++++++++ src/sensors/qsensor.h | 6 +++ src/sensors/qsensor_p.h | 2 + 10 files changed, 105 insertions(+), 15 deletions(-) diff --git a/src/imports/sensors/plugins.qmltypes b/src/imports/sensors/plugins.qmltypes index 1429ae7..fe9c961 100644 --- a/src/imports/sensors/plugins.qmltypes +++ b/src/imports/sensors/plugins.qmltypes @@ -157,6 +157,7 @@ Module { name: "QmlSensor" prototype: "QObject" exports: ["Sensor 5.0", "Sensor 5.1"] + exportMetaObjectRevisions: [0, 1] Property { name: "identifier"; type: "string" } Property { name: "type"; type: "string"; isReadonly: true } Property { name: "connectedToBackend"; type: "bool"; isReadonly: true } @@ -170,6 +171,11 @@ Module { Property { name: "description"; type: "string"; isReadonly: true } Property { name: "error"; type: "int"; isReadonly: true } Property { name: "alwaysOn"; type: "bool" } + Property { name: "skipDuplicates"; revision: 1; type: "bool" } + Signal { + name: "skipDuplicatesChanged" + Parameter { name: "skipDuplicates"; type: "bool" } + } Method { name: "start"; type: "bool" } Method { name: "stop" } } diff --git a/src/imports/sensors/qmlsensor.cpp b/src/imports/sensors/qmlsensor.cpp index ec1b069..40a0ebf 100644 --- a/src/imports/sensors/qmlsensor.cpp +++ b/src/imports/sensors/qmlsensor.cpp @@ -170,6 +170,25 @@ void QmlSensor::setAlwaysOn(bool alwaysOn) sensor()->setAlwaysOn(alwaysOn); } +/*! + \qmlproperty bool Sensor::skipDuplicates + \since QtSensors 5.1 + + This property indicates whether duplicate reading values should be omitted. + + Please see QSensor::skipDuplicates for information about this property. +*/ + +bool QmlSensor::skipDuplicates() const +{ + return sensor()->skipDuplicates(); +} + +void QmlSensor::setSkipDuplicates(bool skipDuplicates) +{ + sensor()->setSkipDuplicates(skipDuplicates); +} + /*! \qmlproperty list Sensor::availableDataRates This property holds the data rates that the sensor supports. @@ -323,6 +342,7 @@ void QmlSensor::componentComplete() connect(sensor(), SIGNAL(sensorError(int)), this, SIGNAL(errorChanged())); connect(sensor(), SIGNAL(activeChanged()), this, SIGNAL(activeChanged())); connect(sensor(), SIGNAL(alwaysOnChanged()), this, SIGNAL(alwaysOnChanged())); + connect(sensor(), SIGNAL(skipDuplicatesChanged(bool)), this, SIGNAL(skipDuplicatesChanged(bool))); // We need to set this on the sensor object now sensor()->setIdentifier(m_identifier.toLocal8Bit()); diff --git a/src/imports/sensors/qmlsensor.h b/src/imports/sensors/qmlsensor.h index a4ac852..e287f19 100644 --- a/src/imports/sensors/qmlsensor.h +++ b/src/imports/sensors/qmlsensor.h @@ -71,6 +71,7 @@ class QmlSensor : public QObject, public QQmlParserStatus Q_PROPERTY(QString description READ description NOTIFY descriptionChanged) Q_PROPERTY(int error READ error NOTIFY errorChanged) Q_PROPERTY(bool alwaysOn READ isAlwaysOn WRITE setAlwaysOn NOTIFY alwaysOnChanged) + Q_PROPERTY(bool skipDuplicates READ skipDuplicates WRITE setSkipDuplicates NOTIFY skipDuplicatesChanged REVISION 1) public: explicit QmlSensor(QObject *parent = 0); ~QmlSensor(); @@ -90,6 +91,9 @@ public: bool isAlwaysOn() const; void setAlwaysOn(bool alwaysOn); + bool skipDuplicates() const; + void setSkipDuplicates(bool skipDuplicates); + QQmlListProperty availableDataRates() const; int dataRate() const; void setDataRate(int rate); @@ -120,6 +124,7 @@ Q_SIGNALS: void descriptionChanged(); void errorChanged(); void alwaysOnChanged(); + void skipDuplicatesChanged(bool skipDuplicates); protected: virtual QSensor *sensor() const = 0; diff --git a/src/imports/sensors/sensors.cpp b/src/imports/sensors/sensors.cpp index 9392baf..3f77431 100644 --- a/src/imports/sensors/sensors.cpp +++ b/src/imports/sensors/sensors.cpp @@ -133,7 +133,7 @@ public: qmlRegisterSingletonType (package, major, minor, "QmlSensors", global_object_50); qmlRegisterUncreatableType(package, major, minor, "Range", QLatin1String("Cannot create Range")); qmlRegisterUncreatableType(package, major, minor, "OutputRange", QLatin1String("Cannot create OutputRange")); - qmlRegisterUncreatableType(package, major, minor, "Sensor", QLatin1String("Cannot create Sensor")); + qmlRegisterUncreatableType(package, major, minor, "Sensor", QLatin1String("Cannot create Sensor")); qmlRegisterUncreatableType(package, major, minor, "SensorReading", QLatin1String("Cannot create SensorReading")); qmlRegisterType (package, major, minor, "Accelerometer"); qmlRegisterUncreatableType(package, major, minor, "AccelerometerReading", QLatin1String("Cannot create AccelerometerReading")); diff --git a/src/plugins/sensors/blackberry/bborientationsensor.cpp b/src/plugins/sensors/blackberry/bborientationsensor.cpp index 68ed735..3d9d120 100644 --- a/src/plugins/sensors/blackberry/bborientationsensor.cpp +++ b/src/plugins/sensors/blackberry/bborientationsensor.cpp @@ -44,6 +44,9 @@ BbOrientationSensor::BbOrientationSensor(QSensor *sensor) : BbSensorBackend(devicePath(), SENSOR_TYPE_ORIENTATION, sensor) { setDescription(QLatin1String("Device orientation")); + + // Orientation rarely changes, so enable skipping of duplicates by default + sensor->setSkipDuplicates(true); } QString BbOrientationSensor::devicePath() @@ -51,19 +54,6 @@ QString BbOrientationSensor::devicePath() return QLatin1String("/dev/sensor/orientation"); } -void BbOrientationSensor::start() -{ - BbSensorBackend::start(); - - // Orientation rarely changes, so enable skiping of duplicates - sensor_devctl_skipdupevent_u deviceSkip; - deviceSkip.tx.enable = 1; - const int result = devctl(deviceFile().handle(), DCMD_SENSOR_SKIPDUPEVENT, &deviceSkip, - sizeof(deviceSkip), NULL); - if (result != EOK) - perror("Enabling duplicate skipping for orientation sensor failed"); -} - void BbOrientationSensor::additionalDeviceInit() { // When querying the OS service for the range, it gives us the angles, which we don't need. diff --git a/src/plugins/sensors/blackberry/bborientationsensor.h b/src/plugins/sensors/blackberry/bborientationsensor.h index 07dc3d0..85c7bd6 100644 --- a/src/plugins/sensors/blackberry/bborientationsensor.h +++ b/src/plugins/sensors/blackberry/bborientationsensor.h @@ -53,7 +53,6 @@ public: static QString devicePath(); - void start() Q_DECL_OVERRIDE; void additionalDeviceInit() Q_DECL_OVERRIDE; bool addDefaultRange() Q_DECL_OVERRIDE; diff --git a/src/plugins/sensors/blackberry/bbsensorbackend.cpp b/src/plugins/sensors/blackberry/bbsensorbackend.cpp index 324929f..9850d4d 100644 --- a/src/plugins/sensors/blackberry/bbsensorbackend.cpp +++ b/src/plugins/sensors/blackberry/bbsensorbackend.cpp @@ -254,6 +254,16 @@ void BbSensorBackendBase::start() } } + // Enable/disable duplicate skipping + sensor_devctl_skipdupevent_u deviceSkip; + deviceSkip.tx.enable = sensor()->skipDuplicates(); + const int result = devctl(deviceFile().handle(), DCMD_SENSOR_SKIPDUPEVENT, &deviceSkip, + sizeof(deviceSkip), NULL); + if (result != EOK) { + perror(QString::fromLatin1("Setting duplicate skipping for %1 failed") + .arg(m_deviceFile.fileName()).toLocal8Bit()); + } + // 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) @@ -299,6 +309,7 @@ bool BbSensorBackendBase::isFeatureSupported(QSensor::Feature feature) const case QSensor::AlwaysOn: case QSensor::Buffering: case QSensor::AccelerationMode: + case QSensor::SkipDuplicates: return true; case QSensor::Reserved: case QSensor::GeoValues: diff --git a/src/sensors/qsensor.cpp b/src/sensors/qsensor.cpp index 4c3715c..f93ef88 100644 --- a/src/sensors/qsensor.cpp +++ b/src/sensors/qsensor.cpp @@ -189,6 +189,9 @@ void QSensorPrivate::init(const QByteArray &sensorType) QSensor::bufferSize property. \value AlwaysOn The backend supports changing the policy on whether to suspend when idle, controlled by the QSensor::alwaysOn property. + \value SkipDuplicates The backend supports skipping of same or very similar successive + readings. This can be enabled by setting the QSensor::skipDuplicates + property to true. The features of QMagnetometer are: @@ -433,6 +436,54 @@ bool QSensor::isAlwaysOn() const return d->alwaysOn; } +/*! + \property QSensor::skipDuplicates + \brief Indicates whether duplicate reading values should be omitted. + \since 5.1 + + When duplicate skipping is enabled, successive readings with the same or very + similar values are omitted. This helps reducing the amount of processing done, as less sensor + readings are made available. As a consequence, readings arrive at an irregular interval. + + Duplicate skipping is not just enabled for readings that are exactly the same, but also for + readings that are quite similar, as each sensor has a bit of jitter even if the device is + not moved. + + Support for this property depends on the backend. Use isFeatureSupported() to check if it is + supported on the current platform. + + Duplicate skipping is disabled by default. + + Duplicate skipping takes effect when the sensor is started, changing the property while the + sensor is active has no immediate effect. +*/ +bool QSensor::skipDuplicates() const +{ + Q_D(const QSensor); + return d->skipDuplicates; +} + +/*! + Sets the duplicate skipping to \a skipDuplicates. + + \since 5.1 +*/ +void QSensor::setSkipDuplicates(bool skipDuplicates) +{ + Q_D(QSensor); + if (d->skipDuplicates != skipDuplicates) { + d->skipDuplicates = skipDuplicates; + emit skipDuplicatesChanged(skipDuplicates); + } +} + +/*! + \fn QSensor::skipDuplicatesChanged(bool skipDuplicates) + \since 5.1 + + This signal is emitted when the skipDuplicates property changes. +*/ + /*! \property QSensor::availableDataRates \brief the data rates that the sensor supports. diff --git a/src/sensors/qsensor.h b/src/sensors/qsensor.h index f142ca4..f716275 100644 --- a/src/sensors/qsensor.h +++ b/src/sensors/qsensor.h @@ -93,6 +93,7 @@ class Q_SENSORS_EXPORT QSensor : public QObject Q_PROPERTY(QString description READ description) Q_PROPERTY(int error READ error NOTIFY sensorError) Q_PROPERTY(bool alwaysOn READ isAlwaysOn WRITE setAlwaysOn NOTIFY alwaysOnChanged REVISION 1) + Q_PROPERTY(bool skipDuplicates READ skipDuplicates WRITE setSkipDuplicates NOTIFY skipDuplicatesChanged) #ifdef Q_QDOC Q_PROPERTY(int maxBufferSize) Q_PROPERTY(int efficientBufferSize) @@ -105,6 +106,7 @@ public: GeoValues, FieldOfView, AccelerationMode, + SkipDuplicates, Reserved = 257 // Make sure at least 2 bytes are used for the enum to avoid breaking BC later }; @@ -127,6 +129,9 @@ public: bool isAlwaysOn() const; void setAlwaysOn(bool alwaysOn); + bool skipDuplicates() const; + void setSkipDuplicates(bool skipDuplicates); + qrangelist availableDataRates() const; int dataRate() const; void setDataRate(int rate); @@ -169,6 +174,7 @@ Q_SIGNALS: void availableSensorsChanged(); void alwaysOnChanged(); void dataRateChanged(); + void skipDuplicatesChanged(bool skipDuplicates); protected: explicit QSensor(const QByteArray &type, QSensorPrivate &dd, QObject* parent = 0); diff --git a/src/sensors/qsensor_p.h b/src/sensors/qsensor_p.h index 80312b6..8504a3f 100644 --- a/src/sensors/qsensor_p.h +++ b/src/sensors/qsensor_p.h @@ -79,6 +79,7 @@ public: , cache_reading(0) , error(0) , alwaysOn(false) + , skipDuplicates(false) { } @@ -108,6 +109,7 @@ public: int error; bool alwaysOn; + bool skipDuplicates; }; class QSensorReadingPrivate -- cgit v1.2.1 From 5700ab09b06617d73b0495d2db0696512913ba51 Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Thu, 10 Jan 2013 14:21:08 +0100 Subject: \since QtSensors 5.0 -> \since 5.0 Change-Id: Ied2ceac07a5f9dd8a3331e1e2d407620450e138e Reviewed-by: Lorn Potter --- src/sensors/gestures/qsensorgestureplugininterface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sensors/gestures/qsensorgestureplugininterface.cpp b/src/sensors/gestures/qsensorgestureplugininterface.cpp index add34c0..de02f89 100644 --- a/src/sensors/gestures/qsensorgestureplugininterface.cpp +++ b/src/sensors/gestures/qsensorgestureplugininterface.cpp @@ -51,7 +51,7 @@ QT_BEGIN_NAMESPACE \brief The QSensorGesturePluginInterface class is the pure virtual interface to sensor gesture plugins. - \since QtSensors 5.0 + \since 5.0 The QSensorGesturePluginInterface class is implemented in sensor gesture plugins to register sensor gesture recognizers with QSensorGestureManager. -- cgit v1.2.1 From 78ad1fabee403ac910d29bb212cf0e3b9a670708 Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Thu, 10 Jan 2013 13:38:43 +0100 Subject: Add a axes remapping feature This allows orientable sensors like accelerometer or compass to change to adapt the reading values based on the current screen orientation. Add support for the BlackBerry backend. Change-Id: If7cfde8f20da4f677fdd13c38f7e11f2ed96bedd Reviewed-by: Thomas McGuire --- src/imports/sensors/plugins.qmltypes | 15 ++ src/imports/sensors/qmlsensor.cpp | 53 +++++++ src/imports/sensors/qmlsensor.h | 23 +++ src/plugins/sensors/blackberry/bbcompass.cpp | 15 +- src/plugins/sensors/blackberry/bbsensorbackend.cpp | 35 ++++- src/plugins/sensors/blackberry/bbsensorbackend.h | 2 +- src/sensors/qsensor.cpp | 175 +++++++++++++++++++++ src/sensors/qsensor.h | 24 +++ src/sensors/qsensor_p.h | 7 + 9 files changed, 338 insertions(+), 11 deletions(-) diff --git a/src/imports/sensors/plugins.qmltypes b/src/imports/sensors/plugins.qmltypes index fe9c961..94db26d 100644 --- a/src/imports/sensors/plugins.qmltypes +++ b/src/imports/sensors/plugins.qmltypes @@ -172,10 +172,25 @@ Module { Property { name: "error"; type: "int"; isReadonly: true } Property { name: "alwaysOn"; type: "bool" } Property { name: "skipDuplicates"; revision: 1; type: "bool" } + Property { name: "axesOrientationMode"; revision: 1; type: "AxesOrientationMode" } + Property { name: "currentOrientation"; revision: 1; type: "int"; isReadonly: true } + Property { name: "userOrientation"; revision: 1; type: "int" } Signal { name: "skipDuplicatesChanged" Parameter { name: "skipDuplicates"; type: "bool" } } + Signal { + name: "axesOrientationModeChanged" + Parameter { name: "axesOrientationMode"; type: "AxesOrientationMode" } + } + Signal { + name: "currentOrientationChanged" + Parameter { name: "currentOrientation"; type: "int" } + } + Signal { + name: "userOrientationChanged" + Parameter { name: "userOrientation"; type: "int" } + } Method { name: "start"; type: "bool" } Method { name: "stop" } } diff --git a/src/imports/sensors/qmlsensor.cpp b/src/imports/sensors/qmlsensor.cpp index 40a0ebf..727526a 100644 --- a/src/imports/sensors/qmlsensor.cpp +++ b/src/imports/sensors/qmlsensor.cpp @@ -306,6 +306,55 @@ QmlSensorReading *QmlSensor::reading() const return m_reading; } +/*! + \qmlproperty Sensor::AxesOrientationMode Sensor::axesOrientationMode + \since QtSensors 5.1 + This property holds the mode that affects how the screen orientation changes reading values. + + Please see QSensor::axesOrientationMode for information about this property. +*/ + +QmlSensor::AxesOrientationMode QmlSensor::axesOrientationMode() const +{ + return static_cast(sensor()->axesOrientationMode()); +} + +void QmlSensor::setAxesOrientationMode(QmlSensor::AxesOrientationMode axesOrientationMode) +{ + sensor()->setAxesOrientationMode(static_cast(axesOrientationMode)); +} + +/*! + \qmlproperty int Sensor::currentOrientation + \since QtSensors 5.1 + This property holds the current orientation that is used for rotating the reading values. + + Please see QSensor::currentOrientation for information about this property. +*/ + +int QmlSensor::currentOrientation() const +{ + return sensor()->currentOrientation(); +} + +/*! + \qmlproperty int Sensor::userOrientation + \since QtSensors 5.1 + This property holds the angle used for rotating the reading values in the UserOrientation mode. + + Please see QSensor::userOrientation for information about this property. +*/ + +int QmlSensor::userOrientation() const +{ + return sensor()->userOrientation(); +} + +void QmlSensor::setUserOrientation(int userOrientation) +{ + sensor()->setUserOrientation(userOrientation); +} + /*! \qmlmethod bool Sensor::start() Start retrieving values from the sensor. Returns true if the sensor was started, false otherwise. @@ -343,6 +392,10 @@ void QmlSensor::componentComplete() connect(sensor(), SIGNAL(activeChanged()), this, SIGNAL(activeChanged())); connect(sensor(), SIGNAL(alwaysOnChanged()), this, SIGNAL(alwaysOnChanged())); connect(sensor(), SIGNAL(skipDuplicatesChanged(bool)), this, SIGNAL(skipDuplicatesChanged(bool))); + connect(sensor(), SIGNAL(axesOrientationModeChanged(AxesOrientationMode)), + this, SIGNAL(axesOrientationModeChanged(AxesOrientationMode))); + connect(sensor(), SIGNAL(userOrientationChanged(int)), this, SIGNAL(userOrientationChanged(int))); + connect(sensor(), SIGNAL(currentOrientationChanged(int)), this, SIGNAL(currentOrientationChanged(int))); // We need to set this on the sensor object now sensor()->setIdentifier(m_identifier.toLocal8Bit()); diff --git a/src/imports/sensors/qmlsensor.h b/src/imports/sensors/qmlsensor.h index e287f19..9b8f7b7 100644 --- a/src/imports/sensors/qmlsensor.h +++ b/src/imports/sensors/qmlsensor.h @@ -57,6 +57,7 @@ class QmlSensorReading; class QmlSensor : public QObject, public QQmlParserStatus { Q_OBJECT + Q_ENUMS(AxesOrientationMode) Q_INTERFACES(QQmlParserStatus) Q_PROPERTY(QString identifier READ identifier WRITE setIdentifier NOTIFY identifierChanged) Q_PROPERTY(QString type READ type NOTIFY typeChanged) @@ -72,7 +73,18 @@ class QmlSensor : public QObject, public QQmlParserStatus Q_PROPERTY(int error READ error NOTIFY errorChanged) Q_PROPERTY(bool alwaysOn READ isAlwaysOn WRITE setAlwaysOn NOTIFY alwaysOnChanged) Q_PROPERTY(bool skipDuplicates READ skipDuplicates WRITE setSkipDuplicates NOTIFY skipDuplicatesChanged REVISION 1) + Q_PROPERTY(AxesOrientationMode axesOrientationMode READ axesOrientationMode WRITE setAxesOrientationMode NOTIFY axesOrientationModeChanged REVISION 1) + Q_PROPERTY(int currentOrientation READ currentOrientation NOTIFY currentOrientationChanged REVISION 1) + Q_PROPERTY(int userOrientation READ userOrientation WRITE setUserOrientation NOTIFY userOrientationChanged REVISION 1) + public: + // Keep in sync with QSensor::AxesOrientationMode + enum AxesOrientationMode { + FixedOrientation, + AutomaticOrientation, + UserOrientation + }; + explicit QmlSensor(QObject *parent = 0); ~QmlSensor(); @@ -107,6 +119,14 @@ public: QmlSensorReading *reading() const; + AxesOrientationMode axesOrientationMode() const; + void setAxesOrientationMode(AxesOrientationMode axesOrientationMode); + + int currentOrientation() const; + + int userOrientation() const; + void setUserOrientation(int userOrientation); + public Q_SLOTS: bool start(); void stop(); @@ -125,6 +145,9 @@ Q_SIGNALS: void errorChanged(); void alwaysOnChanged(); void skipDuplicatesChanged(bool skipDuplicates); + void axesOrientationModeChanged(AxesOrientationMode axesOrientationMode); + void currentOrientationChanged(int currentOrientation); + void userOrientationChanged(int userOrientation); protected: virtual QSensor *sensor() const = 0; diff --git a/src/plugins/sensors/blackberry/bbcompass.cpp b/src/plugins/sensors/blackberry/bbcompass.cpp index 6e33d1a..df8cc2e 100644 --- a/src/plugins/sensors/blackberry/bbcompass.cpp +++ b/src/plugins/sensors/blackberry/bbcompass.cpp @@ -55,19 +55,28 @@ BbCompass::BbCompass(QSensor *sensor) bool BbCompass::updateReadingFromEvent(const sensor_event_t &event, QCompassReading *reading) { + float azimuth; #ifdef HAVE_COMPASS_SENSOR - reading->setAzimuth(event.compass_s.azimuth); + azimuth = event.compass_s.azimuth; #else float xRad, yRad, zRad; matrixToEulerZXY(event.rotation_matrix, xRad, yRad, zRad); - float azimuth = radiansToDegrees(zRad); + azimuth = radiansToDegrees(zRad); if (azimuth < 0) azimuth = -azimuth; else azimuth = 360.0f - azimuth; - reading->setAzimuth(azimuth); #endif + if (isAutoAxisRemappingEnabled()) { + azimuth += orientationForRemapping(); + if (azimuth >= 360.0f) + azimuth -= 360.0f; + } + + reading->setAzimuth(azimuth); + + switch (event.accuracy) { case SENSOR_ACCURACY_UNRELIABLE: reading->setCalibrationLevel(0.0f); diff --git a/src/plugins/sensors/blackberry/bbsensorbackend.cpp b/src/plugins/sensors/blackberry/bbsensorbackend.cpp index 9850d4d..de6661e 100644 --- a/src/plugins/sensors/blackberry/bbsensorbackend.cpp +++ b/src/plugins/sensors/blackberry/bbsensorbackend.cpp @@ -86,6 +86,7 @@ BbSensorBackendBase::BbSensorBackendBase(const QString &devicePath, sensor_type_ m_mappingMatrix[0] = m_mappingMatrix[3] = 1; m_mappingMatrix[1] = m_mappingMatrix[2] = 0; connect(sensor, SIGNAL(alwaysOnChanged()), this, SLOT(applyAlwaysOnProperty())); + connect(sensor, SIGNAL(userOrientationChanged(int)), this, SLOT(updateOrientation())); // Set some sensible default values sensor->setProperty("efficientBufferSize", defaultBufferSize); @@ -183,12 +184,13 @@ qreal BbSensorBackendBase::convertValue(float bbValue) bool BbSensorBackendBase::isAutoAxisRemappingEnabled() const { - return sensor()->property("automaticAxisRemapping").toBool(); + return sensor()->isFeatureSupported(QSensor::AxesOrientation) && + sensor()->axesOrientationMode() != QSensor::FixedOrientation; } void BbSensorBackendBase::remapMatrix(const float inputMatrix[], float outputMatrix[]) { - if (!isAutoAxisRemappingEnabled() || m_guiHelper->currentOrientation() == 0) { + if (!isAutoAxisRemappingEnabled() || orientationForRemapping() == 0) { memcpy(outputMatrix, inputMatrix, sizeof(float) * 9); return; } @@ -199,10 +201,10 @@ void BbSensorBackendBase::remapMatrix(const float inputMatrix[], float outputMat void BbSensorBackendBase::remapAxes(float *x, float *y, float *z) { Q_ASSERT(x && y && z); - if (!isAutoAxisRemappingEnabled() || m_guiHelper->currentOrientation() == 0) + if (!isAutoAxisRemappingEnabled() || orientationForRemapping() == 0) return; - const int angle = m_guiHelper->currentOrientation(); + const int angle = orientationForRemapping(); const float oldX = *x; const float oldY = *y; @@ -306,6 +308,11 @@ void BbSensorBackendBase::stop() bool BbSensorBackendBase::isFeatureSupported(QSensor::Feature feature) const { switch (feature) { + case QSensor::AxesOrientation: + return (sensorType() == SENSOR_TYPE_ACCELEROMETER || sensorType() == SENSOR_TYPE_MAGNETOMETER || + sensorType() == SENSOR_TYPE_GYROSCOPE || sensorType() == SENSOR_TYPE_GRAVITY || + sensorType() == SENSOR_TYPE_LINEAR_ACCEL || sensorType() == SENSOR_TYPE_ROTATION_VECTOR || + sensorType() == SENSOR_TYPE_ROTATION_MATRIX || sensorType() == SENSOR_TYPE_AZIMUTH_PITCH_ROLL); case QSensor::AlwaysOn: case QSensor::Buffering: case QSensor::AccelerationMode: @@ -387,12 +394,26 @@ void BbSensorBackendBase::updatePauseState() void BbSensorBackendBase::updateOrientation() { - // ### I can't really test this, the rotation matrix has too many glitches and drifts over time, - // making any measurement quite hard - const int rotationAngle = guiHelper()->currentOrientation(); + const int rotationAngle = orientationForRemapping(); m_mappingMatrix[0] = cos(rotationAngle*M_PI/180); m_mappingMatrix[1] = sin(rotationAngle*M_PI/180); m_mappingMatrix[2] = -sin(rotationAngle*M_PI/180); m_mappingMatrix[3] = cos(rotationAngle*M_PI/180); + + if (sensor()->isFeatureSupported(QSensor::AxesOrientation)) + sensor()->setCurrentOrientation(rotationAngle); +} + +int BbSensorBackendBase::orientationForRemapping() const +{ + if (!sensor()->isFeatureSupported(QSensor::AxesOrientation)) + return 0; + + switch (sensor()->axesOrientationMode()) { + default: + case QSensor::FixedOrientation: return 0; + case QSensor::AutomaticOrientation: return guiHelper()->currentOrientation(); + case QSensor::UserOrientation: return sensor()->userOrientation(); + } } diff --git a/src/plugins/sensors/blackberry/bbsensorbackend.h b/src/plugins/sensors/blackberry/bbsensorbackend.h index cd9a0e2..48a7216 100644 --- a/src/plugins/sensors/blackberry/bbsensorbackend.h +++ b/src/plugins/sensors/blackberry/bbsensorbackend.h @@ -75,8 +75,8 @@ public: protected: BbGuiHelper *guiHelper() const; QFile& deviceFile(); - sensor_type_e sensorType() const; + int orientationForRemapping() const; void setDevice(const QString &deviceFile, sensor_type_e sensorType); diff --git a/src/sensors/qsensor.cpp b/src/sensors/qsensor.cpp index f93ef88..125d592 100644 --- a/src/sensors/qsensor.cpp +++ b/src/sensors/qsensor.cpp @@ -176,6 +176,40 @@ void QSensorPrivate::init(const QByteArray &sensorType) The sensor data is delivered via QSensorReading and its sub-classes. + \section1 Orientation + + Some sensors react to screen orientation changes, such as QAccelerometer, QMagnetometer and + QRotationSensor. These are so called \e orientable sensors. For orientable sensors, + QSensor supports changing the reporting of the reading values based on the orientation of the + screen. + + For orientable sensors, the axesOrientationMode property controls how the orientation affects + the reading values. + + In the default mode, QSensor::FixedOrientation, the reading values remain + unaffected by the orientation. In the QSensor::AutomaticOrientation mode, the reading + values are automatically rotated by taking the current screen orientation into account. And + finally, in the QSensor::UserOrientation mode, the reading values are rotated + according to a user-specified orientation. + + The functionality of this is only available if it is supported by the backend and if the sensor + is orientable, which can be checked by calling QSensor::isFeatureSupported() + with the QSensor::AxesOrientation flag. + + The orientation values here are always of the screen orientation, not the device orientation. + The screen orientation is the orientation of the GUI. For example when rotating a device by 90 + degrees counter-clockwise, the screen orientation compensates for that by rotating 90 degrees + clockwise, to the effect that the GUI is still facing upright after the device has been rotated. + Note that applications can lock the screen orientation, for example to force portrait or landscape + mode. For locked orientations, orientable sensors will not react with reading changes if the device + orientation is changed, as orientable sensors react to screen orientation changes only. This makes + sense, as the purpose of orientable sensors is to keep the sensor orientation in sync with the screen + orientation. + + The orientation values range from 0 to 270 degrees. The orientation is applied in clockwise direction, + e.g. an orientation value of 90 degrees means that the screen has been rotated 90 degress to the right + from its origin position, to compensate a device rotation of 90 degrees to the left. + \sa QSensorReading */ @@ -208,6 +242,11 @@ void QSensorPrivate::init(const QByteArray &sensorType) \value AccelerationMode The backend supports switching the acceleration mode of the acceleromter with the QAccelerometer::accelerationMode property. + The features of all orientable sensors are: + + \value AxesOrientation The backend supports changing the axes orientation from the default of + QSensor::FixedOrientation to something else. + \omitvalue Reserved \sa QSensor::isFeatureSupported() @@ -815,6 +854,142 @@ int QSensor::error() const return d->error; } +/*! + \enum QSensor::AxesOrientationMode + \since 5.1 + + Describes how reading values are affected by the screen orientation. + + \value FixedOrientation No automatic rotation is applied to the reading values. + + \value AutomaticOrientation The reading values are automatically rotated based on the screen + orientation. + + \value UserOrientation The reading values are rotated based on the angle of the userOrientation property. + + \sa QSensor::axesOrientationMode +*/ + +/*! + \property QSensor::axesOrientationMode + \since 5.1 + \brief The mode that affects how the screen orientation changes reading values. + + When set to FixedOrientation, which is the default mode, no automatic rotation is applied to + the reading. This is the only mode available for backends that do not support the + QSensor::AxesOrientation feature. + + When set to AutomaticOrientation, the reading values are automatically rotated when the + screen orientation changes. In effect, the screen orientation is canceled out. + + As an example, assume the device is rotated by 180 degrees and therefore the screen orientation + also is rotated by 180 degrees from the native orientation. Without automatic axes orientation, + the reading values would now be changed: Both the X and the Y values would be negated, forcing + an application developer to manually cancel out the negation in application code. Automatic + axes orientation does this automatically, in this mode the X and Y values would be the same as + with the default screen orientation. + + This automatic rotation of the axes is handy is some usecases, for example in a bubble level + application that measures how level a surface is by looking at the X axis value of an + accelerometer. When the device and screen orientation change by 90 degrees, an application + developer does not need to change anything, he can continue using the X axis value even though + the device is rotated. Without automatic axes orientation, the application developer would need + to look at the Y values instead, thereby adding code to the application that reads from a + different axis depending on the screen orientation. + + The UserOrientation mode is quite similar to AutomaticOrientation, only that the screen orientation + is manually controlled instead of automatically determined. The angle of the userOrientation + property is then used for rotating the reading values. + + Since the rotation of the reading values is based on the screen orientation, Z values will never + change, as the Z axis is perpendicular to the screen. + As screen orientation changes in 90 degree steps, rotating the reading values is also done in + steps of 90 degrees. + + This property is only used for orientable sensors. +*/ + +QSensor::AxesOrientationMode QSensor::axesOrientationMode() const +{ + Q_D(const QSensor); + return d->axesOrientationMode; +} + +void QSensor::setAxesOrientationMode(QSensor::AxesOrientationMode axesOrientationMode) +{ + Q_D(QSensor); + if (d->axesOrientationMode != axesOrientationMode) { + d->axesOrientationMode = axesOrientationMode; + emit axesOrientationModeChanged(axesOrientationMode); + } +} + +/*! + \property QSensor::currentOrientation + \since 5.1 + \brief The current orientation that is used for rotating the reading values. + + This might not be the same as the screen orientation. For example, in the FixedOrientation mode, + the reading values are not rotated, and therefore the property is 0. + + In the UserOrientation mode, the readings are rotated based on the userOrientation property, + and therefore this property is equal to the userOrientation property. + + In the AutomaticOrientation mode, the readings are rotated based on the screen orientation, + and therefore this property will be equal to the current screen orientation. + + This property is set by the backend and only valid for orientable sensors. +*/ + +int QSensor::currentOrientation() const +{ + Q_D(const QSensor); + return d->currentOrientation; +} + +/*! + \since 5.1 + Sets the current screen orientation to \a currentOrientation. This is to be called from the + backend whenever the screen orientation or the userOrientation property changes. +*/ +void QSensor::setCurrentOrientation(int currentOrientation) +{ + Q_D(QSensor); + if (d->currentOrientation != currentOrientation) { + d->currentOrientation = currentOrientation; + emit currentOrientationChanged(currentOrientation); + } +} + +/*! + \property QSensor::userOrientation + \since 5.1 + \brief The angle used for rotating the reading values in the UserOrientation mode. + + When the axesOrientationMode property is set to UserOrientation, the angle for rotating the + reading values is taken from this property. In other modes, the property has no effect. + + The default is 0. The only valid values are 0, 90, 180 and 270, as those are the only possible + screen orientations. + + This property is only valid for orientable sensors. +*/ + +int QSensor::userOrientation() const +{ + Q_D(const QSensor); + return d->userOrientation; +} + +void QSensor::setUserOrientation(int userOrientation) +{ + Q_D(QSensor); + if (d->userOrientation != userOrientation) { + d->userOrientation = userOrientation; + emit userOrientationChanged(userOrientation); + } +} + /*! \fn QSensor::sensorError(int error) diff --git a/src/sensors/qsensor.h b/src/sensors/qsensor.h index f716275..45d1aa3 100644 --- a/src/sensors/qsensor.h +++ b/src/sensors/qsensor.h @@ -80,6 +80,7 @@ class Q_SENSORS_EXPORT QSensor : public QObject Q_OBJECT Q_ENUMS(Feature) + Q_ENUMS(AxesOrientationMode) Q_PROPERTY(QByteArray identifier READ identifier WRITE setIdentifier) Q_PROPERTY(QByteArray type READ type) Q_PROPERTY(bool connectedToBackend READ isConnectedToBackend) @@ -94,6 +95,9 @@ class Q_SENSORS_EXPORT QSensor : public QObject Q_PROPERTY(int error READ error NOTIFY sensorError) Q_PROPERTY(bool alwaysOn READ isAlwaysOn WRITE setAlwaysOn NOTIFY alwaysOnChanged REVISION 1) Q_PROPERTY(bool skipDuplicates READ skipDuplicates WRITE setSkipDuplicates NOTIFY skipDuplicatesChanged) + Q_PROPERTY(AxesOrientationMode axesOrientationMode READ axesOrientationMode WRITE setAxesOrientationMode NOTIFY axesOrientationModeChanged) + Q_PROPERTY(int currentOrientation READ currentOrientation NOTIFY currentOrientationChanged) + Q_PROPERTY(int userOrientation READ userOrientation WRITE setUserOrientation NOTIFY userOrientationChanged) #ifdef Q_QDOC Q_PROPERTY(int maxBufferSize) Q_PROPERTY(int efficientBufferSize) @@ -107,9 +111,17 @@ public: FieldOfView, AccelerationMode, SkipDuplicates, + AxesOrientation, Reserved = 257 // Make sure at least 2 bytes are used for the enum to avoid breaking BC later }; + // Keep in sync with QmlSensor::AxesOrientationMode + enum AxesOrientationMode { + FixedOrientation, + AutomaticOrientation, + UserOrientation + }; + explicit QSensor(const QByteArray &type, QObject *parent = 0); virtual ~QSensor(); @@ -159,6 +171,15 @@ public: Q_INVOKABLE bool isFeatureSupported(Feature feature) const; + AxesOrientationMode axesOrientationMode() const; + void setAxesOrientationMode(AxesOrientationMode axesOrientationMode); + + int currentOrientation() const; + void setCurrentOrientation(int currentOrientation); + + int userOrientation() const; + void setUserOrientation(int userOrientation); + public Q_SLOTS: // Start receiving values from the sensor bool start(); @@ -175,6 +196,9 @@ Q_SIGNALS: void alwaysOnChanged(); void dataRateChanged(); void skipDuplicatesChanged(bool skipDuplicates); + void axesOrientationModeChanged(AxesOrientationMode axesOrientationMode); + void currentOrientationChanged(int currentOrientation); + void userOrientationChanged(int userOrientation); protected: explicit QSensor(const QByteArray &type, QSensorPrivate &dd, QObject* parent = 0); diff --git a/src/sensors/qsensor_p.h b/src/sensors/qsensor_p.h index 8504a3f..041e4ba 100644 --- a/src/sensors/qsensor_p.h +++ b/src/sensors/qsensor_p.h @@ -80,6 +80,9 @@ public: , error(0) , alwaysOn(false) , skipDuplicates(false) + , axesOrientationMode(QSensor::FixedOrientation) + , currentOrientation(0) + , userOrientation(0) { } @@ -110,6 +113,10 @@ public: bool alwaysOn; bool skipDuplicates; + + QSensor::AxesOrientationMode axesOrientationMode; + int currentOrientation; + int userOrientation; }; class QSensorReadingPrivate -- cgit v1.2.1 From 3b592cc270dfb124056c526a9a7784ff19edd028 Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Wed, 9 Jan 2013 11:00:35 +0100 Subject: Add QHolsterSensor This adds a new QHolsterSensor plus the assorted reading and filter classes, as well as a QML API. Also implement the Blackberry backend for it. Change-Id: I42e76c21ee74a39a65629e7ab6d9a18f23eae4d4 Reviewed-by: Thomas McGuire --- .gitignore | 1 + config.tests/bbsensor_holster/bbsensor_holster.pro | 4 + config.tests/bbsensor_holster/main.cpp | 57 ++++++++ qtsensors.pro | 1 + src/imports/sensors/plugins.qmltypes | 11 ++ src/imports/sensors/qmlholstersensor.cpp | 133 ++++++++++++++++++ src/imports/sensors/qmlholstersensor.h | 88 ++++++++++++ src/imports/sensors/sensors.cpp | 3 + src/imports/sensors/sensors.pro | 2 + src/plugins/sensors/blackberry/bbholstersensor.cpp | 58 ++++++++ src/plugins/sensors/blackberry/bbholstersensor.h | 60 +++++++++ src/plugins/sensors/blackberry/blackberry.pro | 9 ++ src/plugins/sensors/blackberry/main.cpp | 14 ++ src/sensors/doc/src/compatmap.qdoc | 6 + src/sensors/qholstersensor.cpp | 148 +++++++++++++++++++++ src/sensors/qholstersensor.h | 88 ++++++++++++ src/sensors/qholstersensor_p.h | 72 ++++++++++ src/sensors/sensors.pro | 1 + tests/auto/qsensor/test_backends.h | 4 + tests/auto/qsensor/tst_qsensor.cpp | 4 + 20 files changed, 764 insertions(+) create mode 100644 config.tests/bbsensor_holster/bbsensor_holster.pro create mode 100644 config.tests/bbsensor_holster/main.cpp create mode 100644 src/imports/sensors/qmlholstersensor.cpp create mode 100644 src/imports/sensors/qmlholstersensor.h create mode 100644 src/plugins/sensors/blackberry/bbholstersensor.cpp create mode 100644 src/plugins/sensors/blackberry/bbholstersensor.h create mode 100644 src/sensors/qholstersensor.cpp create mode 100644 src/sensors/qholstersensor.h create mode 100644 src/sensors/qholstersensor_p.h diff --git a/.gitignore b/.gitignore index 11a723e..6bbb56a 100644 --- a/.gitignore +++ b/.gitignore @@ -95,6 +95,7 @@ examples/sensors/shakeit/shakeit # Generated config test binaries config.tests/bbsensor_compass/bbsensor_compass config.tests/bbsensor_header/bbsensor_header +config.tests/bbsensor_holster/bbsensor_holster # Directories to ignore # --------------------- diff --git a/config.tests/bbsensor_holster/bbsensor_holster.pro b/config.tests/bbsensor_holster/bbsensor_holster.pro new file mode 100644 index 0000000..349130a --- /dev/null +++ b/config.tests/bbsensor_holster/bbsensor_holster.pro @@ -0,0 +1,4 @@ +TEMPLATE = app +SOURCES += main.cpp +CONFIG += qt +requires(blackberry) diff --git a/config.tests/bbsensor_holster/main.cpp b/config.tests/bbsensor_holster/main.cpp new file mode 100644 index 0000000..52dde46 --- /dev/null +++ b/config.tests/bbsensor_holster/main.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#ifndef Q_OS_BLACKBERRY +#error "Missing Q_OS_BLACKBERRY" +#endif +#include + +int main(int argc, char** argv) +{ + Q_UNUSED(argc); + Q_UNUSED(argv); + sensor_event_t event; + const int type = SENSOR_TYPE_HOLSTER; + const bool holstered = event.holster_s.holstered; + Q_UNUSED(type); + Q_UNUSED(holstered); + return 0; +} diff --git a/qtsensors.pro b/qtsensors.pro index 0c706b2..7744173 100644 --- a/qtsensors.pro +++ b/qtsensors.pro @@ -2,6 +2,7 @@ load(configure) blackberry { qtCompileTest(bbsensor_header) qtCompileTest(bbsensor_compass) + qtCompileTest(bbsensor_holster) } load(qt_parts) diff --git a/src/imports/sensors/plugins.qmltypes b/src/imports/sensors/plugins.qmltypes index 94db26d..541384a 100644 --- a/src/imports/sensors/plugins.qmltypes +++ b/src/imports/sensors/plugins.qmltypes @@ -69,6 +69,17 @@ Module { Property { name: "y"; type: "double"; isReadonly: true } Property { name: "z"; type: "double"; isReadonly: true } } + Component { + name: "QmlHolsterReading" + prototype: "QmlSensorReading" + exports: ["HolsterReading 5.1"] + Property { name: "holstered"; type: "bool"; isReadonly: true } + } + Component { + name: "QmlHolsterSensor" + prototype: "QmlSensor" + exports: ["HolsterSensor 5.1"] + } Component { name: "QmlIRProximitySensor" prototype: "QmlSensor" diff --git a/src/imports/sensors/qmlholstersensor.cpp b/src/imports/sensors/qmlholstersensor.cpp new file mode 100644 index 0000000..a1eae05 --- /dev/null +++ b/src/imports/sensors/qmlholstersensor.cpp @@ -0,0 +1,133 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qmlholstersensor.h" +#include + +/*! + \qmltype HolsterSensor + \instantiates QmlHolsterSensor + \ingroup qml-sensors_type + \inqmlmodule QtSensors 5.0 + \since QtSensors 5.1 + \inherits Sensor + \brief The HolsterSensor element reports on whether a device is holstered. + + The HolsterSensor element reports on whether a device is holstered. + + This element wraps the QHolsterSensor class. Please see the documentation for + QHolsterSensor for details. + + \sa HolsterReading +*/ + +QmlHolsterSensor::QmlHolsterSensor(QObject *parent) + : QmlSensor(parent) + , m_sensor(new QHolsterSensor(this)) +{ +} + +QmlHolsterSensor::~QmlHolsterSensor() +{ +} + +QmlSensorReading *QmlHolsterSensor::createReading() const +{ + return new QmlHolsterReading(m_sensor); +} + +QSensor *QmlHolsterSensor::sensor() const +{ + return m_sensor; +} + +/*! + \qmltype HolsterReading + \instantiates QmlHolsterReading + \ingroup qml-sensors_reading + \inqmlmodule QtSensors 5.0 + \since QtSensors 5.1 + \inherits SensorReading + \brief The HolsterReading element holds the most recent HolsterSensor reading. + + The HolsterReading element holds the most recent HolsterSensor reading. + + This element wraps the QHolsterReading class. Please see the documentation for + QHolsterReading for details. + + This element cannot be directly created. +*/ + +QmlHolsterReading::QmlHolsterReading(QHolsterSensor *sensor) + : QmlSensorReading(sensor) + , m_sensor(sensor) + , m_holstered(false) +{ +} + +QmlHolsterReading::~QmlHolsterReading() +{ +} + +/*! + \qmlproperty qreal HolsterReading::holstered + This property holds whether the device is holstered. + + Please see QHolsterReading::holstered for information about this property. +*/ + +bool QmlHolsterReading::holstered() const +{ + return m_holstered; +} + +QSensorReading *QmlHolsterReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlHolsterReading::readingUpdate() +{ + qreal holstered = m_sensor->reading()->holstered(); + if (m_holstered != holstered) { + m_holstered = holstered; + Q_EMIT holsteredChanged(); + } +} diff --git a/src/imports/sensors/qmlholstersensor.h b/src/imports/sensors/qmlholstersensor.h new file mode 100644 index 0000000..95c7bfa --- /dev/null +++ b/src/imports/sensors/qmlholstersensor.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QMLHOLSTERSENSOR_H +#define QMLHOLSTERSENSOR_H + +#include "qmlsensor.h" + +QT_BEGIN_HEADER +QT_BEGIN_NAMESPACE + +class QHolsterSensor; + +class QmlHolsterSensor : public QmlSensor +{ + Q_OBJECT +public: + explicit QmlHolsterSensor(QObject *parent = 0); + ~QmlHolsterSensor(); + +private: + QSensor *sensor() const Q_DECL_OVERRIDE; + QmlSensorReading *createReading() const Q_DECL_OVERRIDE; + + QHolsterSensor *m_sensor; +}; + +class QmlHolsterReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(bool holstered READ holstered NOTIFY holsteredChanged) +public: + explicit QmlHolsterReading(QHolsterSensor *sensor); + ~QmlHolsterReading(); + + bool holstered() const; + +Q_SIGNALS: + void holsteredChanged(); + +private: + QSensorReading *reading() const Q_DECL_OVERRIDE; + void readingUpdate() Q_DECL_OVERRIDE; + + QHolsterSensor *m_sensor; + bool m_holstered; +}; + +QT_END_NAMESPACE +QT_END_HEADER +#endif diff --git a/src/imports/sensors/sensors.cpp b/src/imports/sensors/sensors.cpp index 3f77431..52b436d 100644 --- a/src/imports/sensors/sensors.cpp +++ b/src/imports/sensors/sensors.cpp @@ -62,6 +62,7 @@ #include "qmlambientlightsensor.h" #include "qmlcompass.h" #include "qmlgyroscope.h" +#include "qmlholstersensor.h" #include "qmlirproximitysensor.h" #include "qmllightsensor.h" #include "qmlmagnetometer.h" @@ -143,6 +144,8 @@ public: qmlRegisterUncreatableType(package, major, minor, "CompassReading", QLatin1String("Cannot create CompassReading")); qmlRegisterType (package, major, minor, "Gyroscope"); qmlRegisterUncreatableType(package, major, minor, "GyroscopeReading", QLatin1String("Cannot create GyroscopeReading")); + qmlRegisterType (package, major, minor, "HolsterSensor"); + qmlRegisterUncreatableType(package, major, minor, "HolsterReading", QLatin1String("Cannot create HolsterReading")); qmlRegisterType (package, major, minor, "IRProximitySensor"); qmlRegisterUncreatableType(package, major, minor, "IRProximityReading", QLatin1String("Cannot create IRProximityReading")); qmlRegisterType (package, major, minor, "LightSensor"); diff --git a/src/imports/sensors/sensors.pro b/src/imports/sensors/sensors.pro index 8224151..102dd30 100644 --- a/src/imports/sensors/sensors.pro +++ b/src/imports/sensors/sensors.pro @@ -12,6 +12,7 @@ HEADERS += \ qmlambientlightsensor.h \ qmlcompass.h \ qmlgyroscope.h \ + qmlholstersensor.h \ qmlirproximitysensor.h \ qmllightsensor.h \ qmlmagnetometer.h \ @@ -31,6 +32,7 @@ SOURCES += sensors.cpp \ qmlambientlightsensor.cpp \ qmlcompass.cpp \ qmlgyroscope.cpp \ + qmlholstersensor.cpp \ qmlirproximitysensor.cpp \ qmllightsensor.cpp \ qmlmagnetometer.cpp \ diff --git a/src/plugins/sensors/blackberry/bbholstersensor.cpp b/src/plugins/sensors/blackberry/bbholstersensor.cpp new file mode 100644 index 0000000..53888f5 --- /dev/null +++ b/src/plugins/sensors/blackberry/bbholstersensor.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "bbholstersensor.h" + +BbHolsterSensor::BbHolsterSensor(QSensor *sensor) + : BbSensorBackend(devicePath(), SENSOR_TYPE_HOLSTER, sensor) +{ + setDescription(QLatin1String("Whether the device is holstered or not")); +} + +bool BbHolsterSensor::updateReadingFromEvent(const sensor_event_t &event, QHolsterReading *reading) +{ + reading->setHolstered(event.holster_s.holstered == 1); + return true; +} + +QString BbHolsterSensor::devicePath() +{ + return QLatin1String("/dev/sensor/holster"); +} diff --git a/src/plugins/sensors/blackberry/bbholstersensor.h b/src/plugins/sensors/blackberry/bbholstersensor.h new file mode 100644 index 0000000..b33b391 --- /dev/null +++ b/src/plugins/sensors/blackberry/bbholstersensor.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef BBHOLSTERSENSOR_H +#define BBHOLSTERSENSOR_H + +#include "bbsensorbackend.h" +#include + +class BbHolsterSensor : public BbSensorBackend +{ + Q_OBJECT + +public: + explicit BbHolsterSensor(QSensor *sensor); + + static QString devicePath(); + +protected: + bool updateReadingFromEvent(const sensor_event_t &event, QHolsterReading *reading) Q_DECL_OVERRIDE; +}; + +#endif diff --git a/src/plugins/sensors/blackberry/blackberry.pro b/src/plugins/sensors/blackberry/blackberry.pro index 73027c2..902239c 100644 --- a/src/plugins/sensors/blackberry/blackberry.pro +++ b/src/plugins/sensors/blackberry/blackberry.pro @@ -12,6 +12,10 @@ config_bbsensor_compass { DEFINES += HAVE_COMPASS_SENSOR } +config_bbsensor_holster { + DEFINES += HAVE_HOLSTER_SENSOR +} + HEADERS += bbsensorbackend.h \ bbaccelerometer.h \ bbaltimeter.h \ @@ -47,4 +51,9 @@ SOURCES += bbsensorbackend.cpp \ bbutil.cpp \ main.cpp +config_bbsensor_holster { + HEADERS += bbholstersensor.h + SOURCES += bbholstersensor.cpp +} + OTHER_FILES = plugin.json diff --git a/src/plugins/sensors/blackberry/main.cpp b/src/plugins/sensors/blackberry/main.cpp index 7b4180a..91efe4b 100644 --- a/src/plugins/sensors/blackberry/main.cpp +++ b/src/plugins/sensors/blackberry/main.cpp @@ -43,6 +43,9 @@ #include "bbambientlightsensor.h" #include "bbcompass.h" #include "bbgyroscope.h" +#ifdef HAVE_HOLSTER_SENSOR +#include "bbholstersensor.h" +#endif #include "bbirproximitysensor.h" #include "bblightsensor.h" #include "bbmagnetometer.h" @@ -61,6 +64,9 @@ static const char *bbAltitmeterId = "bbAltimeter"; static const char *bbAmbientLightSensorId = "bbAmbientLightSensor"; static const char *bbCompassId = "bbCompass"; static const char *bbGyroscopeId = "bbGyroscope"; +#ifdef HAVE_HOLSTER_SENSOR +static const char *bbHolsterSensorId = "bbHolsterSensor"; +#endif static const char *bbIRProximitySensorId = "bbIRProximitySensor"; static const char *bbLightSensorId = "bbLightSensor"; static const char *bbMagnetometerId = "bbMagnetometer"; @@ -89,6 +95,10 @@ public: 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())) @@ -120,6 +130,10 @@ public: backend = new BbCompass(sensor); if (sensor->identifier() == bbGyroscopeId) backend = new BbGyroscope(sensor); +#ifdef HAVE_HOLSTER_SENSOR + if (sensor->identifier() == bbHolsterSensorId) + backend = new BbHolsterSensor(sensor); +#endif if (sensor->identifier() == bbIRProximitySensorId) backend = new BbIRProximitySensor(sensor); if (sensor->identifier() == bbLightSensorId) diff --git a/src/sensors/doc/src/compatmap.qdoc b/src/sensors/doc/src/compatmap.qdoc index 065ff79..1872452 100644 --- a/src/sensors/doc/src/compatmap.qdoc +++ b/src/sensors/doc/src/compatmap.qdoc @@ -82,6 +82,12 @@ + Holster Sensor + + + + + IR Proximity Sensor diff --git a/src/sensors/qholstersensor.cpp b/src/sensors/qholstersensor.cpp new file mode 100644 index 0000000..761910f --- /dev/null +++ b/src/sensors/qholstersensor.cpp @@ -0,0 +1,148 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include "qholstersensor_p.h" + +QT_BEGIN_NAMESPACE + +IMPLEMENT_READING(QHolsterReading) + +/*! + \class QHolsterReading + \ingroup sensors_reading + \inmodule QtSensors + \since 5.1 + + \brief The QHolsterReading class holds readings from the holster sensor. + + \section2 QHolsterReading Units + The holster sensor can detect if a device is holstered or not. A holster is a pocket, + similar to a gun holster, specifically made for the device. If the device is inside of this + pocket, it is holstered. The holster supports the device in detecting whether the device is + holstered or not. +*/ + +/*! + \property QHolsterReading::holstered + \brief A value indicating whether the device is holstered. + + \sa {QHolsterReading Units} +*/ + +bool QHolsterReading::holstered() const +{ + return d->holstered; +} + +/*! + Sets the holstered value to \a holstered. +*/ +void QHolsterReading::setHolstered(bool holstered) +{ + d->holstered = holstered; +} + +// ===================================================================== + +/*! + \class QHolsterFilter + \ingroup sensors_filter + \inmodule QtSensors + \since 5.1 + + \brief The QHolsterFilter class is a convenience wrapper around QSensorFilter. + + The only difference is that the filter() method features a pointer to QHolsterReading + instead of QSensorReading. +*/ + +/*! + \fn QHolsterFilter::filter(QHolsterReading *reading) + + Called when \a reading changes. Returns false to prevent the reading from propagating. + + \sa QSensorFilter::filter() +*/ + +char const * const QHolsterSensor::type("QHolsterSensor"); + +/*! + \class QHolsterSensor + \ingroup sensors_type + \inmodule QtSensors + \since 5.1 + + \brief The QHolsterSensor class is a convenience wrapper around QSensor. + + The only behavioural difference is that this class sets the type properly. + + This class also features a reading() function that returns a QHolsterReading instead of a QSensorReading. + + For details about how the sensor works, see \l QHolsterReading. + + \sa QHolsterReading +*/ + +/*! + Construct the sensor as a child of \a parent. +*/ +QHolsterSensor::QHolsterSensor(QObject *parent) + : QSensor(QHolsterSensor::type, parent) +{ +} + +/*! + Destroy the sensor. Stops the sensor if it has not already been stopped. +*/ +QHolsterSensor::~QHolsterSensor() +{ +} + +/*! + \fn QHolsterSensor::reading() const + + Returns the reading class for this sensor. + + \sa QSensor::reading() +*/ + +#include "moc_qholstersensor.cpp" +QT_END_NAMESPACE diff --git a/src/sensors/qholstersensor.h b/src/sensors/qholstersensor.h new file mode 100644 index 0000000..459f49b --- /dev/null +++ b/src/sensors/qholstersensor.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QHOLSTERSENSOR_H +#define QHOLSTERSENSOR_H + +#include + +QT_BEGIN_HEADER +QT_BEGIN_NAMESPACE + +QT_MODULE(QtSensors) + +class QHolsterReadingPrivate; + +class Q_SENSORS_EXPORT QHolsterReading : public QSensorReading +{ + Q_OBJECT + Q_PROPERTY(bool holstered READ holstered) + DECLARE_READING(QHolsterReading) +public: + bool holstered() const; + void setHolstered(bool holstered); +}; + +class Q_SENSORS_EXPORT QHolsterFilter : public QSensorFilter +{ +public: + virtual bool filter(QHolsterReading *reading) = 0; +private: + bool filter(QSensorReading *reading) Q_DECL_OVERRIDE + { return filter(static_cast(reading)); } +}; + +class Q_SENSORS_EXPORT QHolsterSensor : public QSensor +{ + Q_OBJECT +public: + explicit QHolsterSensor(QObject *parent = 0); + ~QHolsterSensor(); + QHolsterReading *reading() const { return static_cast(QSensor::reading()); } + static char const * const type; + +private: + Q_DISABLE_COPY(QHolsterSensor) +}; + +QT_END_NAMESPACE +QT_END_HEADER + +#endif diff --git a/src/sensors/qholstersensor_p.h b/src/sensors/qholstersensor_p.h new file mode 100644 index 0000000..e13ddef --- /dev/null +++ b/src/sensors/qholstersensor_p.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QHOLSTERSENSOR_P_H +#define QHOLSTERSENSOR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +QT_BEGIN_HEADER +QT_BEGIN_NAMESPACE + +class QHolsterReadingPrivate +{ +public: + QHolsterReadingPrivate() + : holstered(false) + { + } + + bool holstered; +}; + +QT_END_NAMESPACE +QT_END_HEADER + +#endif diff --git a/src/sensors/sensors.pro b/src/sensors/sensors.pro index 6f943ab..f58fb5d 100644 --- a/src/sensors/sensors.pro +++ b/src/sensors/sensors.pro @@ -53,6 +53,7 @@ SENSORS=\ qaccelerometer\ qambientlightsensor\ qcompass\ + qholstersensor\ qlightsensor\ qmagnetometer\ qorientationsensor\ diff --git a/tests/auto/qsensor/test_backends.h b/tests/auto/qsensor/test_backends.h index e47cfd5..a47d705 100644 --- a/tests/auto/qsensor/test_backends.h +++ b/tests/auto/qsensor/test_backends.h @@ -51,6 +51,7 @@ void unregister_test_backends(); #include #include #include +#include #include #include #include @@ -109,6 +110,9 @@ PREPARE_SENSORINTERFACE(QGyroscope, QGyroscopeReading, QGyroscopeFilter, { reading->setY(1.0); reading->setZ(1.0); }) +PREPARE_SENSORINTERFACE(QHolsterSensor, QHolsterReading, QHolsterFilter, { + reading->setHolstered(true); +}) PREPARE_SENSORINTERFACE(QLightSensor, QLightReading, QLightFilter, { reading->setLux(1.0); }) diff --git a/tests/auto/qsensor/tst_qsensor.cpp b/tests/auto/qsensor/tst_qsensor.cpp index 3dbcb68..0845924 100644 --- a/tests/auto/qsensor/tst_qsensor.cpp +++ b/tests/auto/qsensor/tst_qsensor.cpp @@ -862,6 +862,10 @@ private slots: QCOMPARE(reading->z(), 1.0); }) + TEST_SENSORINTERFACE(QHolsterSensor, QHolsterReading, { + QCOMPARE(reading->holstered(), true); + }) + TEST_SENSORINTERFACE(QLightSensor, QLightReading, { QCOMPARE(reading->lux(), 1.0); }) -- cgit v1.2.1 From a57cc59f79b1a229e0266bce25d7e9a8ae920937 Mon Sep 17 00:00:00 2001 From: Sergio Ahumada Date: Mon, 28 Jan 2013 12:22:11 +0100 Subject: Remove QT_{BEGIN,END}_HEADER macro usage The macro was made empty in qtbase/ba3dc5f3b56d1fab6fe37fe7ae08096d7dc68bcb and is no longer necessary or used. Discussed-on: http://lists.qt-project.org/pipermail/development/2013-January/009284.html Change-Id: If3f1040766e1c7de05bb8e90cd8a8a2a349bd096 Reviewed-by: Thomas McGuire --- src/imports/sensors/qmlaccelerometer.h | 2 -- src/imports/sensors/qmlambientlightsensor.h | 2 -- src/imports/sensors/qmlcompass.h | 2 -- src/imports/sensors/qmlgyroscope.h | 2 -- src/imports/sensors/qmlholstersensor.h | 2 -- src/imports/sensors/qmlirproximitysensor.h | 2 -- src/imports/sensors/qmllightsensor.h | 2 -- src/imports/sensors/qmlmagnetometer.h | 2 -- src/imports/sensors/qmlorientationsensor.h | 2 -- src/imports/sensors/qmlpressuresensor.h | 2 -- src/imports/sensors/qmlproximitysensor.h | 2 -- src/imports/sensors/qmlrotationsensor.h | 2 -- src/imports/sensors/qmlsensor.h | 2 -- src/imports/sensors/qmlsensorglobal.h | 2 -- src/imports/sensors/qmlsensorrange.h | 2 -- src/imports/sensors/qmltapsensor.h | 2 -- src/imports/sensors/qmltiltsensor.h | 2 -- src/plugins/sensors/generic/generictiltsensor.h | 2 -- src/sensors/gestures/qsensorgesture.h | 2 -- src/sensors/gestures/qsensorgesture_p.h | 2 -- src/sensors/gestures/qsensorgesturemanager.h | 2 -- src/sensors/gestures/qsensorgesturemanagerprivate_p.h | 2 -- src/sensors/gestures/qsensorgestureplugininterface.h | 2 -- src/sensors/gestures/qsensorgesturerecognizer.h | 2 -- src/sensors/qaccelerometer.h | 2 -- src/sensors/qaccelerometer_p.h | 2 -- src/sensors/qambientlightsensor.h | 2 -- src/sensors/qambientlightsensor_p.h | 2 -- src/sensors/qcompass.h | 2 -- src/sensors/qcompass_p.h | 2 -- src/sensors/qgyroscope.h | 2 -- src/sensors/qgyroscope_p.h | 2 -- src/sensors/qholstersensor.h | 2 -- src/sensors/qholstersensor_p.h | 2 -- src/sensors/qirproximitysensor.h | 2 -- src/sensors/qirproximitysensor_p.h | 2 -- src/sensors/qlightsensor.h | 2 -- src/sensors/qlightsensor_p.h | 2 -- src/sensors/qmagnetometer.h | 2 -- src/sensors/qmagnetometer_p.h | 2 -- src/sensors/qorientationsensor.h | 2 -- src/sensors/qorientationsensor_p.h | 2 -- src/sensors/qpressuresensor.h | 2 -- src/sensors/qpressuresensor_p.h | 2 -- src/sensors/qproximitysensor.h | 2 -- src/sensors/qproximitysensor_p.h | 2 -- src/sensors/qrotationsensor.h | 2 -- src/sensors/qrotationsensor_p.h | 2 -- src/sensors/qsensor.h | 2 -- src/sensors/qsensor_p.h | 2 -- src/sensors/qsensorbackend.h | 2 -- src/sensors/qsensormanager.h | 2 -- src/sensors/qsensorplugin.h | 2 -- src/sensors/qsensorsglobal.h | 2 -- src/sensors/qtapsensor.h | 2 -- src/sensors/qtapsensor_p.h | 2 -- src/sensors/qtiltsensor.h | 2 -- src/sensors/qtiltsensor_p.h | 2 -- src/sensors/sensorlog_p.h | 2 -- 59 files changed, 118 deletions(-) diff --git a/src/imports/sensors/qmlaccelerometer.h b/src/imports/sensors/qmlaccelerometer.h index b2dc671..7a9a4cd 100644 --- a/src/imports/sensors/qmlaccelerometer.h +++ b/src/imports/sensors/qmlaccelerometer.h @@ -44,7 +44,6 @@ #include "qmlsensor.h" -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QAccelerometer; @@ -107,5 +106,4 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/imports/sensors/qmlambientlightsensor.h b/src/imports/sensors/qmlambientlightsensor.h index eecb6b1..7715a39 100644 --- a/src/imports/sensors/qmlambientlightsensor.h +++ b/src/imports/sensors/qmlambientlightsensor.h @@ -45,7 +45,6 @@ #include "qmlsensor.h" #include -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QAmbientLightSensor; @@ -86,5 +85,4 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/imports/sensors/qmlcompass.h b/src/imports/sensors/qmlcompass.h index 30edbf0..76294bf 100644 --- a/src/imports/sensors/qmlcompass.h +++ b/src/imports/sensors/qmlcompass.h @@ -44,7 +44,6 @@ #include "qmlsensor.h" -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QCompass; @@ -88,5 +87,4 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/imports/sensors/qmlgyroscope.h b/src/imports/sensors/qmlgyroscope.h index c5f6c90..f6fb679 100644 --- a/src/imports/sensors/qmlgyroscope.h +++ b/src/imports/sensors/qmlgyroscope.h @@ -44,7 +44,6 @@ #include "qmlsensor.h" -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QGyroscope; @@ -92,5 +91,4 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/imports/sensors/qmlholstersensor.h b/src/imports/sensors/qmlholstersensor.h index 95c7bfa..262ba69 100644 --- a/src/imports/sensors/qmlholstersensor.h +++ b/src/imports/sensors/qmlholstersensor.h @@ -43,7 +43,6 @@ #include "qmlsensor.h" -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QHolsterSensor; @@ -84,5 +83,4 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/imports/sensors/qmlirproximitysensor.h b/src/imports/sensors/qmlirproximitysensor.h index 2b2d4c4..ec39fe8 100644 --- a/src/imports/sensors/qmlirproximitysensor.h +++ b/src/imports/sensors/qmlirproximitysensor.h @@ -44,7 +44,6 @@ #include "qmlsensor.h" -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QIRProximitySensor; @@ -83,5 +82,4 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/imports/sensors/qmllightsensor.h b/src/imports/sensors/qmllightsensor.h index 90fe0b7..de7e394 100644 --- a/src/imports/sensors/qmllightsensor.h +++ b/src/imports/sensors/qmllightsensor.h @@ -44,7 +44,6 @@ #include "qmlsensor.h" -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QLightSensor; @@ -91,5 +90,4 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/imports/sensors/qmlmagnetometer.h b/src/imports/sensors/qmlmagnetometer.h index d6c75c1..a008a36 100644 --- a/src/imports/sensors/qmlmagnetometer.h +++ b/src/imports/sensors/qmlmagnetometer.h @@ -44,7 +44,6 @@ #include "qmlsensor.h" -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QMagnetometer; @@ -99,5 +98,4 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/imports/sensors/qmlorientationsensor.h b/src/imports/sensors/qmlorientationsensor.h index d14197e..35e9d6f 100644 --- a/src/imports/sensors/qmlorientationsensor.h +++ b/src/imports/sensors/qmlorientationsensor.h @@ -45,7 +45,6 @@ #include "qmlsensor.h" #include -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QOrientationSensor; @@ -86,5 +85,4 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/imports/sensors/qmlpressuresensor.h b/src/imports/sensors/qmlpressuresensor.h index e150c7d..627915a 100644 --- a/src/imports/sensors/qmlpressuresensor.h +++ b/src/imports/sensors/qmlpressuresensor.h @@ -43,7 +43,6 @@ #include "qmlsensor.h" -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QPressureSensor; @@ -84,5 +83,4 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/imports/sensors/qmlproximitysensor.h b/src/imports/sensors/qmlproximitysensor.h index afbc3a0..17cb2f9 100644 --- a/src/imports/sensors/qmlproximitysensor.h +++ b/src/imports/sensors/qmlproximitysensor.h @@ -44,7 +44,6 @@ #include "qmlsensor.h" -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QProximitySensor; @@ -84,5 +83,4 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/imports/sensors/qmlrotationsensor.h b/src/imports/sensors/qmlrotationsensor.h index db3b62f..105b0fb 100644 --- a/src/imports/sensors/qmlrotationsensor.h +++ b/src/imports/sensors/qmlrotationsensor.h @@ -44,7 +44,6 @@ #include "qmlsensor.h" -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QRotationSensor; @@ -96,5 +95,4 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/imports/sensors/qmlsensor.h b/src/imports/sensors/qmlsensor.h index 9b8f7b7..e538ed0 100644 --- a/src/imports/sensors/qmlsensor.h +++ b/src/imports/sensors/qmlsensor.h @@ -46,7 +46,6 @@ #include #include "qmlsensorrange.h" -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QSensor; @@ -187,6 +186,5 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/imports/sensors/qmlsensorglobal.h b/src/imports/sensors/qmlsensorglobal.h index fbbd30d..cd28ffe 100644 --- a/src/imports/sensors/qmlsensorglobal.h +++ b/src/imports/sensors/qmlsensorglobal.h @@ -45,7 +45,6 @@ #include #include -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QSensor; @@ -69,6 +68,5 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/imports/sensors/qmlsensorrange.h b/src/imports/sensors/qmlsensorrange.h index 261825b..f2fcb51 100644 --- a/src/imports/sensors/qmlsensorrange.h +++ b/src/imports/sensors/qmlsensorrange.h @@ -44,7 +44,6 @@ #include -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QmlSensorRange : public QObject @@ -94,5 +93,4 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/imports/sensors/qmltapsensor.h b/src/imports/sensors/qmltapsensor.h index f9ae94b..234af27 100644 --- a/src/imports/sensors/qmltapsensor.h +++ b/src/imports/sensors/qmltapsensor.h @@ -45,7 +45,6 @@ #include "qmlsensor.h" #include -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QTapSensor; @@ -97,5 +96,4 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/imports/sensors/qmltiltsensor.h b/src/imports/sensors/qmltiltsensor.h index 9afed56..422c21d 100644 --- a/src/imports/sensors/qmltiltsensor.h +++ b/src/imports/sensors/qmltiltsensor.h @@ -45,7 +45,6 @@ #include "qmlsensor.h" #include -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QTiltSensor; @@ -90,5 +89,4 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/plugins/sensors/generic/generictiltsensor.h b/src/plugins/sensors/generic/generictiltsensor.h index 0633662..4d228bb 100644 --- a/src/plugins/sensors/generic/generictiltsensor.h +++ b/src/plugins/sensors/generic/generictiltsensor.h @@ -46,7 +46,6 @@ #include #include -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class GenericTiltSensor : public QSensorBackend, public QAccelerometerFilter @@ -77,7 +76,6 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/sensors/gestures/qsensorgesture.h b/src/sensors/gestures/qsensorgesture.h index 65d204c..6464909 100644 --- a/src/sensors/gestures/qsensorgesture.h +++ b/src/sensors/gestures/qsensorgesture.h @@ -52,7 +52,6 @@ #include -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(QtSensors) @@ -93,7 +92,6 @@ Q_SIGNALS: }; QT_END_NAMESPACE -QT_END_HEADER #endif // QSENSORGESTURE_H diff --git a/src/sensors/gestures/qsensorgesture_p.h b/src/sensors/gestures/qsensorgesture_p.h index 5bad75b..4ee19b9 100644 --- a/src/sensors/gestures/qsensorgesture_p.h +++ b/src/sensors/gestures/qsensorgesture_p.h @@ -61,7 +61,6 @@ #include "qsensorgesturemanager.h" #include -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QSensorGesturePrivate : public QObject @@ -84,6 +83,5 @@ public: QT_END_NAMESPACE -QT_END_HEADER #endif // QSENSORGESTURE_P_H diff --git a/src/sensors/gestures/qsensorgesturemanager.h b/src/sensors/gestures/qsensorgesturemanager.h index da5048a..a189ce3 100644 --- a/src/sensors/gestures/qsensorgesturemanager.h +++ b/src/sensors/gestures/qsensorgesturemanager.h @@ -48,7 +48,6 @@ #include #include -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(QtSensors) @@ -78,6 +77,5 @@ Q_SIGNALS: QT_END_NAMESPACE -QT_END_HEADER #endif // QSENSORGESTUREMANAGER_P_H diff --git a/src/sensors/gestures/qsensorgesturemanagerprivate_p.h b/src/sensors/gestures/qsensorgesturemanagerprivate_p.h index 50770c7..0994b2a 100644 --- a/src/sensors/gestures/qsensorgesturemanagerprivate_p.h +++ b/src/sensors/gestures/qsensorgesturemanagerprivate_p.h @@ -52,7 +52,6 @@ #include "qsensorgesture.h" #include "qsensorgesturerecognizer.h" -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QFactoryLoader; @@ -99,6 +98,5 @@ private slots: }; QT_END_NAMESPACE -QT_END_HEADER #endif // QSENSORGESTUREMANAGERPRIVATE_P_H diff --git a/src/sensors/gestures/qsensorgestureplugininterface.h b/src/sensors/gestures/qsensorgestureplugininterface.h index 6b6a683..71e4ecd 100644 --- a/src/sensors/gestures/qsensorgestureplugininterface.h +++ b/src/sensors/gestures/qsensorgestureplugininterface.h @@ -48,7 +48,6 @@ #include #include -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(QtSensors) @@ -68,6 +67,5 @@ public: Q_DECLARE_INTERFACE(QSensorGesturePluginInterface, "org.qt-project.QSensorGesturePluginInterface"); QT_END_NAMESPACE -QT_END_HEADER #endif // QSENSORGESTUREPLUGININTERFACE_H diff --git a/src/sensors/gestures/qsensorgesturerecognizer.h b/src/sensors/gestures/qsensorgesturerecognizer.h index bebc5ce..a951dfc 100644 --- a/src/sensors/gestures/qsensorgesturerecognizer.h +++ b/src/sensors/gestures/qsensorgesturerecognizer.h @@ -48,7 +48,6 @@ #include -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(QtSensors) @@ -84,6 +83,5 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif // QSENSORGESTURERECOGNIZER_H diff --git a/src/sensors/qaccelerometer.h b/src/sensors/qaccelerometer.h index d230eb1..ee7b037 100644 --- a/src/sensors/qaccelerometer.h +++ b/src/sensors/qaccelerometer.h @@ -44,7 +44,6 @@ #include -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(QtSensors) @@ -111,7 +110,6 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/sensors/qaccelerometer_p.h b/src/sensors/qaccelerometer_p.h index 371535b..e8023db 100644 --- a/src/sensors/qaccelerometer_p.h +++ b/src/sensors/qaccelerometer_p.h @@ -55,7 +55,6 @@ #include "qsensor_p.h" -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QAccelerometerReadingPrivate @@ -85,7 +84,6 @@ public: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/sensors/qambientlightsensor.h b/src/sensors/qambientlightsensor.h index 8b69fc2..b74e269 100644 --- a/src/sensors/qambientlightsensor.h +++ b/src/sensors/qambientlightsensor.h @@ -44,7 +44,6 @@ #include -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(QtSensors) @@ -93,7 +92,6 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/sensors/qambientlightsensor_p.h b/src/sensors/qambientlightsensor_p.h index 5faf853..c921c6b 100644 --- a/src/sensors/qambientlightsensor_p.h +++ b/src/sensors/qambientlightsensor_p.h @@ -53,7 +53,6 @@ // We mean it. // -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QAmbientLightReadingPrivate @@ -68,7 +67,6 @@ public: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/sensors/qcompass.h b/src/sensors/qcompass.h index 17b0658..0399f23 100644 --- a/src/sensors/qcompass.h +++ b/src/sensors/qcompass.h @@ -44,7 +44,6 @@ #include -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(QtSensors) @@ -87,7 +86,6 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/sensors/qcompass_p.h b/src/sensors/qcompass_p.h index 04a3b79..49da19b 100644 --- a/src/sensors/qcompass_p.h +++ b/src/sensors/qcompass_p.h @@ -53,7 +53,6 @@ // We mean it. // -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QCompassReadingPrivate @@ -70,7 +69,6 @@ public: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/sensors/qgyroscope.h b/src/sensors/qgyroscope.h index 7589c6c..d23e97f 100644 --- a/src/sensors/qgyroscope.h +++ b/src/sensors/qgyroscope.h @@ -44,7 +44,6 @@ #include -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(QtSensors) @@ -91,7 +90,6 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/sensors/qgyroscope_p.h b/src/sensors/qgyroscope_p.h index 21bcde4..a5e4276 100644 --- a/src/sensors/qgyroscope_p.h +++ b/src/sensors/qgyroscope_p.h @@ -53,7 +53,6 @@ // We mean it. // -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QGyroscopeReadingPrivate @@ -72,7 +71,6 @@ public: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/sensors/qholstersensor.h b/src/sensors/qholstersensor.h index 459f49b..63f8133 100644 --- a/src/sensors/qholstersensor.h +++ b/src/sensors/qholstersensor.h @@ -43,7 +43,6 @@ #include -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(QtSensors) @@ -83,6 +82,5 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/sensors/qholstersensor_p.h b/src/sensors/qholstersensor_p.h index e13ddef..a90613f 100644 --- a/src/sensors/qholstersensor_p.h +++ b/src/sensors/qholstersensor_p.h @@ -52,7 +52,6 @@ // We mean it. // -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QHolsterReadingPrivate @@ -67,6 +66,5 @@ public: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/sensors/qirproximitysensor.h b/src/sensors/qirproximitysensor.h index c6b8925..6c98ec3 100644 --- a/src/sensors/qirproximitysensor.h +++ b/src/sensors/qirproximitysensor.h @@ -44,7 +44,6 @@ #include -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(QtSensors) @@ -83,7 +82,6 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/sensors/qirproximitysensor_p.h b/src/sensors/qirproximitysensor_p.h index 6241b62..9b16af5 100644 --- a/src/sensors/qirproximitysensor_p.h +++ b/src/sensors/qirproximitysensor_p.h @@ -53,7 +53,6 @@ // We mean it. // -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QIRProximityReadingPrivate @@ -68,6 +67,5 @@ public: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/sensors/qlightsensor.h b/src/sensors/qlightsensor.h index 096df93..5e0bf35 100644 --- a/src/sensors/qlightsensor.h +++ b/src/sensors/qlightsensor.h @@ -44,7 +44,6 @@ #include -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(QtSensors) @@ -86,7 +85,6 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/sensors/qlightsensor_p.h b/src/sensors/qlightsensor_p.h index da84463..bd0edfc 100644 --- a/src/sensors/qlightsensor_p.h +++ b/src/sensors/qlightsensor_p.h @@ -55,7 +55,6 @@ #include "qsensor_p.h" -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QLightReadingPrivate : public QSensorReadingPrivate @@ -70,7 +69,6 @@ public: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/sensors/qmagnetometer.h b/src/sensors/qmagnetometer.h index 60e142d..d5ed288 100644 --- a/src/sensors/qmagnetometer.h +++ b/src/sensors/qmagnetometer.h @@ -44,7 +44,6 @@ #include -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(QtSensors) @@ -98,7 +97,6 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/sensors/qmagnetometer_p.h b/src/sensors/qmagnetometer_p.h index 2b42cfd..9ac824c 100644 --- a/src/sensors/qmagnetometer_p.h +++ b/src/sensors/qmagnetometer_p.h @@ -53,7 +53,6 @@ // We mean it. // -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QMagnetometerReadingPrivate @@ -74,7 +73,6 @@ public: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/sensors/qorientationsensor.h b/src/sensors/qorientationsensor.h index 641f355..3f5e4ce 100644 --- a/src/sensors/qorientationsensor.h +++ b/src/sensors/qorientationsensor.h @@ -44,7 +44,6 @@ #include -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(QtSensors) @@ -94,7 +93,6 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/sensors/qorientationsensor_p.h b/src/sensors/qorientationsensor_p.h index 09a65a7..433f3dd 100644 --- a/src/sensors/qorientationsensor_p.h +++ b/src/sensors/qorientationsensor_p.h @@ -53,7 +53,6 @@ // We mean it. // -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QOrientationReadingPrivate @@ -68,7 +67,6 @@ public: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/sensors/qpressuresensor.h b/src/sensors/qpressuresensor.h index 80c99f0..9f09245 100644 --- a/src/sensors/qpressuresensor.h +++ b/src/sensors/qpressuresensor.h @@ -43,7 +43,6 @@ #include -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(QtSensors) @@ -83,6 +82,5 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/sensors/qpressuresensor_p.h b/src/sensors/qpressuresensor_p.h index 4067ccb..1c74e7f 100644 --- a/src/sensors/qpressuresensor_p.h +++ b/src/sensors/qpressuresensor_p.h @@ -52,7 +52,6 @@ // We mean it. // -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QPressureReadingPrivate @@ -67,6 +66,5 @@ public: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/sensors/qproximitysensor.h b/src/sensors/qproximitysensor.h index efabead..9da948d 100644 --- a/src/sensors/qproximitysensor.h +++ b/src/sensors/qproximitysensor.h @@ -44,7 +44,6 @@ #include -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(QtSensors) @@ -83,7 +82,6 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/sensors/qproximitysensor_p.h b/src/sensors/qproximitysensor_p.h index 57125d5..8f951e6 100644 --- a/src/sensors/qproximitysensor_p.h +++ b/src/sensors/qproximitysensor_p.h @@ -53,7 +53,6 @@ // We mean it. // -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QProximityReadingPrivate @@ -68,7 +67,6 @@ public: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/sensors/qrotationsensor.h b/src/sensors/qrotationsensor.h index c049238..f59eadc 100644 --- a/src/sensors/qrotationsensor.h +++ b/src/sensors/qrotationsensor.h @@ -44,7 +44,6 @@ #include -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(QtSensors) @@ -91,7 +90,6 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/sensors/qrotationsensor_p.h b/src/sensors/qrotationsensor_p.h index f6ce13f..bf3aef7 100644 --- a/src/sensors/qrotationsensor_p.h +++ b/src/sensors/qrotationsensor_p.h @@ -53,7 +53,6 @@ // We mean it. // -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QRotationReadingPrivate @@ -72,7 +71,6 @@ public: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/sensors/qsensor.h b/src/sensors/qsensor.h index 45d1aa3..8e921c5 100644 --- a/src/sensors/qsensor.h +++ b/src/sensors/qsensor.h @@ -50,7 +50,6 @@ #include #include -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(QtSensors) @@ -284,7 +283,6 @@ private: QT_END_NAMESPACE -QT_END_HEADER Q_DECLARE_METATYPE(qrange) Q_DECLARE_METATYPE(qrangelist) diff --git a/src/sensors/qsensor_p.h b/src/sensors/qsensor_p.h index 041e4ba..9b6e7e5 100644 --- a/src/sensors/qsensor_p.h +++ b/src/sensors/qsensor_p.h @@ -57,7 +57,6 @@ #include "private/qobject_p.h" -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE typedef QList QFilterList; @@ -132,7 +131,6 @@ public: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/sensors/qsensorbackend.h b/src/sensors/qsensorbackend.h index fcf3624..f3ac09f 100644 --- a/src/sensors/qsensorbackend.h +++ b/src/sensors/qsensorbackend.h @@ -45,7 +45,6 @@ #include #include -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(QtSensors) @@ -94,7 +93,6 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/sensors/qsensormanager.h b/src/sensors/qsensormanager.h index c2037f7..5f24b8a 100644 --- a/src/sensors/qsensormanager.h +++ b/src/sensors/qsensormanager.h @@ -44,7 +44,6 @@ #include -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(QtSensors) @@ -77,7 +76,6 @@ protected: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/sensors/qsensorplugin.h b/src/sensors/qsensorplugin.h index bac35b8..e8f59a7 100644 --- a/src/sensors/qsensorplugin.h +++ b/src/sensors/qsensorplugin.h @@ -46,7 +46,6 @@ #include -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(QtSensors) @@ -71,7 +70,6 @@ Q_DECLARE_INTERFACE(QSensorPluginInterface, "com.nokia.Qt.QSensorPluginInterface Q_DECLARE_INTERFACE(QSensorChangesInterface, "com.nokia.Qt.QSensorChangesInterface/5.0"); QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/sensors/qsensorsglobal.h b/src/sensors/qsensorsglobal.h index bdd016f..337e398 100644 --- a/src/sensors/qsensorsglobal.h +++ b/src/sensors/qsensorsglobal.h @@ -44,7 +44,6 @@ #include -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(QtSensors) @@ -60,7 +59,6 @@ QT_MODULE(QtSensors) #endif QT_END_NAMESPACE -QT_END_HEADER #endif // QSENSORSGLOBAL_H diff --git a/src/sensors/qtapsensor.h b/src/sensors/qtapsensor.h index e8a450c..4fff773 100644 --- a/src/sensors/qtapsensor.h +++ b/src/sensors/qtapsensor.h @@ -44,7 +44,6 @@ #include -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(QtSensors) @@ -107,7 +106,6 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/sensors/qtapsensor_p.h b/src/sensors/qtapsensor_p.h index 68270e8..bc2b8e9 100644 --- a/src/sensors/qtapsensor_p.h +++ b/src/sensors/qtapsensor_p.h @@ -53,7 +53,6 @@ // We mean it. // -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QTapReadingPrivate @@ -70,7 +69,6 @@ public: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/sensors/qtiltsensor.h b/src/sensors/qtiltsensor.h index 68dcdfe..6617fb8 100644 --- a/src/sensors/qtiltsensor.h +++ b/src/sensors/qtiltsensor.h @@ -44,7 +44,6 @@ #include -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(QtSensors) @@ -91,5 +90,4 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/sensors/qtiltsensor_p.h b/src/sensors/qtiltsensor_p.h index 1494624..e8cce13 100644 --- a/src/sensors/qtiltsensor_p.h +++ b/src/sensors/qtiltsensor_p.h @@ -53,7 +53,6 @@ // We mean it. // -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QTiltReadingPrivate @@ -70,5 +69,4 @@ public: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/sensors/sensorlog_p.h b/src/sensors/sensorlog_p.h index d1cde70..f808ab2 100644 --- a/src/sensors/sensorlog_p.h +++ b/src/sensors/sensorlog_p.h @@ -53,7 +53,6 @@ // We mean it. // -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE #ifdef ENABLE_RUNTIME_SENSORLOG @@ -83,7 +82,6 @@ static bool logEnabled() #endif QT_END_NAMESPACE -QT_END_HEADER #endif -- cgit v1.2.1 From b0fd0f8a7bfcbf5cd9667d2950bccb4c059b1ad9 Mon Sep 17 00:00:00 2001 From: Sergio Ahumada Date: Mon, 28 Jan 2013 14:28:49 +0100 Subject: Don't use QT_{BEGIN,END}_HEADER macros This macro is useless from Qt 5.1 on, so: - Don't generate these macros when using make_sensor.pl - There is no need to blacklist these in qt-cpp-ignore.qdocconf Change-Id: I91b1050aaf406fb140ab9d28369992e4d08b5cd0 Reviewed-by: Thomas McGuire --- doc/config/qt-cpp-ignore.qdocconf | 2 -- src/sensors/make_sensor.pl | 6 ------ 2 files changed, 8 deletions(-) diff --git a/doc/config/qt-cpp-ignore.qdocconf b/doc/config/qt-cpp-ignore.qdocconf index 9b09a60..28c2119 100644 --- a/doc/config/qt-cpp-ignore.qdocconf +++ b/doc/config/qt-cpp-ignore.qdocconf @@ -19,9 +19,7 @@ Cpp.ignoretokens = QAXFACTORY_EXPORT \ QM_EXPORT_XML \ QT_ASCII_CAST_WARN \ QT_ASCII_CAST_WARN_CONSTRUCTOR \ - QT_BEGIN_HEADER \ QT_DESIGNER_STATIC \ - QT_END_HEADER \ QT_FASTCALL \ QT_WIDGET_PLUGIN_EXPORT \ Q_COMPAT_EXPORT \ diff --git a/src/sensors/make_sensor.pl b/src/sensors/make_sensor.pl index 4d35739..f3bb33a 100755 --- a/src/sensors/make_sensor.pl +++ b/src/sensors/make_sensor.pl @@ -97,7 +97,6 @@ if (! -e $qmlheader) { #include "qmlsensor.h" -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class '.$sensor.'; @@ -138,7 +137,6 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif '; close OUT; @@ -263,7 +261,6 @@ if (! -e $pheader) { // We mean it. // -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class '.$reading_private.' @@ -284,7 +281,6 @@ public: }; QT_END_NAMESPACE -QT_END_HEADER #endif '; @@ -300,7 +296,6 @@ if (! -e $header) { #include -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(QtSensors) @@ -340,7 +335,6 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif '; -- cgit v1.2.1 From 15ce61a7106ea112c27970c196d685eb779dd37c Mon Sep 17 00:00:00 2001 From: Sergio Ahumada Date: Mon, 28 Jan 2013 22:30:04 +0100 Subject: Remove the use of QT_MODULE() The macro was made empty in qtbase/4ecf82795de54fba530ac9c386f3afff2174edbd and is no longer necessary or used. Also, don't generate this macro when using make_sensor.pl Change-Id: I19121c9f0a1775011f1dd08b9d7d5d85336b1122 Reviewed-by: Thomas McGuire --- src/sensors/gestures/qsensorgesture.h | 2 -- src/sensors/gestures/qsensorgesturemanager.h | 2 -- src/sensors/gestures/qsensorgestureplugininterface.h | 2 -- src/sensors/gestures/qsensorgesturerecognizer.h | 2 -- src/sensors/make_sensor.pl | 2 -- src/sensors/qaccelerometer.h | 2 -- src/sensors/qambientlightsensor.h | 2 -- src/sensors/qcompass.h | 2 -- src/sensors/qgyroscope.h | 2 -- src/sensors/qholstersensor.h | 2 -- src/sensors/qirproximitysensor.h | 2 -- src/sensors/qlightsensor.h | 2 -- src/sensors/qmagnetometer.h | 2 -- src/sensors/qorientationsensor.h | 2 -- src/sensors/qpressuresensor.h | 2 -- src/sensors/qproximitysensor.h | 2 -- src/sensors/qrotationsensor.h | 2 -- src/sensors/qsensor.h | 2 -- src/sensors/qsensorbackend.h | 2 -- src/sensors/qsensormanager.h | 2 -- src/sensors/qsensorplugin.h | 2 -- src/sensors/qsensorsglobal.h | 2 -- src/sensors/qtapsensor.h | 2 -- src/sensors/qtiltsensor.h | 2 -- 24 files changed, 48 deletions(-) diff --git a/src/sensors/gestures/qsensorgesture.h b/src/sensors/gestures/qsensorgesture.h index 6464909..6c65120 100644 --- a/src/sensors/gestures/qsensorgesture.h +++ b/src/sensors/gestures/qsensorgesture.h @@ -54,8 +54,6 @@ QT_BEGIN_NAMESPACE -QT_MODULE(QtSensors) - class QSensorGesturePrivate; class Q_SENSORS_EXPORT QSensorGesture : public QObject diff --git a/src/sensors/gestures/qsensorgesturemanager.h b/src/sensors/gestures/qsensorgesturemanager.h index a189ce3..96ea971 100644 --- a/src/sensors/gestures/qsensorgesturemanager.h +++ b/src/sensors/gestures/qsensorgesturemanager.h @@ -50,8 +50,6 @@ QT_BEGIN_NAMESPACE -QT_MODULE(QtSensors) - class QSensorGestureManagerPrivate; class Q_SENSORS_EXPORT QSensorGestureManager : public QObject { diff --git a/src/sensors/gestures/qsensorgestureplugininterface.h b/src/sensors/gestures/qsensorgestureplugininterface.h index 71e4ecd..ad50eac 100644 --- a/src/sensors/gestures/qsensorgestureplugininterface.h +++ b/src/sensors/gestures/qsensorgestureplugininterface.h @@ -50,8 +50,6 @@ QT_BEGIN_NAMESPACE -QT_MODULE(QtSensors) - class QSensorGestureRecognizer; class Q_SENSORS_EXPORT QSensorGesturePluginInterface diff --git a/src/sensors/gestures/qsensorgesturerecognizer.h b/src/sensors/gestures/qsensorgesturerecognizer.h index a951dfc..c35c25b 100644 --- a/src/sensors/gestures/qsensorgesturerecognizer.h +++ b/src/sensors/gestures/qsensorgesturerecognizer.h @@ -50,8 +50,6 @@ QT_BEGIN_NAMESPACE -QT_MODULE(QtSensors) - class QSensorGestureRecognizerPrivate; class Q_SENSORS_EXPORT QSensorGestureRecognizer : public QObject { diff --git a/src/sensors/make_sensor.pl b/src/sensors/make_sensor.pl index f3bb33a..2732251 100755 --- a/src/sensors/make_sensor.pl +++ b/src/sensors/make_sensor.pl @@ -298,8 +298,6 @@ if (! -e $header) { QT_BEGIN_NAMESPACE -QT_MODULE(QtSensors) - class '.$reading_private.'; class Q_SENSORS_EXPORT '.$reading.' : public QSensorReading diff --git a/src/sensors/qaccelerometer.h b/src/sensors/qaccelerometer.h index ee7b037..4478235 100644 --- a/src/sensors/qaccelerometer.h +++ b/src/sensors/qaccelerometer.h @@ -46,8 +46,6 @@ QT_BEGIN_NAMESPACE -QT_MODULE(QtSensors) - class QAccelerometerReadingPrivate; class Q_SENSORS_EXPORT QAccelerometerReading : public QSensorReading diff --git a/src/sensors/qambientlightsensor.h b/src/sensors/qambientlightsensor.h index b74e269..3dae639 100644 --- a/src/sensors/qambientlightsensor.h +++ b/src/sensors/qambientlightsensor.h @@ -46,8 +46,6 @@ QT_BEGIN_NAMESPACE -QT_MODULE(QtSensors) - class QAmbientLightReadingPrivate; class Q_SENSORS_EXPORT QAmbientLightReading : public QSensorReading diff --git a/src/sensors/qcompass.h b/src/sensors/qcompass.h index 0399f23..8b858ff 100644 --- a/src/sensors/qcompass.h +++ b/src/sensors/qcompass.h @@ -46,8 +46,6 @@ QT_BEGIN_NAMESPACE -QT_MODULE(QtSensors) - class QCompassReadingPrivate; class Q_SENSORS_EXPORT QCompassReading : public QSensorReading diff --git a/src/sensors/qgyroscope.h b/src/sensors/qgyroscope.h index d23e97f..32c01da 100644 --- a/src/sensors/qgyroscope.h +++ b/src/sensors/qgyroscope.h @@ -46,8 +46,6 @@ QT_BEGIN_NAMESPACE -QT_MODULE(QtSensors) - class QGyroscopeReadingPrivate; class Q_SENSORS_EXPORT QGyroscopeReading : public QSensorReading diff --git a/src/sensors/qholstersensor.h b/src/sensors/qholstersensor.h index 63f8133..f44b381 100644 --- a/src/sensors/qholstersensor.h +++ b/src/sensors/qholstersensor.h @@ -45,8 +45,6 @@ QT_BEGIN_NAMESPACE -QT_MODULE(QtSensors) - class QHolsterReadingPrivate; class Q_SENSORS_EXPORT QHolsterReading : public QSensorReading diff --git a/src/sensors/qirproximitysensor.h b/src/sensors/qirproximitysensor.h index 6c98ec3..29eb49c 100644 --- a/src/sensors/qirproximitysensor.h +++ b/src/sensors/qirproximitysensor.h @@ -46,8 +46,6 @@ QT_BEGIN_NAMESPACE -QT_MODULE(QtSensors) - class QIRProximityReadingPrivate; class Q_SENSORS_EXPORT QIRProximityReading : public QSensorReading diff --git a/src/sensors/qlightsensor.h b/src/sensors/qlightsensor.h index 5e0bf35..ddfca17 100644 --- a/src/sensors/qlightsensor.h +++ b/src/sensors/qlightsensor.h @@ -46,8 +46,6 @@ QT_BEGIN_NAMESPACE -QT_MODULE(QtSensors) - class QLightReadingPrivate; class Q_SENSORS_EXPORT QLightReading : public QSensorReading diff --git a/src/sensors/qmagnetometer.h b/src/sensors/qmagnetometer.h index d5ed288..b4ed56a 100644 --- a/src/sensors/qmagnetometer.h +++ b/src/sensors/qmagnetometer.h @@ -46,8 +46,6 @@ QT_BEGIN_NAMESPACE -QT_MODULE(QtSensors) - class QMagnetometerReadingPrivate; class Q_SENSORS_EXPORT QMagnetometerReading : public QSensorReading diff --git a/src/sensors/qorientationsensor.h b/src/sensors/qorientationsensor.h index 3f5e4ce..fa508f3 100644 --- a/src/sensors/qorientationsensor.h +++ b/src/sensors/qorientationsensor.h @@ -46,8 +46,6 @@ QT_BEGIN_NAMESPACE -QT_MODULE(QtSensors) - class QOrientationReadingPrivate; class Q_SENSORS_EXPORT QOrientationReading : public QSensorReading diff --git a/src/sensors/qpressuresensor.h b/src/sensors/qpressuresensor.h index 9f09245..50379b5 100644 --- a/src/sensors/qpressuresensor.h +++ b/src/sensors/qpressuresensor.h @@ -45,8 +45,6 @@ QT_BEGIN_NAMESPACE -QT_MODULE(QtSensors) - class QPressureReadingPrivate; class Q_SENSORS_EXPORT QPressureReading : public QSensorReading diff --git a/src/sensors/qproximitysensor.h b/src/sensors/qproximitysensor.h index 9da948d..cc8eb78 100644 --- a/src/sensors/qproximitysensor.h +++ b/src/sensors/qproximitysensor.h @@ -46,8 +46,6 @@ QT_BEGIN_NAMESPACE -QT_MODULE(QtSensors) - class QProximityReadingPrivate; class Q_SENSORS_EXPORT QProximityReading : public QSensorReading diff --git a/src/sensors/qrotationsensor.h b/src/sensors/qrotationsensor.h index f59eadc..77da31c 100644 --- a/src/sensors/qrotationsensor.h +++ b/src/sensors/qrotationsensor.h @@ -46,8 +46,6 @@ QT_BEGIN_NAMESPACE -QT_MODULE(QtSensors) - class QRotationReadingPrivate; class Q_SENSORS_EXPORT QRotationReading : public QSensorReading diff --git a/src/sensors/qsensor.h b/src/sensors/qsensor.h index 8e921c5..5c47df3 100644 --- a/src/sensors/qsensor.h +++ b/src/sensors/qsensor.h @@ -52,8 +52,6 @@ QT_BEGIN_NAMESPACE -QT_MODULE(QtSensors) - class QSensorPrivate; class QSensorBackend; class QSensorReading; diff --git a/src/sensors/qsensorbackend.h b/src/sensors/qsensorbackend.h index f3ac09f..feb05f0 100644 --- a/src/sensors/qsensorbackend.h +++ b/src/sensors/qsensorbackend.h @@ -47,8 +47,6 @@ QT_BEGIN_NAMESPACE -QT_MODULE(QtSensors) - class Q_SENSORS_EXPORT QSensorBackend : public QObject { Q_OBJECT diff --git a/src/sensors/qsensormanager.h b/src/sensors/qsensormanager.h index 5f24b8a..8fa87d1 100644 --- a/src/sensors/qsensormanager.h +++ b/src/sensors/qsensormanager.h @@ -46,8 +46,6 @@ QT_BEGIN_NAMESPACE -QT_MODULE(QtSensors) - class QSensorBackend; class QSensorBackendFactory; class QSensorPluginInterface; diff --git a/src/sensors/qsensorplugin.h b/src/sensors/qsensorplugin.h index e8f59a7..63f0ae2 100644 --- a/src/sensors/qsensorplugin.h +++ b/src/sensors/qsensorplugin.h @@ -48,8 +48,6 @@ QT_BEGIN_NAMESPACE -QT_MODULE(QtSensors) - class Q_SENSORS_EXPORT QSensorPluginInterface { public: diff --git a/src/sensors/qsensorsglobal.h b/src/sensors/qsensorsglobal.h index 337e398..496ff4a 100644 --- a/src/sensors/qsensorsglobal.h +++ b/src/sensors/qsensorsglobal.h @@ -46,8 +46,6 @@ QT_BEGIN_NAMESPACE -QT_MODULE(QtSensors) - #ifndef QT_STATIC # if defined(QT_BUILD_SENSORS_LIB) # define Q_SENSORS_EXPORT Q_DECL_EXPORT diff --git a/src/sensors/qtapsensor.h b/src/sensors/qtapsensor.h index 4fff773..af19e59 100644 --- a/src/sensors/qtapsensor.h +++ b/src/sensors/qtapsensor.h @@ -46,8 +46,6 @@ QT_BEGIN_NAMESPACE -QT_MODULE(QtSensors) - class QTapReadingPrivate; class Q_SENSORS_EXPORT QTapReading : public QSensorReading diff --git a/src/sensors/qtiltsensor.h b/src/sensors/qtiltsensor.h index 6617fb8..246a103 100644 --- a/src/sensors/qtiltsensor.h +++ b/src/sensors/qtiltsensor.h @@ -46,8 +46,6 @@ QT_BEGIN_NAMESPACE -QT_MODULE(QtSensors) - class QTiltReadingPrivate; class Q_SENSORS_EXPORT QTiltReading : public QSensorReading -- cgit v1.2.1 From e2bee30ba347f781c9fd635375040604c7270621 Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Tue, 29 Jan 2013 15:01:15 +0100 Subject: Add missing AxesOrientationMode to the QML plugin description Change-Id: I2eef34cd39243deff640e24d1debae9dab1e5310 Reviewed-by: Lorn Potter --- src/imports/sensors/plugins.qmltypes | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/imports/sensors/plugins.qmltypes b/src/imports/sensors/plugins.qmltypes index 541384a..78011ee 100644 --- a/src/imports/sensors/plugins.qmltypes +++ b/src/imports/sensors/plugins.qmltypes @@ -169,6 +169,14 @@ Module { prototype: "QObject" exports: ["Sensor 5.0", "Sensor 5.1"] exportMetaObjectRevisions: [0, 1] + Enum { + name: "AxesOrientationMode" + values: { + "FixedOrientation": 0, + "AutomaticOrientation": 1, + "UserOrientation": 2 + } + } Property { name: "identifier"; type: "string" } Property { name: "type"; type: "string"; isReadonly: true } Property { name: "connectedToBackend"; type: "bool"; isReadonly: true } -- cgit v1.2.1 From 270e896a26713cb4d7e7c5703a03413bce76e581 Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Fri, 1 Feb 2013 11:49:18 +0100 Subject: Add a QAltimeter class. Port the Blackberry backend to use it. Change-Id: I3d3bc1d6fa8b42d3d0d64bcd3245050b67a37dc7 Reviewed-by: Thomas McGuire --- src/imports/sensors/plugins.qmltypes | 11 ++ src/imports/sensors/qmlaltimeter.cpp | 133 ++++++++++++++++++++++ src/imports/sensors/qmlaltimeter.h | 86 ++++++++++++++ src/imports/sensors/sensors.cpp | 4 + src/imports/sensors/sensors.pro | 2 + src/plugins/sensors/blackberry/bbaltimeter.cpp | 27 +---- src/plugins/sensors/blackberry/bbaltimeter.h | 17 +-- src/plugins/sensors/blackberry/main.cpp | 2 +- src/sensors/doc/src/compatmap.qdoc | 6 + src/sensors/qaltimeter.cpp | 148 +++++++++++++++++++++++++ src/sensors/qaltimeter.h | 84 ++++++++++++++ src/sensors/qaltimeter_p.h | 70 ++++++++++++ src/sensors/sensors.pro | 1 + tests/auto/qsensor/test_backends.h | 4 + tests/auto/qsensor/tst_qsensor.cpp | 4 + 15 files changed, 559 insertions(+), 40 deletions(-) create mode 100644 src/imports/sensors/qmlaltimeter.cpp create mode 100644 src/imports/sensors/qmlaltimeter.h create mode 100644 src/sensors/qaltimeter.cpp create mode 100644 src/sensors/qaltimeter.h create mode 100644 src/sensors/qaltimeter_p.h diff --git a/src/imports/sensors/plugins.qmltypes b/src/imports/sensors/plugins.qmltypes index 78011ee..b6f724a 100644 --- a/src/imports/sensors/plugins.qmltypes +++ b/src/imports/sensors/plugins.qmltypes @@ -33,6 +33,17 @@ Module { Property { name: "y"; type: "double"; isReadonly: true } Property { name: "z"; type: "double"; isReadonly: true } } + Component { + name: "QmlAltimeter" + prototype: "QmlSensor" + exports: ["Altimeter 5.1"] + } + Component { + name: "QmlAltimeterReading" + prototype: "QmlSensorReading" + exports: ["AltimeterReading 5.1"] + Property { name: "altitude"; type: "double"; isReadonly: true } + } Component { name: "QmlAmbientLightSensor" prototype: "QmlSensor" diff --git a/src/imports/sensors/qmlaltimeter.cpp b/src/imports/sensors/qmlaltimeter.cpp new file mode 100644 index 0000000..abe3f92 --- /dev/null +++ b/src/imports/sensors/qmlaltimeter.cpp @@ -0,0 +1,133 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qmlaltimeter.h" +#include + +/*! + \qmltype Altimeter + \instantiates QmlAltimeter + \ingroup qml-sensors_type + \inqmlmodule QtSensors 5.0 + \since QtSensors 5.1 + \inherits Sensor + \brief The Altimeter element reports on altitude. + + The Altimeter element reports on altitude. + + This element wraps the QAltimeter class. Please see the documentation for + QAltimeter for details. + + \sa AltimeterReading +*/ + +QmlAltimeter::QmlAltimeter(QObject *parent) + : QmlSensor(parent) + , m_sensor(new QAltimeter(this)) +{ +} + +QmlAltimeter::~QmlAltimeter() +{ +} + +QmlSensorReading *QmlAltimeter::createReading() const +{ + return new QmlAltimeterReading(m_sensor); +} + +QSensor *QmlAltimeter::sensor() const +{ + return m_sensor; +} + +/*! + \qmltype AltimeterReading + \instantiates QmlAltimeterReading + \ingroup qml-sensors_reading + \inqmlmodule QtSensors 5.0 + \since QtSensors 5.1 + \inherits SensorReading + \brief The AltimeterReading element holds the most recent Altimeter reading. + + The AltimeterReading element holds the most recent Altimeter reading. + + This element wraps the QAltimeterReading class. Please see the documentation for + QAltimeterReading for details. + + This element cannot be directly created. +*/ + +QmlAltimeterReading::QmlAltimeterReading(QAltimeter *sensor) + : QmlSensorReading(sensor) + , m_sensor(sensor) + , m_altitude(0) +{ +} + +QmlAltimeterReading::~QmlAltimeterReading() +{ +} + +/*! + \qmlproperty qreal AltimeterReading::altitude + This property holds the altitude of the device. + + Please see QAltimeterReading::altitude for information about this property. +*/ + +qreal QmlAltimeterReading::altitude() const +{ + return m_altitude; +} + +QSensorReading *QmlAltimeterReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlAltimeterReading::readingUpdate() +{ + qreal altitude = m_sensor->reading()->altitude(); + if (m_altitude != altitude) { + m_altitude = altitude; + Q_EMIT altitudeChanged(); + } +} diff --git a/src/imports/sensors/qmlaltimeter.h b/src/imports/sensors/qmlaltimeter.h new file mode 100644 index 0000000..4568baa --- /dev/null +++ b/src/imports/sensors/qmlaltimeter.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QMLALTIMETER_H +#define QMLALTIMETER_H + +#include "qmlsensor.h" + +QT_BEGIN_NAMESPACE + +class QAltimeter; + +class QmlAltimeter : public QmlSensor +{ + Q_OBJECT +public: + explicit QmlAltimeter(QObject *parent = 0); + ~QmlAltimeter(); + +private: + QSensor *sensor() const Q_DECL_OVERRIDE; + QmlSensorReading *createReading() const Q_DECL_OVERRIDE; + + QAltimeter *m_sensor; +}; + +class QmlAltimeterReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal altitude READ altitude NOTIFY altitudeChanged) +public: + explicit QmlAltimeterReading(QAltimeter *sensor); + ~QmlAltimeterReading(); + + qreal altitude() const; + +Q_SIGNALS: + void altitudeChanged(); + +private: + QSensorReading *reading() const Q_DECL_OVERRIDE; + void readingUpdate() Q_DECL_OVERRIDE; + + QAltimeter *m_sensor; + qreal m_altitude; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/imports/sensors/sensors.cpp b/src/imports/sensors/sensors.cpp index 52b436d..725776e 100644 --- a/src/imports/sensors/sensors.cpp +++ b/src/imports/sensors/sensors.cpp @@ -44,6 +44,7 @@ #include #include +#include #include #include #include @@ -59,6 +60,7 @@ #include "qmlsensorglobal.h" #include "qmlsensor.h" #include "qmlaccelerometer.h" +#include "qmlaltimeter.h" #include "qmlambientlightsensor.h" #include "qmlcompass.h" #include "qmlgyroscope.h" @@ -138,6 +140,8 @@ public: qmlRegisterUncreatableType(package, major, minor, "SensorReading", QLatin1String("Cannot create SensorReading")); qmlRegisterType (package, major, minor, "Accelerometer"); qmlRegisterUncreatableType(package, major, minor, "AccelerometerReading", QLatin1String("Cannot create AccelerometerReading")); + qmlRegisterType (package, major, minor, "Altimeter"); + qmlRegisterUncreatableType(package, major, minor, "AltimeterReading", QLatin1String("Cannot create AltimeterReading")); qmlRegisterType (package, major, minor, "AmbientLightSensor"); qmlRegisterUncreatableType(package, major, minor, "AmbientLightReading", QLatin1String("Cannot create AmbientLightReading")); qmlRegisterType (package, major, minor, "Compass"); diff --git a/src/imports/sensors/sensors.pro b/src/imports/sensors/sensors.pro index 102dd30..61994b0 100644 --- a/src/imports/sensors/sensors.pro +++ b/src/imports/sensors/sensors.pro @@ -9,6 +9,7 @@ HEADERS += \ qmlsensor.h \ qmlsensorrange.h \ qmlaccelerometer.h \ + qmlaltimeter.h \ qmlambientlightsensor.h \ qmlcompass.h \ qmlgyroscope.h \ @@ -29,6 +30,7 @@ SOURCES += sensors.cpp \ qmlsensor.cpp \ qmlsensorrange.cpp \ qmlaccelerometer.cpp \ + qmlaltimeter.cpp \ qmlambientlightsensor.cpp \ qmlcompass.cpp \ qmlgyroscope.cpp \ diff --git a/src/plugins/sensors/blackberry/bbaltimeter.cpp b/src/plugins/sensors/blackberry/bbaltimeter.cpp index 07aa264..3d21ef3 100644 --- a/src/plugins/sensors/blackberry/bbaltimeter.cpp +++ b/src/plugins/sensors/blackberry/bbaltimeter.cpp @@ -40,36 +40,13 @@ ****************************************************************************/ #include "bbaltimeter.h" -class BbAltimeterReadingPrivate -{ -public: - BbAltimeterReadingPrivate() - : altitude(0) - { - } - - qreal altitude; -}; - -IMPLEMENT_READING(BbAltimeterReading) - -qreal BbAltimeterReading::altitude() const -{ - return d->altitude; -} - -void BbAltimeterReading::setAltitude(qreal altitude) -{ - d->altitude = altitude; -} - BbAltimeter::BbAltimeter(QSensor *sensor) - : BbSensorBackend(devicePath(), SENSOR_TYPE_ALTIMETER, 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) +bool BbAltimeter::updateReadingFromEvent(const sensor_event_t &event, QAltimeterReading *reading) { reading->setAltitude(event.altitude_s.altitude); return true; diff --git a/src/plugins/sensors/blackberry/bbaltimeter.h b/src/plugins/sensors/blackberry/bbaltimeter.h index 4744a3f..b369c6c 100644 --- a/src/plugins/sensors/blackberry/bbaltimeter.h +++ b/src/plugins/sensors/blackberry/bbaltimeter.h @@ -42,20 +42,9 @@ #define BBALTIMETER_H #include "bbsensorbackend.h" +#include -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 +class BbAltimeter : public BbSensorBackend { Q_OBJECT @@ -65,7 +54,7 @@ public: static QString devicePath(); protected: - bool updateReadingFromEvent(const sensor_event_t &event, BbAltimeterReading *reading) Q_DECL_OVERRIDE; + bool updateReadingFromEvent(const sensor_event_t &event, QAltimeterReading *reading) Q_DECL_OVERRIDE; }; #endif diff --git a/src/plugins/sensors/blackberry/main.cpp b/src/plugins/sensors/blackberry/main.cpp index 91efe4b..ce7aa23 100644 --- a/src/plugins/sensors/blackberry/main.cpp +++ b/src/plugins/sensors/blackberry/main.cpp @@ -88,7 +88,7 @@ public: if (sensorSupported(BbAccelerometer::devicePath())) QSensorManager::registerBackend(QAccelerometer::type, bbAccelerometerId, this); if (sensorSupported(BbAltimeter::devicePath())) - QSensorManager::registerBackend("BbAltimeter", bbAltitmeterId, this); + QSensorManager::registerBackend(QAltimeter::type, bbAltitmeterId, this); if (sensorSupported(BbAmbientLightSensor::devicePath())) QSensorManager::registerBackend(QAmbientLightSensor::type, bbAmbientLightSensorId, this); if (sensorSupported(BbCompass::devicePath())) diff --git a/src/sensors/doc/src/compatmap.qdoc b/src/sensors/doc/src/compatmap.qdoc index 1872452..67562b9 100644 --- a/src/sensors/doc/src/compatmap.qdoc +++ b/src/sensors/doc/src/compatmap.qdoc @@ -64,6 +64,12 @@ + Altimeter + + + + + Ambient Light Sensor diff --git a/src/sensors/qaltimeter.cpp b/src/sensors/qaltimeter.cpp new file mode 100644 index 0000000..6a7caa7 --- /dev/null +++ b/src/sensors/qaltimeter.cpp @@ -0,0 +1,148 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include "qaltimeter_p.h" + +QT_BEGIN_NAMESPACE + +IMPLEMENT_READING(QAltimeterReading) + +/*! + \class QAltimeterReading + \ingroup sensors_reading + \inmodule QtSensors + \since 5.1 + + \brief The QAltimeterReading class holds readings from the altimeter sensor. + + The altitude is reported in meters relative to mean sea level. + + On BlackBerry, the altimeter uses a combination of pressure and location to determine + the altitude, as using pressure alone would yield to inaccurate results due to changes + in air pressure caused by the weather. The location information is used to compensate for + the weather. This requires that the user has enabled location services in the global + settings. +*/ + +/*! + \property QAltimeterReading::altitude + \brief The altitude in meters relative to mean sea level. +*/ + +qreal QAltimeterReading::altitude() const +{ + return d->altitude; +} + +/*! + Sets the altitude to \a altitude. +*/ +void QAltimeterReading::setAltitude(qreal altitude) +{ + d->altitude = altitude; +} + +// ===================================================================== + +/*! + \class QAltimeterFilter + \ingroup sensors_filter + \inmodule QtSensors + \since 5.1 + + \brief The QAltimeterFilter class is a convenience wrapper around QSensorFilter. + + The only difference is that the filter() method features a pointer to QAltimeterReading + instead of QSensorReading. +*/ + +/*! + \fn QAltimeterFilter::filter(QAltimeterReading *reading) + + Called when \a reading changes. Returns false to prevent the reading from propagating. + + \sa QSensorFilter::filter() +*/ + +char const * const QAltimeter::type("QAltimeter"); + +/*! + \class QAltimeter + \ingroup sensors_type + \inmodule QtSensors + \since 5.1 + + \brief The QAltimeter class is a convenience wrapper around QSensor. + + The only behavioural difference is that this class sets the type properly. + + This class also features a reading() function that returns a QAltimeterReading instead of a QSensorReading. + + For details about how the sensor works, see \l QAltimeterReading. + + \sa QAltimeterReading +*/ + +/*! + Construct the sensor as a child of \a parent. +*/ +QAltimeter::QAltimeter(QObject *parent) + : QSensor(QAltimeter::type, parent) +{ +} + +/*! + Destroy the sensor. Stops the sensor if it has not already been stopped. +*/ +QAltimeter::~QAltimeter() +{ +} + +/*! + \fn QAltimeter::reading() const + + Returns the reading class for this sensor. + + \sa QSensor::reading() +*/ + +#include "moc_qaltimeter.cpp" +QT_END_NAMESPACE diff --git a/src/sensors/qaltimeter.h b/src/sensors/qaltimeter.h new file mode 100644 index 0000000..6b7d223 --- /dev/null +++ b/src/sensors/qaltimeter.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QALTIMETER_H +#define QALTIMETER_H + +#include + +QT_BEGIN_NAMESPACE + +class QAltimeterReadingPrivate; + +class Q_SENSORS_EXPORT QAltimeterReading : public QSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal altitude READ altitude) + DECLARE_READING(QAltimeterReading) +public: + qreal altitude() const; + void setAltitude(qreal altitude); +}; + +class Q_SENSORS_EXPORT QAltimeterFilter : public QSensorFilter +{ +public: + virtual bool filter(QAltimeterReading *reading) = 0; +private: + bool filter(QSensorReading *reading) Q_DECL_OVERRIDE + { return filter(static_cast(reading)); } +}; + +class Q_SENSORS_EXPORT QAltimeter : public QSensor +{ + Q_OBJECT +public: + explicit QAltimeter(QObject *parent = 0); + ~QAltimeter(); + QAltimeterReading *reading() const { return static_cast(QSensor::reading()); } + static char const * const type; + +private: + Q_DISABLE_COPY(QAltimeter) +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/sensors/qaltimeter_p.h b/src/sensors/qaltimeter_p.h new file mode 100644 index 0000000..dfc3ebd --- /dev/null +++ b/src/sensors/qaltimeter_p.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QALTIMETER_P_H +#define QALTIMETER_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +QT_BEGIN_NAMESPACE + +class QAltimeterReadingPrivate +{ +public: + QAltimeterReadingPrivate() + : altitude(0) + { + } + + qreal altitude; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/sensors/sensors.pro b/src/sensors/sensors.pro index f58fb5d..473e225 100644 --- a/src/sensors/sensors.pro +++ b/src/sensors/sensors.pro @@ -51,6 +51,7 @@ simulator { SENSORS=\ qsensor\ qaccelerometer\ + qaltimeter\ qambientlightsensor\ qcompass\ qholstersensor\ diff --git a/tests/auto/qsensor/test_backends.h b/tests/auto/qsensor/test_backends.h index a47d705..6a04df7 100644 --- a/tests/auto/qsensor/test_backends.h +++ b/tests/auto/qsensor/test_backends.h @@ -48,6 +48,7 @@ void register_test_backends(); void unregister_test_backends(); #include +#include #include #include #include @@ -98,6 +99,9 @@ PREPARE_SENSORINTERFACE(QAccelerometer, QAccelerometerReading, QAccelerometerFil reading->setY(1.0); reading->setZ(1.0); }) +PREPARE_SENSORINTERFACE(QAltimeter, QAltimeterReading, QAltimeterFilter, { + reading->setAltitude(8848); +}) PREPARE_SENSORINTERFACE(QAmbientLightSensor, QAmbientLightReading, QAmbientLightFilter, { reading->setLightLevel(QAmbientLightReading::Twilight); }) diff --git a/tests/auto/qsensor/tst_qsensor.cpp b/tests/auto/qsensor/tst_qsensor.cpp index 0845924..232590c 100644 --- a/tests/auto/qsensor/tst_qsensor.cpp +++ b/tests/auto/qsensor/tst_qsensor.cpp @@ -847,6 +847,10 @@ private slots: QCOMPARE(reading->z(), 1.0); }) + TEST_SENSORINTERFACE(QAltimeter, QAltimeterReading, { + QCOMPARE(reading->altitude(), 8848.0); + }) + TEST_SENSORINTERFACE(QAmbientLightSensor, QAmbientLightReading, { QCOMPARE(reading->lightLevel(), QAmbientLightReading::Twilight); }) -- cgit v1.2.1 From b974efa5ca4306b1b9474207317ade4da33bdbc9 Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Fri, 1 Feb 2013 10:31:57 +0100 Subject: Convert QLightSensor::fieldOfView to a proper property Change-Id: Ic6e5388e0cbc2a0045157873c05aa241ffe5e82d Reviewed-by: Lorn Potter --- src/imports/sensors/plugins.qmltypes | 4 ++++ src/imports/sensors/qmllightsensor.cpp | 10 +++------- src/imports/sensors/qmllightsensor.h | 4 +--- src/sensors/qlightsensor.cpp | 28 +++++++++++++++++++++++++++- src/sensors/qlightsensor.h | 13 ++++++++++--- src/sensors/qlightsensor_p.h | 11 +++++++++++ 6 files changed, 56 insertions(+), 14 deletions(-) diff --git a/src/imports/sensors/plugins.qmltypes b/src/imports/sensors/plugins.qmltypes index b6f724a..88f61f9 100644 --- a/src/imports/sensors/plugins.qmltypes +++ b/src/imports/sensors/plugins.qmltypes @@ -107,6 +107,10 @@ Module { prototype: "QmlSensor" exports: ["LightSensor 5.0", "LightSensor 5.1"] Property { name: "fieldOfView"; type: "double"; isReadonly: true } + Signal { + name: "fieldOfViewChanged" + Parameter { name: "fieldOfView"; type: "double" } + } } Component { name: "QmlLightSensorReading" diff --git a/src/imports/sensors/qmllightsensor.cpp b/src/imports/sensors/qmllightsensor.cpp index 1c3fed2..86126a2 100644 --- a/src/imports/sensors/qmllightsensor.cpp +++ b/src/imports/sensors/qmllightsensor.cpp @@ -63,6 +63,8 @@ QmlLightSensor::QmlLightSensor(QObject *parent) : QmlSensor(parent) , m_sensor(new QLightSensor(this)) { + connect(m_sensor, SIGNAL(fieldOfViewChanged(qreal)), + this, SIGNAL(fieldOfViewChanged(qreal))); } QmlLightSensor::~QmlLightSensor() @@ -88,13 +90,7 @@ QSensor *QmlLightSensor::sensor() const qreal QmlLightSensor::fieldOfView() const { - return m_sensor->property("fieldOfView").value(); -} - -void QmlLightSensor::_update() -{ - if (fieldOfView() != qreal()) - Q_EMIT fieldOfViewChanged(); + return m_sensor->fieldOfView(); } /*! diff --git a/src/imports/sensors/qmllightsensor.h b/src/imports/sensors/qmllightsensor.h index de7e394..e42d781 100644 --- a/src/imports/sensors/qmllightsensor.h +++ b/src/imports/sensors/qmllightsensor.h @@ -58,13 +58,11 @@ public: qreal fieldOfView() const; - Q_SIGNALS: - void fieldOfViewChanged(); + void fieldOfViewChanged(qreal fieldOfView); private: QSensor *sensor() const Q_DECL_OVERRIDE; - void _update(); QLightSensor *m_sensor; QmlSensorReading *createReading() const Q_DECL_OVERRIDE; }; diff --git a/src/sensors/qlightsensor.cpp b/src/sensors/qlightsensor.cpp index b712bb6..f02f6b1 100644 --- a/src/sensors/qlightsensor.cpp +++ b/src/sensors/qlightsensor.cpp @@ -120,7 +120,7 @@ char const * const QLightSensor::type("QLightSensor"); Construct the sensor as a child of \a parent. */ QLightSensor::QLightSensor(QObject *parent) - : QSensor(QLightSensor::type, parent) + : QSensor(QLightSensor::type, *new QLightSensorPrivate, parent) { } @@ -144,7 +144,33 @@ QLightSensor::~QLightSensor() \brief a value indicating the field of view. This is an angle that represents the field of view of the sensor. + + Not all light sensor support retrieving their field of view. For sensors + that don't support this property, the value will be 0. Whether the field of + view is supported can be checked with QSensor::isFeatureSupported() and the + QSensor::FieldOfView flag. +*/ + +qreal QLightSensor::fieldOfView() const +{ + Q_D(const QLightSensor); + return d->fieldOfView; +} + +/*! + \since 5.1 + + Sets the field of view. This is to be called from the + backend. */ +void QLightSensor::setFieldOfView(qreal fieldOfView) +{ + Q_D(QLightSensor); + if (d->fieldOfView != fieldOfView) { + d->fieldOfView = fieldOfView; + emit fieldOfViewChanged(fieldOfView); + } +} #include "moc_qlightsensor.cpp" QT_END_NAMESPACE diff --git a/src/sensors/qlightsensor.h b/src/sensors/qlightsensor.h index ddfca17..1da8449 100644 --- a/src/sensors/qlightsensor.h +++ b/src/sensors/qlightsensor.h @@ -66,19 +66,26 @@ private: bool filter(QSensorReading *reading) { return filter(static_cast(reading)); } }; +class QLightSensorPrivate; + class Q_SENSORS_EXPORT QLightSensor : public QSensor { Q_OBJECT -#ifdef Q_QDOC - Q_PROPERTY(qreal fieldOfView) -#endif + Q_PROPERTY(qreal fieldOfView READ fieldOfView NOTIFY fieldOfViewChanged) public: explicit QLightSensor(QObject *parent = 0); virtual ~QLightSensor(); QLightReading *reading() const { return static_cast(QSensor::reading()); } static char const * const type; + qreal fieldOfView() const; + void setFieldOfView(qreal fieldOfView); + +Q_SIGNALS: + void fieldOfViewChanged(qreal fieldOfView); + private: + Q_DECLARE_PRIVATE(QLightSensor) Q_DISABLE_COPY(QLightSensor) }; diff --git a/src/sensors/qlightsensor_p.h b/src/sensors/qlightsensor_p.h index bd0edfc..a9df63e 100644 --- a/src/sensors/qlightsensor_p.h +++ b/src/sensors/qlightsensor_p.h @@ -68,6 +68,17 @@ public: qreal lux; }; +class QLightSensorPrivate : public QSensorPrivate +{ +public: + QLightSensorPrivate() + : fieldOfView(0) + { + } + + qreal fieldOfView; +}; + QT_END_NAMESPACE #endif -- cgit v1.2.1 From a3f4766964022ff0dc7ea0832922c2a58ab47e82 Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Fri, 1 Feb 2013 10:10:43 +0100 Subject: Convert QTapSensor::returnDoubleTapEvents to a proper property Change-Id: I62f626a8df765a50815f3b275da8b858cb24a30d Reviewed-by: Lorn Potter --- src/imports/sensors/plugins.qmltypes | 4 ++++ src/imports/sensors/qmltapsensor.cpp | 8 ++++---- src/imports/sensors/qmltapsensor.h | 3 +-- src/sensors/qtapsensor.cpp | 18 ++++++++++++++++-- src/sensors/qtapsensor.h | 14 +++++++++++--- src/sensors/qtapsensor_p.h | 13 +++++++++++++ 6 files changed, 49 insertions(+), 11 deletions(-) diff --git a/src/imports/sensors/plugins.qmltypes b/src/imports/sensors/plugins.qmltypes index 88f61f9..86ba0ad 100644 --- a/src/imports/sensors/plugins.qmltypes +++ b/src/imports/sensors/plugins.qmltypes @@ -285,6 +285,10 @@ Module { prototype: "QmlSensor" exports: ["TapSensor 5.0", "TapSensor 5.1"] Property { name: "returnDoubleTapEvents"; type: "bool" } + Signal { + name: "returnDoubleTapEventsChanged" + Parameter { name: "returnDoubleTapEvents"; type: "bool" } + } } Component { name: "QmlTapSensorReading" diff --git a/src/imports/sensors/qmltapsensor.cpp b/src/imports/sensors/qmltapsensor.cpp index 65afcb5..8877b0b 100644 --- a/src/imports/sensors/qmltapsensor.cpp +++ b/src/imports/sensors/qmltapsensor.cpp @@ -65,6 +65,8 @@ QmlTapSensor::QmlTapSensor(QObject *parent) : QmlSensor(parent) , m_sensor(new QTapSensor(this)) { + connect(m_sensor, SIGNAL(returnDoubleTapEventsChanged(bool)), + this, SIGNAL(returnDoubleTapEventsChanged(bool))); } QmlTapSensor::~QmlTapSensor() @@ -90,14 +92,12 @@ QSensor *QmlTapSensor::sensor() const bool QmlTapSensor::returnDoubleTapEvents() const { - return m_sensor->property("returnDoubleTapEvents").toBool(); + return m_sensor->returnDoubleTapEvents(); } void QmlTapSensor::setReturnDoubleTapEvents(bool ret) { - if (m_sensor->property("returnDoubleTapEvents").toBool() == ret) return; - m_sensor->setProperty("returnDoubleTapEvents", ret); - Q_EMIT returnDoubleTapEventsChanged(); + m_sensor->setReturnDoubleTapEvents(ret); } /*! diff --git a/src/imports/sensors/qmltapsensor.h b/src/imports/sensors/qmltapsensor.h index 234af27..b0c2fa5 100644 --- a/src/imports/sensors/qmltapsensor.h +++ b/src/imports/sensors/qmltapsensor.h @@ -60,9 +60,8 @@ public: bool returnDoubleTapEvents() const; void setReturnDoubleTapEvents(bool ret); - Q_SIGNALS: - void returnDoubleTapEventsChanged(); + void returnDoubleTapEventsChanged(bool returnDoubleTapEvents); private: QSensor *sensor() const Q_DECL_OVERRIDE; diff --git a/src/sensors/qtapsensor.cpp b/src/sensors/qtapsensor.cpp index bd65196..23ec492 100644 --- a/src/sensors/qtapsensor.cpp +++ b/src/sensors/qtapsensor.cpp @@ -211,7 +211,7 @@ char const * const QTapSensor::type("QTapSensor"); Construct the sensor as a child of \a parent. */ QTapSensor::QTapSensor(QObject *parent) - : QSensor(QTapSensor::type, parent) + : QSensor(QTapSensor::type, *new QTapSensorPrivate, parent) { } @@ -240,10 +240,24 @@ QTapSensor::~QTapSensor() It is not possible to have the sensor report both single and double tap events. If both are needed the app should create 2 sensor objects. - Note that you must access this property via QObject::property() and QObject::setProperty(). The property must be set before calling start(). */ +bool QTapSensor::returnDoubleTapEvents() const +{ + Q_D(const QTapSensor); + return d->returnDoubleTapEvents; +} + +void QTapSensor::setReturnDoubleTapEvents(bool returnDoubleTapEvents) +{ + Q_D(QTapSensor); + if (d->returnDoubleTapEvents != returnDoubleTapEvents) { + d->returnDoubleTapEvents = returnDoubleTapEvents; + emit returnDoubleTapEventsChanged(returnDoubleTapEvents); + } +} + #include "moc_qtapsensor.cpp" QT_END_NAMESPACE diff --git a/src/sensors/qtapsensor.h b/src/sensors/qtapsensor.h index af19e59..f44609b 100644 --- a/src/sensors/qtapsensor.h +++ b/src/sensors/qtapsensor.h @@ -87,19 +87,27 @@ private: bool filter(QSensorReading *reading) { return filter(static_cast(reading)); } }; +class QTapSensorPrivate; + class Q_SENSORS_EXPORT QTapSensor : public QSensor { Q_OBJECT -#ifdef Q_QDOC - Q_PROPERTY(bool returnDoubleTapEvents) -#endif + Q_PROPERTY(bool returnDoubleTapEvents READ returnDoubleTapEvents WRITE setReturnDoubleTapEvents + NOTIFY returnDoubleTapEventsChanged) public: explicit QTapSensor(QObject *parent = 0); virtual ~QTapSensor(); QTapReading *reading() const { return static_cast(QSensor::reading()); } static char const * const type; + bool returnDoubleTapEvents() const; + void setReturnDoubleTapEvents(bool returnDoubleTapEvents); + +Q_SIGNALS: + void returnDoubleTapEventsChanged(bool returnDoubleTapEvents); + private: + Q_DECLARE_PRIVATE(QTapSensor); Q_DISABLE_COPY(QTapSensor); }; diff --git a/src/sensors/qtapsensor_p.h b/src/sensors/qtapsensor_p.h index bc2b8e9..6bf8147 100644 --- a/src/sensors/qtapsensor_p.h +++ b/src/sensors/qtapsensor_p.h @@ -53,6 +53,8 @@ // We mean it. // +#include "qsensor_p.h" + QT_BEGIN_NAMESPACE class QTapReadingPrivate @@ -68,6 +70,17 @@ public: bool doubleTap; }; +class QTapSensorPrivate : public QSensorPrivate +{ +public: + QTapSensorPrivate() + : returnDoubleTapEvents(true) + { + } + + bool returnDoubleTapEvents; +}; + QT_END_NAMESPACE #endif -- cgit v1.2.1 From ae6d8a286b760198705e877a5ba4c1eecc7a5e8d Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Fri, 1 Feb 2013 09:44:00 +0100 Subject: Convert QRotationSensor::hasZ to a proper property Change-Id: I32edf761653fbe9d08710703b02fb1c0183aba3e Reviewed-by: Lorn Potter --- src/imports/sensors/plugins.qmltypes | 4 ++++ src/imports/sensors/qmlrotationsensor.cpp | 3 ++- src/imports/sensors/qmlrotationsensor.h | 4 +++- .../sensors/generic/genericrotationsensor.cpp | 4 +++- src/sensors/qrotationsensor.cpp | 24 +++++++++++++++++++++- src/sensors/qrotationsensor.h | 13 +++++++++--- src/sensors/qrotationsensor_p.h | 13 ++++++++++++ 7 files changed, 58 insertions(+), 7 deletions(-) diff --git a/src/imports/sensors/plugins.qmltypes b/src/imports/sensors/plugins.qmltypes index 86ba0ad..97a2bcd 100644 --- a/src/imports/sensors/plugins.qmltypes +++ b/src/imports/sensors/plugins.qmltypes @@ -170,6 +170,10 @@ Module { prototype: "QmlSensor" exports: ["RotationSensor 5.0", "RotationSensor 5.1"] Property { name: "hasZ"; type: "bool"; isReadonly: true } + Signal { + name: "hasZChanged" + Parameter { name: "hasZ"; type: "bool" } + } } Component { name: "QmlRotationSensorReading" diff --git a/src/imports/sensors/qmlrotationsensor.cpp b/src/imports/sensors/qmlrotationsensor.cpp index e58a3f8..f182164 100644 --- a/src/imports/sensors/qmlrotationsensor.cpp +++ b/src/imports/sensors/qmlrotationsensor.cpp @@ -65,6 +65,7 @@ QmlRotationSensor::QmlRotationSensor(QObject *parent) : QmlSensor(parent) , m_sensor(new QRotationSensor(this)) { + connect(m_sensor, SIGNAL(hasZChanged(bool)), this, SIGNAL(hasZChanged(bool))); } QmlRotationSensor::~QmlRotationSensor() @@ -90,7 +91,7 @@ QSensor *QmlRotationSensor::sensor() const bool QmlRotationSensor::hasZ() const { - return m_sensor->property("hasZ").toBool(); + return m_sensor->hasZ(); } void QmlRotationSensor::_update() diff --git a/src/imports/sensors/qmlrotationsensor.h b/src/imports/sensors/qmlrotationsensor.h index 105b0fb..4d7b543 100644 --- a/src/imports/sensors/qmlrotationsensor.h +++ b/src/imports/sensors/qmlrotationsensor.h @@ -51,13 +51,15 @@ class QRotationSensor; class QmlRotationSensor : public QmlSensor { Q_OBJECT - Q_PROPERTY(bool hasZ READ hasZ) + Q_PROPERTY(bool hasZ READ hasZ NOTIFY hasZChanged) public: explicit QmlRotationSensor(QObject *parent = 0); ~QmlRotationSensor(); bool hasZ() const; +Q_SIGNALS: + void hasZChanged(bool hasZ); private: QSensor *sensor() const Q_DECL_OVERRIDE; diff --git a/src/plugins/sensors/generic/genericrotationsensor.cpp b/src/plugins/sensors/generic/genericrotationsensor.cpp index b5f80cb..0548adc 100644 --- a/src/plugins/sensors/generic/genericrotationsensor.cpp +++ b/src/plugins/sensors/generic/genericrotationsensor.cpp @@ -57,7 +57,9 @@ genericrotationsensor::genericrotationsensor(QSensor *sensor) setReading(&m_reading); setDataRates(accelerometer); - sensor->setProperty("hasZ", false); + QRotationSensor * const rotationSensor = qobject_cast(sensor); + if (rotationSensor) + rotationSensor->setHasZ(false); } void genericrotationsensor::start() diff --git a/src/sensors/qrotationsensor.cpp b/src/sensors/qrotationsensor.cpp index 9acc1cd..ea0515c 100644 --- a/src/sensors/qrotationsensor.cpp +++ b/src/sensors/qrotationsensor.cpp @@ -201,7 +201,7 @@ char const * const QRotationSensor::type("QRotationSensor"); Construct the sensor as a child of \a parent. */ QRotationSensor::QRotationSensor(QObject *parent) - : QSensor(QRotationSensor::type, parent) + : QSensor(QRotationSensor::type, *new QRotationSensorPrivate, parent) { } @@ -228,6 +228,28 @@ QRotationSensor::~QRotationSensor() Returns false if z is not available. */ +bool QRotationSensor::hasZ() const +{ + Q_D(const QRotationSensor); + return (d->hasZ); +} + +/*! + \since 5.1 + + Sets whether the z angle is available. This is to be called from the + backend. By default the hasZ property is true, so a backend only has to + call this if its rotation sensor can not report z angles. +*/ +void QRotationSensor::setHasZ(bool hasZ) +{ + Q_D(QRotationSensor); + if (d->hasZ != hasZ) { + d->hasZ = hasZ; + emit hasZChanged(hasZ); + } +} + #include "moc_qrotationsensor.cpp" QT_END_NAMESPACE diff --git a/src/sensors/qrotationsensor.h b/src/sensors/qrotationsensor.h index 77da31c..68a0d1d 100644 --- a/src/sensors/qrotationsensor.h +++ b/src/sensors/qrotationsensor.h @@ -71,19 +71,26 @@ private: bool filter(QSensorReading *reading) { return filter(static_cast(reading)); } }; +class QRotationSensorPrivate; + class Q_SENSORS_EXPORT QRotationSensor : public QSensor { Q_OBJECT -#ifdef Q_QDOC - Q_PROPERTY(bool hasZ) -#endif + Q_PROPERTY(bool hasZ READ hasZ NOTIFY hasZChanged) public: explicit QRotationSensor(QObject *parent = 0); virtual ~QRotationSensor(); QRotationReading *reading() const { return static_cast(QSensor::reading()); } static char const * const type; + bool hasZ() const; + void setHasZ(bool hasZ); + +Q_SIGNALS: + void hasZChanged(bool hasZ); + private: + Q_DECLARE_PRIVATE(QRotationSensor) Q_DISABLE_COPY(QRotationSensor) }; diff --git a/src/sensors/qrotationsensor_p.h b/src/sensors/qrotationsensor_p.h index bf3aef7..401c214 100644 --- a/src/sensors/qrotationsensor_p.h +++ b/src/sensors/qrotationsensor_p.h @@ -53,6 +53,8 @@ // We mean it. // +#include "qsensor_p.h" + QT_BEGIN_NAMESPACE class QRotationReadingPrivate @@ -70,6 +72,17 @@ public: qreal z; }; +class QRotationSensorPrivate : public QSensorPrivate +{ +public: + QRotationSensorPrivate() + : hasZ(true) + { + } + + bool hasZ; +}; + QT_END_NAMESPACE #endif -- cgit v1.2.1 From 034fda27751b506ee13caf18820d07b73b95c915 Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Fri, 1 Feb 2013 09:35:11 +0100 Subject: genericrotationsensor: Remove unused magnetometer member Change-Id: I29a3736537b0b2602f4b5ef1a3ba74e55331d24e Reviewed-by: Lorn Potter --- src/plugins/sensors/generic/genericrotationsensor.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/plugins/sensors/generic/genericrotationsensor.h b/src/plugins/sensors/generic/genericrotationsensor.h index 3475caf..ffa48ea 100644 --- a/src/plugins/sensors/generic/genericrotationsensor.h +++ b/src/plugins/sensors/generic/genericrotationsensor.h @@ -62,7 +62,6 @@ public: private: QRotationReading m_reading; QAccelerometer *accelerometer; - QMagnetometer *magnetometer; }; #endif -- cgit v1.2.1 From 2dba878107fbe290782af720981ce28ec3723e7a Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Thu, 31 Jan 2013 18:59:24 +0100 Subject: Convert QMagnetometer::returnGeoValues to a proper property Change-Id: I39cde0046e8a3fc77edbcf5c9510e2dcf6c731c7 Reviewed-by: Lorn Potter --- src/imports/sensors/plugins.qmltypes | 5 +++++ src/imports/sensors/qmlmagnetometer.cpp | 7 ++++--- src/imports/sensors/qmlmagnetometer.h | 3 +++ src/imports/sensors/qmlsensor.h | 2 ++ src/plugins/sensors/blackberry/bbmagnetometer.cpp | 4 +++- src/sensors/qmagnetometer.cpp | 18 ++++++++++++++++-- src/sensors/qmagnetometer.h | 13 ++++++++++--- src/sensors/qmagnetometer_p.h | 13 +++++++++++++ 8 files changed, 56 insertions(+), 9 deletions(-) diff --git a/src/imports/sensors/plugins.qmltypes b/src/imports/sensors/plugins.qmltypes index 97a2bcd..bd879f8 100644 --- a/src/imports/sensors/plugins.qmltypes +++ b/src/imports/sensors/plugins.qmltypes @@ -122,6 +122,11 @@ Module { name: "QmlMagnetometer" prototype: "QmlSensor" exports: ["Magnetometer 5.0", "Magnetometer 5.1"] + Property { name: "returnGeoValues"; type: "bool" } + Signal { + name: "returnGeoValuesChanged" + Parameter { name: "returnGeoValues"; type: "bool" } + } } Component { name: "QmlMagnetometerReading" diff --git a/src/imports/sensors/qmlmagnetometer.cpp b/src/imports/sensors/qmlmagnetometer.cpp index 1f95b3f..2c531f7 100644 --- a/src/imports/sensors/qmlmagnetometer.cpp +++ b/src/imports/sensors/qmlmagnetometer.cpp @@ -65,6 +65,8 @@ QmlMagnetometer::QmlMagnetometer(QObject *parent) : QmlSensor(parent) , m_sensor(new QMagnetometer(this)) { + connect(m_sensor, SIGNAL(returnGeoValuesChanged(bool)), + this, SIGNAL(returnGeoValuesChanged(bool))); } QmlMagnetometer::~QmlMagnetometer() @@ -90,13 +92,12 @@ QSensor *QmlMagnetometer::sensor() const bool QmlMagnetometer::returnGeoValues() const { - return m_sensor->property("returnGeoValues").toBool(); + return m_sensor->returnGeoValues(); } void QmlMagnetometer::setReturnGeoValues(bool geo) { - if (m_sensor->property("returnGeoValues").toBool() == geo) return; - m_sensor->setProperty("returnGeoValues", geo); + m_sensor->setReturnGeoValues(geo); } /*! diff --git a/src/imports/sensors/qmlmagnetometer.h b/src/imports/sensors/qmlmagnetometer.h index a008a36..6e5facd 100644 --- a/src/imports/sensors/qmlmagnetometer.h +++ b/src/imports/sensors/qmlmagnetometer.h @@ -51,6 +51,7 @@ class QMagnetometer; class QmlMagnetometer : public QmlSensor { Q_OBJECT + Q_PROPERTY(bool returnGeoValues READ returnGeoValues WRITE setReturnGeoValues NOTIFY returnGeoValuesChanged) public: explicit QmlMagnetometer(QObject *parent = 0); ~QmlMagnetometer(); @@ -58,6 +59,8 @@ public: bool returnGeoValues() const; void setReturnGeoValues(bool geo); +Q_SIGNALS: + void returnGeoValuesChanged(bool returnGeoValues); private: QSensor *sensor() const Q_DECL_OVERRIDE; diff --git a/src/imports/sensors/qmlsensor.h b/src/imports/sensors/qmlsensor.h index e538ed0..b68a7b9 100644 --- a/src/imports/sensors/qmlsensor.h +++ b/src/imports/sensors/qmlsensor.h @@ -154,6 +154,8 @@ protected: private Q_SLOTS: void updateReading(); + +protected Q_SLOTS: void componentComplete(); private: diff --git a/src/plugins/sensors/blackberry/bbmagnetometer.cpp b/src/plugins/sensors/blackberry/bbmagnetometer.cpp index 489a048..5ece465 100644 --- a/src/plugins/sensors/blackberry/bbmagnetometer.cpp +++ b/src/plugins/sensors/blackberry/bbmagnetometer.cpp @@ -63,7 +63,9 @@ bool BbMagnetometer::updateReadingFromEvent(const sensor_event_t &event, QMagnet reading->setY(y); reading->setZ(z); - const bool returnGeoValues = sensor()->property("returnGeoValues").toBool(); + QMagnetometer * const magnetometer = qobject_cast(sensor()); + Q_ASSERT(magnetometer); + const bool returnGeoValues = magnetometer->returnGeoValues(); if (returnGeoValues) { switch (event.accuracy) { case SENSOR_ACCURACY_UNRELIABLE: reading->setCalibrationLevel(0.0f); break; diff --git a/src/sensors/qmagnetometer.cpp b/src/sensors/qmagnetometer.cpp index 60b2df8..f5f563a 100644 --- a/src/sensors/qmagnetometer.cpp +++ b/src/sensors/qmagnetometer.cpp @@ -210,7 +210,7 @@ char const * const QMagnetometer::type("QMagnetometer"); Construct the sensor as a child of \a parent. */ QMagnetometer::QMagnetometer(QObject *parent) - : QSensor(QMagnetometer::type, parent) + : QSensor(QMagnetometer::type, *new QMagnetometerPrivate, parent) { } @@ -236,10 +236,24 @@ QMagnetometer::~QMagnetometer() Set to true to return geomagnetic flux density. Set to false (the default) to return raw magnetic flux density. - Note that you must access this property via QObject::property() and QObject::setProperty(). The property must be set before calling start(). */ +bool QMagnetometer::returnGeoValues() const +{ + Q_D(const QMagnetometer); + return d->returnGeoValues; +} + +void QMagnetometer::setReturnGeoValues(bool returnGeoValues) +{ + Q_D(QMagnetometer); + if (d->returnGeoValues != returnGeoValues) { + d->returnGeoValues = returnGeoValues; + emit returnGeoValuesChanged(returnGeoValues); + } +} + #include "moc_qmagnetometer.cpp" QT_END_NAMESPACE diff --git a/src/sensors/qmagnetometer.h b/src/sensors/qmagnetometer.h index b4ed56a..93b6157 100644 --- a/src/sensors/qmagnetometer.h +++ b/src/sensors/qmagnetometer.h @@ -78,19 +78,26 @@ private: bool filter(QSensorReading *reading) { return filter(static_cast(reading)); } }; +class QMagnetometerPrivate; + class Q_SENSORS_EXPORT QMagnetometer : public QSensor { Q_OBJECT -#ifdef Q_QDOC - Q_PROPERTY(bool returnGeoValues) -#endif + Q_PROPERTY(bool returnGeoValues READ returnGeoValues WRITE setReturnGeoValues NOTIFY returnGeoValuesChanged) public: explicit QMagnetometer(QObject *parent = 0); virtual ~QMagnetometer(); QMagnetometerReading *reading() const { return static_cast(QSensor::reading()); } static char const * const type; + bool returnGeoValues() const; + void setReturnGeoValues(bool returnGeoValues); + +Q_SIGNALS: + void returnGeoValuesChanged(bool returnGeoValues); + private: + Q_DECLARE_PRIVATE(QMagnetometer) Q_DISABLE_COPY(QMagnetometer) }; diff --git a/src/sensors/qmagnetometer_p.h b/src/sensors/qmagnetometer_p.h index 9ac824c..3c38e6c 100644 --- a/src/sensors/qmagnetometer_p.h +++ b/src/sensors/qmagnetometer_p.h @@ -53,8 +53,21 @@ // We mean it. // +#include "qsensor_p.h" + QT_BEGIN_NAMESPACE +class QMagnetometerPrivate : public QSensorPrivate +{ +public: + QMagnetometerPrivate() + : returnGeoValues(false) + { + } + + bool returnGeoValues; +}; + class QMagnetometerReadingPrivate { public: -- cgit v1.2.1 From 27cc67b75373905931448c3228e20a6c8d0797e6 Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Thu, 31 Jan 2013 18:13:12 +0100 Subject: Add a QAmbientTemperatureSensor class. Port the Blackberry backend to use it. Change-Id: I6d4395f5ab9e0ce3fb6f76c47282929103929557 Reviewed-by: Lorn Potter --- src/imports/sensors/plugins.qmltypes | 11 ++ .../sensors/qmlambienttemperaturesensor.cpp | 133 +++++++++++++++++++ src/imports/sensors/qmlambienttemperaturesensor.h | 86 ++++++++++++ src/imports/sensors/sensors.cpp | 4 + src/imports/sensors/sensors.pro | 2 + .../sensors/blackberry/bbtemperaturesensor.cpp | 27 +--- .../sensors/blackberry/bbtemperaturesensor.h | 17 +-- src/plugins/sensors/blackberry/main.cpp | 2 +- src/sensors/doc/src/compatmap.qdoc | 8 +- src/sensors/qambienttemperaturesensor.cpp | 144 +++++++++++++++++++++ src/sensors/qambienttemperaturesensor.h | 84 ++++++++++++ src/sensors/qambienttemperaturesensor_p.h | 70 ++++++++++ src/sensors/sensors.pro | 1 + tests/auto/qsensor/test_backends.h | 4 + tests/auto/qsensor/tst_qsensor.cpp | 4 + 15 files changed, 556 insertions(+), 41 deletions(-) create mode 100644 src/imports/sensors/qmlambienttemperaturesensor.cpp create mode 100644 src/imports/sensors/qmlambienttemperaturesensor.h create mode 100644 src/sensors/qambienttemperaturesensor.cpp create mode 100644 src/sensors/qambienttemperaturesensor.h create mode 100644 src/sensors/qambienttemperaturesensor_p.h diff --git a/src/imports/sensors/plugins.qmltypes b/src/imports/sensors/plugins.qmltypes index bd879f8..974f714 100644 --- a/src/imports/sensors/plugins.qmltypes +++ b/src/imports/sensors/plugins.qmltypes @@ -55,6 +55,17 @@ Module { exports: ["AmbientLightReading 5.0", "AmbientLightReading 5.1"] Property { name: "lightLevel"; type: "QAmbientLightReading::LightLevel"; isReadonly: true } } + Component { + name: "QmlAmbientTemperatureReading" + prototype: "QmlSensorReading" + exports: ["AmbientTemperatureReading 5.1"] + Property { name: "temperature"; type: "double"; isReadonly: true } + } + Component { + name: "QmlAmbientTemperatureSensor" + prototype: "QmlSensor" + exports: ["AmbientTemperatureSensor 5.1"] + } Component { name: "QmlCompass" prototype: "QmlSensor" diff --git a/src/imports/sensors/qmlambienttemperaturesensor.cpp b/src/imports/sensors/qmlambienttemperaturesensor.cpp new file mode 100644 index 0000000..1190fca --- /dev/null +++ b/src/imports/sensors/qmlambienttemperaturesensor.cpp @@ -0,0 +1,133 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qmlambienttemperaturesensor.h" +#include + +/*! + \qmltype AmbientTemperatureSensor + \instantiates QmlAmbientTemperatureSensor + \ingroup qml-sensors_type + \inqmlmodule QtSensors 5.0 + \since QtSensors 5.1 + \inherits Sensor + \brief The AmbientTemperatureSensor element reports on the ambient temperature. + + The AmbientTemperatureSensor element reports on the ambient temperature. + + This element wraps the QAmbientTemperatureSensor class. Please see the documentation for + QAmbientTemperatureSensor for details. + + \sa AmbientTemperatureReading +*/ + +QmlAmbientTemperatureSensor::QmlAmbientTemperatureSensor(QObject *parent) + : QmlSensor(parent) + , m_sensor(new QAmbientTemperatureSensor(this)) +{ +} + +QmlAmbientTemperatureSensor::~QmlAmbientTemperatureSensor() +{ +} + +QmlSensorReading *QmlAmbientTemperatureSensor::createReading() const +{ + return new QmlAmbientTemperatureReading(m_sensor); +} + +QSensor *QmlAmbientTemperatureSensor::sensor() const +{ + return m_sensor; +} + +/*! + \qmltype AmbientTemperatureReading + \instantiates QmlAmbientTemperatureReading + \ingroup qml-sensors_reading + \inqmlmodule QtSensors 5.0 + \since QtSensors 5.1 + \inherits SensorReading + \brief The AmbientTemperatureReading element holds the most recent temperature reading. + + The AmbientTemperatureReading element holds the most recent temperature reading. + + This element wraps the QAmbientTemperatureReading class. Please see the documentation for + QAmbientTemperatureReading for details. + + This element cannot be directly created. +*/ + +QmlAmbientTemperatureReading::QmlAmbientTemperatureReading(QAmbientTemperatureSensor *sensor) + : QmlSensorReading(sensor) + , m_sensor(sensor) + , m_temperature(0) +{ +} + +QmlAmbientTemperatureReading::~QmlAmbientTemperatureReading() +{ +} + +/*! + \qmlproperty qreal AmbientTemperatureReading::temperature + This property holds the ambient temperature in degree Celsius. + + Please see QAmbientTemperatureReading::temperature for information about this property. +*/ + +qreal QmlAmbientTemperatureReading::temperature() const +{ + return m_temperature; +} + +QSensorReading *QmlAmbientTemperatureReading::reading() const +{ + return m_sensor->reading(); +} + +void QmlAmbientTemperatureReading::readingUpdate() +{ + const qreal temperature = m_sensor->reading()->temperature(); + if (m_temperature != temperature) { + m_temperature = temperature; + Q_EMIT temperatureChanged(); + } +} diff --git a/src/imports/sensors/qmlambienttemperaturesensor.h b/src/imports/sensors/qmlambienttemperaturesensor.h new file mode 100644 index 0000000..1c1d8dd --- /dev/null +++ b/src/imports/sensors/qmlambienttemperaturesensor.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QMLAMBIENTTEMPERATURESENSOR_H +#define QMLAMBIENTTEMPERATURESENSOR_H + +#include "qmlsensor.h" + +QT_BEGIN_NAMESPACE + +class QAmbientTemperatureSensor; + +class QmlAmbientTemperatureSensor : public QmlSensor +{ + Q_OBJECT +public: + explicit QmlAmbientTemperatureSensor(QObject *parent = 0); + ~QmlAmbientTemperatureSensor(); + +private: + QSensor *sensor() const Q_DECL_OVERRIDE; + QmlSensorReading *createReading() const Q_DECL_OVERRIDE; + + QAmbientTemperatureSensor *m_sensor; +}; + +class QmlAmbientTemperatureReading : public QmlSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal temperature READ temperature NOTIFY temperatureChanged) +public: + explicit QmlAmbientTemperatureReading(QAmbientTemperatureSensor *sensor); + ~QmlAmbientTemperatureReading(); + + qreal temperature() const; + +Q_SIGNALS: + void temperatureChanged(); + +private: + QSensorReading *reading() const Q_DECL_OVERRIDE; + void readingUpdate() Q_DECL_OVERRIDE; + + QAmbientTemperatureSensor *m_sensor; + qreal m_temperature; +}; + +QT_END_NAMESPACE +#endif diff --git a/src/imports/sensors/sensors.cpp b/src/imports/sensors/sensors.cpp index 725776e..77ad754 100644 --- a/src/imports/sensors/sensors.cpp +++ b/src/imports/sensors/sensors.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -62,6 +63,7 @@ #include "qmlaccelerometer.h" #include "qmlaltimeter.h" #include "qmlambientlightsensor.h" +#include "qmlambienttemperaturesensor.h" #include "qmlcompass.h" #include "qmlgyroscope.h" #include "qmlholstersensor.h" @@ -144,6 +146,8 @@ public: qmlRegisterUncreatableType(package, major, minor, "AltimeterReading", QLatin1String("Cannot create AltimeterReading")); qmlRegisterType (package, major, minor, "AmbientLightSensor"); qmlRegisterUncreatableType(package, major, minor, "AmbientLightReading", QLatin1String("Cannot create AmbientLightReading")); + qmlRegisterType (package, major, minor, "AmbientTemperatureSensor"); + qmlRegisterUncreatableType(package, major, minor, "AmbientTemperatureReading", QLatin1String("Cannot create AmbientTemperatureReading")); qmlRegisterType (package, major, minor, "Compass"); qmlRegisterUncreatableType(package, major, minor, "CompassReading", QLatin1String("Cannot create CompassReading")); qmlRegisterType (package, major, minor, "Gyroscope"); diff --git a/src/imports/sensors/sensors.pro b/src/imports/sensors/sensors.pro index 61994b0..2236ce1 100644 --- a/src/imports/sensors/sensors.pro +++ b/src/imports/sensors/sensors.pro @@ -11,6 +11,7 @@ HEADERS += \ qmlaccelerometer.h \ qmlaltimeter.h \ qmlambientlightsensor.h \ + qmlambienttemperaturesensor.h \ qmlcompass.h \ qmlgyroscope.h \ qmlholstersensor.h \ @@ -32,6 +33,7 @@ SOURCES += sensors.cpp \ qmlaccelerometer.cpp \ qmlaltimeter.cpp \ qmlambientlightsensor.cpp \ + qmlambienttemperaturesensor.cpp \ qmlcompass.cpp \ qmlgyroscope.cpp \ qmlholstersensor.cpp \ diff --git a/src/plugins/sensors/blackberry/bbtemperaturesensor.cpp b/src/plugins/sensors/blackberry/bbtemperaturesensor.cpp index f3ec634..b38fba4 100644 --- a/src/plugins/sensors/blackberry/bbtemperaturesensor.cpp +++ b/src/plugins/sensors/blackberry/bbtemperaturesensor.cpp @@ -40,31 +40,8 @@ ****************************************************************************/ #include "bbtemperaturesensor.h" -class BbTemperatureReadingPrivate -{ -public: - BbTemperatureReadingPrivate() - : temperature(0) - { - } - - qreal temperature; -}; - -IMPLEMENT_READING(BbTemperatureReading) - -qreal BbTemperatureReading::temperature() const -{ - return d->temperature; -} - -void BbTemperatureReading::setTemperature(qreal temperature) -{ - d->temperature = temperature; -} - BbTemperatureSensor::BbTemperatureSensor(QSensor *sensor) - : BbSensorBackend(devicePath(), SENSOR_TYPE_TEMPERATURE, sensor) + : BbSensorBackend(devicePath(), SENSOR_TYPE_TEMPERATURE, sensor) { setDescription(QLatin1String("Temperature in degrees Celsius")); } @@ -74,7 +51,7 @@ QString BbTemperatureSensor::devicePath() return QLatin1String("/dev/sensor/temp"); } -bool BbTemperatureSensor::updateReadingFromEvent(const sensor_event_t &event, BbTemperatureReading *reading) +bool BbTemperatureSensor::updateReadingFromEvent(const sensor_event_t &event, QAmbientTemperatureReading *reading) { // TODO: I was unable to test this since the device I was testing this with did not have // a temperature sensor. Verify that this works and check that the units are correct. diff --git a/src/plugins/sensors/blackberry/bbtemperaturesensor.h b/src/plugins/sensors/blackberry/bbtemperaturesensor.h index 1b9ea1b..a24c67e 100644 --- a/src/plugins/sensors/blackberry/bbtemperaturesensor.h +++ b/src/plugins/sensors/blackberry/bbtemperaturesensor.h @@ -42,20 +42,9 @@ #define BBTEMPERATURESENSOR_H #include "bbsensorbackend.h" +#include -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 +class BbTemperatureSensor : public BbSensorBackend { Q_OBJECT @@ -65,7 +54,7 @@ public: static QString devicePath(); protected: - bool updateReadingFromEvent(const sensor_event_t &event, BbTemperatureReading *reading); + bool updateReadingFromEvent(const sensor_event_t &event, QAmbientTemperatureReading *reading); }; #endif diff --git a/src/plugins/sensors/blackberry/main.cpp b/src/plugins/sensors/blackberry/main.cpp index ce7aa23..9d8e87f 100644 --- a/src/plugins/sensors/blackberry/main.cpp +++ b/src/plugins/sensors/blackberry/main.cpp @@ -114,7 +114,7 @@ public: if (sensorSupported(BbRotationSensor::devicePath())) QSensorManager::registerBackend(QRotationSensor::type, bbRotationSensorId, this); if (sensorSupported(BbTemperatureSensor::devicePath())) - QSensorManager::registerBackend("BbTemperatureSensor", bbTemperatureSensorId, this); + QSensorManager::registerBackend(QAmbientTemperatureSensor::type, bbTemperatureSensorId, this); } QSensorBackend *createBackend(QSensor *sensor) Q_DECL_OVERRIDE diff --git a/src/sensors/doc/src/compatmap.qdoc b/src/sensors/doc/src/compatmap.qdoc index 67562b9..abb71a1 100644 --- a/src/sensors/doc/src/compatmap.qdoc +++ b/src/sensors/doc/src/compatmap.qdoc @@ -73,7 +73,13 @@ Ambient Light Sensor - + + + + Ambient Temperature Sensor + + + Compass diff --git a/src/sensors/qambienttemperaturesensor.cpp b/src/sensors/qambienttemperaturesensor.cpp new file mode 100644 index 0000000..9ecde6d --- /dev/null +++ b/src/sensors/qambienttemperaturesensor.cpp @@ -0,0 +1,144 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include "qambienttemperaturesensor_p.h" + +QT_BEGIN_NAMESPACE + +IMPLEMENT_READING(QAmbientTemperatureReading) + +/*! + \class QAmbientTemperatureReading + \ingroup sensors_reading + \inmodule QtSensors + \since 5.1 + + \brief The QAmbientTemperatureReading class holds readings of the ambient temperature. + + The ambient (room) temperature is the temperature in degree Celsius. +*/ + +/*! + \property QAmbientTemperatureReading::temperature + \brief The ambient temperature + + Measured in degree Celsius. +*/ + +qreal QAmbientTemperatureReading::temperature() const +{ + return d->temperature; +} + +/*! + Sets ambient temperature to \a temperature. +*/ +void QAmbientTemperatureReading::setTemperature(qreal temperature) +{ + d->temperature = temperature; +} + +// ===================================================================== + +/*! + \class QAmbientTemperatureFilter + \ingroup sensors_filter + \inmodule QtSensors + \since 5.1 + + \brief The QAmbientTemperatureFilter class is a convenience wrapper around QSensorFilter. + + The only difference is that the filter() method features a pointer to QAmbientTemperatureReading + instead of QSensorReading. +*/ + +/*! + \fn QAmbientTemperatureFilter::filter(QAmbientTemperatureReading *reading) + + Called when \a reading changes. Returns false to prevent the reading from propagating. + + \sa QSensorFilter::filter() +*/ + +char const * const QAmbientTemperatureSensor::type("QAmbientTemperatureSensor"); + +/*! + \class QAmbientTemperatureSensor + \ingroup sensors_type + \inmodule QtSensors + \since 5.1 + + \brief The QAmbientTemperatureSensor class is a convenience wrapper around QSensor. + + The only behavioural difference is that this class sets the type properly. + + This class also features a reading() function that returns a QAmbientTemperatureReading instead of a QSensorReading. + + For details about how the sensor works, see \l QAmbientTemperatureReading. + + \sa QAmbientTemperatureReading +*/ + +/*! + Construct the sensor as a child of \a parent. +*/ +QAmbientTemperatureSensor::QAmbientTemperatureSensor(QObject *parent) + : QSensor(QAmbientTemperatureSensor::type, parent) +{ +} + +/*! + Destroy the sensor. Stops the sensor if it has not already been stopped. +*/ +QAmbientTemperatureSensor::~QAmbientTemperatureSensor() +{ +} + +/*! + \fn QAmbientTemperatureSensor::reading() const + + Returns the reading class for this sensor. + + \sa QSensor::reading() +*/ + +#include "moc_qambienttemperaturesensor.cpp" +QT_END_NAMESPACE diff --git a/src/sensors/qambienttemperaturesensor.h b/src/sensors/qambienttemperaturesensor.h new file mode 100644 index 0000000..134e5a9 --- /dev/null +++ b/src/sensors/qambienttemperaturesensor.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QAMBIENTTEMPERATURESENSOR_H +#define QAMBIENTTEMPERATURESENSOR_H + +#include + +QT_BEGIN_NAMESPACE + +class QAmbientTemperatureReadingPrivate; + +class Q_SENSORS_EXPORT QAmbientTemperatureReading : public QSensorReading +{ + Q_OBJECT + Q_PROPERTY(qreal temperature READ temperature) + DECLARE_READING(QAmbientTemperatureReading) +public: + qreal temperature() const; + void setTemperature(qreal temperature); +}; + +class Q_SENSORS_EXPORT QAmbientTemperatureFilter : public QSensorFilter +{ +public: + virtual bool filter(QAmbientTemperatureReading *reading) = 0; +private: + bool filter(QSensorReading *reading) Q_DECL_OVERRIDE + { return filter(static_cast(reading)); } +}; + +class Q_SENSORS_EXPORT QAmbientTemperatureSensor : public QSensor +{ + Q_OBJECT +public: + explicit QAmbientTemperatureSensor(QObject *parent = 0); + ~QAmbientTemperatureSensor(); + QAmbientTemperatureReading *reading() const { return static_cast(QSensor::reading()); } + static char const * const type; + +private: + Q_DISABLE_COPY(QAmbientTemperatureSensor) +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/sensors/qambienttemperaturesensor_p.h b/src/sensors/qambienttemperaturesensor_p.h new file mode 100644 index 0000000..63fe145 --- /dev/null +++ b/src/sensors/qambienttemperaturesensor_p.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Research In Motion +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QAMBIENTTEMPERATURESENSOR_P_H +#define QAMBIENTTEMPERATURESENSOR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +QT_BEGIN_NAMESPACE + +class QAmbientTemperatureReadingPrivate +{ +public: + QAmbientTemperatureReadingPrivate() + : temperature(0) + { + } + + qreal temperature; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/sensors/sensors.pro b/src/sensors/sensors.pro index 473e225..b70c17c 100644 --- a/src/sensors/sensors.pro +++ b/src/sensors/sensors.pro @@ -53,6 +53,7 @@ SENSORS=\ qaccelerometer\ qaltimeter\ qambientlightsensor\ + qambienttemperaturesensor\ qcompass\ qholstersensor\ qlightsensor\ diff --git a/tests/auto/qsensor/test_backends.h b/tests/auto/qsensor/test_backends.h index 6a04df7..b76d412 100644 --- a/tests/auto/qsensor/test_backends.h +++ b/tests/auto/qsensor/test_backends.h @@ -50,6 +50,7 @@ void unregister_test_backends(); #include #include #include +#include #include #include #include @@ -105,6 +106,9 @@ PREPARE_SENSORINTERFACE(QAltimeter, QAltimeterReading, QAltimeterFilter, { PREPARE_SENSORINTERFACE(QAmbientLightSensor, QAmbientLightReading, QAmbientLightFilter, { reading->setLightLevel(QAmbientLightReading::Twilight); }) +PREPARE_SENSORINTERFACE(QAmbientTemperatureSensor, QAmbientTemperatureReading, QAmbientTemperatureFilter, { + reading->setTemperature(30); +}) PREPARE_SENSORINTERFACE(QCompass, QCompassReading, QCompassFilter, { reading->setAzimuth(1.0); reading->setCalibrationLevel(1.0); diff --git a/tests/auto/qsensor/tst_qsensor.cpp b/tests/auto/qsensor/tst_qsensor.cpp index 232590c..a410f71 100644 --- a/tests/auto/qsensor/tst_qsensor.cpp +++ b/tests/auto/qsensor/tst_qsensor.cpp @@ -855,6 +855,10 @@ private slots: QCOMPARE(reading->lightLevel(), QAmbientLightReading::Twilight); }) + TEST_SENSORINTERFACE(QAmbientTemperatureSensor, QAmbientTemperatureReading, { + QCOMPARE(reading->temperature(), 30.0); + }) + TEST_SENSORINTERFACE(QCompass, QCompassReading, { QCOMPARE(reading->azimuth(), 1.0); QCOMPARE(reading->calibrationLevel(), 1.0); -- cgit v1.2.1 From 62ce0b92ee34a1ae6b2f4e81bb0efbaa2a7d53c9 Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Thu, 31 Jan 2013 17:42:18 +0100 Subject: Repair duplicate skipping for the tilt sensor Found because the compiler was warning about an unused "change" variable. Change-Id: Iac968685ba8da7a4d38a00427d22d1e01e31b25f Reviewed-by: Lorn Potter --- src/plugins/sensors/generic/generictiltsensor.cpp | 30 +++++++++++------------ src/plugins/sensors/generic/generictiltsensor.h | 2 ++ 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/plugins/sensors/generic/generictiltsensor.cpp b/src/plugins/sensors/generic/generictiltsensor.cpp index 01281bd..dc118bf 100644 --- a/src/plugins/sensors/generic/generictiltsensor.cpp +++ b/src/plugins/sensors/generic/generictiltsensor.cpp @@ -159,27 +159,22 @@ bool GenericTiltSensor::filter(QAccelerometerReading *reading) qDebug() << "new yrot: " << yrot; qDebug() << "----------------------------------"; #endif - qreal dxrot = xrot - xRotation; - qreal dyrot = yrot - yRotation; + qreal dxrot = rad2deg(xrot) - xRotation; + qreal dyrot = rad2deg(yrot) - yRotation; if (dxrot < 0) dxrot = -dxrot; if (dyrot < 0) dyrot = -dyrot; - bool change = false; - if (dxrot >= radAccuracy){ - xRotation = xrot; - change = true; + bool setNewReading = false; + if (dxrot >= rad2deg(radAccuracy) || !sensor()->skipDuplicates()) { + xRotation = rad2deg(xrot); + setNewReading = true; } - if (dyrot >= radAccuracy){ - yRotation = yrot; - change = true; + if (dyrot >= rad2deg(radAccuracy) || !sensor()->skipDuplicates()) { + yRotation = rad2deg(yrot); + setNewReading = true; } - xRotation = rad2deg(xRotation); - yRotation = rad2deg(yRotation); - - if (xRotation != m_reading.xRotation() - || yRotation != m_reading.yRotation() - || m_reading.timestamp() == 0) { + if (setNewReading || m_reading.timestamp() == 0) { m_reading.setTimestamp(reading->timestamp()); m_reading.setXRotation(xRotation); m_reading.setYRotation(yRotation); @@ -188,3 +183,8 @@ bool GenericTiltSensor::filter(QAccelerometerReading *reading) return false; } + +bool GenericTiltSensor::isFeatureSupported(QSensor::Feature feature) const +{ + return (feature == QSensor::SkipDuplicates); +} diff --git a/src/plugins/sensors/generic/generictiltsensor.h b/src/plugins/sensors/generic/generictiltsensor.h index 4d228bb..0f84ca6 100644 --- a/src/plugins/sensors/generic/generictiltsensor.h +++ b/src/plugins/sensors/generic/generictiltsensor.h @@ -63,6 +63,8 @@ public: bool filter(QAccelerometerReading *reading); + bool isFeatureSupported(QSensor::Feature feature) const Q_DECL_OVERRIDE; + private: QTiltReading m_reading; QAccelerometer *accelerometer; -- cgit v1.2.1 From 4d9edb754b3dff3331c8d8790a04548f0981f315 Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Tue, 29 Jan 2013 15:01:40 +0100 Subject: Use real properties for QSensor::bufferSize & co The #ifdef Q_DOC hack is not really needed and was confusing. In addition, expose those properties to the QML API. As a result, the backends can now listen to the bufferSizeChanged() signal to update the buffering while the sensor is running. This has been implemented for the BlackBerry platform. Change-Id: I5239ba2a4b791cfc9f684b44ff2bc103a7b5b0da Reviewed-by: Lorn Potter --- src/imports/sensors/plugins.qmltypes | 15 +++++ src/imports/sensors/qmlsensor.cpp | 47 ++++++++++++++ src/imports/sensors/qmlsensor.h | 13 ++++ src/plugins/sensors/blackberry/bbsensorbackend.cpp | 66 +++++++++++++------- src/plugins/sensors/blackberry/bbsensorbackend.h | 2 + src/sensors/qsensor.cpp | 72 +++++++++++++++++++--- src/sensors/qsensor.h | 20 ++++-- src/sensors/qsensor_p.h | 7 +++ 8 files changed, 208 insertions(+), 34 deletions(-) diff --git a/src/imports/sensors/plugins.qmltypes b/src/imports/sensors/plugins.qmltypes index 974f714..2deff79 100644 --- a/src/imports/sensors/plugins.qmltypes +++ b/src/imports/sensors/plugins.qmltypes @@ -229,6 +229,9 @@ Module { Property { name: "axesOrientationMode"; revision: 1; type: "AxesOrientationMode" } Property { name: "currentOrientation"; revision: 1; type: "int"; isReadonly: true } Property { name: "userOrientation"; revision: 1; type: "int" } + Property { name: "maxBufferSize"; revision: 1; type: "int"; isReadonly: true } + Property { name: "efficientBufferSize"; revision: 1; type: "int"; isReadonly: true } + Property { name: "bufferSize"; revision: 1; type: "int" } Signal { name: "skipDuplicatesChanged" Parameter { name: "skipDuplicates"; type: "bool" } @@ -245,6 +248,18 @@ Module { name: "userOrientationChanged" Parameter { name: "userOrientation"; type: "int" } } + Signal { + name: "maxBufferSizeChanged" + Parameter { name: "maxBufferSize"; type: "int" } + } + Signal { + name: "efficientBufferSizeChanged" + Parameter { name: "efficientBufferSize"; type: "int" } + } + Signal { + name: "bufferSizeChanged" + Parameter { name: "bufferSize"; type: "int" } + } Method { name: "start"; type: "bool" } Method { name: "stop" } } diff --git a/src/imports/sensors/qmlsensor.cpp b/src/imports/sensors/qmlsensor.cpp index 727526a..3d59a72 100644 --- a/src/imports/sensors/qmlsensor.cpp +++ b/src/imports/sensors/qmlsensor.cpp @@ -355,6 +355,50 @@ void QmlSensor::setUserOrientation(int userOrientation) sensor()->setUserOrientation(userOrientation); } +/*! + \qmlproperty int Sensor::maxBufferSize + \since QtSensors 5.1 + This property holds the maximum buffer size. + + Please see QSensor::maxBufferSize for information about this property. +*/ + +int QmlSensor::maxBufferSize() const +{ + return sensor()->maxBufferSize(); +} + +/*! + \qmlproperty int Sensor::efficientBufferSize + \since QtSensors 5.1 + The property holds the most efficient buffer size. + + Please see QSensor::efficientBufferSize for information about this property. +*/ + +int QmlSensor::efficientBufferSize() const +{ + return sensor()->efficientBufferSize(); +} + +/*! + \qmlproperty int Sensor::bufferSize + \since QtSensors 5.1 + This property holds the size of the buffer. + + Please see QSensor::bufferSize for information about this property. +*/ + +int QmlSensor::bufferSize() const +{ + return sensor()->bufferSize(); +} + +void QmlSensor::setBufferSize(int bufferSize) +{ + sensor()->setBufferSize(bufferSize); +} + /*! \qmlmethod bool Sensor::start() Start retrieving values from the sensor. Returns true if the sensor was started, false otherwise. @@ -396,6 +440,9 @@ void QmlSensor::componentComplete() this, SIGNAL(axesOrientationModeChanged(AxesOrientationMode))); connect(sensor(), SIGNAL(userOrientationChanged(int)), this, SIGNAL(userOrientationChanged(int))); connect(sensor(), SIGNAL(currentOrientationChanged(int)), this, SIGNAL(currentOrientationChanged(int))); + connect(sensor(), SIGNAL(bufferSizeChanged(int)), this, SIGNAL(bufferSizeChanged(int))); + connect(sensor(), SIGNAL(maxBufferSizeChanged(int)), this, SIGNAL(maxBufferSizeChanged(int))); + connect(sensor(), SIGNAL(efficientBufferSizeChanged(int)), this, SIGNAL(efficientBufferSizeChanged(int))); // We need to set this on the sensor object now sensor()->setIdentifier(m_identifier.toLocal8Bit()); diff --git a/src/imports/sensors/qmlsensor.h b/src/imports/sensors/qmlsensor.h index b68a7b9..f72234a 100644 --- a/src/imports/sensors/qmlsensor.h +++ b/src/imports/sensors/qmlsensor.h @@ -75,6 +75,9 @@ class QmlSensor : public QObject, public QQmlParserStatus Q_PROPERTY(AxesOrientationMode axesOrientationMode READ axesOrientationMode WRITE setAxesOrientationMode NOTIFY axesOrientationModeChanged REVISION 1) Q_PROPERTY(int currentOrientation READ currentOrientation NOTIFY currentOrientationChanged REVISION 1) Q_PROPERTY(int userOrientation READ userOrientation WRITE setUserOrientation NOTIFY userOrientationChanged REVISION 1) + Q_PROPERTY(int maxBufferSize READ maxBufferSize NOTIFY maxBufferSizeChanged REVISION 1) + Q_PROPERTY(int efficientBufferSize READ efficientBufferSize NOTIFY efficientBufferSizeChanged REVISION 1) + Q_PROPERTY(int bufferSize READ bufferSize WRITE setBufferSize NOTIFY bufferSizeChanged REVISION 1) public: // Keep in sync with QSensor::AxesOrientationMode @@ -126,6 +129,13 @@ public: int userOrientation() const; void setUserOrientation(int userOrientation); + int maxBufferSize() const; + + int efficientBufferSize() const; + + int bufferSize() const; + void setBufferSize(int bufferSize); + public Q_SLOTS: bool start(); void stop(); @@ -147,6 +157,9 @@ Q_SIGNALS: void axesOrientationModeChanged(AxesOrientationMode axesOrientationMode); void currentOrientationChanged(int currentOrientation); void userOrientationChanged(int userOrientation); + void maxBufferSizeChanged(int maxBufferSize); + void efficientBufferSizeChanged(int efficientBufferSize); + void bufferSizeChanged(int bufferSize); protected: virtual QSensor *sensor() const = 0; diff --git a/src/plugins/sensors/blackberry/bbsensorbackend.cpp b/src/plugins/sensors/blackberry/bbsensorbackend.cpp index de6661e..fec40c5 100644 --- a/src/plugins/sensors/blackberry/bbsensorbackend.cpp +++ b/src/plugins/sensors/blackberry/bbsensorbackend.cpp @@ -81,16 +81,17 @@ static void remapMatrix(const float inputMatrix[3*3], BbSensorBackendBase::BbSensorBackendBase(const QString &devicePath, sensor_type_e sensorType, QSensor *sensor) : QSensorBackend(sensor), m_deviceFile(devicePath), m_sensorType(sensorType), m_guiHelper(0), - m_started(false) + m_started(false), m_applyingBufferSize(false) { m_mappingMatrix[0] = m_mappingMatrix[3] = 1; m_mappingMatrix[1] = m_mappingMatrix[2] = 0; connect(sensor, SIGNAL(alwaysOnChanged()), this, SLOT(applyAlwaysOnProperty())); + connect(sensor, SIGNAL(bufferSizeChanged(int)), this, SLOT(applyBuffering())); connect(sensor, SIGNAL(userOrientationChanged(int)), this, SLOT(updateOrientation())); // Set some sensible default values - sensor->setProperty("efficientBufferSize", defaultBufferSize); - sensor->setProperty("maxBufferSize", defaultBufferSize); + sensor->setEfficientBufferSize(defaultBufferSize); + sensor->setMaxBufferSize(defaultBufferSize); } BbGuiHelper *BbSensorBackendBase::guiHelper() const @@ -278,24 +279,7 @@ void BbSensorBackendBase::start() 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); - } - + applyBuffering(); applyAlwaysOnProperty(); } @@ -365,6 +349,46 @@ void BbSensorBackendBase::applyAlwaysOnProperty() updatePauseState(); } +void BbSensorBackendBase::applyBuffering() +{ + if (!m_deviceFile.isOpen() || !m_started || m_applyingBufferSize) + return; + + // Flag to prevent recursion. We call setBufferSize() below, and because of the changed signal, + // we might end up in this slot again. + // The call to setBufferSize() is needed since the requested buffer size is most likely different + // from the actual buffer size that will be used. + m_applyingBufferSize = true; + + const bool enableBuffering = sensor()->bufferSize() > 1; + sensor_devctl_queue_u queueControl; + queueControl.tx.enable = enableBuffering ? 1 : 0; + const int result = devctl(m_deviceFile.handle(), DCMD_SENSOR_QUEUE, &queueControl, sizeof(queueControl), NULL); + if (result != EOK) { + perror(QString::fromLatin1("Enabling sensor queuing for %1 failed") + .arg(m_deviceFile.fileName()).toLocal8Bit()); + } else { + if (enableBuffering) { + int actualBufferSize = queueControl.rx.size; + + // Some firmware versions don't report the buffer size correctly. Simply pretend the + // buffer size is the same as the requested buffer size, as setting the buffer size to + // 1 here would seem as if buffering were disabled. + if (actualBufferSize == 1) + actualBufferSize = sensor()->bufferSize(); + + sensor()->setBufferSize(actualBufferSize); + sensor()->setEfficientBufferSize(actualBufferSize); + sensor()->setMaxBufferSize(actualBufferSize); + } else { + sensor()->setBufferSize(1); + sensor()->setEfficientBufferSize(defaultBufferSize); + sensor()->setMaxBufferSize(defaultBufferSize); + } + } + m_applyingBufferSize = false; +} + bool BbSensorBackendBase::setPaused(bool paused) { if (!m_deviceFile.isOpen()) diff --git a/src/plugins/sensors/blackberry/bbsensorbackend.h b/src/plugins/sensors/blackberry/bbsensorbackend.h index 48a7216..4e7b810 100644 --- a/src/plugins/sensors/blackberry/bbsensorbackend.h +++ b/src/plugins/sensors/blackberry/bbsensorbackend.h @@ -107,6 +107,7 @@ protected: private slots: void dataAvailable(); void applyAlwaysOnProperty(); + void applyBuffering(); bool setPaused(bool paused); void updatePauseState(); void updateOrientation(); @@ -118,6 +119,7 @@ private: BbGuiHelper *m_guiHelper; float m_mappingMatrix[4]; bool m_started; + bool m_applyingBufferSize; }; template diff --git a/src/sensors/qsensor.cpp b/src/sensors/qsensor.cpp index 125d592..01a4f7b 100644 --- a/src/sensors/qsensor.cpp +++ b/src/sensors/qsensor.cpp @@ -1016,11 +1016,33 @@ void QSensor::setUserOrientation(int userOrientation) The property holds the maximum buffer size. - Note that this may be undefined, in which case the sensor does not support any form of buffering. + Note that this may be 1, in which case the sensor does not support any form of buffering. + In that case, isFeatureSupported(QSensor::Buffering) will also return false. \sa QSensor::bufferSize, QSensor::efficientBufferSize */ +int QSensor::maxBufferSize() const +{ + Q_D(const QSensor); + return d->maxBufferSize; +} + +/*! + \since 5.1 + Sets the maximum buffer size to \a maxBufferSize. This is to be called from the + backend. +*/ +void QSensor::setMaxBufferSize(int maxBufferSize) +{ + // ### Qt 6: Remove the entire maxBufferSize property, no backend really uses it + Q_D(QSensor); + if (d->maxBufferSize != maxBufferSize) { + d->maxBufferSize = maxBufferSize; + emit maxBufferSizeChanged(maxBufferSize); + } +} + /*! \property QSensor::efficientBufferSize @@ -1028,17 +1050,36 @@ void QSensor::setUserOrientation(int userOrientation) no particular size is most efficient). Some sensor drivers have a FIFO buffer which makes it more efficient to deliver the FIFO's size worth of readings at one time. - Note that this may be undefined, in which case the sensor does not support any form of buffering. - \sa QSensor::bufferSize, QSensor::maxBufferSize */ +int QSensor::efficientBufferSize() const +{ + Q_D(const QSensor); + return d->efficientBufferSize; +} + +/*! + \since 5.1 + Sets the efficient buffer size to \a efficientBufferSize. This is to be called from the + backend. +*/ +void QSensor::setEfficientBufferSize(int efficientBufferSize) +{ + // ### Qt 6: Remove the entire efficientBufferSize property, no backend really uses it + Q_D(QSensor); + if (d->efficientBufferSize != efficientBufferSize) { + d->efficientBufferSize = efficientBufferSize; + emit efficientBufferSizeChanged(efficientBufferSize); + } +} + /*! \property QSensor::bufferSize - This property holds the size of the buffer. By default (and if the property - is left undefined), the buffer size is 1, which means no buffering. - If the maximum buffer size is 1 (or undefined), then buffering is not supported + This property holds the size of the buffer. By default, the buffer size is 1, + which means no buffering. + If the maximum buffer size is 1, then buffering is not supported by the sensor. Setting bufferSize greater than maxBufferSize will cause maxBufferSize to be used. @@ -1065,11 +1106,26 @@ void QSensor::setUserOrientation(int userOrientation) in time, for example when the event loop is blocked for too long. Without a buffer, these readings would simply be dropped. - The buffer size can only be changed while the sensor is not active. - \sa QSensor::maxBufferSize, QSensor::efficientBufferSize */ +int QSensor::bufferSize() const +{ + Q_D(const QSensor); + return d->bufferSize; +} + +void QSensor::setBufferSize(int bufferSize) +{ + // ### Qt 6: Currently only the Blackberry backend supports this, but only as an on/off switch. + // We should consider changing this to a more appropriate API. + Q_D(QSensor); + if (d->bufferSize != bufferSize) { + d->bufferSize = bufferSize; + emit bufferSizeChanged(bufferSize); + } +} + // ===================================================================== /*! diff --git a/src/sensors/qsensor.h b/src/sensors/qsensor.h index 5c47df3..2314fb9 100644 --- a/src/sensors/qsensor.h +++ b/src/sensors/qsensor.h @@ -95,11 +95,9 @@ class Q_SENSORS_EXPORT QSensor : public QObject Q_PROPERTY(AxesOrientationMode axesOrientationMode READ axesOrientationMode WRITE setAxesOrientationMode NOTIFY axesOrientationModeChanged) Q_PROPERTY(int currentOrientation READ currentOrientation NOTIFY currentOrientationChanged) Q_PROPERTY(int userOrientation READ userOrientation WRITE setUserOrientation NOTIFY userOrientationChanged) -#ifdef Q_QDOC - Q_PROPERTY(int maxBufferSize) - Q_PROPERTY(int efficientBufferSize) - Q_PROPERTY(int bufferSize) -#endif + Q_PROPERTY(int maxBufferSize READ maxBufferSize NOTIFY maxBufferSizeChanged) + Q_PROPERTY(int efficientBufferSize READ efficientBufferSize NOTIFY efficientBufferSizeChanged) + Q_PROPERTY(int bufferSize READ bufferSize WRITE setBufferSize NOTIFY bufferSizeChanged) public: enum Feature { Buffering, @@ -177,6 +175,15 @@ public: int userOrientation() const; void setUserOrientation(int userOrientation); + int maxBufferSize() const; + void setMaxBufferSize(int maxBufferSize); + + int efficientBufferSize() const; + void setEfficientBufferSize(int efficientBufferSize); + + int bufferSize() const; + void setBufferSize(int bufferSize); + public Q_SLOTS: // Start receiving values from the sensor bool start(); @@ -196,6 +203,9 @@ Q_SIGNALS: void axesOrientationModeChanged(AxesOrientationMode axesOrientationMode); void currentOrientationChanged(int currentOrientation); void userOrientationChanged(int userOrientation); + void maxBufferSizeChanged(int maxBufferSize); + void efficientBufferSizeChanged(int efficientBufferSize); + void bufferSizeChanged(int bufferSize); protected: explicit QSensor(const QByteArray &type, QSensorPrivate &dd, QObject* parent = 0); diff --git a/src/sensors/qsensor_p.h b/src/sensors/qsensor_p.h index 9b6e7e5..71a5b6e 100644 --- a/src/sensors/qsensor_p.h +++ b/src/sensors/qsensor_p.h @@ -82,6 +82,9 @@ public: , axesOrientationMode(QSensor::FixedOrientation) , currentOrientation(0) , userOrientation(0) + , bufferSize(1) + , maxBufferSize(1) + , efficientBufferSize(1) { } @@ -116,6 +119,10 @@ public: QSensor::AxesOrientationMode axesOrientationMode; int currentOrientation; int userOrientation; + + int bufferSize; + int maxBufferSize; + int efficientBufferSize; }; class QSensorReadingPrivate -- cgit v1.2.1 From 5809a8b0ec112ced99d34c9670d097f1f0dc3171 Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Fri, 8 Feb 2013 11:19:04 +0100 Subject: BlackBerry: Remove outdated TODO comment The proximity sensor has been tested in the meantime and works as expected. Change-Id: Ifd27055e36d58f860809d4a5c5dc3f4203094771 Reviewed-by: Lorn Potter --- src/plugins/sensors/blackberry/bbproximitysensor.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/plugins/sensors/blackberry/bbproximitysensor.cpp b/src/plugins/sensors/blackberry/bbproximitysensor.cpp index 79f3834..1177f74 100644 --- a/src/plugins/sensors/blackberry/bbproximitysensor.cpp +++ b/src/plugins/sensors/blackberry/bbproximitysensor.cpp @@ -53,9 +53,6 @@ QString BbProximitySensor::devicePath() bool BbProximitySensor::updateReadingFromEvent(const sensor_event_t &event, QProximityReading *reading) { - // TODO: I was unable to test this since the device I was testing this with did not have - // a proximity sensor. Verify that this works, check that the units are correct - // and that the threshold makes sense. const qreal minProximity = sensor()->outputRanges().first().minimum; reading->setClose(event.proximity_s.distance <= minProximity); return true; -- cgit v1.2.1 From c0f3653aea1c86ba2fecb0f8b0c6865f025031a4 Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Fri, 8 Feb 2013 10:48:30 +0100 Subject: Document the IR Proximity value behavior on BlackBerry Task-number: QTBUG-28087 Change-Id: Ibf2a37dce4c57506bf2073bee9f483d48c94e71c Reviewed-by: Tennessee Carmel-Veilleux Reviewed-by: Lorn Potter --- src/sensors/qirproximitysensor.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/sensors/qirproximitysensor.cpp b/src/sensors/qirproximitysensor.cpp index 4b7eeec..6197bb9 100644 --- a/src/sensors/qirproximitysensor.cpp +++ b/src/sensors/qirproximitysensor.cpp @@ -63,6 +63,12 @@ IMPLEMENT_READING(QIRProximityReading) The sensor reports reflectance as a decimal fraction in the range of 0 - 1. That is, 0 indicates nothing was detected within the range of the sensor and 1 indicates the infra-red signal returned at the full power level that it was sent at. + + With some IR sensors, it is quite uncommon to reach the top and the bottom of the + value range, and some parts of the range ends might not be obtainable at all. This is due to the + behavior of the sensor hardware. With these sensors, the absolute value of reflectance should never + be used directly. Instead, applications should react to the relative change of the reading values. Use + QProximitySensor if it is only necessary to check if something is close to the device or not. */ /*! -- cgit v1.2.1 From 86ed8422a65e3a781c51ce5e93deb03b254e9a81 Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Tue, 26 Feb 2013 16:12:38 +0100 Subject: Fix some doc warnings Change-Id: Ia955a9071ae6662b211d57708624d339d9ec5e4f Reviewed-by: Jerome Pasion --- src/sensors/qlightsensor.cpp | 4 +++- src/sensors/qrotationsensor.cpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/sensors/qlightsensor.cpp b/src/sensors/qlightsensor.cpp index f02f6b1..1e80ef0 100644 --- a/src/sensors/qlightsensor.cpp +++ b/src/sensors/qlightsensor.cpp @@ -84,6 +84,7 @@ void QLightReading::setLux(qreal lux) /*! \class QLightFilter \ingroup sensors_filter + \inmodule QtSensors \brief The QLightFilter class is a convenience wrapper around QSensorFilter. @@ -104,6 +105,7 @@ char const * const QLightSensor::type("QLightSensor"); /*! \class QLightSensor \ingroup sensors_type + \inmodule QtSensors \brief The QLightSensor class is a convenience wrapper around QSensor. @@ -160,7 +162,7 @@ qreal QLightSensor::fieldOfView() const /*! \since 5.1 - Sets the field of view. This is to be called from the + Sets the field of view to \a fieldOfView. This is to be called from the backend. */ void QLightSensor::setFieldOfView(qreal fieldOfView) diff --git a/src/sensors/qrotationsensor.cpp b/src/sensors/qrotationsensor.cpp index ea0515c..06ee406 100644 --- a/src/sensors/qrotationsensor.cpp +++ b/src/sensors/qrotationsensor.cpp @@ -237,7 +237,7 @@ bool QRotationSensor::hasZ() const /*! \since 5.1 - Sets whether the z angle is available. This is to be called from the + Sets whether the z angle is available to \a hasZ. This is to be called from the backend. By default the hasZ property is true, so a backend only has to call this if its rotation sensor can not report z angles. */ -- cgit v1.2.1 From 8c86ff31f47e1e1f11374c4723f254cb4b34ece7 Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Tue, 26 Feb 2013 10:58:11 +0100 Subject: Update qdocconf - Use version tags rather than hardcoded versions - Add a QML Types section to the TOC - Fix link to the overview page - Keep the rest more in line with other modules (used qtcore to compare) Change-Id: Ia86aad1fc50b8471847b2fb808bacf2cbcf1471c Reviewed-by: Jerome Pasion --- src/sensors/doc/qtsensors.qdocconf | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/sensors/doc/qtsensors.qdocconf b/src/sensors/doc/qtsensors.qdocconf index 7c53c02..2ede8cf 100644 --- a/src/sensors/doc/qtsensors.qdocconf +++ b/src/sensors/doc/qtsensors.qdocconf @@ -3,33 +3,36 @@ include($QT_INSTALL_DOCS/global/qt-module-defaults.qdocconf) project = QtSensors description = Qt Sensors Reference Documentation -url = http://qt-project.org/doc/qt-5.0/qtsensors-index.html -version = 5.0.0 +url = http://qt-project.org/doc/qt-$QT_VER/qtsensors +version = $QT_VERSION qhp.projects = QtSensors qhp.QtSensors.file = qtsensors.qhp -qhp.QtSensors.namespace = org.qt-project.qtsensors.500 -qhp.QtSensors.virtualFolder = qdoc -qhp.QtSensors.indexTitle = Qt Sensors Reference Documentation +qhp.QtSensors.namespace = org.qt-project.qtsensors.$QT_VERSION_TAG +qhp.QtSensors.virtualFolder = qtsensors +qhp.QtSensors.indexTitle = Qt Sensors qhp.QtSensors.indexRoot = -qhp.QtSensors.filterAttributes = qtsensors 5.0.0 qtrefdoc -qhp.QtSensors.customFilters.Qt.name = QtSensors 5.0.0 -qhp.QtSensors.customFilters.Qt.filterAttributes = qtsensors 5.0.0 -qhp.QtSensors.subprojects = classes overviews examples -qhp.QtSensors.subprojects.classes.title = Classes -qhp.QtSensors.subprojects.classes.indexTitle = Qt Sensors's Classes +qhp.QtSensors.filterAttributes = qtsensors $QT_VERSION qtrefdoc +qhp.QtSensors.customFilters.Qt.name = QtSensors $QT_VERSION +qhp.QtSensors.customFilters.Qt.filterAttributes = qtsensors $QT_VERSION +qhp.QtSensors.subprojects = overviews classes qmltypes examples +qhp.QtSensors.subprojects.overviews.title = Overview +qhp.QtSensors.subprojects.overviews.indexTitle = Qt Sensors +qhp.QtSensors.subprojects.overviews.selectors = fake:page,group,module +qhp.QtSensors.subprojects.classes.title = C++ Classes +qhp.QtSensors.subprojects.classes.indexTitle = Qt Sensors C++ Classes qhp.QtSensors.subprojects.classes.selectors = class fake:headerfile qhp.QtSensors.subprojects.classes.sortPages = true -qhp.QtSensors.subprojects.overviews.title = Overviews -qhp.QtSensors.subprojects.overviews.indexTitle = All Overviews and HOWTOs -qhp.QtSensors.subprojects.overviews.selectors = fake:page,group,module -qhp.QtSensors.subprojects.examples.title = Qt Sensors Examples +qhp.QtSensors.subprojects.qmltypes.title = QML Types +qhp.QtSensors.subprojects.qmltypes.indexTitle = Qt Sensors QML Types +qhp.QtSensors.subprojects.qmltypes.selectors = fake:qmlclass +qhp.QtSensors.subprojects.qmltypes.sortPages = true +qhp.QtSensors.subprojects.examples.title = Examples qhp.QtSensors.subprojects.examples.indexTitle = Qt Sensors Examples qhp.QtSensors.subprojects.examples.selectors = fake:example -outputdir = ../../../doc/qtsensors tagfile = ../../../doc/qtsensors/qtsensors.tags headerdirs += .. \ @@ -45,3 +48,5 @@ exampledirs += ../../../examples/sensors \ imagedirs += images + +depends += qtcore qtdoc qtgui -- cgit v1.2.1 From fa17193dedbcbb46ecc9493f5f43cfe5738d8d0a Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Tue, 26 Feb 2013 13:56:27 +0100 Subject: Update the porting documentation - Remove some references to the legacy imports - Mention the biggest change, separate QML types - Add some examples on what changed in the QML API Change-Id: Icdbf8271935499ec449a35919d947ad762d2cf03 Reviewed-by: Bernd Weimer Reviewed-by: Lorn Potter --- src/sensors/doc/src/porting.qdoc | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/sensors/doc/src/porting.qdoc b/src/sensors/doc/src/porting.qdoc index fa2b3fb..0d5b572 100644 --- a/src/sensors/doc/src/porting.qdoc +++ b/src/sensors/doc/src/porting.qdoc @@ -39,21 +39,26 @@ \section1 QML - Compatibility for QML applications is provided by shipping the legacy \c QtMobility.sensors - QML import. QML applications should not require any changes to continue operating. + In QtMobility, the C++ classes like QAccelerometer were directly used as QML types. + In Qt Sensors, there are now separate classes for the QML types, which have no public + C++ API. - Applications using the legacy QML import may not be able to trivially port over - to the new QML import because the new QML import does not provide types for - every sensor like the legacy QML import does. + The new QML types in Qt Sensors fix some issues the former QtMobility QML types had, + for example: + \list + \li The reading types now have proper change notifications + \li \c availableDataRates and \c outputRanges of the \c Sensor type are now proper list types + \li The \c identifier and \c type properties of \c Sensor can now be used + \li The \c lux property of \c LightSensorReading has been renamed to \c illuminance + \li The \c QmlSensors singleton now allows to query for sensor types + \endlist - \table - \row - \li \l {Qt Sensors QML Types}{QML API} - \li Information about the Qt Sensors QML API - \endtable + For more information, see the \l {Qt Sensors QML Types}{QML API} documentation. \section1 C++ + The C++ API mainly remained the same as in QtMobility. + \section2 Includes QtMobility Sensors installed headers into a \c Qt Sensors directory. This is -- cgit v1.2.1 From 3a9e30eb6229a6212150dbc1a3627246d51c8be2 Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Wed, 27 Feb 2013 09:35:05 +0100 Subject: Blackberry: Prevent spurious calls to dataAvailable() when stopped Explicitly disable the socket notifier and drain the device file to avoid dataAvailable() being called spuriously. This fixes high CPU usage that occurred in some circumstances after stopping the sensor. Many thanks to Dmytro Mishchenko for reporting and helping to track down the problem. Change-Id: Idcaff1432b96b392d033e5b21c2b379259792212 Reviewed-by: Adam Parco Reviewed-by: Lorn Potter --- src/plugins/sensors/blackberry/bbsensorbackend.cpp | 35 ++++++++++++++-------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/plugins/sensors/blackberry/bbsensorbackend.cpp b/src/plugins/sensors/blackberry/bbsensorbackend.cpp index fec40c5..a244a97 100644 --- a/src/plugins/sensors/blackberry/bbsensorbackend.cpp +++ b/src/plugins/sensors/blackberry/bbsensorbackend.cpp @@ -130,6 +130,19 @@ void BbSensorBackendBase::initSensorInfo() qDebug() << "Failed to open sensor" << m_deviceFile.fileName() << ":" << m_deviceFile.errorString(); } else { + + // Explicitly switch to non-blocking mode, otherwise read() will wait until new sensor + // data is available, and we have no way to check if there is more data or not (bytesAvailable() + // does not work for unbuffered mode) + const int oldFlags = fcntl(m_deviceFile.handle(), F_GETFL); + if (fcntl(m_deviceFile.handle(), F_SETFL, oldFlags | O_NONBLOCK) == -1) { + perror(QString::fromLatin1("Starting sensor %1 failed, fcntl() returned -1") + .arg(m_deviceFile.fileName()).toLocal8Bit()); + sensorError(errno); + stop(); + return; + } + sensor_devctl_info_u deviceInfo; const int result = devctl(m_deviceFile.handle(), DCMD_SENSOR_INFO, &deviceInfo, sizeof(deviceInfo), NULL); @@ -156,6 +169,7 @@ void BbSensorBackendBase::initSensorInfo() setPaused(true); m_socketNotifier.reset(new QSocketNotifier(m_deviceFile.handle(), QSocketNotifier::Read)); + m_socketNotifier->setEnabled(false); connect(m_socketNotifier.data(), SIGNAL(activated(int)), this, SLOT(dataAvailable())); } } @@ -267,18 +281,6 @@ void BbSensorBackendBase::start() .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; - } - applyBuffering(); applyAlwaysOnProperty(); } @@ -313,8 +315,12 @@ bool BbSensorBackendBase::isFeatureSupported(QSensor::Feature feature) const void BbSensorBackendBase::dataAvailable() { - if (!m_started) + if (!m_started) { + // Spurious dataAvailable() call, drain the device file of data. We also disable + // the socket notifier for this, so this is just added safety here. + m_deviceFile.readAll(); return; + } Q_FOREVER { sensor_event_t event; @@ -397,6 +403,9 @@ bool BbSensorBackendBase::setPaused(bool paused) sensor_devctl_enable_u enableState; enableState.tx.enable = paused ? 0 : 1; + if (m_socketNotifier) + m_socketNotifier->setEnabled(!paused); + const int result = devctl(m_deviceFile.handle(), DCMD_SENSOR_ENABLE, &enableState, sizeof(enableState), NULL); if (result != EOK) { perror(QString::fromLatin1("Setting sensor enabled (%1) for %2 failed") -- cgit v1.2.1 From 4ef58f952f6fb87059cecddfe6447b14919be066 Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Tue, 26 Feb 2013 15:49:28 +0100 Subject: BlackBerry: Support QMagnetometer::returnGeoValues Change-Id: Ib81074bb9ea2b922fb8c599e7e758346e85bb6e0 Reviewed-by: Adam Parco Reviewed-by: Lorn Potter --- src/plugins/sensors/blackberry/bbmagnetometer.cpp | 30 +++++++++++++++------- src/plugins/sensors/blackberry/bbsensorbackend.cpp | 7 ++++- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/plugins/sensors/blackberry/bbmagnetometer.cpp b/src/plugins/sensors/blackberry/bbmagnetometer.cpp index 5ece465..45fd49b 100644 --- a/src/plugins/sensors/blackberry/bbmagnetometer.cpp +++ b/src/plugins/sensors/blackberry/bbmagnetometer.cpp @@ -53,15 +53,7 @@ QString BbMagnetometer::devicePath() bool BbMagnetometer::updateReadingFromEvent(const sensor_event_t &event, QMagnetometerReading *reading) { - // TODO: In the future, support returnGeoValues here. Right now, /dev/sensors/mag has no - // geomagnatic mode, but will gain it in the future. - float x = convertValue(event.motion.dsp.x); - float y = convertValue(event.motion.dsp.y); - float z = convertValue(event.motion.dsp.z); - remapAxes(&x, &y, &z); - reading->setX(x); - reading->setY(y); - reading->setZ(z); + float x, y, z; QMagnetometer * const magnetometer = qobject_cast(sensor()); Q_ASSERT(magnetometer); @@ -78,10 +70,30 @@ bool BbMagnetometer::updateReadingFromEvent(const sensor_event_t &event, QMagnet case SENSOR_ACCURACY_MEDIUM: reading->setCalibrationLevel(1.0f); break; case SENSOR_ACCURACY_HIGH: reading->setCalibrationLevel(1.0f); break; } + + x = convertValue(event.motion.dsp.x); + y = convertValue(event.motion.dsp.y); + z = convertValue(event.motion.dsp.z); + } else { reading->setCalibrationLevel(1.0f); + +#ifndef Q_OS_BLACKBERRY_TABLET + x = convertValue(event.motion.raw.x); + y = convertValue(event.motion.raw.y); + z = convertValue(event.motion.raw.z); +#else + // Blackberry Tablet OS does not support raw reading values + x = convertValue(event.motion.dsp.x); + y = convertValue(event.motion.dsp.y); + z = convertValue(event.motion.dsp.z); +#endif } + remapAxes(&x, &y, &z); + reading->setX(x); + reading->setY(y); + reading->setZ(z); return true; } diff --git a/src/plugins/sensors/blackberry/bbsensorbackend.cpp b/src/plugins/sensors/blackberry/bbsensorbackend.cpp index a244a97..6b614a8 100644 --- a/src/plugins/sensors/blackberry/bbsensorbackend.cpp +++ b/src/plugins/sensors/blackberry/bbsensorbackend.cpp @@ -304,8 +304,13 @@ bool BbSensorBackendBase::isFeatureSupported(QSensor::Feature feature) const case QSensor::AccelerationMode: case QSensor::SkipDuplicates: return true; - case QSensor::Reserved: case QSensor::GeoValues: +#ifndef Q_OS_BLACKBERRY_TABLET + return (sensorType() == SENSOR_TYPE_MAGNETOMETER); +#else + return false; +#endif + case QSensor::Reserved: case QSensor::FieldOfView: break; } -- cgit v1.2.1 From d0af60fcfd3d591cc1e5ecfbb31801314e3ca99f Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Tue, 12 Feb 2013 17:20:10 +0100 Subject: Initialize variables The old values of xRotation and yRotation are used in calculations. This should fix the bug where the tilt sensor would occasionally report NaN. Change-Id: I87e67cdbf66976f0c74e91d0f1660f7fc12f31cc Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/plugins/sensors/generic/generictiltsensor.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/plugins/sensors/generic/generictiltsensor.cpp b/src/plugins/sensors/generic/generictiltsensor.cpp index dc118bf..f37e42b 100644 --- a/src/plugins/sensors/generic/generictiltsensor.cpp +++ b/src/plugins/sensors/generic/generictiltsensor.cpp @@ -53,6 +53,8 @@ GenericTiltSensor::GenericTiltSensor(QSensor *sensor) , roll(0) , calibratedPitch(0) , calibratedRoll(0) + , xRotation(0) + , yRotation(0) { accelerometer = new QAccelerometer(this); accelerometer->addFilter(this); -- cgit v1.2.1 From 8eb638313957e367040931c34483a010a0276f99 Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Thu, 7 Feb 2013 16:06:21 +0100 Subject: Spell "tesla" correctly in the documentation. Change-Id: I3f5ac0b1adcdee9ba2c7ddd54302c3aca7a94bfb Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/sensors/qmagnetometer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sensors/qmagnetometer.cpp b/src/sensors/qmagnetometer.cpp index f5f563a..7c5c965 100644 --- a/src/sensors/qmagnetometer.cpp +++ b/src/sensors/qmagnetometer.cpp @@ -84,7 +84,7 @@ IMPLEMENT_READING(QMagnetometerReading) \property QMagnetometerReading::x \brief the raw magnetic flux density on the X axis. - Measured as telsas. + Measured as teslas. \sa {QMagnetometerReading Units} */ @@ -105,7 +105,7 @@ void QMagnetometerReading::setX(qreal x) \property QMagnetometerReading::y \brief the raw magnetic flux density on the Y axis. - Measured as telsas. + Measured as teslas. \sa {QMagnetometerReading Units} */ @@ -126,7 +126,7 @@ void QMagnetometerReading::setY(qreal y) \property QMagnetometerReading::z \brief the raw magnetic flux density on the Z axis. - Measured as telsas. + Measured as teslas. \sa {QMagnetometerReading Units} */ -- cgit v1.2.1 From 61ce0635fca7c7d38d64e7c59bc99d9512d2d879 Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Tue, 12 Feb 2013 15:50:45 +0100 Subject: Make debug code compile again Change-Id: I96458c3e79e979ed5e682df48765d76482bfead6 Reviewed-by: Eskil Abrahamsen Blomfeldt Reviewed-by: Oswald Buddenhagen --- src/plugins/sensors/generic/generictiltsensor.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/plugins/sensors/generic/generictiltsensor.cpp b/src/plugins/sensors/generic/generictiltsensor.cpp index f37e42b..95c8525 100644 --- a/src/plugins/sensors/generic/generictiltsensor.cpp +++ b/src/plugins/sensors/generic/generictiltsensor.cpp @@ -126,16 +126,16 @@ bool GenericTiltSensor::filter(QAccelerometerReading *reading) qreal az = reading->z(); #ifdef LOGCALIBRATION qDebug() << "------------ new value -----------"; - qDebug() << "old _pitch: " << _pitch; - qDebug() << "old _roll: " << _roll; - qDebug() << "_calibratedPitch: " << _calibratedPitch; - qDebug() << "_calibratedRoll: " << _calibratedRoll; + qDebug() << "old _pitch: " << pitch; + qDebug() << "old _roll: " << roll; + qDebug() << "_calibratedPitch: " << calibratedPitch; + qDebug() << "_calibratedRoll: " << calibratedRoll; #endif pitch = calcPitch(ax, ay, az); roll = calcRoll (ax, ay, az); #ifdef LOGCALIBRATION - qDebug() << "_pitch: " << _pitch; - qDebug() << "_roll: " << _roll; + qDebug() << "_pitch: " << pitch; + qDebug() << "_roll: " << roll; #endif qreal xrot = roll - calibratedRoll; qreal yrot = pitch - calibratedPitch; -- cgit v1.2.1 From 96d4de7b36188cf8fe87b1d3f840bf9371744956 Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Mon, 4 Mar 2013 14:09:10 +0100 Subject: Sensor implementation for Android Based on the Necessitas project by Bogdan Vatra. Contributors to the Qt5 project: BogDan Vatra Eskil Abrahamsen Blomfeldt Paul Olav Tvete The full history of the Qt5 port can be found in refs/old-heads/android, SHA-1 caa4103a80ef90db5eb9836f6b6028b7ce36c73a Change-Id: I57e772ee5079c0ea74f685b65ae2864d73e7c750 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/plugins/sensors/android/android.pro | 2 + .../sensors/android/jar/AndroidManifest.xml | 6 + src/plugins/sensors/android/jar/jar.pro | 10 + .../qtproject/qt5/android/sensors/QtSensors.java | 161 ++++++++++++++ .../sensors/android/src/androidaccelerometer.cpp | 63 ++++++ .../sensors/android/src/androidaccelerometer.h | 59 +++++ .../sensors/android/src/androidcommonsensor.h | 88 ++++++++ .../sensors/android/src/androidgyroscope.cpp | 64 ++++++ src/plugins/sensors/android/src/androidgyroscope.h | 57 +++++ .../sensors/android/src/androidjnisensors.cpp | 245 +++++++++++++++++++++ .../sensors/android/src/androidjnisensors.h | 83 +++++++ src/plugins/sensors/android/src/androidlight.cpp | 62 ++++++ src/plugins/sensors/android/src/androidlight.h | 57 +++++ .../sensors/android/src/androidmagnetometer.cpp | 63 ++++++ .../sensors/android/src/androidmagnetometer.h | 57 +++++ .../sensors/android/src/androidrotation.cpp | 65 ++++++ src/plugins/sensors/android/src/androidrotation.h | 56 +++++ src/plugins/sensors/android/src/main.cpp | 135 ++++++++++++ src/plugins/sensors/android/src/plugin.json | 1 + src/plugins/sensors/android/src/src.pro | 29 +++ src/plugins/sensors/generic/generic.pro | 12 +- src/plugins/sensors/generic/main.cpp | 34 ++- src/plugins/sensors/sensors.pro | 4 + src/sensors/doc/src/compatmap.qdoc | 24 ++ src/sensors/sensors.pro | 5 + 25 files changed, 1434 insertions(+), 8 deletions(-) create mode 100644 src/plugins/sensors/android/android.pro create mode 100644 src/plugins/sensors/android/jar/AndroidManifest.xml create mode 100644 src/plugins/sensors/android/jar/jar.pro create mode 100644 src/plugins/sensors/android/jar/src/org/qtproject/qt5/android/sensors/QtSensors.java create mode 100644 src/plugins/sensors/android/src/androidaccelerometer.cpp create mode 100644 src/plugins/sensors/android/src/androidaccelerometer.h create mode 100644 src/plugins/sensors/android/src/androidcommonsensor.h create mode 100644 src/plugins/sensors/android/src/androidgyroscope.cpp create mode 100644 src/plugins/sensors/android/src/androidgyroscope.h create mode 100644 src/plugins/sensors/android/src/androidjnisensors.cpp create mode 100644 src/plugins/sensors/android/src/androidjnisensors.h create mode 100644 src/plugins/sensors/android/src/androidlight.cpp create mode 100644 src/plugins/sensors/android/src/androidlight.h create mode 100644 src/plugins/sensors/android/src/androidmagnetometer.cpp create mode 100644 src/plugins/sensors/android/src/androidmagnetometer.h create mode 100644 src/plugins/sensors/android/src/androidrotation.cpp create mode 100644 src/plugins/sensors/android/src/androidrotation.h create mode 100644 src/plugins/sensors/android/src/main.cpp create mode 100644 src/plugins/sensors/android/src/plugin.json create mode 100644 src/plugins/sensors/android/src/src.pro diff --git a/src/plugins/sensors/android/android.pro b/src/plugins/sensors/android/android.pro new file mode 100644 index 0000000..0dc6a3f --- /dev/null +++ b/src/plugins/sensors/android/android.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS += jar src diff --git a/src/plugins/sensors/android/jar/AndroidManifest.xml b/src/plugins/sensors/android/jar/AndroidManifest.xml new file mode 100644 index 0000000..5d15cab --- /dev/null +++ b/src/plugins/sensors/android/jar/AndroidManifest.xml @@ -0,0 +1,6 @@ + + + diff --git a/src/plugins/sensors/android/jar/jar.pro b/src/plugins/sensors/android/jar/jar.pro new file mode 100644 index 0000000..a935074 --- /dev/null +++ b/src/plugins/sensors/android/jar/jar.pro @@ -0,0 +1,10 @@ +load(qt_build_paths) + +CONFIG += java +TARGET = QtSensors +DESTDIR = $$MODULE_BASE_OUTDIR/jar + +JAVACLASSPATH += $$PWD/src + +JAVASOURCES += \ + $$PWD/src/org/qtproject/qt5/android/sensors/QtSensors.java diff --git a/src/plugins/sensors/android/jar/src/org/qtproject/qt5/android/sensors/QtSensors.java b/src/plugins/sensors/android/jar/src/org/qtproject/qt5/android/sensors/QtSensors.java new file mode 100644 index 0000000..c7956d2 --- /dev/null +++ b/src/plugins/sensors/android/jar/src/org/qtproject/qt5/android/sensors/QtSensors.java @@ -0,0 +1,161 @@ +/**************************************************************************** +** +** Copyright (C) 2013 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensor module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +package org.qtproject.qt5.android.sensors; + +import java.util.HashSet; +import java.util.List; + +import android.app.Activity; +import android.hardware.Sensor; +import android.hardware.SensorEvent; +import android.hardware.SensorEventListener; +import android.hardware.SensorManager; +import android.os.Build; +import android.util.SparseArray; + +import android.util.Log; + +public class QtSensors implements SensorEventListener +{ + static final QtSensors m_sensorsListener = new QtSensors(); + static SensorManager m_sensorManager = null; + static SparseArray m_registeredSensors = new SparseArray(); + static Object m_syncObject = new Object(); + static public void setActivity(Activity activity, Object acitvityDelegate) + { + try { + m_sensorManager = (SensorManager)activity.getSystemService(Activity.SENSOR_SERVICE); + } catch(Exception e) { + e.printStackTrace(); + } + } + + private static String getSensorDescription(int sensorType) + { + try { + Sensor s = m_sensorManager.getDefaultSensor(sensorType); + return s.getName() + " " + s.getVendor() + " v" + s.getVersion(); + } catch(Exception e) { + e.printStackTrace(); + } + return null; + } + + private static int[] getSensorList() + { + try { + List list = m_sensorManager.getSensorList(Sensor.TYPE_ALL); + HashSet filteredList = new HashSet(); + for (Sensor s : list) + filteredList.add(s.getType()); + int retList[] = new int[filteredList.size()]; + int pos = 0; + for (int type : filteredList) + retList[pos++] = type; + return retList; + } catch(Exception e) { + e.printStackTrace(); + } + return null; + } + + private static boolean registerSensor(int sensorType, int rate) + { + synchronized (m_syncObject) { + try { + Sensor s = m_sensorManager.getDefaultSensor(sensorType); + m_sensorManager.registerListener(m_sensorsListener, s, rate); + m_registeredSensors.put(sensorType, s); + } catch(Exception e) { + e.printStackTrace(); + return false; + } + } + return true; + } + + private static boolean unregisterSensor(int sensorType) + { + synchronized (m_syncObject) { + try { + Sensor s = m_registeredSensors.get(sensorType); + if (s != null) { + m_sensorManager.unregisterListener(m_sensorsListener, m_registeredSensors.get(sensorType)); + m_registeredSensors.remove(sensorType); + } + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + return true; + } + + private static float[] convertQuaternionToEuler(float[] rotationVector) + { + float matrix[] = new float[9]; + SensorManager.getRotationMatrixFromVector (matrix, rotationVector); + float angles[] = new float[3]; + SensorManager.getOrientation (matrix, angles); + return angles; + } + + public static native void accuracyChanged(int sensorType, int accuracy); + public static native void sensorChanged(int sensorType, long timestamp, float[] values); + + @Override + public void onAccuracyChanged(Sensor sensor, int accuracy) + { + accuracyChanged(sensor.getType(), accuracy); + } + + @Override + public void onSensorChanged(SensorEvent sensorEvent) + { + if (sensorEvent.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) { + //#### hacky, but much easier than exposing the convert function and converting the arrays back and forth... + sensorChanged(sensorEvent.sensor.getType(), sensorEvent.timestamp, convertQuaternionToEuler(sensorEvent.values)); + } else { + sensorChanged(sensorEvent.sensor.getType(), sensorEvent.timestamp, sensorEvent.values); + } + } +} diff --git a/src/plugins/sensors/android/src/androidaccelerometer.cpp b/src/plugins/sensors/android/src/androidaccelerometer.cpp new file mode 100644 index 0000000..b64536e --- /dev/null +++ b/src/plugins/sensors/android/src/androidaccelerometer.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2013 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "androidaccelerometer.h" + +AndroidAccelerometer::AndroidAccelerometer(AndroidSensors::AndroidSensorType type, QSensor *sensor) + : AndroidCommonSensor(type, sensor) +{} + +void AndroidAccelerometer::onSensorChanged(jlong timestamp, const jfloat *values, uint size) +{ + if (size < 3) + return; + m_reader.setTimestamp(timestamp); + // check https://developer.android.com/reference/android/hardware/SensorEvent.html#values + m_reader.setX(values[0]); + m_reader.setY(values[1]); + m_reader.setZ(values[2]); + newReadingAvailable(); +} + +void AndroidAccelerometer::onAccuracyChanged(jint accuracy) +{ + Q_UNUSED(accuracy) +} diff --git a/src/plugins/sensors/android/src/androidaccelerometer.h b/src/plugins/sensors/android/src/androidaccelerometer.h new file mode 100644 index 0000000..6c95fdb --- /dev/null +++ b/src/plugins/sensors/android/src/androidaccelerometer.h @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2013 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ANDROIDACCELEROMETER_H +#define ANDROIDACCELEROMETER_H +#include + +#include "androidcommonsensor.h" + +class AndroidAccelerometer : public AndroidCommonSensor +{ +public: + AndroidAccelerometer(AndroidSensors::AndroidSensorType type, QSensor *sensor); + +private: + virtual void onAccuracyChanged(jint accuracy); + virtual void onSensorChanged(jlong timestamp, const jfloat *values, uint size); + +}; + +#endif // ANDROIDACCELEROMETER_H diff --git a/src/plugins/sensors/android/src/androidcommonsensor.h b/src/plugins/sensors/android/src/androidcommonsensor.h new file mode 100644 index 0000000..40f118e --- /dev/null +++ b/src/plugins/sensors/android/src/androidcommonsensor.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2013 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ANDROIDCOMMONSENSOR_H +#define ANDROIDCOMMONSENSOR_H + +#include +#include +#include "androidjnisensors.h" + +template +class AndroidCommonSensor : public QSensorBackend, protected AndroidSensors::AndroidSensorsListenerInterface +{ +public: + AndroidCommonSensor(AndroidSensors::AndroidSensorType type, QSensor *sensor) : QSensorBackend(sensor) + { + setDescription(AndroidSensors::sensorDescription(type)); + setReading(&m_reader); + m_type = type; + m_isStarted = false; + } + + virtual ~AndroidCommonSensor() + { + if (m_isStarted) + stop(); + } + virtual void start() + { + if (AndroidSensors::registerListener(m_type, this, sensor()->dataRate())) + m_isStarted = true; + } + + virtual void stop() + { + if (m_isStarted) { + m_isStarted = false; + AndroidSensors::unregisterListener(m_type, this); + } + } + +protected: + ReaderType m_reader; + +private: + AndroidSensors::AndroidSensorType m_type; + bool m_isStarted; +}; + +#endif // ANDROIDCOMMONSENSOR_H diff --git a/src/plugins/sensors/android/src/androidgyroscope.cpp b/src/plugins/sensors/android/src/androidgyroscope.cpp new file mode 100644 index 0000000..69a05c1 --- /dev/null +++ b/src/plugins/sensors/android/src/androidgyroscope.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2013 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "androidgyroscope.h" +#include + +AndroidGyroscope::AndroidGyroscope(AndroidSensors::AndroidSensorType type, QSensor *sensor) + : AndroidCommonSensor(type, sensor) +{} + +void AndroidGyroscope::onSensorChanged(jlong timestamp, const jfloat *values, uint size) +{ + if (size < 3) + return; + m_reader.setTimestamp(timestamp); + // check https://developer.android.com/reference/android/hardware/SensorEvent.html#values + m_reader.setX(values[0]*180/M_PI); + m_reader.setY(values[1]*180/M_PI); + m_reader.setZ(values[2]*180/M_PI); + newReadingAvailable(); +} + +void AndroidGyroscope::onAccuracyChanged(jint accuracy) +{ + Q_UNUSED(accuracy) +} diff --git a/src/plugins/sensors/android/src/androidgyroscope.h b/src/plugins/sensors/android/src/androidgyroscope.h new file mode 100644 index 0000000..3b633b7 --- /dev/null +++ b/src/plugins/sensors/android/src/androidgyroscope.h @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2013 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ANDROIDGYROSCOPE_H +#define ANDROIDGYROSCOPE_H +#include + +#include "androidcommonsensor.h" + +class AndroidGyroscope : public AndroidCommonSensor +{ +public: + AndroidGyroscope(AndroidSensors::AndroidSensorType type, QSensor *sensor); +private: + virtual void onAccuracyChanged(jint accuracy); + virtual void onSensorChanged(jlong timestamp, const jfloat *values, uint size); +}; + +#endif // ANDROIDGYROSCOPE_H diff --git a/src/plugins/sensors/android/src/androidjnisensors.cpp b/src/plugins/sensors/android/src/androidjnisensors.cpp new file mode 100644 index 0000000..6365433 --- /dev/null +++ b/src/plugins/sensors/android/src/androidjnisensors.cpp @@ -0,0 +1,245 @@ +/**************************************************************************** +** +** Copyright (C) 2013 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include + +#include "androidjnisensors.h" + +static JavaVM *javaVM = 0; +jclass sensorsClass; + +static jmethodID getSensorListMethodId; +static jmethodID registerSensorMethodId; +static jmethodID unregisterSensorMethodId; +static jmethodID getSensorDescriptionMethodId; + +static QHash > listenersHash; +QReadWriteLock listenersLocker; +enum { + SENSOR_DELAY_FASTEST = 0, + SENSOR_DELAY_GAME = 1, + SENSOR_DELAY_NORMAL = 3, + SENSOR_DELAY_UI =2 +}; +namespace AndroidSensors +{ + struct AttachedJNIEnv + { + AttachedJNIEnv() + { + attached = false; + if (javaVM->GetEnv((void**)&jniEnv, JNI_VERSION_1_6) < 0) { + if (javaVM->AttachCurrentThread(&jniEnv, NULL) < 0) { + __android_log_print(ANDROID_LOG_ERROR, "Qt", "AttachCurrentThread failed"); + jniEnv = 0; + return; + } + attached = true; + } + } + + ~AttachedJNIEnv() + { + if (attached) + javaVM->DetachCurrentThread(); + } + bool attached; + JNIEnv *jniEnv; + }; + + QVector availableSensors() + { + QVector ret; + AttachedJNIEnv aenv; + if (!aenv.jniEnv) + return ret; + jintArray jsensors = static_cast(aenv.jniEnv->CallStaticObjectMethod(sensorsClass, + getSensorListMethodId)); + jint *sensors = aenv.jniEnv->GetIntArrayElements(jsensors, 0); + const uint sz = aenv.jniEnv->GetArrayLength(jsensors); + for (uint i = 0; i < sz; i++) + ret.push_back(AndroidSensorType(sensors[i])); + aenv.jniEnv->ReleaseIntArrayElements(jsensors, sensors, 0); + return ret; + } + + QString sensorDescription(AndroidSensorType sensor) + { + AttachedJNIEnv aenv; + if (!aenv.jniEnv) + return QString(); + jstring jstr = static_cast(aenv.jniEnv->CallStaticObjectMethod(sensorsClass, + getSensorDescriptionMethodId, + jint(sensor))); + const jchar *pstr = aenv.jniEnv->GetStringChars(jstr, 0); + QString ret(reinterpret_cast(pstr), aenv.jniEnv->GetStringLength(jstr)); + aenv.jniEnv->ReleaseStringChars(jstr, pstr); + aenv.jniEnv->DeleteLocalRef(jstr); + return ret; + } + + bool registerListener(AndroidSensorType sensor, AndroidSensorsListenerInterface *listener, int dataRate) + { + listenersLocker.lockForWrite(); + bool startService = listenersHash[sensor].empty(); + listenersHash[sensor].push_back(listener); + listenersLocker.unlock(); + if (startService) { + AttachedJNIEnv aenv; + if (!aenv.jniEnv) + return false; + int rate = dataRate > 0 ? 1000000/dataRate : SENSOR_DELAY_GAME; + return aenv.jniEnv->CallStaticBooleanMethod(sensorsClass, + registerSensorMethodId, + jint(sensor), + jint(rate)); + } + return true; + } + + bool unregisterListener(AndroidSensorType sensor, AndroidSensorsListenerInterface *listener) + { + listenersLocker.lockForWrite(); + listenersHash[sensor].removeOne(listener); + bool stopService = listenersHash[sensor].empty(); + if (stopService) + listenersHash.remove(sensor); + listenersLocker.unlock(); + if (stopService) { + AttachedJNIEnv aenv; + if (!aenv.jniEnv) + return false; + return aenv.jniEnv->CallStaticBooleanMethod(sensorsClass, unregisterSensorMethodId, jint(sensor)); + } + return true; + } +} + +static const char logTag[] = "Qt"; +static const char classErrorMsg[] = "Can't find class \"%s\""; +static const char methodErrorMsg[] = "Can't find method \"%s%s\""; + +static void accuracyChanged(JNIEnv * /*env*/, jobject /*thiz*/, jint sensor, jint accuracy) +{ + listenersLocker.lockForRead(); + foreach (AndroidSensors::AndroidSensorsListenerInterface *listener, listenersHash[sensor]) + listener->onAccuracyChanged(accuracy); + listenersLocker.unlock(); +} + +static void sensorChanged(JNIEnv *env, jobject /*thiz*/, jint sensor, jlong timeStamp, jfloatArray array) +{ + uint size = env->GetArrayLength(array); + jfloat *values = env->GetFloatArrayElements(array, 0); + listenersLocker.lockForRead(); + foreach (AndroidSensors::AndroidSensorsListenerInterface *listener, listenersHash[sensor]) + listener->onSensorChanged(timeStamp, values, size); + listenersLocker.unlock(); + env->ReleaseFloatArrayElements(array, values, JNI_ABORT); // don't copy back the elements + +} + +static JNINativeMethod methods[] = { + {"accuracyChanged", "(II)V", (void *)accuracyChanged}, + {"sensorChanged", "(IJ[F)V", (void *)sensorChanged} +}; + +#define FIND_AND_CHECK_CLASS(CLASS_NAME) \ +clazz = env->FindClass(CLASS_NAME); \ +if (!clazz) { \ + __android_log_print(ANDROID_LOG_FATAL, logTag, classErrorMsg, CLASS_NAME); \ + return JNI_FALSE; \ +} + +#define GET_AND_CHECK_STATIC_METHOD(VAR, CLASS, METHOD_NAME, METHOD_SIGNATURE) \ +VAR = env->GetStaticMethodID(CLASS, METHOD_NAME, METHOD_SIGNATURE); \ +if (!VAR) { \ + __android_log_print(ANDROID_LOG_FATAL, logTag, methodErrorMsg, METHOD_NAME, METHOD_SIGNATURE); \ + return JNI_FALSE; \ +} + +static bool registerNatives(JNIEnv *env) +{ + jclass clazz; + FIND_AND_CHECK_CLASS("org/qtproject/qt5/android/sensors/QtSensors"); + sensorsClass = static_cast(env->NewGlobalRef(clazz)); + + if (env->RegisterNatives(sensorsClass, methods, sizeof(methods) / sizeof(methods[0])) < 0) { + __android_log_print(ANDROID_LOG_FATAL, logTag, "RegisterNatives failed"); + return JNI_FALSE; + } + + GET_AND_CHECK_STATIC_METHOD(getSensorListMethodId, sensorsClass, "getSensorList", "()[I"); + GET_AND_CHECK_STATIC_METHOD(registerSensorMethodId, sensorsClass, "registerSensor", "(II)Z"); + GET_AND_CHECK_STATIC_METHOD(unregisterSensorMethodId, sensorsClass, "unregisterSensor", "(I)Z"); + GET_AND_CHECK_STATIC_METHOD(getSensorDescriptionMethodId, sensorsClass, "getSensorDescription", "(I)Ljava/lang/String;"); + + return true; +} + +Q_DECL_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void * /*reserved*/) +{ + typedef union { + JNIEnv *nativeEnvironment; + void *venv; + } UnionJNIEnvToVoid; + + __android_log_print(ANDROID_LOG_INFO, logTag, "Sensors start"); + UnionJNIEnvToVoid uenv; + uenv.venv = NULL; + javaVM = 0; + + if (vm->GetEnv(&uenv.venv, JNI_VERSION_1_4) != JNI_OK) { + __android_log_print(ANDROID_LOG_FATAL, logTag, "GetEnv failed"); + return -1; + } + JNIEnv *env = uenv.nativeEnvironment; + if (!registerNatives(env)) { + __android_log_print(ANDROID_LOG_FATAL, logTag, "registerNatives failed"); + return -1; + } + + javaVM = vm; + return JNI_VERSION_1_4; +} diff --git a/src/plugins/sensors/android/src/androidjnisensors.h b/src/plugins/sensors/android/src/androidjnisensors.h new file mode 100644 index 0000000..53ca58d --- /dev/null +++ b/src/plugins/sensors/android/src/androidjnisensors.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2013 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ANDROIDJNISENSORS_H +#define ANDROIDJNISENSORS_H + +#include + +#include +#include + +namespace AndroidSensors +{ + // must be in sync with https://developer.android.com/reference/android/hardware/Sensor.html#TYPE_ACCELEROMETER + enum AndroidSensorType + { + TYPE_ACCELEROMETER = 1, + TYPE_AMBIENT_TEMPERATURE = 13, + TYPE_GRAVITY = 9, + TYPE_GYROSCOPE = 4, + TYPE_LIGHT = 5, + TYPE_LINEAR_ACCELERATION = 10, + TYPE_MAGNETIC_FIELD = 2, + TYPE_ORIENTATION = 3, //This constant was deprecated in API level 8. use SensorManager.getOrientation() instead. + TYPE_PRESSURE = 6, + TYPE_PROXIMITY = 8, + TYPE_RELATIVE_HUMIDITY = 12, + TYPE_ROTATION_VECTOR = 11, + TYPE_TEMPERATURE = 7 //This constant was deprecated in API level 14. use Sensor.TYPE_AMBIENT_TEMPERATURE instead. + }; + + struct AndroidSensorsListenerInterface + { + virtual ~AndroidSensorsListenerInterface() {} + virtual void onAccuracyChanged(jint accuracy) = 0; + virtual void onSensorChanged(jlong timestamp, const jfloat *values, uint size) = 0; + }; + + QVector availableSensors(); + QString sensorDescription(AndroidSensorType sensor); + bool registerListener(AndroidSensorType sensor, AndroidSensorsListenerInterface *listener, int dataRate = 0); + bool unregisterListener(AndroidSensorType sensor, AndroidSensorsListenerInterface *listener); +} + +#endif // ANDROIDJNISENSORS_H diff --git a/src/plugins/sensors/android/src/androidlight.cpp b/src/plugins/sensors/android/src/androidlight.cpp new file mode 100644 index 0000000..42295e5 --- /dev/null +++ b/src/plugins/sensors/android/src/androidlight.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2013 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "androidlight.h" + +AndroidLight::AndroidLight(AndroidSensors::AndroidSensorType type, QSensor *sensor) + : AndroidCommonSensor(type, sensor) +{} + + +void AndroidLight::onAccuracyChanged(jint accuracy) +{ + Q_UNUSED(accuracy) +} + +void AndroidLight::onSensorChanged(jlong timestamp, const jfloat *values, uint size) +{ + if (size < 1) + return; + m_reader.setTimestamp(timestamp); + // check https://developer.android.com/reference/android/hardware/SensorEvent.html#values + m_reader.setLux(values[0]); + newReadingAvailable(); +} diff --git a/src/plugins/sensors/android/src/androidlight.h b/src/plugins/sensors/android/src/androidlight.h new file mode 100644 index 0000000..fdea3ed --- /dev/null +++ b/src/plugins/sensors/android/src/androidlight.h @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2013 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ANDROIDLIGHT_H +#define ANDROIDLIGHT_H +#include + +#include "androidcommonsensor.h" + +class AndroidLight : public AndroidCommonSensor +{ +public: + AndroidLight(AndroidSensors::AndroidSensorType type, QSensor *sensor); +private: + virtual void onAccuracyChanged(jint accuracy); + virtual void onSensorChanged(jlong timestamp, const jfloat *values, uint size); +}; + +#endif // ANDROIDLIGHT_H diff --git a/src/plugins/sensors/android/src/androidmagnetometer.cpp b/src/plugins/sensors/android/src/androidmagnetometer.cpp new file mode 100644 index 0000000..9175f58 --- /dev/null +++ b/src/plugins/sensors/android/src/androidmagnetometer.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2013 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "androidmagnetometer.h" + +AndroidMagnetometer::AndroidMagnetometer(AndroidSensors::AndroidSensorType type, QSensor *sensor) + :AndroidCommonSensor(type, sensor) +{} + +void AndroidMagnetometer::onAccuracyChanged(jint accuracy) +{ + m_reader.setCalibrationLevel(accuracy); +} + +void AndroidMagnetometer::onSensorChanged(jlong timestamp, const jfloat *values, uint size) +{ + if (size<3) + return; + m_reader.setTimestamp(timestamp); + // check https://developer.android.com/reference/android/hardware/SensorEvent.html#values + m_reader.setX(values[0]/1e6); + m_reader.setY(values[1]/1e6); + m_reader.setZ(values[2]/1e6); + newReadingAvailable(); +} diff --git a/src/plugins/sensors/android/src/androidmagnetometer.h b/src/plugins/sensors/android/src/androidmagnetometer.h new file mode 100644 index 0000000..57d9f36 --- /dev/null +++ b/src/plugins/sensors/android/src/androidmagnetometer.h @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2013 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ANDROIDMAGNETOMETER_H +#define ANDROIDMAGNETOMETER_H +#include + +#include "androidcommonsensor.h" + +class AndroidMagnetometer : public AndroidCommonSensor +{ +public: + AndroidMagnetometer(AndroidSensors::AndroidSensorType type, QSensor *sensor); +private: + virtual void onAccuracyChanged(jint accuracy); + virtual void onSensorChanged(jlong timestamp, const jfloat *values, uint size); +}; + +#endif // ANDROIDMAGNETOMETER_H diff --git a/src/plugins/sensors/android/src/androidrotation.cpp b/src/plugins/sensors/android/src/androidrotation.cpp new file mode 100644 index 0000000..602575f --- /dev/null +++ b/src/plugins/sensors/android/src/androidrotation.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2013 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "androidrotation.h" +#include + +AndroidRotation::AndroidRotation(AndroidSensors::AndroidSensorType type, QSensor *sensor) + : AndroidCommonSensor(type, sensor) +{} + +void AndroidRotation::onAccuracyChanged(jint accuracy) +{ + Q_UNUSED(accuracy) +} + +void AndroidRotation::onSensorChanged(jlong timestamp, const jfloat *values, uint size) +{ + if (size < 3) + return; + m_reader.setTimestamp(timestamp); + + float rz = -values[0]*180/M_PI; + float rx = -values[1]*180/M_PI; + float ry = values[2]*180/M_PI; + m_reader.setFromEuler(rx, ry, rz); + newReadingAvailable(); +} diff --git a/src/plugins/sensors/android/src/androidrotation.h b/src/plugins/sensors/android/src/androidrotation.h new file mode 100644 index 0000000..cd2c4d6 --- /dev/null +++ b/src/plugins/sensors/android/src/androidrotation.h @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2013 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ANDROIDROTATION_H +#define ANDROIDROTATION_H +#include + +#include "androidcommonsensor.h" +class AndroidRotation : public AndroidCommonSensor +{ +public: + AndroidRotation(AndroidSensors::AndroidSensorType type, QSensor *sensor); +private: + virtual void onAccuracyChanged(jint accuracy); + virtual void onSensorChanged(jlong timestamp, const jfloat *values, uint size); +}; + +#endif // ANDROIDROTATION_H diff --git a/src/plugins/sensors/android/src/main.cpp b/src/plugins/sensors/android/src/main.cpp new file mode 100644 index 0000000..0cb4de4 --- /dev/null +++ b/src/plugins/sensors/android/src/main.cpp @@ -0,0 +1,135 @@ +/**************************************************************************** +** +** Copyright (C) 2013 BogDan Vatra +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include "androidaccelerometer.h" +#include "androidgyroscope.h" +#include "androidlight.h" +#include "androidmagnetometer.h" +#include "androidrotation.h" + +using namespace AndroidSensors; + +class AndroidSensorPlugin : public QObject, public QSensorPluginInterface, public QSensorBackendFactory +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QSensorPluginInterface/1.0" FILE "plugin.json") + Q_INTERFACES(QSensorPluginInterface) +public: + void registerSensors() + { + foreach (AndroidSensorType sensor, availableSensors()) { + switch (sensor) { + case TYPE_ACCELEROMETER: + QSensorManager::registerBackend(QAccelerometer::type, QByteArray::number(sensor), this); + break; + case TYPE_AMBIENT_TEMPERATURE: + case TYPE_TEMPERATURE: + break; // add the temperature sensor backend + case TYPE_GRAVITY: + break; // add the gravity sensor backend + case TYPE_GYROSCOPE: + QSensorManager::registerBackend(QGyroscope::type, QByteArray::number(sensor), this); + break; + case TYPE_LIGHT: + QSensorManager::registerBackend(QLightSensor::type, QByteArray::number(sensor), this); + break; // add the light sensor backend + case TYPE_LINEAR_ACCELERATION: + break; // add the linear acceleration sensor backend + case TYPE_MAGNETIC_FIELD: + QSensorManager::registerBackend(QMagnetometer::type, QByteArray::number(sensor), this); + break; + case TYPE_ORIENTATION: + break; // add the orientation sensor backend + case TYPE_PRESSURE: + break; // add the pressure sensor backend + case TYPE_PROXIMITY: + break; // add the proximity sensor backend + case TYPE_RELATIVE_HUMIDITY: + break; // add the relative humidity sensor backend + case TYPE_ROTATION_VECTOR: + QSensorManager::registerBackend(QRotationSensor::type, QByteArray::number(sensor), this); + break; + } + } + } + + QSensorBackend *createBackend(QSensor *sensor) + { + AndroidSensorType type = static_cast(sensor->identifier().toInt()); + switch (type) { + case TYPE_ACCELEROMETER: + return new AndroidAccelerometer(type, sensor); + case TYPE_AMBIENT_TEMPERATURE: + case TYPE_TEMPERATURE: + break; // add the temperature sensor backend + case TYPE_GRAVITY: + break; // add the gravity sensor backend + case TYPE_GYROSCOPE: + return new AndroidGyroscope(type, sensor); + case TYPE_LIGHT: + return new AndroidLight(type, sensor); + case TYPE_LINEAR_ACCELERATION: + break; // add the linear acceleration sensor backend + case TYPE_MAGNETIC_FIELD: + return new AndroidMagnetometer(type, sensor); + case TYPE_ORIENTATION: + break; // add the orientation sensor backend + case TYPE_PRESSURE: + break; // add the pressure sensor backend + case TYPE_PROXIMITY: + break; // add the proximity sensor backend + case TYPE_RELATIVE_HUMIDITY: + break; // add the relative humidity sensor backend + case TYPE_ROTATION_VECTOR: + return new AndroidRotation(type, sensor); + } + return 0; + } +}; + +Q_IMPORT_PLUGIN (AndroidSensorPlugin) // automatically register the plugin + +#include "main.moc" + diff --git a/src/plugins/sensors/android/src/plugin.json b/src/plugins/sensors/android/src/plugin.json new file mode 100644 index 0000000..8a55b3a --- /dev/null +++ b/src/plugins/sensors/android/src/plugin.json @@ -0,0 +1 @@ +{ "Keys": [ "notused" ] } diff --git a/src/plugins/sensors/android/src/src.pro b/src/plugins/sensors/android/src/src.pro new file mode 100644 index 0000000..715a011 --- /dev/null +++ b/src/plugins/sensors/android/src/src.pro @@ -0,0 +1,29 @@ +TARGET = qtsensors_android +QT = sensors core + +PLUGIN_TYPE = sensors +load(qt_plugin) + +# STATICPLUGIN needed because there's a Q_IMPORT_PLUGIN in main.cpp +# Yes, the plugin imports itself statically +DEFINES += QT_STATICPLUGIN + +HEADERS = \ + androidjnisensors.h \ + androidaccelerometer.h \ + androidcommonsensor.h \ + androidgyroscope.h \ + androidmagnetometer.h \ + androidrotation.h \ + androidlight.h + +SOURCES = \ + main.cpp \ + androidjnisensors.cpp \ + androidaccelerometer.cpp \ + androidgyroscope.cpp \ + androidmagnetometer.cpp \ + androidrotation.cpp \ + androidlight.cpp + +OTHER_FILES = plugin.json diff --git a/src/plugins/sensors/generic/generic.pro b/src/plugins/sensors/generic/generic.pro index 5bfeff6..fcc1bfc 100644 --- a/src/plugins/sensors/generic/generic.pro +++ b/src/plugins/sensors/generic/generic.pro @@ -8,15 +8,23 @@ HEADERS += generictiltsensor.h SOURCES += main.cpp\ generictiltsensor.cpp +DEFINES += QTSENSORS_GENERICTILTSENSOR !blackberry { HEADERS += genericorientationsensor.h\ - genericrotationsensor.h\ genericalssensor.h SOURCES += genericorientationsensor.cpp\ - genericrotationsensor.cpp\ genericalssensor.cpp + DEFINES += QTSENSORS_GENERICORIENTATIONSENSOR QTSENSORS_GENERICALSSENSOR +} + +!blackberry:!android { + HEADERS += genericrotationsensor.h + + SOURCES += genericrotationsensor.cpp + + DEFINES += QTSENSORS_GENERICROTATIONSENSOR } OTHER_FILES = plugin.json diff --git a/src/plugins/sensors/generic/main.cpp b/src/plugins/sensors/generic/main.cpp index 4b348b1..aa9f58c 100644 --- a/src/plugins/sensors/generic/main.cpp +++ b/src/plugins/sensors/generic/main.cpp @@ -39,12 +39,18 @@ ** ****************************************************************************/ -#ifndef Q_OS_BLACKBERRY +#ifdef QTSENSORS_GENERICORIENTATIONSENSOR #include "genericorientationsensor.h" +#endif +#ifdef QTSENSORS_GENERICROTATIONSENSOR #include "genericrotationsensor.h" +#endif +#ifdef QTSENSORS_GENERICALSSENSOR #include "genericalssensor.h" #endif +#ifdef QTSENSORS_GENERICTILTSENSOR #include "generictiltsensor.h" +#endif #include #include #include @@ -66,44 +72,60 @@ public: { if (!QSensor::defaultSensorForType(QAccelerometer::type).isEmpty()) { // There is an accelerometer available. Register the backends -#ifndef Q_OS_BLACKBERRY +#ifdef QTSENSORS_GENERICORIENTATIONSENSOR if (!QSensorManager::isBackendRegistered(QOrientationSensor::type, genericorientationsensor::id)) QSensorManager::registerBackend(QOrientationSensor::type, genericorientationsensor::id, this); +#endif +#ifdef QTSENSORS_GENERICROTATIONSENSOR if (!QSensorManager::isBackendRegistered(QRotationSensor::type, genericrotationsensor::id)) QSensorManager::registerBackend(QRotationSensor::type, genericrotationsensor::id, this); +#endif +#ifdef QTSENSORS_GENERICALSSENSOR if (!QSensorManager::isBackendRegistered(QAmbientLightSensor::type, genericalssensor::id)) QSensorManager::registerBackend(QAmbientLightSensor::type, genericalssensor::id, this); #endif +#ifdef QTSENSORS_GENERICTILTSENSOR if (!QSensorManager::isBackendRegistered(QTiltSensor::type, GenericTiltSensor::id)) QSensorManager::registerBackend(QTiltSensor::type, GenericTiltSensor::id, this); +#endif } else { -#ifndef Q_OS_BLACKBERRY +#ifdef QTSENSORS_GENERICORIENTATIONSENSOR if (QSensorManager::isBackendRegistered(QOrientationSensor::type, genericorientationsensor::id)) QSensorManager::unregisterBackend(QOrientationSensor::type, genericorientationsensor::id); +#endif +#ifdef QTSENSORS_GENERICROTATIONSENSOR if (QSensorManager::isBackendRegistered(QRotationSensor::type, genericrotationsensor::id)) QSensorManager::unregisterBackend(QRotationSensor::type, genericrotationsensor::id); +#endif +#ifdef QTSENSORS_GENERICALSSENSOR if (QSensorManager::isBackendRegistered(QAmbientLightSensor::type, genericalssensor::id)) QSensorManager::unregisterBackend(QAmbientLightSensor::type, genericalssensor::id); #endif +#ifdef QTSENSORS_GENERICTILTSENSOR if (QSensorManager::isBackendRegistered(QTiltSensor::type, GenericTiltSensor::id)) QSensorManager::unregisterBackend(QTiltSensor::type, GenericTiltSensor::id); +#endif } } QSensorBackend *createBackend(QSensor *sensor) { -#ifndef Q_OS_BLACKBERRY +#ifdef QTSENSORS_GENERICORIENTATIONSENSOR if (sensor->identifier() == genericorientationsensor::id) return new genericorientationsensor(sensor); - +#endif +#ifdef QTSENSORS_GENERICROTATIONSENSOR if (sensor->identifier() == genericrotationsensor::id) return new genericrotationsensor(sensor); - +#endif +#ifdef QTSENSORS_GENERICALSSENSOR if (sensor->identifier() == genericalssensor::id) return new genericalssensor(sensor); #endif +#ifdef QTSENSORS_GENERICTILTSENSOR if (sensor->identifier() == GenericTiltSensor::id) return new GenericTiltSensor(sensor); +#endif return 0; } diff --git a/src/plugins/sensors/sensors.pro b/src/plugins/sensors/sensors.pro index a8b59b0..3822daf 100644 --- a/src/plugins/sensors/sensors.pro +++ b/src/plugins/sensors/sensors.pro @@ -4,9 +4,13 @@ TEMPLATE = subdirs # of these. This reduces compile time and plugin loading time. blackberry { isEmpty(SENSORS_PLUGINS): SENSORS_PLUGINS = blackberry generic +} else: android { + SENSORS_PLUGINS = android generic } + isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, dummy):SUBDIRS += dummy isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, generic):SUBDIRS += generic isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, simulator):simulator:SUBDIRS += simulator isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, blackberry):blackberry:SUBDIRS += blackberry isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, linux):linux:SUBDIRS += linux +isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, android):android:SUBDIRS += android diff --git a/src/sensors/doc/src/compatmap.qdoc b/src/sensors/doc/src/compatmap.qdoc index abb71a1..8fe24ad 100644 --- a/src/sensors/doc/src/compatmap.qdoc +++ b/src/sensors/doc/src/compatmap.qdoc @@ -54,6 +54,7 @@ Feature Blackberry + Android Linux Generic @@ -61,6 +62,7 @@ Accelerometer + @@ -68,28 +70,33 @@ + Ambient Light Sensor + Ambient Temperature Sensor + Compass + Gyroscope + @@ -98,22 +105,26 @@ + IR Proximity Sensor + Light Sensor + Magnetometer + @@ -121,6 +132,7 @@ Orientation Sensor + @@ -128,16 +140,19 @@ + Proximity Sensor + Rotation Sensor + @@ -146,11 +161,20 @@ + + + + Tilt Sensor + + + + Sensor Gestures + 1) diff --git a/src/sensors/sensors.pro b/src/sensors/sensors.pro index b70c17c..fe10a5e 100644 --- a/src/sensors/sensors.pro +++ b/src/sensors/sensors.pro @@ -12,6 +12,11 @@ simulator { QMAKE_DOCS = $$PWD/doc/qtsensors.qdocconf +ANDROID_JAR_DEPENDENCIES = \ + jar/QtSensors.jar:org.qtproject.qt5.android.sensors.QtSensors +ANDROID_LIB_DEPENDENCIES = \ + plugins/sensors/libqtsensors_android.so + load(qt_module) PUBLIC_HEADERS += \ -- cgit v1.2.1 From fe2a949996e1e93f0824f4e49b423b4b57090a72 Mon Sep 17 00:00:00 2001 From: Lorn Potter Date: Wed, 6 Mar 2013 03:45:47 +1000 Subject: add sensorfw based sensor plugin ported from qtmobility. Change-Id: Ia4ee6e2b7ecbc441c5f6605f1bbabfec22ddcd09 Reviewed-by: Lorn Potter --- src/plugins/sensors/sensorfw/Sensors.conf | 11 ++ src/plugins/sensors/sensorfw/main.cpp | 109 ++++++++++++ src/plugins/sensors/sensorfw/plugin.json | 1 + src/plugins/sensors/sensorfw/sensorfw.pri | 26 +++ src/plugins/sensors/sensorfw/sensorfw.pro | 17 ++ .../sensors/sensorfw/sensorfwaccelerometer.cpp | 91 ++++++++++ .../sensors/sensorfw/sensorfwaccelerometer.h | 74 ++++++++ src/plugins/sensors/sensorfw/sensorfwals.cpp | 111 ++++++++++++ src/plugins/sensors/sensorfw/sensorfwals.h | 75 ++++++++ src/plugins/sensors/sensorfw/sensorfwcompass.cpp | 80 +++++++++ src/plugins/sensors/sensorfw/sensorfwcompass.h | 70 ++++++++ src/plugins/sensors/sensorfw/sensorfwgyroscope.cpp | 90 ++++++++++ src/plugins/sensors/sensorfw/sensorfwgyroscope.h | 78 +++++++++ .../sensors/sensorfw/sensorfwirproximitysensor.cpp | 81 +++++++++ .../sensors/sensorfw/sensorfwirproximitysensor.h | 71 ++++++++ .../sensors/sensorfw/sensorfwlightsensor.cpp | 71 ++++++++ src/plugins/sensors/sensorfw/sensorfwlightsensor.h | 72 ++++++++ .../sensors/sensorfw/sensorfwmagnetometer.cpp | 98 +++++++++++ .../sensors/sensorfw/sensorfwmagnetometer.h | 79 +++++++++ .../sensors/sensorfw/sensorfworientationsensor.cpp | 98 +++++++++++ .../sensors/sensorfw/sensorfworientationsensor.h | 74 ++++++++ .../sensors/sensorfw/sensorfwproximitysensor.cpp | 87 ++++++++++ .../sensors/sensorfw/sensorfwproximitysensor.h | 75 ++++++++ .../sensors/sensorfw/sensorfwrotationsensor.cpp | 79 +++++++++ .../sensors/sensorfw/sensorfwrotationsensor.h | 75 ++++++++ .../sensors/sensorfw/sensorfwsensorbase.cpp | 189 +++++++++++++++++++++ src/plugins/sensors/sensorfw/sensorfwsensorbase.h | 170 ++++++++++++++++++ src/plugins/sensors/sensorfw/sensorfwtapsensor.cpp | 110 ++++++++++++ src/plugins/sensors/sensorfw/sensorfwtapsensor.h | 73 ++++++++ src/plugins/sensors/sensors.pro | 12 +- src/sensors/doc/src/compatmap.qdoc | 14 +- src/sensors/doc/src/qtsensors.qdoc | 3 + src/sensors/doc/src/sensorfwbackend.qdoc | 39 +++++ 33 files changed, 2400 insertions(+), 3 deletions(-) create mode 100644 src/plugins/sensors/sensorfw/Sensors.conf create mode 100644 src/plugins/sensors/sensorfw/main.cpp create mode 100644 src/plugins/sensors/sensorfw/plugin.json create mode 100644 src/plugins/sensors/sensorfw/sensorfw.pri create mode 100644 src/plugins/sensors/sensorfw/sensorfw.pro create mode 100644 src/plugins/sensors/sensorfw/sensorfwaccelerometer.cpp create mode 100644 src/plugins/sensors/sensorfw/sensorfwaccelerometer.h create mode 100644 src/plugins/sensors/sensorfw/sensorfwals.cpp create mode 100644 src/plugins/sensors/sensorfw/sensorfwals.h create mode 100644 src/plugins/sensors/sensorfw/sensorfwcompass.cpp create mode 100644 src/plugins/sensors/sensorfw/sensorfwcompass.h create mode 100644 src/plugins/sensors/sensorfw/sensorfwgyroscope.cpp create mode 100644 src/plugins/sensors/sensorfw/sensorfwgyroscope.h create mode 100644 src/plugins/sensors/sensorfw/sensorfwirproximitysensor.cpp create mode 100644 src/plugins/sensors/sensorfw/sensorfwirproximitysensor.h create mode 100644 src/plugins/sensors/sensorfw/sensorfwlightsensor.cpp create mode 100644 src/plugins/sensors/sensorfw/sensorfwlightsensor.h create mode 100644 src/plugins/sensors/sensorfw/sensorfwmagnetometer.cpp create mode 100644 src/plugins/sensors/sensorfw/sensorfwmagnetometer.h create mode 100644 src/plugins/sensors/sensorfw/sensorfworientationsensor.cpp create mode 100644 src/plugins/sensors/sensorfw/sensorfworientationsensor.h create mode 100644 src/plugins/sensors/sensorfw/sensorfwproximitysensor.cpp create mode 100644 src/plugins/sensors/sensorfw/sensorfwproximitysensor.h create mode 100644 src/plugins/sensors/sensorfw/sensorfwrotationsensor.cpp create mode 100644 src/plugins/sensors/sensorfw/sensorfwrotationsensor.h create mode 100644 src/plugins/sensors/sensorfw/sensorfwsensorbase.cpp create mode 100644 src/plugins/sensors/sensorfw/sensorfwsensorbase.h create mode 100644 src/plugins/sensors/sensorfw/sensorfwtapsensor.cpp create mode 100644 src/plugins/sensors/sensorfw/sensorfwtapsensor.h create mode 100644 src/sensors/doc/src/sensorfwbackend.qdoc diff --git a/src/plugins/sensors/sensorfw/Sensors.conf b/src/plugins/sensors/sensorfw/Sensors.conf new file mode 100644 index 0000000..a003f12 --- /dev/null +++ b/src/plugins/sensors/sensorfw/Sensors.conf @@ -0,0 +1,11 @@ +[Default] +QAccelerometer=sensorfw.accelerometer +QAmbientLightSensor=sensorfw.als +QCompass=sensorfw.compass +QMagnetometer=sensorfw.magnetometer +QOrientationSensor=sensorfw.orientationsensor +QProximitySensor=sensorfw.proximitysensor +QRotationSensor=sensorfw.rotationsensor +QTapSensor=sensorfw.tapsensor +QLightSensor=sensorfw.lightsensor +QIRProximitySensor=sensorfw.irproximitysensor diff --git a/src/plugins/sensors/sensorfw/main.cpp b/src/plugins/sensors/sensorfw/main.cpp new file mode 100644 index 0000000..f12a193 --- /dev/null +++ b/src/plugins/sensors/sensorfw/main.cpp @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sensorfwaccelerometer.h" +#include "sensorfwals.h" +#include "sensorfwcompass.h" +#include "sensorfwmagnetometer.h" +#include "sensorfworientationsensor.h" +#include "sensorfwproximitysensor.h" +#include "sensorfwirproximitysensor.h" +#include "sensorfwrotationsensor.h" +#include "sensorfwtapsensor.h" +#include "sensorfwgyroscope.h" +#include "sensorfwlightsensor.h" + +#include +#include +#include +#include +#include + +class sensorfwSensorPlugin : public QObject, public QSensorPluginInterface, public QSensorBackendFactory +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "com.qt-project.Qt.QSensorPluginInterface/1.0" FILE "plugin.json") + Q_INTERFACES(QSensorPluginInterface) + +public: + + void registerSensors() + { + // if no default - no support either, uses Sensors.conf + QSettings settings(QSettings::SystemScope, QLatin1String("QtProject"), QLatin1String("Sensors")); + settings.beginGroup(QLatin1String("Default")); + QStringList keys = settings.allKeys(); + for (int i=0,l=keys.size(); iidentifier() == sensorfwaccelerometer::id) + return new sensorfwaccelerometer(sensor); + if (sensor->identifier() == Sensorfwals::id) + return new Sensorfwals(sensor); + if (sensor->identifier() == SensorfwCompass::id) + return new SensorfwCompass(sensor); + if (sensor->identifier() == SensorfwMagnetometer::id) + return new SensorfwMagnetometer(sensor); + if (sensor->identifier() == SensorfwOrientationSensor::id) + return new SensorfwOrientationSensor(sensor); + if (sensor->identifier() == SensorfwProximitySensor::id) + return new SensorfwProximitySensor(sensor); + if (sensor->identifier() == SensorfwRotationSensor::id) + return new SensorfwRotationSensor(sensor); + if (sensor->identifier() == SensorfwTapSensor::id) + return new SensorfwTapSensor(sensor); + if (sensor->identifier() == SensorfwGyroscope::id) + return new SensorfwGyroscope(sensor); + if (sensor->identifier() == SensorfwLightSensor::id) + return new SensorfwLightSensor(sensor); + if (sensor->identifier() == SensorfwIrProximitySensor::id) + return new SensorfwIrProximitySensor(sensor); + return 0; + } +}; + +#include "main.moc" diff --git a/src/plugins/sensors/sensorfw/plugin.json b/src/plugins/sensors/sensorfw/plugin.json new file mode 100644 index 0000000..8a55b3a --- /dev/null +++ b/src/plugins/sensors/sensorfw/plugin.json @@ -0,0 +1 @@ +{ "Keys": [ "notused" ] } diff --git a/src/plugins/sensors/sensorfw/sensorfw.pri b/src/plugins/sensors/sensorfw/sensorfw.pri new file mode 100644 index 0000000..31d7254 --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfw.pri @@ -0,0 +1,26 @@ +HEADERS += sensorfwsensorbase.h \ + sensorfwaccelerometer.h \ + sensorfwals.h \ + sensorfwcompass.h \ + sensorfwgyroscope.h \ + sensorfwmagnetometer.h \ + sensorfworientationsensor.h \ + sensorfwproximitysensor.h \ + sensorfwrotationsensor.h \ + sensorfwtapsensor.h \ + sensorfwlightsensor.h \ + sensorfwirproximitysensor.h + +SOURCES += sensorfwsensorbase.cpp \ + sensorfwaccelerometer.cpp \ + sensorfwals.cpp \ + sensorfwcompass.cpp \ + sensorfwgyroscope.cpp \ + sensorfwmagnetometer.cpp \ + sensorfworientationsensor.cpp \ + sensorfwproximitysensor.cpp \ + sensorfwirproximitysensor.cpp \ + sensorfwrotationsensor.cpp \ + sensorfwtapsensor.cpp \ + sensorfwlightsensor.cpp \ + main.cpp diff --git a/src/plugins/sensors/sensorfw/sensorfw.pro b/src/plugins/sensors/sensorfw/sensorfw.pro new file mode 100644 index 0000000..8d67c81 --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfw.pro @@ -0,0 +1,17 @@ +TARGET = qtsensors_sensorfw +QT = core sensors network + +PLUGIN_TYPE = sensors +load(qt_plugin) + +include(sensorfw.pri) + + +CONFIG += link_pkgconfig +PKGCONFIG += sensord + +CONFIGFILES.files = Sensors.conf +CONFIGFILES.path = /etc/xdg/QtProject/ +INSTALLS += CONFIGFILES + +OTHER_FILES = plugin.json diff --git a/src/plugins/sensors/sensorfw/sensorfwaccelerometer.cpp b/src/plugins/sensors/sensorfw/sensorfwaccelerometer.cpp new file mode 100644 index 0000000..ddbaa9c --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwaccelerometer.cpp @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sensorfwaccelerometer.h" + +char const * const sensorfwaccelerometer::id("sensorfw.accelerometer"); +bool sensorfwaccelerometer::m_initDone = false; + +sensorfwaccelerometer::sensorfwaccelerometer(QSensor *sensor) + : SensorfwSensorBase(sensor) +{ + initSensor(m_initDone); + setDescription(QLatin1String("x, y, and z axes accelerations in m/s^2")); + setRanges(GRAVITY_EARTH_THOUSANDTH); + setReading(&m_reading); +} + +void sensorfwaccelerometer::slotDataAvailable(const XYZ& data) +{ + // Convert from milli-Gs to meters per second per second + // Using 1 G = 9.80665 m/s^2 + m_reading.setX(-data.x() * GRAVITY_EARTH_THOUSANDTH); + m_reading.setY(-data.y() * GRAVITY_EARTH_THOUSANDTH); + m_reading.setZ(-data.z() * GRAVITY_EARTH_THOUSANDTH); + m_reading.setTimestamp(data.XYZData().timestamp_); + newReadingAvailable(); +} + +void sensorfwaccelerometer::slotFrameAvailable(const QVector& frame) +{ + for (int i=0, l=frame.size(); i& )),this, SLOT(slotFrameAvailable(const QVector& ))); +} + + +QString sensorfwaccelerometer::sensorName() const +{ + return "accelerometersensor"; +} + + +qreal sensorfwaccelerometer::correctionFactor() const +{ + return GRAVITY_EARTH_THOUSANDTH; +} diff --git a/src/plugins/sensors/sensorfw/sensorfwaccelerometer.h b/src/plugins/sensors/sensorfw/sensorfwaccelerometer.h new file mode 100644 index 0000000..1c94aae --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwaccelerometer.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef SENSORFWACCELEROMETER_H +#define SENSORFWACCELEROMETER_H + +#include "sensorfwsensorbase.h" +#include + +#include +#include + + + +class sensorfwaccelerometer : public SensorfwSensorBase +{ + Q_OBJECT + +public: + static char const * const id; + sensorfwaccelerometer(QSensor *sensor); +protected: + virtual bool doConnect(); + virtual QString sensorName() const; + virtual qreal correctionFactor() const; + + +private: + QAccelerometerReading m_reading; + static bool m_initDone; + +private slots: + void slotDataAvailable(const XYZ& data); + void slotFrameAvailable(const QVector&); +}; + +#endif diff --git a/src/plugins/sensors/sensorfw/sensorfwals.cpp b/src/plugins/sensors/sensorfw/sensorfwals.cpp new file mode 100644 index 0000000..811da77 --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwals.cpp @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include "sensorfwals.h" + +char const * const Sensorfwals::id("sensorfw.als"); +bool Sensorfwals::m_initDone = false; + +Sensorfwals::Sensorfwals(QSensor *sensor) + : SensorfwSensorBase(sensor) +{ + initSensor(m_initDone); + setReading(&m_reading); + // metadata + setDescription(QLatin1String("ambient light intensity given as 5 pre-defined levels")); + addOutputRange(0, 5, 1); + addDataRate(10,10); +} + +void Sensorfwals::start() +{ + if (m_sensorInterface) { + Unsigned data(((ALSSensorChannelInterface*)m_sensorInterface)->lux()); + m_reading.setLightLevel(getLightLevel(data.x())); + m_reading.setTimestamp(data.UnsignedData().timestamp_); + newReadingAvailable(); + } + SensorfwSensorBase::start(); +} + + +void Sensorfwals::slotDataAvailable(const Unsigned& data) +{ + QAmbientLightReading::LightLevel level = getLightLevel(data.x()); + if (level != m_reading.lightLevel()) { + m_reading.setLightLevel(level); + m_reading.setTimestamp(data.UnsignedData().timestamp_); + newReadingAvailable(); + } +} + +bool Sensorfwals::doConnect() +{ + return QObject::connect(m_sensorInterface, SIGNAL(ALSChanged(const Unsigned&)), + this, SLOT(slotDataAvailable(const Unsigned&))); +} + + +QString Sensorfwals::sensorName() const +{ + return "alssensor"; +} + + +QAmbientLightReading::LightLevel Sensorfwals::getLightLevel(int lux) +{ + // Convert from integer to fixed levels + if (lux < 0) { + return QAmbientLightReading::Undefined; + } else if (lux < 10) { + return QAmbientLightReading::Dark; + } else if (lux < 50) { + return QAmbientLightReading::Twilight; + } else if (lux < 100) { + return QAmbientLightReading::Light; + } else if (lux < 150) { + return QAmbientLightReading::Bright; + } else { + return QAmbientLightReading::Sunny; + } + +} diff --git a/src/plugins/sensors/sensorfw/sensorfwals.h b/src/plugins/sensors/sensorfw/sensorfwals.h new file mode 100644 index 0000000..ba7c9af --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwals.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SENSORFWALS_H +#define SENSORFWALS_H + +#include "sensorfwsensorbase.h" +#include + +#include +#include + + + +class Sensorfwals : public SensorfwSensorBase +{ + Q_OBJECT + +public: + static char const * const id; + Sensorfwals(QSensor *sensor); +protected: + virtual bool doConnect(); + virtual QString sensorName() const; + virtual void start(); + + +private: + QAmbientLightReading m_reading; + static bool m_initDone; +private slots: + void slotDataAvailable(const Unsigned& data); + static QAmbientLightReading::LightLevel getLightLevel(int lux); + +}; + +#endif diff --git a/src/plugins/sensors/sensorfw/sensorfwcompass.cpp b/src/plugins/sensors/sensorfw/sensorfwcompass.cpp new file mode 100644 index 0000000..00741a1 --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwcompass.cpp @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include "sensorfwcompass.h" + +char const * const SensorfwCompass::id("sensorfw.compass"); +bool SensorfwCompass::m_initDone = false; + +SensorfwCompass::SensorfwCompass(QSensor *sensor) + : SensorfwSensorBase(sensor) +{ + initSensor(m_initDone); + setReading(&m_reading); +} + +void SensorfwCompass::slotDataAvailable(const Compass& data) +{ + // The scale for level is [0,3], where 3 is the best + // Qt: Measured as a value from 0 to 1 with higher values being better. + m_reading.setCalibrationLevel(((float) data.level()) / 3.0); + + // The scale for degrees from sensord is [0,359] + // Value can be directly used as azimuth + m_reading.setAzimuth(data.degrees()); + + m_reading.setTimestamp(data.data().timestamp_); + newReadingAvailable(); +} + + +bool SensorfwCompass::doConnect() +{ + return QObject::connect(m_sensorInterface, SIGNAL(dataAvailable(const Compass&)), + this, SLOT(slotDataAvailable(const Compass&))); +} + +QString SensorfwCompass::sensorName() const +{ + return "compasssensor"; +} + diff --git a/src/plugins/sensors/sensorfw/sensorfwcompass.h b/src/plugins/sensors/sensorfw/sensorfwcompass.h new file mode 100644 index 0000000..e54c348 --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwcompass.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef SENSORFWCOMPASS_H +#define SENSORFWCOMPASS_H + +#include "sensorfwsensorbase.h" +#include + +#include +#include + + + +class SensorfwCompass : public SensorfwSensorBase +{ + Q_OBJECT + +public: + static char const * const id; + SensorfwCompass(QSensor *sensor); +protected: + virtual bool doConnect(); + virtual QString sensorName() const; + +private: + QCompassReading m_reading; + static bool m_initDone; +private slots: + void slotDataAvailable(const Compass& data); +}; + +#endif diff --git a/src/plugins/sensors/sensorfw/sensorfwgyroscope.cpp b/src/plugins/sensors/sensorfw/sensorfwgyroscope.cpp new file mode 100644 index 0000000..238993a --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwgyroscope.cpp @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sensorfwgyroscope.h" + +char const * const SensorfwGyroscope::id("sensorfw.gyroscope"); +const float SensorfwGyroscope::MILLI = 0.001; +bool SensorfwGyroscope::m_initDone = false; + +SensorfwGyroscope::SensorfwGyroscope(QSensor *sensor) + : SensorfwSensorBase(sensor) +{ + initSensor(m_initDone); + setDescription(QLatin1String("angular velocities around x, y, and z axis in degrees per second")); + setRanges(MILLI); + setReading(&m_reading); + addDataRate(10, 10); + addDataRate(50, 50); +} + +void SensorfwGyroscope::slotDataAvailable(const XYZ& data) +{ + m_reading.setX((qreal)(data.x()*MILLI)); + m_reading.setY((qreal)(data.y()*MILLI)); + m_reading.setZ((qreal)(data.z()*MILLI)); + m_reading.setTimestamp(data.XYZData().timestamp_); + newReadingAvailable(); +} + +void SensorfwGyroscope::slotFrameAvailable(const QVector& frame) +{ + for (int i=0, l=frame.size(); i& )),this, SLOT(slotFrameAvailable(const QVector& ))); +} + +QString SensorfwGyroscope::sensorName() const +{ + return "gyroscopesensor"; +} + +qreal SensorfwGyroscope::correctionFactor() const +{ + return MILLI; +} diff --git a/src/plugins/sensors/sensorfw/sensorfwgyroscope.h b/src/plugins/sensors/sensorfw/sensorfwgyroscope.h new file mode 100644 index 0000000..e982c80 --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwgyroscope.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#ifndef SENSORFWGYROSCOPE_H +#define SENSORFWGYROSCOPE_H + +#include "sensorfwsensorbase.h" +#include +#include +#include + + + + +class SensorfwGyroscope : public SensorfwSensorBase +{ + Q_OBJECT + +public: + static char const * const id; + SensorfwGyroscope(QSensor *sensor); +protected: + virtual bool doConnect(); + virtual QString sensorName() const; + virtual qreal correctionFactor() const; + + +private: + QGyroscopeReading m_reading; + static bool m_initDone; + static const float MILLI; +private slots: + void slotDataAvailable(const XYZ& data); + void slotFrameAvailable(const QVector&); + +}; + + +#endif // sensorfwGYROSCOPE_H diff --git a/src/plugins/sensors/sensorfw/sensorfwirproximitysensor.cpp b/src/plugins/sensors/sensorfw/sensorfwirproximitysensor.cpp new file mode 100644 index 0000000..865d376 --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwirproximitysensor.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sensorfwirproximitysensor.h" +#define RM680_PS "/dev/bh1770glc_ps" + +char const * const SensorfwIrProximitySensor::id("sensorfw.irproximitysensor"); +bool SensorfwIrProximitySensor::m_initDone = false; + + + +SensorfwIrProximitySensor::SensorfwIrProximitySensor(QSensor *sensor) + : SensorfwSensorBase(sensor) +{ + initSensor(m_initDone); + setReading(&m_reading); + setDescription(QLatin1String("reflectance as percentage (%) of maximum")); + addOutputRange(0, 100, 1); + addDataRate(10,10); + rangeMax = QFile::exists(RM680_PS)?255:1023; +} + +void SensorfwIrProximitySensor::slotDataAvailable(const Proximity& proximity) +{ + m_reading.setReflectance((float)proximity.reflectance()*100 / rangeMax); + m_reading.setTimestamp(proximity.UnsignedData().timestamp_); + newReadingAvailable(); +} + + +bool SensorfwIrProximitySensor::doConnect() +{ + return QObject::connect(m_sensorInterface, SIGNAL(reflectanceDataAvailable(const Proximity&)), + this, SLOT(slotDataAvailable(const Proximity&))); +} + + +QString SensorfwIrProximitySensor::sensorName() const +{ + return "proximitysensor"; +} + + diff --git a/src/plugins/sensors/sensorfw/sensorfwirproximitysensor.h b/src/plugins/sensors/sensorfw/sensorfwirproximitysensor.h new file mode 100644 index 0000000..c729f59 --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwirproximitysensor.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SENSORFWIRPROXIMITYSENSOR_H +#define SENSORFWIRPROXIMITYSENSOR_H + +#include "sensorfwsensorbase.h" +#include +#include + + +class SensorfwIrProximitySensor : public SensorfwSensorBase +{ + Q_OBJECT + +public: + static char const * const id; + + SensorfwIrProximitySensor(QSensor *sensor); +protected: + virtual bool doConnect(); + virtual QString sensorName() const; + +private: + QIRProximityReading m_reading; + static bool m_initDone; + int rangeMax; + +private slots: + void slotDataAvailable(const Proximity& proximity); +}; + +#endif diff --git a/src/plugins/sensors/sensorfw/sensorfwlightsensor.cpp b/src/plugins/sensors/sensorfw/sensorfwlightsensor.cpp new file mode 100644 index 0000000..b49e7b2 --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwlightsensor.cpp @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sensorfwlightsensor.h" + +char const * const SensorfwLightSensor::id("sensorfw.lightsensor"); +bool SensorfwLightSensor::m_initDone = false; + +SensorfwLightSensor::SensorfwLightSensor(QSensor *sensor) + : SensorfwSensorBase(sensor) +{ + initSensor(m_initDone); + setReading(&m_reading); +} + +void SensorfwLightSensor::slotDataAvailable(const Unsigned& data) +{ + m_reading.setLux(data.x()); + m_reading.setTimestamp(data.UnsignedData().timestamp_); + newReadingAvailable(); +} + +bool SensorfwLightSensor::doConnect() +{ + return QObject::connect(m_sensorInterface, SIGNAL(ALSChanged(const Unsigned&)), + this, SLOT(slotDataAvailable(const Unsigned&))); +} + + +QString SensorfwLightSensor::sensorName() const +{ + return "alssensor"; +} diff --git a/src/plugins/sensors/sensorfw/sensorfwlightsensor.h b/src/plugins/sensors/sensorfw/sensorfwlightsensor.h new file mode 100644 index 0000000..83591fa --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwlightsensor.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#ifndef SENSORFWLIGHTSENSOR_H +#define SENSORFWLIGHTSENSOR_H + +#include "sensorfwsensorbase.h" +#include + +#include +#include + + + +class SensorfwLightSensor : public SensorfwSensorBase +{ + Q_OBJECT + +public: + static char const * const id; + SensorfwLightSensor(QSensor *sensor); +protected: + virtual bool doConnect(); + virtual QString sensorName() const; + +private: + QLightReading m_reading; + static bool m_initDone; +private slots: + void slotDataAvailable(const Unsigned& data); +}; + +#endif diff --git a/src/plugins/sensors/sensorfw/sensorfwmagnetometer.cpp b/src/plugins/sensors/sensorfw/sensorfwmagnetometer.cpp new file mode 100644 index 0000000..9778b95 --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwmagnetometer.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sensorfwmagnetometer.h" + +char const * const SensorfwMagnetometer::id("sensorfw.magnetometer"); +bool SensorfwMagnetometer::m_initDone = false; +const float SensorfwMagnetometer::NANO = 0.000000001; + + +SensorfwMagnetometer::SensorfwMagnetometer(QSensor *sensor) + : SensorfwSensorBase(sensor) +{ + initSensor(m_initDone); + setDescription(QLatin1String("magnetic flux density in teslas (T)")); + setRanges(NANO); + setReading(&m_reading); +} + +void SensorfwMagnetometer::start() +{ + m_isGeoMagnetometer = sensor()->returnGeoValues(); + SensorfwSensorBase::start(); +} + +void SensorfwMagnetometer::slotDataAvailable(const MagneticField& data) +{ + //nanoTeslas given, divide with 10^9 to get Teslas + m_reading.setX( NANO * (m_isGeoMagnetometer?data.x():data.rx())); + m_reading.setY( NANO * (m_isGeoMagnetometer?data.y():data.ry())); + m_reading.setZ( NANO * (m_isGeoMagnetometer?data.z():data.rz())); + m_reading.setCalibrationLevel( m_isGeoMagnetometer?((float) data.level()) / 3.0 :1); + m_reading.setTimestamp(data.timestamp()); + newReadingAvailable(); +} + + +void SensorfwMagnetometer::slotFrameAvailable(const QVector& frame) +{ + for (int i=0, l=frame.size(); i& )),this, SLOT(slotFrameAvailable(const QVector& ))); +} + +QString SensorfwMagnetometer::sensorName() const +{ + return "magnetometersensor"; +} + +qreal SensorfwMagnetometer::correctionFactor() const +{ + return SensorfwMagnetometer::NANO; +} diff --git a/src/plugins/sensors/sensorfw/sensorfwmagnetometer.h b/src/plugins/sensors/sensorfw/sensorfwmagnetometer.h new file mode 100644 index 0000000..dff70c0 --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwmagnetometer.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SENSORFWMAGNETOMETER_H +#define SENSORFWMAGNETOMETER_H + +#include "sensorfwsensorbase.h" +#include + +#include +#include + + + +class SensorfwMagnetometer : public SensorfwSensorBase +{ + Q_OBJECT + +public: + static char const * const id; + SensorfwMagnetometer(QSensor *sensor); +protected: + virtual bool doConnect(); + virtual void start(); + virtual QString sensorName() const; + virtual qreal correctionFactor() const; + + +private: + static const float NANO; + QMagnetometerReading m_reading; + static bool m_initDone; + bool m_isGeoMagnetometer; + +private slots: + void slotDataAvailable(const MagneticField& data); + void slotFrameAvailable(const QVector&); + +}; + +#endif diff --git a/src/plugins/sensors/sensorfw/sensorfworientationsensor.cpp b/src/plugins/sensors/sensorfw/sensorfworientationsensor.cpp new file mode 100644 index 0000000..09dfb0e --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfworientationsensor.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sensorfworientationsensor.h" + +#include + +char const * const SensorfwOrientationSensor::id("sensorfw.orientationsensor"); +bool SensorfwOrientationSensor::m_initDone = false; + +SensorfwOrientationSensor::SensorfwOrientationSensor(QSensor *sensor) + : SensorfwSensorBase(sensor) +{ + initSensor(m_initDone); + setReading(&m_reading); +} + + +void SensorfwOrientationSensor::start() +{ + if (m_sensorInterface) { + Unsigned data(((OrientationSensorChannelInterface*)m_sensorInterface)->orientation()); + m_reading.setOrientation(SensorfwOrientationSensor::getOrientation(data.x())); + m_reading.setTimestamp(data.UnsignedData().timestamp_); + newReadingAvailable(); + } + SensorfwSensorBase::start(); +} + + +void SensorfwOrientationSensor::slotDataAvailable(const Unsigned& data) +{ + m_reading.setOrientation(SensorfwOrientationSensor::getOrientation(data.x())); + m_reading.setTimestamp(data.UnsignedData().timestamp_); + newReadingAvailable(); +} + +bool SensorfwOrientationSensor::doConnect() +{ + return QObject::connect(m_sensorInterface, SIGNAL(orientationChanged(const Unsigned&)), + this, SLOT(slotDataAvailable(const Unsigned&))); +} + +QString SensorfwOrientationSensor::sensorName() const +{ + return "orientationsensor"; +} + +QOrientationReading::Orientation SensorfwOrientationSensor::getOrientation(int orientation) +{ + switch (orientation) { + case PoseData::BottomDown: return QOrientationReading::TopUp; + case PoseData::BottomUp: return QOrientationReading::TopDown; + case PoseData::LeftUp: return QOrientationReading::LeftUp; + case PoseData::RightUp: return QOrientationReading::RightUp; + case PoseData::FaceUp: return QOrientationReading::FaceUp; + case PoseData::FaceDown: return QOrientationReading::FaceDown; + } + return QOrientationReading::Undefined; +} diff --git a/src/plugins/sensors/sensorfw/sensorfworientationsensor.h b/src/plugins/sensors/sensorfw/sensorfworientationsensor.h new file mode 100644 index 0000000..496939c --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfworientationsensor.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SENSORFWORIENTATIONSENSOR_H +#define SENSORFWORIENTATIONSENSOR_H + +#include "sensorfwsensorbase.h" +#include + +#include +#include + + + +class SensorfwOrientationSensor : public SensorfwSensorBase +{ + Q_OBJECT + +public: + static char const * const id; + SensorfwOrientationSensor(QSensor *sensor); +protected: + virtual bool doConnect(); + virtual QString sensorName() const; + virtual void start(); + +private: + QOrientationReading m_reading; + static QOrientationReading::Orientation getOrientation(int orientation); + static bool m_initDone; + +private slots: + void slotDataAvailable(const Unsigned& orientation); +}; + +#endif diff --git a/src/plugins/sensors/sensorfw/sensorfwproximitysensor.cpp b/src/plugins/sensors/sensorfw/sensorfwproximitysensor.cpp new file mode 100644 index 0000000..4602a9a --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwproximitysensor.cpp @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sensorfwproximitysensor.h" + +char const * const SensorfwProximitySensor::id("sensorfw.proximitysensor"); +bool SensorfwProximitySensor::m_initDone = false; + +SensorfwProximitySensor::SensorfwProximitySensor(QSensor *sensor) + : SensorfwSensorBase(sensor), m_exClose(false) +{ + initSensor(m_initDone); + setReading(&m_reading); + addDataRate(10,10); //TODO: fix this when we know better +} + +void SensorfwProximitySensor::start() +{ + if (m_sensorInterface) { + Unsigned data(((ProximitySensorChannelInterface*)m_sensorInterface)->proximity()); + m_reading.setClose(data.x()? true: false); + m_reading.setTimestamp(data.UnsignedData().timestamp_); + newReadingAvailable(); + } + SensorfwSensorBase::start(); +} + + +void SensorfwProximitySensor::slotDataAvailable(const Unsigned& data) +{ + bool close = data.x()? true: false; + if (close == m_exClose) return; + m_reading.setClose(close); + m_reading.setTimestamp(data.UnsignedData().timestamp_); + newReadingAvailable(); + m_exClose = close; +} + +bool SensorfwProximitySensor::doConnect() +{ + return (QObject::connect(m_sensorInterface, SIGNAL(dataAvailable(const Unsigned&)), + this, SLOT(slotDataAvailable(const Unsigned&)))); +} + + +QString SensorfwProximitySensor::sensorName() const +{ + return "proximitysensor"; +} diff --git a/src/plugins/sensors/sensorfw/sensorfwproximitysensor.h b/src/plugins/sensors/sensorfw/sensorfwproximitysensor.h new file mode 100644 index 0000000..91800c2 --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwproximitysensor.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SENSORFWPROXIMITYSENSOR_H +#define SENSORFWPROXIMITYSENSOR_H + +#include "sensorfwsensorbase.h" +#include + +#include +#include + + + +class SensorfwProximitySensor : public SensorfwSensorBase +{ + Q_OBJECT + +public: + static char const * const id; + SensorfwProximitySensor(QSensor *sensor); +protected: + virtual bool doConnect(); + virtual QString sensorName() const; + virtual void start(); + + +private: + QProximityReading m_reading; + static bool m_initDone; + bool m_exClose; + +private slots: + void slotDataAvailable(const Unsigned& data); +}; + +#endif diff --git a/src/plugins/sensors/sensorfw/sensorfwrotationsensor.cpp b/src/plugins/sensors/sensorfw/sensorfwrotationsensor.cpp new file mode 100644 index 0000000..d577402 --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwrotationsensor.cpp @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sensorfwrotationsensor.h" + +char const * const SensorfwRotationSensor::id("sensorfw.rotationsensor"); +bool SensorfwRotationSensor::m_initDone = false; + +SensorfwRotationSensor::SensorfwRotationSensor(QSensor *sensor) + : SensorfwSensorBase(sensor) +{ + initSensor(m_initDone); + setReading(&m_reading); + sensor()->setHasZ(true); +} + +void SensorfwRotationSensor::slotDataAvailable(const XYZ& data) +{ + m_reading.setFromEuler(data.x(),data.y(),data.z()); + m_reading.setTimestamp(data.XYZData().timestamp_); + newReadingAvailable(); +} + +void SensorfwRotationSensor::slotFrameAvailable(const QVector& frame) +{ + for (int i=0, l=frame.size(); i& )),this, SLOT(slotFrameAvailable(const QVector& ))); +} + +QString SensorfwRotationSensor::sensorName() const +{ + return "rotationsensor"; +} diff --git a/src/plugins/sensors/sensorfw/sensorfwrotationsensor.h b/src/plugins/sensors/sensorfw/sensorfwrotationsensor.h new file mode 100644 index 0000000..5b5556d --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwrotationsensor.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#ifndef SENSORFWROTATION_H +#define SENSORFWROTATION_H + +#include "sensorfwsensorbase.h" +#include + +#include +#include + + + +class SensorfwRotationSensor : public SensorfwSensorBase +{ + Q_OBJECT + +public: + static char const * const id; + SensorfwRotationSensor(QSensor *sensor); +protected: + virtual bool doConnect(); + virtual QString sensorName() const; + +private: + QRotationReading m_reading; + static bool m_initDone; + +private slots: + void slotDataAvailable(const XYZ& data); + void slotFrameAvailable(const QVector&); + +}; + +#endif diff --git a/src/plugins/sensors/sensorfw/sensorfwsensorbase.cpp b/src/plugins/sensors/sensorfw/sensorfwsensorbase.cpp new file mode 100644 index 0000000..85968e2 --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwsensorbase.cpp @@ -0,0 +1,189 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sensorfwsensorbase.h" + + +SensorManagerInterface* SensorfwSensorBase::m_remoteSensorManager = 0; + +//According to wikipedia link http://en.wikipedia.org/wiki/Standard_gravity +//const float sensorfwsensorbase::GRAVITY_EARTH = 9.812865328; +const float SensorfwSensorBase::GRAVITY_EARTH_THOUSANDTH = 0.009812865328; +const int SensorfwSensorBase::KErrNotFound=-1; +const int SensorfwSensorBase::KErrInUse=-14; +QStringList SensorfwSensorBase::m_bufferingSensors = QStringList() + <<"sensorfw.accelerometer"<<"sensorfw.magnetometer" + <<"sensorfw.gyroscope"<<"sensorfw.rotationsensor"; + +SensorfwSensorBase::SensorfwSensorBase(QSensor *sensor) + : QSensorBackend(sensor), m_sensorInterface(0), m_bufferSize(-1), m_prevOutputRange(0), m_efficientBufferSize(1), m_maxBufferSize(1) +{ + if (!m_remoteSensorManager) + m_remoteSensorManager = &SensorManagerInterface::instance(); +} + +SensorfwSensorBase::~SensorfwSensorBase() +{ + if (m_sensorInterface) { + stop(); + delete m_sensorInterface, m_sensorInterface = 0; + } +} + +void SensorfwSensorBase::start() +{ + if (m_sensorInterface) { + // dataRate + QByteArray type = sensor()->type(); + if (type != QTapSensor::type() && type != QProximitySensor::type()) { + int dataRate = sensor()->dataRate(); + int interval = dataRate > 0 ? 1000 / dataRate : 0; + // for testing maximum speed + //interval = 1; + //dataRate = 1000; + m_sensorInterface->setInterval(interval); + } + + // outputRange + int currentRange = sensor()->outputRange(); + int l = sensor()->outputRanges().size(); + if (l > 1) { + if (currentRange != m_prevOutputRange) { +//#ifdef Q_WS_MAEMO_6 + bool isOk = m_sensorInterface->setDataRangeIndex(currentRange); //NOTE THAT THE CHANGE MIGHT NOT SUCCEED, FIRST COME FIRST SERVED + if (!isOk) sensorError(KErrInUse); + else m_prevOutputRange = currentRange; +//#else +// // TODO: remove when sensord integrated, in sensorfw env there is a delay +// qoutputrange range = sensor()->outputRanges().at(currentRange); +// qreal correction = 1/correctionFactor(); +// DataRange range1(range.minimum*correction, range.maximum*correction, range.accuracy*correction); +// m_sensorInterface->requestDataRange(range1); +// m_prevOutputRange = currentRange; +//#endif + } + } + + // always on + bool alwaysOn = sensor()->isAlwaysOn(); + m_sensorInterface->setStandbyOverride(alwaysOn); + + // connects after buffering checks + doConnectAfterCheck(); + + int returnCode = m_sensorInterface->start().error().type(); + if (returnCode == 0) return; + qWarning() << "m_sensorInterface did not start, error code:" << returnCode; + } + sensorStopped(); +} + +void SensorfwSensorBase::stop() +{ + if (m_sensorInterface) m_sensorInterface->stop(); +} + +void SensorfwSensorBase::setRanges(qreal correctionFactor) +{ + if (!m_sensorInterface) return; + + QList ranges = m_sensorInterface->getAvailableDataRanges(); + + for (int i = 0, l = ranges.size(); i < l; i++) { + DataRange range = ranges.at(i); + qreal rangeMin = range.min * correctionFactor; + qreal rangeMax = range.max * correctionFactor; + qreal resolution = range.resolution * correctionFactor; + addOutputRange(rangeMin, rangeMax, resolution); + } +} + + +bool SensorfwSensorBase::doConnectAfterCheck() +{ + if (!m_sensorInterface) return false; + + // buffer size + int size = bufferSize(); + if (size == m_bufferSize) return true; + + if (m_bufferingSensors.contains(sensor()->identifier())) + m_sensorInterface->setBufferSize(size); + else + size = 1; + + // if multiple->single or single->multiple or if uninitialized + if ((m_bufferSize > 1 && size == 1) || (m_bufferSize == 1 && size > 1) || m_bufferSize == -1) { + m_bufferSize = size; + disconnect(this); + if (!doConnect()) { + qWarning() << "Unable to connect "<< sensorName(); + return false; + } + return true; + } + m_bufferSize = size; + return true; +} + +int SensorfwSensorBase::bufferSize() const +{ + int bufferSize = sensor()->bufferSize(); + if (bufferSize == 1) + return 1; + + // otherwise check validit + if (bufferSize < 1) { + qWarning() << "bufferSize cannot be " << bufferSize << ", must be a positive number >= 1"; + return 1; + } + if (bufferSize > m_maxBufferSize) { + qWarning() << "bufferSize cannot be " << bufferSize << ", MAX value is " << m_maxBufferSize; + return m_maxBufferSize; + } + return bufferSize; +} + +qreal SensorfwSensorBase::correctionFactor() const +{ + return 1; +} + diff --git a/src/plugins/sensors/sensorfw/sensorfwsensorbase.h b/src/plugins/sensors/sensorfw/sensorfwsensorbase.h new file mode 100644 index 0000000..78a6c14 --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwsensorbase.h @@ -0,0 +1,170 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#ifndef SENSORFWSENSORBASE_H +#define SENSORFWSENSORBASE_H + +#include +#include +#include + +class SensorfwSensorBase : public QSensorBackend +{ +public: + SensorfwSensorBase(QSensor *sensor); + virtual ~SensorfwSensorBase(); + + +protected: + virtual bool doConnect()=0; + virtual void start(); + virtual void stop(); + + static const float GRAVITY_EARTH; + static const float GRAVITY_EARTH_THOUSANDTH; //for speed + static const int KErrNotFound; + static const int KErrInUse; + static QStringList m_bufferingSensors; + + void setRanges(qreal correctionFactor=1); + virtual QString sensorName() const=0; + + template + void initSensor(bool &initDone) + { + + const QString name = sensorName(); + + if (!initDone) { + if (!m_remoteSensorManager->loadPlugin(name)) { + sensorError(KErrNotFound); + return; + } + m_remoteSensorManager->registerSensorInterface(name); + } + m_sensorInterface = T::controlInterface(name); + if (!m_sensorInterface) { + m_sensorInterface = const_cast(T::listenInterface(name)); + } + if (!m_sensorInterface) { + sensorError(KErrNotFound); + return; + } + if (!m_sensorInterface) { + sensorError(KErrNotFound); + return; + } + + initDone = true; + + //metadata + QList intervals = m_sensorInterface->getAvailableIntervals(); + + for (int i = 0, l = intervals.size(); i < l; i++) { + qreal intervalMax = ((DataRange)(intervals.at(i))).max; + qreal intervalMin =((DataRange)(intervals.at(i))).min; + + if (intervalMin == 0 && intervalMax == 0) { + // 0 interval has different meanings in e.g. magge/acce + // magge -> best-effort + // acce -> lowest possible + // in Qt API setting 0 means default + continue; + } + + qreal rateMin = intervalMax < 1 ? 1 : 1 / intervalMax * 1000; + rateMin = rateMin < 1 ? 1 : rateMin; + + intervalMin = intervalMin < 1 ? 10: intervalMin; // do not divide with 0 + qreal rateMax = 1 / intervalMin * 1000; + addDataRate(rateMin, rateMax); + } + + //bufferSizes + if (m_bufferingSensors.contains(sensor()->identifier())) { + + IntegerRangeList sizes = m_sensorInterface->getAvailableBufferSizes(); + int l = sizes.size(); + for (int i = 0; i < l; i++) { + int second = sizes.at(i).second; + m_maxBufferSize = second > m_bufferSize ? second : m_maxBufferSize; + } + m_maxBufferSize = m_maxBufferSize < 0 ? 1 : m_maxBufferSize; + //SensorFW guarantees to provide the most efficient size first + //TODO: remove from comments + //m_efficientBufferSize = m_sensorInterface->hwBuffering()? (l>0?sizes.at(0).first:1) : 1; + } + else + m_maxBufferSize = 1; + + sensor()->setMaxBufferSize(m_maxBufferSize); + sensor()->efficientBufferSize(m_efficientBufferSize); + + QByteArray type = sensor()->type(); + if (type == QAmbientLightSensor::type()) return; // SensorFW returns lux values, plugin enumerated values + if (type == QIRProximitySensor::type()) return; // SensorFW returns raw reflectance values, plugin % of max reflectance + if (name == "accelerometersensor") return; // SensorFW returns milliGs, plugin m/s^2 + if (name == "magnetometersensor") return; // SensorFW returns nanoTeslas, plugin Teslas + if (name == "gyroscopesensor") return; // SensorFW returns DSPs, plugin milliDSPs + + setDescription(m_sensorInterface->description()); + + if (name == "tapsensor") return; + setRanges(); + }; + + + AbstractSensorChannelInterface* m_sensorInterface; + int m_bufferSize; + int bufferSize() const; + virtual qreal correctionFactor() const; + +private: + + static SensorManagerInterface* m_remoteSensorManager; + int m_prevOutputRange; + bool doConnectAfterCheck(); + int m_efficientBufferSize, m_maxBufferSize; + +}; + +#endif diff --git a/src/plugins/sensors/sensorfw/sensorfwtapsensor.cpp b/src/plugins/sensors/sensorfw/sensorfwtapsensor.cpp new file mode 100644 index 0000000..c945ac1 --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwtapsensor.cpp @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sensorfwtapsensor.h" + +char const * const SensorfwTapSensor::id("sensorfw.tapsensor"); +bool SensorfwTapSensor::m_initDone = false; + +SensorfwTapSensor::SensorfwTapSensor(QSensor *sensor) + : SensorfwSensorBase(sensor), m_isOnceStarted(false) +{ + initSensor(m_initDone); + setReading(&m_reading); + addOutputRange(QTapReading::Undefined, QTapReading::Z_Both, 1); + addDataRate(10,10); //TODO: fix this when we know better +} + + +void SensorfwTapSensor::start() +{ + bool b = sensor()->returnDoubleTapEvents(); + bool isDoubleTapSensor = m_isDoubleTapSensor; + if (!b) { + sensor()->setReturnDoubleTapEvents(true); //by default doubles + m_isDoubleTapSensor = true; + } + else m_isDoubleTapSensor = b; + + if (!m_isOnceStarted || (m_isOnceStarted && isDoubleTapSensor != m_isDoubleTapSensor)) + ((TapSensorChannelInterface*)m_sensorInterface)-> + setTapType(m_isDoubleTapSensor?TapSensorChannelInterface::Double:TapSensorChannelInterface::Single); + + SensorfwSensorBase::start(); + // Set tap type (single/double) + m_reading.setDoubleTap(m_isDoubleTapSensor); + m_isOnceStarted = true; +} + + +void SensorfwTapSensor::slotDataAvailable(const Tap& data) +{ + // Set tap direction + QTapReading::TapDirection o; + switch (data.direction()) { + case TapData::X: o = QTapReading::X_Both; break; + case TapData::Y: o = QTapReading::Y_Both; break; + case TapData::Z: o = QTapReading::Z_Both; break; + case TapData::LeftRight: o = QTapReading::X_Pos; break; + case TapData::RightLeft: o = QTapReading::X_Neg; break; + case TapData::TopBottom: o = QTapReading::Z_Neg; break; + case TapData::BottomTop: o = QTapReading::Z_Pos; break; + case TapData::FaceBack: o = QTapReading::Y_Pos; break; + case TapData::BackFace: o = QTapReading::Y_Neg; break; + default: o = QTapReading::Undefined; + } + m_reading.setTapDirection(o); + m_reading.setTimestamp(data.tapData().timestamp_); + newReadingAvailable(); +} + + +bool SensorfwTapSensor::doConnect() +{ + return QObject::connect(m_sensorInterface, SIGNAL(dataAvailable(const Tap&)), + this, SLOT(slotDataAvailable(const Tap&))); +} + + +QString SensorfwTapSensor::sensorName() const +{ + return "tapsensor"; +} diff --git a/src/plugins/sensors/sensorfw/sensorfwtapsensor.h b/src/plugins/sensors/sensorfw/sensorfwtapsensor.h new file mode 100644 index 0000000..6df3bcf --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwtapsensor.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef SENSORFWTAPSENSOR_H +#define SENSORFWTAPSENSOR_H + +#include "sensorfwsensorbase.h" +#include + +#include +#include + + + +class SensorfwTapSensor : public SensorfwSensorBase +{ + Q_OBJECT + +public: + static char const * const id; + SensorfwTapSensor(QSensor *sensor); +protected: + virtual bool doConnect(); + virtual void start(); + virtual QString sensorName() const; + +private: + QTapReading m_reading; + static bool m_initDone; + bool m_isDoubleTapSensor; + bool m_isOnceStarted; +private slots: + void slotDataAvailable(const Tap&); +}; + +#endif diff --git a/src/plugins/sensors/sensors.pro b/src/plugins/sensors/sensors.pro index 3822daf..ef15f13 100644 --- a/src/plugins/sensors/sensors.pro +++ b/src/plugins/sensors/sensors.pro @@ -4,8 +4,14 @@ TEMPLATE = subdirs # of these. This reduces compile time and plugin loading time. blackberry { isEmpty(SENSORS_PLUGINS): SENSORS_PLUGINS = blackberry generic -} else: android { - SENSORS_PLUGINS = android generic +} + +android { + isEmpty(SENSORS_PLUGINS): SENSORS_PLUGINS = android generic +} + +sensorfw { + isEmpty(SENSORS_PLUGINS): SENSORS_PLUGINS = sensorfw generic } isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, dummy):SUBDIRS += dummy @@ -14,3 +20,5 @@ isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, simulator):simulator:SUBDIRS isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, blackberry):blackberry:SUBDIRS += blackberry isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, linux):linux:SUBDIRS += linux isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, android):android:SUBDIRS += android +isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, sensorfw):sensorfw:SUBDIRS += sensorfw + diff --git a/src/sensors/doc/src/compatmap.qdoc b/src/sensors/doc/src/compatmap.qdoc index 8fe24ad..a40a7a0 100644 --- a/src/sensors/doc/src/compatmap.qdoc +++ b/src/sensors/doc/src/compatmap.qdoc @@ -57,6 +57,7 @@ Android Linux Generic + Sensorfw Accelerometer @@ -64,6 +65,7 @@ + Altimeter @@ -78,6 +80,7 @@ + Ambient Temperature Sensor @@ -92,6 +95,7 @@ + Gyroscope @@ -99,6 +103,7 @@ + Holster Sensor @@ -120,6 +125,7 @@ + Magnetometer @@ -127,6 +133,7 @@ + Orientation Sensor @@ -134,6 +141,7 @@ + Pressure Sensor @@ -148,6 +156,7 @@ + Rotation Sensor @@ -155,6 +164,7 @@ + Tap Sensor @@ -169,13 +179,15 @@ + Sensor Gestures - 1) + + diff --git a/src/sensors/doc/src/qtsensors.qdoc b/src/sensors/doc/src/qtsensors.qdoc index 6128673..9213371 100644 --- a/src/sensors/doc/src/qtsensors.qdoc +++ b/src/sensors/doc/src/qtsensors.qdoc @@ -112,6 +112,9 @@ \row \li \l {Generic Backend}{Generic Backend} \li Information about the generic sensor backend. + \row + \li \l {Sensorfw Backend}{Sensorfw Backend} + \li Information about the Sensorfw sensor backend. \endtable */ diff --git a/src/sensors/doc/src/sensorfwbackend.qdoc b/src/sensors/doc/src/sensorfwbackend.qdoc new file mode 100644 index 0000000..fcfbb5d --- /dev/null +++ b/src/sensors/doc/src/sensorfwbackend.qdoc @@ -0,0 +1,39 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Jolla Mobile +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** 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 Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \page senorfwbackend.html + \title Sensorfw Backend + \brief Information about the Sensorfw sensor backend + + The Sensorfw sensor backend requires the Sensorfw and sensor daemon. Sensorfw was originally used in MeeGo, and is available + from http://meego.gitorious.org/meego-middleware/sensorfw + + To compile the sensorfw backend, you need sensorfw installed and run qmake with CONFIG+=sensorfw + +*/ + -- cgit v1.2.1 From adcf31b15cf5ae9dfbde024a89121667acec94b2 Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Mon, 4 Mar 2013 09:33:51 +0100 Subject: Document the generic tilt sensor in genericbackend.qdoc Change-Id: I7b5e947ddc097744be2a90a118331a5af24f38ee Reviewed-by: Lorn Potter --- src/sensors/doc/src/genericbackend.qdoc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/sensors/doc/src/genericbackend.qdoc b/src/sensors/doc/src/genericbackend.qdoc index 689b412..a273352 100644 --- a/src/sensors/doc/src/genericbackend.qdoc +++ b/src/sensors/doc/src/genericbackend.qdoc @@ -49,6 +49,9 @@ \row \li Rotation Sensor \li Accelerometer + \row + \li Tilt Sensor + \li Accelerometer \endtable If a platform doesn't support the source sensor, then the sensor can not be emulated. */ -- cgit v1.2.1 From 1f266d31dcdf1ced8a6d05f57a1ff77848d21f3e Mon Sep 17 00:00:00 2001 From: Lorn Potter Date: Sun, 10 Mar 2013 04:44:54 +1000 Subject: fix up compatibility map and mention that sensor gestures are platform independent. Change-Id: Iee0cf4185d095e1e97cc7b222f35271bb72a75ab Reviewed-by: Thomas McGuire --- src/sensors/doc/src/compatmap.qdoc | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/sensors/doc/src/compatmap.qdoc b/src/sensors/doc/src/compatmap.qdoc index a40a7a0..ffca5f6 100644 --- a/src/sensors/doc/src/compatmap.qdoc +++ b/src/sensors/doc/src/compatmap.qdoc @@ -73,6 +73,7 @@ + Ambient Light Sensor @@ -88,6 +89,7 @@ + Compass @@ -111,6 +113,7 @@ + IR Proximity Sensor @@ -118,6 +121,7 @@ + Light Sensor @@ -125,7 +129,7 @@ - + Magnetometer @@ -133,7 +137,7 @@ - + Orientation Sensor @@ -149,6 +153,7 @@ + Proximity Sensor @@ -172,6 +177,7 @@ + Tilt Sensor @@ -186,7 +192,7 @@ - + @@ -198,5 +204,8 @@ In addition to the table above, each sensor type might support specific features. For example a magnetometer might support returning geo values. See QSensor::isFeatureSupported() for additional details. + + Sensor Gestures are mostly platform independent, and will run if the platform has the needed sensors. + Whether they are supported and work well or not depends on the platform. */ -- cgit v1.2.1 From 94d62b006d145f4f3df6bd5299d412aa0d6a9c87 Mon Sep 17 00:00:00 2001 From: Lorn Potter Date: Sat, 24 Nov 2012 20:39:46 +1000 Subject: iOS: implement accelerometer for iOS This change implements an accelerometer for iOS. Change-Id: Id6de98427312bc0be42935fd9704117665d1e4a2 Reviewed-by: Thomas McGuire --- src/plugins/sensors/ios/ios.pro | 17 ++++ src/plugins/sensors/ios/iosaccelerometer.h | 71 ++++++++++++++ src/plugins/sensors/ios/iosaccelerometer.mm | 143 ++++++++++++++++++++++++++++ src/plugins/sensors/ios/iosmotionmanager.h | 55 +++++++++++ src/plugins/sensors/ios/iosmotionmanager.mm | 57 +++++++++++ src/plugins/sensors/ios/main.mm | 70 ++++++++++++++ src/plugins/sensors/ios/plugin.json | 1 + src/plugins/sensors/sensors.pro | 2 +- src/sensors/doc/src/compatmap.qdoc | 18 ++++ 9 files changed, 433 insertions(+), 1 deletion(-) create mode 100644 src/plugins/sensors/ios/ios.pro create mode 100644 src/plugins/sensors/ios/iosaccelerometer.h create mode 100644 src/plugins/sensors/ios/iosaccelerometer.mm create mode 100644 src/plugins/sensors/ios/iosmotionmanager.h create mode 100644 src/plugins/sensors/ios/iosmotionmanager.mm create mode 100644 src/plugins/sensors/ios/main.mm create mode 100644 src/plugins/sensors/ios/plugin.json diff --git a/src/plugins/sensors/ios/ios.pro b/src/plugins/sensors/ios/ios.pro new file mode 100644 index 0000000..4242cfc --- /dev/null +++ b/src/plugins/sensors/ios/ios.pro @@ -0,0 +1,17 @@ +TARGET = qtsensors_ios +QT = core sensors + +PLUGIN_TYPE = sensors +PLUGIN_CLASS_NAME = IOSSensorPlugin +load(qt_plugin) + +OTHER_FILES = plugin.json + +HEADERS += iosaccelerometer.h \ + iosmotionmanager.h + +OBJECTIVE_SOURCES += main.mm \ + iosaccelerometer.mm \ + iosmotionmanager.mm + +LIBS += -framework UIKit -framework CoreMotion diff --git a/src/plugins/sensors/ios/iosaccelerometer.h b/src/plugins/sensors/ios/iosaccelerometer.h new file mode 100644 index 0000000..34cc3eb --- /dev/null +++ b/src/plugins/sensors/ios/iosaccelerometer.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Lorn Potter +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef IOSACCELEROMETER_H +#define IOSACCELEROMETER_H + +#include +#include + +QT_BEGIN_NAMESPACE + +@class QtIoAccelListener; + +class IOSAccelerometer : public QSensorBackend +{ +public: + static char const * const id; + + explicit IOSAccelerometer(QSensor *sensor); + ~IOSAccelerometer(); + + void start(); + void stop(); + void readingsChanged(quint64,qreal,qreal,qreal); + +private: + QtIoAccelListener *m_listener; + QAccelerometerReading m_reading; +}; +QT_END_NAMESPACE + +#endif // IOSACCELEROMETER_H + diff --git a/src/plugins/sensors/ios/iosaccelerometer.mm b/src/plugins/sensors/ios/iosaccelerometer.mm new file mode 100644 index 0000000..ef7d2a6 --- /dev/null +++ b/src/plugins/sensors/ios/iosaccelerometer.mm @@ -0,0 +1,143 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Lorn Potter +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "iosaccelerometer.h" +#include "iosmotionmanager.h" + +#include +#include + +char const * const IOSAccelerometer::id("ios.accelerometer"); + +@interface QtIoAccelListener : NSObject +{ + IOSAccelerometer *m_qiosAccelerometer; + NSOperationQueue *m_updateQueue; +} +@end + +@implementation QtIoAccelListener + +-(id)initWithQIOSAccelerometer:(IOSAccelerometer *) qiosAccelerometer +{ + self = [super init]; + if (self) { + m_qiosAccelerometer = qiosAccelerometer; + m_updateQueue = [[NSOperationQueue alloc] init]; + } + return self; +} + +-(void)dealloc +{ + [m_updateQueue release]; + [super dealloc]; +} + +-(void)startAccelerometer +{ + CMMotionManager *motionManager = [QIOSMotionManager sharedManager]; + + if (motionManager.deviceMotionAvailable) { + [motionManager startAccelerometerUpdatesToQueue:m_updateQueue withHandler:^(CMAccelerometerData *data, NSError *error) { + dispatch_async(dispatch_get_main_queue(), ^{ + Q_UNUSED(error); + CMAcceleration acc = data.acceleration; + // Convert from G to m/s2, and flip axes: + const qreal G = 9.8066; + qreal x = qreal(acc.x) * G * -1; + qreal y = qreal(acc.y) * G * -1; + qreal z = qreal(acc.z) * G * -1; + m_qiosAccelerometer->readingsChanged(quint64(data.timestamp), x, y, z); + }); + }]; + } +} + +-(void)stopAccelerometer +{ + [[QIOSMotionManager sharedManager] stopAccelerometerUpdates]; +} + +-(void)setInterval:(NSTimeInterval) interval +{ + [QIOSMotionManager sharedManager].accelerometerUpdateInterval = interval; +} + +@end + +QT_BEGIN_NAMESPACE + +IOSAccelerometer::IOSAccelerometer(QSensor *sensor) + : QSensorBackend(sensor) + , m_listener([[QtIoAccelListener alloc] initWithQIOSAccelerometer:this]) +{ + setReading(&m_reading); + addDataRate(1, 100); // 100Hz + addOutputRange(-22.418, 22.418, 0.17651); // 2G +} + +IOSAccelerometer::~IOSAccelerometer() +{ + [m_listener dealloc]; +} + +void IOSAccelerometer::start() +{ + [m_listener startAccelerometer]; +} + +void IOSAccelerometer::stop() +{ + [m_listener stopAccelerometer]; +} + +void IOSAccelerometer::readingsChanged(quint64 ts, qreal x, qreal y, qreal z) +{ + m_reading.setTimestamp(ts); + m_reading.setX(x); + m_reading.setY(y); + m_reading.setZ(z); + + newReadingAvailable(); +} + +QT_END_NAMESPACE diff --git a/src/plugins/sensors/ios/iosmotionmanager.h b/src/plugins/sensors/ios/iosmotionmanager.h new file mode 100644 index 0000000..7babfc3 --- /dev/null +++ b/src/plugins/sensors/ios/iosmotionmanager.h @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Lorn Potter +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef IOSMOTIONMANAGER_H +#define IOSMOTIONMANAGER_H + +#import +#import + +@interface QIOSMotionManager : NSObject { +} + ++ (CMMotionManager *)sharedManager; +@end + +#endif //IOSMOTIONMANAGER_H + diff --git a/src/plugins/sensors/ios/iosmotionmanager.mm b/src/plugins/sensors/ios/iosmotionmanager.mm new file mode 100644 index 0000000..a367c49 --- /dev/null +++ b/src/plugins/sensors/ios/iosmotionmanager.mm @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Lorn Potter +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "iosmotionmanager.h" + +static CMMotionManager *sharedManager = nil; + +@implementation QIOSMotionManager + ++ (CMMotionManager *)sharedManager +{ + static dispatch_once_t staticToken; + dispatch_once(&staticToken, ^{ + sharedManager = [[CMMotionManager alloc] init]; + }); + return sharedManager; +} + +@end diff --git a/src/plugins/sensors/ios/main.mm b/src/plugins/sensors/ios/main.mm new file mode 100644 index 0000000..3c73939 --- /dev/null +++ b/src/plugins/sensors/ios/main.mm @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + +#include "iosaccelerometer.h" + +class IOSSensorPlugin : public QObject, public QSensorPluginInterface, public QSensorBackendFactory +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "com.qt-project.Qt.QSensorPluginInterface/1.0" FILE "plugin.json") + Q_INTERFACES(QSensorPluginInterface) +public: + void registerSensors() + { + if (!QSensorManager::isBackendRegistered(QAccelerometer::type, IOSAccelerometer::id)) + QSensorManager::registerBackend(QAccelerometer::type, IOSAccelerometer::id, this); + } + + QSensorBackend *createBackend(QSensor *sensor) + { + if (sensor->identifier() == IOSAccelerometer::id) + return new IOSAccelerometer(sensor); + + return 0; + } +}; + +#include "main.moc" + diff --git a/src/plugins/sensors/ios/plugin.json b/src/plugins/sensors/ios/plugin.json new file mode 100644 index 0000000..8a55b3a --- /dev/null +++ b/src/plugins/sensors/ios/plugin.json @@ -0,0 +1 @@ +{ "Keys": [ "notused" ] } diff --git a/src/plugins/sensors/sensors.pro b/src/plugins/sensors/sensors.pro index ef15f13..73f4267 100644 --- a/src/plugins/sensors/sensors.pro +++ b/src/plugins/sensors/sensors.pro @@ -21,4 +21,4 @@ isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, blackberry):blackberry:SUBDIR isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, linux):linux:SUBDIRS += linux isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, android):android:SUBDIRS += android isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, sensorfw):sensorfw:SUBDIRS += sensorfw - +isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, ios):ios:SUBDIRS += ios diff --git a/src/sensors/doc/src/compatmap.qdoc b/src/sensors/doc/src/compatmap.qdoc index ffca5f6..62f94de 100644 --- a/src/sensors/doc/src/compatmap.qdoc +++ b/src/sensors/doc/src/compatmap.qdoc @@ -56,6 +56,7 @@ Blackberry Android Linux + iOS Generic Sensorfw @@ -64,6 +65,7 @@ + @@ -74,6 +76,7 @@ + Ambient Light Sensor @@ -81,6 +84,7 @@ + @@ -90,6 +94,7 @@ + Compass @@ -97,6 +102,7 @@ + @@ -105,6 +111,7 @@ + @@ -114,6 +121,7 @@ + IR Proximity Sensor @@ -121,6 +129,7 @@ + @@ -129,6 +138,7 @@ + @@ -137,6 +147,7 @@ + @@ -144,6 +155,7 @@ + @@ -154,6 +166,7 @@ + Proximity Sensor @@ -161,6 +174,7 @@ + @@ -168,6 +182,7 @@ + @@ -178,12 +193,14 @@ + Tilt Sensor + @@ -193,6 +210,7 @@ + -- cgit v1.2.1 From 879e5536b033302b2ad976750cd2351674e161d6 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Tue, 26 Feb 2013 12:52:41 +0100 Subject: define MODULE_VERSION Task-number: QTBUG-29838 Change-Id: I64f1d9a6990d88f8ba889e18ab35a215b72982dd Reviewed-by: Thomas McGuire --- .qmake.conf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.qmake.conf b/.qmake.conf index 42ba8e4..f5a422c 100644 --- a/.qmake.conf +++ b/.qmake.conf @@ -1 +1,3 @@ load(qt_build_config) + +MODULE_VERSION = 5.1.0 -- cgit v1.2.1