From 6b2c7688b3f344f350125f8b9713a6a77b82c3dd Mon Sep 17 00:00:00 2001 From: Wolfgang Beck Date: Fri, 2 Sep 2011 13:29:38 +1000 Subject: MTMW-98 QML API Version 2 Change-Id: I10c610ae22974d291fad663088c5a11449a86b05 Reviewed-on: http://codereview.qt-project.org/4107 Reviewed-by: Wolfgang Beck --- doc/src/examples/sensors.qdoc | 10 +- doc/src/images/FaceDown.gif | Bin 0 -> 6681 bytes doc/src/images/FaceUp.gif | Bin 0 -> 6736 bytes doc/src/images/LeftUp.gif | Bin 0 -> 7210 bytes doc/src/images/RightUp.gif | Bin 0 -> 7146 bytes doc/src/images/TopDown.gif | Bin 0 -> 7455 bytes doc/src/images/TopUp.gif | Bin 0 -> 7172 bytes doc/src/images/XAngle.gif | Bin 0 -> 46224 bytes doc/src/images/XAngleNegative.gif | Bin 0 -> 38468 bytes doc/src/images/YAngle.gif | Bin 0 -> 44322 bytes doc/src/images/YAngleNegative.gif | Bin 0 -> 39741 bytes doc/src/imports/qml-qtsensors5.qdoc | 100 ++++ doc/src/imports/qml-sensors.qdoc | 99 ++++ doc/src/mobility_sensors.qdoc | 524 +++++++++++++++++++++ doc/src/plugins/qml-sensors.qdoc | 99 ---- doc/src/sensors.qdoc | 493 +------------------ examples/sensors/qmlqtsensors5/Button.qml | 34 ++ examples/sensors/qmlqtsensors5/SelectionButton.qml | 37 ++ examples/sensors/qmlqtsensors5/checked.gif | Bin 0 -> 246 bytes examples/sensors/qmlqtsensors5/icon.png | Bin 0 -> 2030 bytes examples/sensors/qmlqtsensors5/info.json | 14 + examples/sensors/qmlqtsensors5/main.qml | 290 ++++++++++++ .../sensors/qmlqtsensors5/qmlqtsensors5.qmlproject | 20 + examples/sensors/qmlqtsensors5/unchecked.gif | Bin 0 -> 170 bytes src/imports/imports.pro | 1 + src/imports/sensors/sensors.cpp | 120 +++-- src/imports/sensors2/qmldir | 1 + src/imports/sensors2/qsensor2ambientlight.cpp | 149 ++++++ src/imports/sensors2/qsensor2ambientlight.h | 90 ++++ src/imports/sensors2/qsensor2proximity.cpp | 121 +++++ src/imports/sensors2/qsensor2proximity.h | 81 ++++ src/imports/sensors2/qsensor2tilt.cpp | 365 ++++++++++++++ src/imports/sensors2/qsensor2tilt.h | 108 +++++ src/imports/sensors2/qsensors2import.pri | 38 ++ src/imports/sensors2/sensors2.cpp | 72 +++ src/imports/sensors2/sensors2.pro | 39 ++ tests/auto/auto.pro | 2 +- tests/auto/sensors2qmlapi/qbackends.h | 105 +++++ tests/auto/sensors2qmlapi/qdeclaccelerometer.h | 80 ++++ .../auto/sensors2qmlapi/qdeclambientlightsensor.h | 79 ++++ tests/auto/sensors2qmlapi/qdeclproximitysensor.h | 78 +++ tests/auto/sensors2qmlapi/sensors2qmlapi.pro | 20 + tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp | 270 +++++++++++ 43 files changed, 2901 insertions(+), 638 deletions(-) create mode 100644 doc/src/images/FaceDown.gif create mode 100644 doc/src/images/FaceUp.gif create mode 100644 doc/src/images/LeftUp.gif create mode 100644 doc/src/images/RightUp.gif create mode 100644 doc/src/images/TopDown.gif create mode 100644 doc/src/images/TopUp.gif create mode 100644 doc/src/images/XAngle.gif create mode 100644 doc/src/images/XAngleNegative.gif create mode 100644 doc/src/images/YAngle.gif create mode 100644 doc/src/images/YAngleNegative.gif create mode 100644 doc/src/imports/qml-qtsensors5.qdoc create mode 100644 doc/src/imports/qml-sensors.qdoc create mode 100644 doc/src/mobility_sensors.qdoc delete mode 100644 doc/src/plugins/qml-sensors.qdoc create mode 100644 examples/sensors/qmlqtsensors5/Button.qml create mode 100644 examples/sensors/qmlqtsensors5/SelectionButton.qml create mode 100644 examples/sensors/qmlqtsensors5/checked.gif create mode 100755 examples/sensors/qmlqtsensors5/icon.png create mode 100644 examples/sensors/qmlqtsensors5/info.json create mode 100644 examples/sensors/qmlqtsensors5/main.qml create mode 100644 examples/sensors/qmlqtsensors5/qmlqtsensors5.qmlproject create mode 100644 examples/sensors/qmlqtsensors5/unchecked.gif create mode 100644 src/imports/sensors2/qmldir create mode 100644 src/imports/sensors2/qsensor2ambientlight.cpp create mode 100644 src/imports/sensors2/qsensor2ambientlight.h create mode 100644 src/imports/sensors2/qsensor2proximity.cpp create mode 100644 src/imports/sensors2/qsensor2proximity.h create mode 100644 src/imports/sensors2/qsensor2tilt.cpp create mode 100644 src/imports/sensors2/qsensor2tilt.h create mode 100644 src/imports/sensors2/qsensors2import.pri create mode 100644 src/imports/sensors2/sensors2.cpp create mode 100644 src/imports/sensors2/sensors2.pro create mode 100644 tests/auto/sensors2qmlapi/qbackends.h create mode 100644 tests/auto/sensors2qmlapi/qdeclaccelerometer.h create mode 100644 tests/auto/sensors2qmlapi/qdeclambientlightsensor.h create mode 100644 tests/auto/sensors2qmlapi/qdeclproximitysensor.h create mode 100644 tests/auto/sensors2qmlapi/sensors2qmlapi.pro create mode 100644 tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp diff --git a/doc/src/examples/sensors.qdoc b/doc/src/examples/sensors.qdoc index 4ecc4e16..3f5a9a2a 100644 --- a/doc/src/examples/sensors.qdoc +++ b/doc/src/examples/sensors.qdoc @@ -79,13 +79,13 @@ light sensor. In the start method, the backend should be sure to call the sensorStopped() or sensorBusy() methods if it cannot start. - \snippet ../../examples/sensors/grueplugin/gruesensorimpl.cpp start + \snippet ../examples/sensors/grueplugin/gruesensorimpl.cpp start The setReading method is needed so that the sensors library knows where the readings are coming from. This backend has a local copy of the reading so it passes a pointer to the function. - \snippet ../../examples/sensors/grueplugin/gruesensorimpl.cpp setReading + \snippet ../examples/sensors/grueplugin/gruesensorimpl.cpp setReading However it is also possible to pass null to the setReading method in which case the sensors library will create an instance and return a pointer. @@ -142,15 +142,15 @@ The accelerometer is created and the filter is added. - \snippet ../../examples/sensors/cubehouse/view.cpp accelerometer + \snippet ../examples/sensors/cubehouse/view.cpp accelerometer When new values are available, the view is recalculated. - \snippet ../../examples/sensors/cubehouse/view.cpp accelerometer2 + \snippet ../examples/sensors/cubehouse/view.cpp accelerometer2 The filter is defined like this. - \snippet ../../examples/sensors/cubehouse/view.cpp smoothed + \snippet ../examples/sensors/cubehouse/view.cpp smoothed */ diff --git a/doc/src/images/FaceDown.gif b/doc/src/images/FaceDown.gif new file mode 100644 index 00000000..9236a8a7 Binary files /dev/null and b/doc/src/images/FaceDown.gif differ diff --git a/doc/src/images/FaceUp.gif b/doc/src/images/FaceUp.gif new file mode 100644 index 00000000..a53894f0 Binary files /dev/null and b/doc/src/images/FaceUp.gif differ diff --git a/doc/src/images/LeftUp.gif b/doc/src/images/LeftUp.gif new file mode 100644 index 00000000..2c8d57ae Binary files /dev/null and b/doc/src/images/LeftUp.gif differ diff --git a/doc/src/images/RightUp.gif b/doc/src/images/RightUp.gif new file mode 100644 index 00000000..8e29cbc9 Binary files /dev/null and b/doc/src/images/RightUp.gif differ diff --git a/doc/src/images/TopDown.gif b/doc/src/images/TopDown.gif new file mode 100644 index 00000000..6314fc91 Binary files /dev/null and b/doc/src/images/TopDown.gif differ diff --git a/doc/src/images/TopUp.gif b/doc/src/images/TopUp.gif new file mode 100644 index 00000000..f6747c46 Binary files /dev/null and b/doc/src/images/TopUp.gif differ diff --git a/doc/src/images/XAngle.gif b/doc/src/images/XAngle.gif new file mode 100644 index 00000000..045f235f Binary files /dev/null and b/doc/src/images/XAngle.gif differ diff --git a/doc/src/images/XAngleNegative.gif b/doc/src/images/XAngleNegative.gif new file mode 100644 index 00000000..92fc9233 Binary files /dev/null and b/doc/src/images/XAngleNegative.gif differ diff --git a/doc/src/images/YAngle.gif b/doc/src/images/YAngle.gif new file mode 100644 index 00000000..004fdd15 Binary files /dev/null and b/doc/src/images/YAngle.gif differ diff --git a/doc/src/images/YAngleNegative.gif b/doc/src/images/YAngleNegative.gif new file mode 100644 index 00000000..1dce6532 Binary files /dev/null and b/doc/src/images/YAngleNegative.gif differ diff --git a/doc/src/imports/qml-qtsensors5.qdoc b/doc/src/imports/qml-qtsensors5.qdoc new file mode 100644 index 00000000..a7ba0786 --- /dev/null +++ b/doc/src/imports/qml-qtsensors5.qdoc @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** GNU Free Documentation License +** 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. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms +** and conditions contained in a signed written agreement between you +** and Nokia. +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \qmlmodule QtSensors 5 + \title Sensors QML Plugin for Qt 5 + \brief A QML plugin for the Qt 5 Project Sensors API. +*/ + +/*! + \page qmlqtsensors5.html + \title Sensors 5 QML Plugin example + \example qmlqtsensors5 +*/ + +/*! + \page qml-sensors5.html + \title Sensors 5 QML Plugin + + \brief A QML plugin for the Qt Project Sensors 5 API. + + \section1 Overview + + The identifying string for this component is \i {"Qt.QtSensors"}. + Use this in the QML \i {import} statement. + + The QML Sensors 5 Plugin provides an easy to use interface to the Sensors API. + It enables us to receive sensor events and to read current values from + sensors. + + The plugin contains many sensor types and properties to read values + from them. As an example consider the tilt sensor. The qmlsensors2 + simply displays text on-screen to show the current tilt. + + The QML code that reads the value is quite simple. Here we see a QML component + tilt declared which is an \l TiltSensor element. First + the sensor is started by setting the running property + to true. The element receives a signal when the x and y rotation changes and it + can be picked up by the onXRotationChanged and onYRotationChanged slot. Now the + xRotation and yRotation property of this element can be + used to extract the current tilt so that it can be used for further calulations. + + \qml + TiltSensor { + id: tilt + radian: false + measureFrom: TiltSensor.FaceUp + running: false + } + \endqml + + \qml + Text { + x:5 + y:160 + text: "X Rotation: " + tilt.xRotation + } + \endqml + + \qml + Text { + x:5 + y:180 + text: "Y Rotation: " + tilt.yRotation + } + + \endqml + + \section1 QML Elements + \annotatedlist qml-QtSensors5 + + \section1 QML QtSensors Example + The \l {qmlqtsensors5}{qmlqtsensors5} example shows you how to use all those diferent QML elements. +*/ + + diff --git a/doc/src/imports/qml-sensors.qdoc b/doc/src/imports/qml-sensors.qdoc new file mode 100644 index 00000000..e547daa9 --- /dev/null +++ b/doc/src/imports/qml-sensors.qdoc @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** GNU Free Documentation License +** 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. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms +** and conditions contained in a signed written agreement between you +** and Nokia. +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \group qml-sensors + \title QML Sensors API Plugin + QML Support for the QtMobility Project Sensors API. +*/ + +/*! + \page qml-sensors.html + + \title Sensors QML Plugin + + \brief A QML plugin for the QtMobility Project Sensors API. + + \section1 Overview + + The QML Sensors Plugin provides an easy to use interface to the Sensors API. + It enables us to receive sensor events and to read current values from + sensors. + + The plugin contains many sensor types and access functions to read values + from them. As an example consider the orientation sensor. The orientation + example simply displays text on-screen to show the current orientation. + + The QML code that reads the value is quite simple. Here we see a QML component + \i orientation declared which is an \l OrientationSensor element. First + the sensor is started by setting the \l {Sensor::active}{active} property + to \i true. The element receives a signal when the reading changes and it + is picked up by the \i onReadingChanged slot. Now the + \l {OrientationSensor::reading}{reading} property of this element can be + used to extract the current orientation so that it can be compared against + the defined values of various orientations in the \l OrientationReading + element. + + \qml + OrientationSensor { + id: orientation + active: true + + onReadingChanged: { + + if (reading.orientation == OrientationReading.FaceUp) + content.state = "FaceUp"; + + // ... more tests for different orientations ... + } + } + + \endqml + + Other sensors can be treated in a similar manner. For example, the \l Compass + sensor could have almost identical coding + + \qml + Compass { + id: compass + active: true + + onReadingChanged: { + compassHeading.text = reading.azimuth; + + // ... + } + } + \endqml + + \section1 QML Elements + \annotatedlist qml-sensors_type + \annotatedlist qml-sensors_reading + +*/ + + diff --git a/doc/src/mobility_sensors.qdoc b/doc/src/mobility_sensors.qdoc new file mode 100644 index 00000000..4fc69cc6 --- /dev/null +++ b/doc/src/mobility_sensors.qdoc @@ -0,0 +1,524 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Free Documentation License +** 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! +\page mobility-sensors-api.html +\title QtMobility Sensors +\brief The Sensors API provides access to sensors. +\ingroup mobility +\ingroup technology-apis + + +The Sensors API is primarily concerned with low-level, real-time sensors such as +the accelerometer although there are higher-level, event-driven sensors represented too. + +\tableofcontents + +\section1 Sensor Types + +On a device there can be many types of sensors. Not all of the types that the Sensors API +supports may be available. There may also be types available that are not defined in the +Sensors API. You can find the sensor types available on a device using the +\l QSensor::sensorTypes() function. + +For a list of built-in sensor types, see the \l{Sensor Classes} section below. + +\section1 Common Conventions + +Unless otherwise specified, sensors shall use the +\l{http://en.wikipedia.org/wiki/Cartesian_coordinate_system}{Right Hand Cartesian coordinate system}. + +\image sensors-coordinates.jpg + +To allow for measurements in all 6 directions, negative values are used. + +\image sensors-coordinates2.jpg + +Where rotation around an axis is used, the rotation shall be expressed as a Right Hand rotation. + +\image sensors-coordinates3.jpg + +In general, sensor data is oriented to the top of the device. If values are to be displayed on +the screen the values may need to be transformed so that they match the user interface orientation. A sensor +may define its data as being oriented to the UI. This will be noted in the documentation for the +sensor. + +\image sensors-sides2.jpg + +\section1 Using a Sensor + +The life cycle of a sensor is typically: + +\list +\o Create an instance of QSensor or one of its sub-classes on the stack or heap. +\o Setup as required by the application. +\o Start receiving values. +\o Sensor data is used by the application. +\o Stop receiving values. +\endlist + +Here is an example of creating a sensor on the heap and on the stack. + +\snippet ../doc/src/snippets/sensors/creating.cpp Creating a sensor + +\section1 Accessing sensor data in a generic fashion + +The preferred way to deal with sensor data is via the \l{Reading Classes}. +However, sometimes this may not be possible. For example, you may be deploying +an application to a device that has a new sensor type but no C++ header +describing the reading class is available. + +Thanks to Qt's property system you can still access the sensor data. You need to know +3 pieces of information in order to do this: + +\list +\o The sensor type. +\o The property name or index. +\o The property type or a comparable type. +\endlist + +For example, here is an example of how you can access a property of the accelerometer. +This code does not require any compile-time links to \l QAccelerometer or +\l QAccelerometerReading. + +\snippet ../doc/src/snippets/sensors/start.cpp Starting a sensor + +You can discover all of this information at runtime too. The sensor_explorer example +shows you information about available sensors. + +\section1 Platform notes + +\section2 S60 3rd Edition + +Note that support for sensors in S60 3.1 device is extremely limited due to the native API. +Only the accelerometer is supported and only a few devices. + +Some devices running S60 3.2 support a newer native API and therefore support more sensors. + +More information about these platforms can be found \l{http://wiki.forum.nokia.com/index.php/Nokia_Sensor_APIs}{here}. + +Note that timestamps on this platform come from the system clock. +Applications need to handle shifts in time caused by the user manually setting the clock or +from the automatic time synchronization feature setting the clock. + +\section2 Symbian + +Most Symbian devices have their sensor data read via the Sensor Framework API. Some limitations +appear in the Sensors API as a result. + +Only specific data rates can be selected. Setting an invalid data rate has no effect so applications +that need to influence the used data rate should connect to the sensor, check the available data rates +and select one as appropriate. + +Readings are delivered to the application via a queue. If the application blocks the event loop or otherwise +interferes with the ability of the system to deliver readings (eg. by using up too much CPU time), they can +get blocked in this queue. Since delayed readings are not useful, the system will drop readings as needed +so that the application is always dealing with the most recent reading available. The application can tweak +the policy by setting properties on the sensor. + +The default policy is to accept up to 100 readings from the system at once and to discard all but the last one. + +\code +QAccelerometer sensor; +sensor.setProperty("maximumReadingCount", 100); +sensor.setProperty("processAllReadings", false); +\endcode + +Applications that desire the original behaviour can set the maximumReadingCount to 1. Note that this does not +guarantee that readings will not be dropped by the system. If the queue fills up, readings will be dropped. + +\code +QAccelerometer sensor; +sensor.setProperty("maximumReadingCount", 1); +\endcode + +Larger maximumReadingCount values reduce the need for the lower-priority sensor daemon to get CPU timeslices. +If the application is using lots of CPU but is still able to process readings quickly, it can request that +all the fetched readings are processed. + +\code +QAccelerometer sensor; +sensor.setProperty("maximumReadingCount", 10); +sensor.setProperty("processAllReadings", true); +\endcode + +More information about the native API can be found \l{http://wiki.forum.nokia.com/index.php/Nokia_Sensor_APIs}{here}. + +Note that timestamps on this platform come from the system clock. +Applications need to handle shifts in time caused by the user manually setting the clock or +from the automatic time synchronization feature setting the clock. + +The ambient light sensor can only detect changes. Unlike all other sensors, it cannot report the "current value" +so it is not possible to determine the current ambient light level. + +\section2 Maemo 5 + +The N900 represents a unique device for the Sensors API. Unlike the Symbian and MeeGo platforms, sensor data is +retrieved directly from the kernel and this has implications on the API. + +Axes are rotated when compared to Symbian or MeeGo devices. While Symbian and MeeGo devices orient their +hardware sensors towards a portrait orientation, the N900 does not do this. Instead, it orients the hardware sensors +towards its default landscape orientation. This has portability implications for applications that want to force the +use of a particular screen orientation and use sensors. The following code shows how accelerometer values can be +interpreted to ensure consistent results on the N900 as well as Symbian and MeeGo devices. + +\code +#ifdef Q_WS_MAEMO_5 + qreal x = reading->y(); + qreal y = -reading->x(); +#else + qreal x = reading->x(); + qreal y = reading->y(); +#endif + qreal z = reading->z(); +\endcode + +Alternatively, applications can set the environment variable \c N900_PORTRAIT_SENSORS to 1. This must be done +before any Sensors API calls are made so the beginning of the main function is a good place to do it. + +\code +int main(int argc, char **argv) +{ + qputenv("N900_PORTRAIT_SENSORS", "1"); + ... +\endcode + +Despite hardware that allows for multiple data rates and output ranges, the Sensors API does not allow access to +these due to permissions issues. + +Readings are polled using a timer. If the application blocks the event loop or otherwise interferes with the +ability of the timer to fire, readings will be missed. There are no queues so applications must ensure that +they process the readings promptly (possibly saving them into a buffer for later processing if required). + +\section2 MeeGo + +The data rates offered by MeeGo are not tied to how fast the hardware runs. + +The default data rate for a sensor is likely to be low when compared to Symbian or Maemo 5. Applications should +request a suitable data rate, taking care to avoid selecting invalid rates on other devices. + +Sensors may be suspended by the system in order to save power. Applications can avoid this by setting a property +on the sensor object. + +\code +QAccelerometer *accelerometer = new QAccelerometer(this); +accelerometer->setProperty("alwaysOn", true); +accelerometer->start(); +\endcode + +Unlike Symbian and N900, MeeGo does not currently provide initial readings. Thus, certain sensors must detect +a change in value before a value can be reported. Examples include the orientation sensor and ambient light +sensor. + +\section1 Front end, back end + +The Sensors API has a front end, for application developers to use and a back end, +where device implementors write code to access their hardware. As an application +developer you do not need to access the back end though it may be useful to understand +how it works. + +Commands from the application are delivered through QSensor and then down to the +device plugin. Data comes back through the QSensorReading class. + +\image sensors-overview.png + +More information about the back end can be found in \l{Sensors Backend}. + +\section1 Main Classes + +The primary classes that make up the Sensors API. + +\annotatedlist sensors_main + +\section1 Reading Classes + +The best way to access sensor data is via one of these classes. + +\annotatedlist sensors_reading + +\section1 Sensor Classes + +These classes provide convenience wrappers that reduce the need for casting. +Each of these classes represents a sensor type that the Sensors API knows +about. Note that additional types may be made available at run-time. See +\l{Sensor Types} for more information. + +\annotatedlist sensors_type + +\section1 Filter Classes + +As with the sensor classes, these provide convenience wrappers that reduce +the need for casting. + +\annotatedlist sensors_filter + +*/ + +/*! +\page sensors-backend.html +\title Sensors Backend +\brief The Sensors Backend connects the Sensors API to the platform services or hardware sensors. + +The Sensors Backend connects the Sensors API to the platform services or hardware sensors. + +\tableofcontents + +\section1 Overview + +\section1 Backend API + +QSensor instances talk to a backend object. Backends are usually supplied +with the QtSensors library for a specific device although third party +backends may be used as well. A backend may talk +directly to hardware or it may talk to a system service. In some instances +it may even talk to another sensor. +An example of this is the orientation sensor backend that talks to an +accelerometer to determine the orientation. + +There are also some \l{Sensors Backend Topics}{topics} specific to backend +implementors. + +\section1 Backend Classes +If you are making sensors available through the Sensors API, these are the +classes to use. +\annotatedlist sensors_backend + +\sa {Sensors Backend Topics} + +*/ + +/*! +\group sensors_backend_topics +\title Sensors Backend Topics +\generatelist related +*/ + +/*! +\page creating-a-sensor-plugin.html +\title Creating a sensor plugin +\ingroup sensors_backend_topics + +\section1 How a sensor plugin is loaded + +Since sensor backends are created on demand, the sensor plugin is loaded and asked +to register the sensor backends it handles. The plugin should implement +QSensorPluginInterface::registerSensors() and call QSensorManager::registerBackend() +to register available backends. Typically the plugin will also inherit from +QSensorBackendFactory and implement +QSensorBackendFactory::createBackend() in order to instantiate backends it has registered. + +The simplest plugin will have just once sensor backend although there is no reason +that multiple sensor backends cannot be in a plugin. + +An example follows. + +\snippet ../doc/src/snippets/sensors/plugin.cpp Plugin + +If you would like to build a backend into a library or application you can use the +REGISTER_STATIC_PLUGIN() macro although it may not work in all situations as it +uses static initialization. + +*/ + +/*! +\page determining-the-default-sensor-for-a-type.html +\title Determining the default sensor for a type +\ingroup sensors_backend_topics + +\section1 Multiple sensors can exist for a type + +Sensors was designed so that multiple sensors could exist for a given type. Why? +Consider this example. + +The N900 has an accelerometer built-in. It also features bluetooth and can pair +with a gaming controller that features an accelerometer. To a developer writing +a game these two devices are conceptually the same type. + +\section1 Default sensor for a type + +To avoid the need to know (or check) what the default sensor for a type is, the system will +use the default sensor for a type. Most of the time this is what the app developer wants to +do. In cases where the app developer wants to select a specific sensor they must call the +QSensor::setIdentifier() method before they start the sensor so that the appropriate backend +is used. + +From a system perspective though, selecting which sensor should be the default gets tricky. +The sensors library uses the first registered identifier as the default. This means that the +order in which sensor backends are registered is important so the system will allow a config +file to determine the default instead. + +\section1 Sensors.conf + +The config file that determines the default sensor for a type is called Sensors.conf. If present, +it is located in /etc/xdg/Nokia. It is read using QSettings so it has the standard formatting +of a QSettings .conf file. + +The settings live in the Default group and the general format is: +\code +type = identifier +\endcode + +An example Sensors.conf that ensures the N900 accelerometer is used as the default no matter the +order in which backends were registered is presented here. + +\code +[Default] +QAccelerometer = n900.accelerometer +\endcode + +If Sensors.conf specifies an identifier that is not registered then the system will fall back to +the first registered identifier as the default. + +Note that there is special case logic to prevent the generic plugin's backends from becoming the +default when another backend is registered for the same type. This logic means that a backend +identifier starting with \c{generic.} will only be the default if no other backends have been +registered for that type or if it is specified in \c{Sensors.conf}. + +*/ + +/*! +\page dynamic-sensor-backend-registration.html +\title Dynamic Sensor Backend Registration +\ingroup sensors_backend_topics + +\section1 Static Backend Registration + +Sensor backends are generally registered statically. The registration happens when the sensors +library is first used and the registration remains in effect while the program runs. + +\image sensors-static.png + +Statically registered backends may still exhibit some dynamic behaviour as the +QSensorBackendFactory is free to return 0 to indicate that a backend cannot be created. + +\section1 Dynamic Backend Registration + +While static registration is fine for most backends there are some situations where this is +problematic. + +The clearest example is backends that represent non-fixed hardware. As an example, lets consider +a game controller that is connected via Bluetooth. As there may be more than one game controller +in range of the phone, the program wants to record that a specific game controller should be used. +If the backend had been registered statically there would have been no unique information about +the controller. Instead, the registration is delayed until the controller is seen. + +\image sensors-dynamic.png + +\section1 Suggested Registration Policy + +A backend for fixed hardware should be registered immediately. Applications can see that the +sensor can be used. + +A backend for remote hardware should not be registered immediately. Applications can see that +the sensor cannot be used. When the remote hardware becomes available the backend should be +registered. Applications can see that the sensor is now available. + +If it is necessary to return 0 from a factory for a backend that was registered, the backend +should be unregistered. Applications can see that the sensor is no longer available. If the +factory can create the backend again it should be registered. Applications can see that the +sensor is available again. + +When the underlying hardware is no longer available, the backend should be deregistered. +Existing instances of the backend should report error states to the application but should +handle the situation gracefully. + +*/ + +/*! +\page qml-sensors.html +\title Sensors QML Plugin +\brief A QML plugin for the QtMobility Project Sensors API. + +\section1 Overview + +The identifying string for this component is \i {"QtMobility.sensors"}. +Use this in the QML \i {import} statement. + +The Sensors QML Plugin registers the C++ Sensors classes directly to the QML environment. +This causes some limitations due to the use of types that do not work in the QML environment. +See \l{Sensors QML Limitations}{below} for a list of the known limitations. + +See \l Sensors for more information about the Sensors API. + +\section1 Sensors QML Limitations + +The following limitations affect the Sensors QML bindings for Qt Mobility 1.1 and 1.2. + +\list 1 +\o The QSensor::sensorid property cannot be set because QML does not support QByteArray. + This means that it is not possible to specify a particular sensor when two or more have + been registered with the same type. +\o The QSensor::availableDataRates property cannot be used because QML does not support \l qrangelist. +\o The QSensor::outputRanges property cannot be used because QML does not support \l qoutputrangelist. +\o The QLightSensor::fieldOfView property cannot be used because QML cannot access dynamic properties. +\o The QMagnetometer::returnGeoValues property cannot be used because QML cannot access dynamic properties. +\o The QRotationSensor::hasZ property cannot be used because QML cannot access dynamic properties. +\o The QTapSensor::returnDoubleTapEvents property cannot be used because QML cannot access dynamic properties. +\endlist + +\section1 QML Sensor Elements + +These elements represent specific types of sensors. + +\annotatedlist qml-sensors_type + +\section1 QML Reading Elements + +The data from a sensor comes through a reading class. + +\annotatedlist qml-sensors_reading + +*/ + +/*! +\page meego-integration-notes.html +\title MeeGo Integration Notes +\ingroup sensors_backend_topics + +\section1 MeeGo Integration Notes + +The implementation of the API builds on top of the MeeGo Sensor Framework +that provides all the sensors specified in 1.2 API version. + +\section2 Available sensors + +If HW sensor is missing, the configuration file "Sensors.conf" +must be updated and sensor removed. The file +has the following format: + +\code +[Default] +QAccelerometer=meego.accelerometer +QAmbientLightSensor=meego.als +\endcode + +It lists sensor types and type's default implementation by giving the sensor id. +If the type is omitted then the backend does not support it in this device; this +gives a way of controlling and differentiating the supported sensor set. + +*/ + diff --git a/doc/src/plugins/qml-sensors.qdoc b/doc/src/plugins/qml-sensors.qdoc deleted file mode 100644 index 15f4c993..00000000 --- a/doc/src/plugins/qml-sensors.qdoc +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** GNU Free Documentation License -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms -** and conditions contained in a signed written agreement between you -** and Nokia. -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! - \group qml-sensors - \title QML Sensors API Plugin - QML Support for the QtMobility Project Sensors API. -*/ - -/*! - \page qml-sensors.html - - \title Sensors QML Plugin - - \brief A QML plugin for the QtMobility Project Sensors API. - - \section1 Overview - - The QML Sensors Plugin provides an easy to use interface to the Sensors API. - It enables us to receive sensor events and to read current values from - sensors. - - The plugin contains many sensor types and access functions to read values - from them. As an example consider the orientation sensor. The orientation - example simply displays text on-screen to show the current orientation. - - The QML code that reads the value is quite simple. Here we see a QML component - \e orientation declared which is an \l OrientationSensor element. First - the sensor is started by setting the \l {Sensor::active}{active} property - to \e true. The element receives a signal when the reading changes and it - is picked up by the \e onReadingChanged slot. Now the - \l {OrientationSensor::reading}{reading} property of this element can be - used to extract the current orientation so that it can be compared against - the defined values of various orientations in the \l OrientationReading - element. - - \qml - OrientationSensor { - id: orientation - active: true - - onReadingChanged: { - - if (reading.orientation == OrientationReading.FaceUp) - content.state = "FaceUp"; - - // ... more tests for different orientations ... - } - } - - \endqml - - Other sensors can be treated in a similar manner. For example, the \l Compass - sensor could have almost identical coding - - \qml - Compass { - id: compass - active: true - - onReadingChanged: { - compassHeading.text = reading.azimuth; - - // ... - } - } - \endqml - - \section1 QML Elements - \annotatedlist qml-sensors_type - \annotatedlist qml-sensors_reading - -*/ - - diff --git a/doc/src/sensors.qdoc b/doc/src/sensors.qdoc index a23d812d..11be0a12 100644 --- a/doc/src/sensors.qdoc +++ b/doc/src/sensors.qdoc @@ -29,496 +29,21 @@ \page sensors-api.html \title Sensors \brief The Sensors API provides access to sensors. -\ingroup mobility -\ingroup technology-apis +The Qt Sensors API is the Sensor API which should primarily used. +Application which uses the old QtMobility sensor api can still use the QtMobility sensor api +Read the \l {mobility-sensors-api.html} +{QtMobility sensor api reference Documentation}. -The Sensors API is primarily concerned with low-level, real-time sensors such as -the accelerometer although there are higher-level, event-driven sensors represented too. \tableofcontents \section1 Sensor Types -On a device there can be many types of sensors. Not all of the types that the Sensors API -supports may be available. There may also be types available that are not defined in the -Sensors API. You can find the sensor types available on a device using the -\l QSensor::sensorTypes() function. - -For a list of built-in sensor types, see the \l{Sensor Classes} section below. - \section1 Common Conventions -Unless otherwise specified, sensors shall use the -\l{http://en.wikipedia.org/wiki/Cartesian_coordinate_system}{Right Hand Cartesian coordinate system}. - -\image sensors-coordinates.jpg - -To allow for measurements in all 6 directions, negative values are used. - -\image sensors-coordinates2.jpg - -Where rotation around an axis is used, the rotation shall be expressed as a Right Hand rotation. - -\image sensors-coordinates3.jpg - -In general, sensor data is oriented to the top of the device. If values are to be displayed on -the screen the values may need to be transformed so that they match the user interface orientation. A sensor -may define its data as being oriented to the UI. This will be noted in the documentation for the -sensor. - -\image sensors-sides2.jpg - -\section1 Using a Sensor - -The life cycle of a sensor is typically: - -\list -\o Create an instance of QSensor or one of its sub-classes on the stack or heap. -\o Setup as required by the application. -\o Start receiving values. -\o Sensor data is used by the application. -\o Stop receiving values. -\endlist - -Here is an example of creating a sensor on the heap and on the stack. - -\snippet snippets/sensors/creating.cpp Creating a sensor - -\section1 Accessing sensor data in a generic fashion - -The preferred way to deal with sensor data is via the \l{Reading Classes}. -However, sometimes this may not be possible. For example, you may be deploying -an application to a device that has a new sensor type but no C++ header -describing the reading class is available. - -Thanks to Qt's property system you can still access the sensor data. You need to know -3 pieces of information in order to do this: - -\list -\o The sensor type. -\o The property name or index. -\o The property type or a comparable type. -\endlist - -For example, here is an example of how you can access a property of the accelerometer. -This code does not require any compile-time links to \l QAccelerometer or -\l QAccelerometerReading. - -\snippet snippets/sensors/start.cpp Starting a sensor - -You can discover all of this information at runtime too. The sensor_explorer example -shows you information about available sensors. - -\section1 Platform notes - -\section2 S60 3rd Edition - -Note that support for sensors in S60 3.1 device is extremely limited due to the native API. -Only the accelerometer is supported and only a few devices. - -Some devices running S60 3.2 support a newer native API and therefore support more sensors. - -More information about these platforms can be found \l{http://wiki.forum.nokia.com/index.php/Nokia_Sensor_APIs}{here}. - -Note that timestamps on this platform come from the system clock. -Applications need to handle shifts in time caused by the user manually setting the clock or -from the automatic time synchronization feature setting the clock. - -\section2 Symbian - -Most Symbian devices have their sensor data read via the Sensor Framework API. Some limitations -appear in the Sensors API as a result. - -Only specific data rates can be selected. Setting an invalid data rate has no effect so applications -that need to influence the used data rate should connect to the sensor, check the available data rates -and select one as appropriate. - -Readings are delivered to the application via a queue. If the application blocks the event loop or otherwise -interferes with the ability of the system to deliver readings (eg. by using up too much CPU time), they can -get blocked in this queue. Since delayed readings are not useful, the system will drop readings as needed -so that the application is always dealing with the most recent reading available. The application can tweak -the policy by setting properties on the sensor. - -The default policy is to accept up to 100 readings from the system at once and to discard all but the last one. - -\code -QAccelerometer sensor; -sensor.setProperty("maximumReadingCount", 100); -sensor.setProperty("processAllReadings", false); -\endcode - -Applications that desire the original behaviour can set the maximumReadingCount to 1. Note that this does not -guarantee that readings will not be dropped by the system. If the queue fills up, readings will be dropped. - -\code -QAccelerometer sensor; -sensor.setProperty("maximumReadingCount", 1); -\endcode - -Larger maximumReadingCount values reduce the need for the lower-priority sensor daemon to get CPU timeslices. -If the application is using lots of CPU but is still able to process readings quickly, it can request that -all the fetched readings are processed. - -\code -QAccelerometer sensor; -sensor.setProperty("maximumReadingCount", 10); -sensor.setProperty("processAllReadings", true); -\endcode - -More information about the native API can be found \l{http://wiki.forum.nokia.com/index.php/Nokia_Sensor_APIs}{here}. - -Note that timestamps on this platform come from the system clock. -Applications need to handle shifts in time caused by the user manually setting the clock or -from the automatic time synchronization feature setting the clock. - -The ambient light sensor can only detect changes. Unlike all other sensors, it cannot report the "current value" -so it is not possible to determine the current ambient light level. - -\section2 Maemo 5 - -The N900 represents a unique device for the Sensors API. Unlike the Symbian and MeeGo platforms, sensor data is -retrieved directly from the kernel and this has implications on the API. - -Axes are rotated when compared to Symbian or MeeGo devices. While Symbian and MeeGo devices orient their -hardware sensors towards a portrait orientation, the N900 does not do this. Instead, it orients the hardware sensors -towards its default landscape orientation. This has portability implications for applications that want to force the -use of a particular screen orientation and use sensors. The following code shows how accelerometer values can be -interpreted to ensure consistent results on the N900 as well as Symbian and MeeGo devices. - -\code -#ifdef Q_WS_MAEMO_5 - qreal x = reading->y(); - qreal y = -reading->x(); -#else - qreal x = reading->x(); - qreal y = reading->y(); -#endif - qreal z = reading->z(); -\endcode - -Alternatively, applications can set the environment variable \c N900_PORTRAIT_SENSORS to 1. This must be done -before any Sensors API calls are made so the beginning of the main function is a good place to do it. - -\code -int main(int argc, char **argv) -{ - qputenv("N900_PORTRAIT_SENSORS", "1"); - ... -\endcode - -Despite hardware that allows for multiple data rates and output ranges, the Sensors API does not allow access to -these due to permissions issues. - -Readings are polled using a timer. If the application blocks the event loop or otherwise interferes with the -ability of the timer to fire, readings will be missed. There are no queues so applications must ensure that -they process the readings promptly (possibly saving them into a buffer for later processing if required). - -\section2 MeeGo - -The data rates offered by MeeGo are not tied to how fast the hardware runs. - -The default data rate for a sensor is likely to be low when compared to Symbian or Maemo 5. Applications should -request a suitable data rate, taking care to avoid selecting invalid rates on other devices. - -Sensors may be suspended by the system in order to save power. Applications can avoid this by setting a property -on the sensor object. - -\code -QAccelerometer *accelerometer = new QAccelerometer(this); -accelerometer->setProperty("alwaysOn", true); -accelerometer->start(); -\endcode - -Unlike Symbian and N900, MeeGo does not currently provide initial readings. Thus, certain sensors must detect -a change in value before a value can be reported. Examples include the orientation sensor and ambient light -sensor. - -\section1 Front end, back end - -The Sensors API has a front end, for application developers to use and a back end, -where device implementors write code to access their hardware. As an application -developer you do not need to access the back end though it may be useful to understand -how it works. - -Commands from the application are delivered through QSensor and then down to the -device plugin. Data comes back through the QSensorReading class. - -\image sensors-overview.png - -More information about the back end can be found in \l{Sensors Backend}. - -\section1 Main Classes - -The primary classes that make up the Sensors API. - -\annotatedlist sensors_main - -\section1 Reading Classes - -The best way to access sensor data is via one of these classes. - -\annotatedlist sensors_reading - -\section1 Sensor Classes - -These classes provide convenience wrappers that reduce the need for casting. -Each of these classes represents a sensor type that the Sensors API knows -about. Note that additional types may be made available at run-time. See -\l{Sensor Types} for more information. - -\annotatedlist sensors_type - -\section1 Filter Classes - -As with the sensor classes, these provide convenience wrappers that reduce -the need for casting. - -\annotatedlist sensors_filter - -*/ - -/*! -\page sensors-backend.html -\title Sensors Backend -\brief The Sensors Backend connects the Sensors API to the platform services or hardware sensors. - -The Sensors Backend connects the Sensors API to the platform services or hardware sensors. - -\tableofcontents - -\section1 Overview - -\section1 Backend API - -QSensor instances talk to a backend object. Backends are usually supplied -with the QtSensors library for a specific device although third party -backends may be used as well. A backend may talk -directly to hardware or it may talk to a system service. In some instances -it may even talk to another sensor. -An example of this is the orientation sensor backend that talks to an -accelerometer to determine the orientation. - -There are also some \l{Sensors Backend Topics}{topics} specific to backend -implementors. - -\section1 Backend Classes -If you are making sensors available through the Sensors API, these are the -classes to use. -\annotatedlist sensors_backend - -\sa {Sensors Backend Topics} - -*/ - -/*! -\group sensors_backend_topics -\title Sensors Backend Topics -\generatelist related -*/ - -/*! -\page creating-a-sensor-plugin.html -\title Creating a sensor plugin -\ingroup sensors_backend_topics - -\section1 How a sensor plugin is loaded - -Since sensor backends are created on demand, the sensor plugin is loaded and asked -to register the sensor backends it handles. The plugin should implement -QSensorPluginInterface::registerSensors() and call QSensorManager::registerBackend() -to register available backends. Typically the plugin will also inherit from -QSensorBackendFactory and implement -QSensorBackendFactory::createBackend() in order to instantiate backends it has registered. - -The simplest plugin will have just once sensor backend although there is no reason -that multiple sensor backends cannot be in a plugin. - -An example follows. - -\snippet snippets/sensors/plugin.cpp Plugin - -If you would like to build a backend into a library or application you can use the -REGISTER_STATIC_PLUGIN() macro although it may not work in all situations as it -uses static initialization. - -*/ - -/*! -\page determining-the-default-sensor-for-a-type.html -\title Determining the default sensor for a type -\ingroup sensors_backend_topics - -\section1 Multiple sensors can exist for a type - -Sensors was designed so that multiple sensors could exist for a given type. Why? -Consider this example. - -The N900 has an accelerometer built-in. It also features bluetooth and can pair -with a gaming controller that features an accelerometer. To a developer writing -a game these two devices are conceptually the same type. - -\section1 Default sensor for a type - -To avoid the need to know (or check) what the default sensor for a type is, the system will -use the default sensor for a type. Most of the time this is what the app developer wants to -do. In cases where the app developer wants to select a specific sensor they must call the -QSensor::setIdentifier() method before they start the sensor so that the appropriate backend -is used. - -From a system perspective though, selecting which sensor should be the default gets tricky. -The sensors library uses the first registered identifier as the default. This means that the -order in which sensor backends are registered is important so the system will allow a config -file to determine the default instead. - -\section1 Sensors.conf - -The config file that determines the default sensor for a type is called Sensors.conf. If present, -it is located in /etc/xdg/Nokia. It is read using QSettings so it has the standard formatting -of a QSettings .conf file. - -The settings live in the Default group and the general format is: -\code -type = identifier -\endcode - -An example Sensors.conf that ensures the N900 accelerometer is used as the default no matter the -order in which backends were registered is presented here. - -\code -[Default] -QAccelerometer = n900.accelerometer -\endcode - -If Sensors.conf specifies an identifier that is not registered then the system will fall back to -the first registered identifier as the default. - -Note that there is special case logic to prevent the generic plugin's backends from becoming the -default when another backend is registered for the same type. This logic means that a backend -identifier starting with \c{generic.} will only be the default if no other backends have been -registered for that type or if it is specified in \c{Sensors.conf}. - -*/ - -/*! -\page dynamic-sensor-backend-registration.html -\title Dynamic Sensor Backend Registration -\ingroup sensors_backend_topics - -\section1 Static Backend Registration - -Sensor backends are generally registered statically. The registration happens when the sensors -library is first used and the registration remains in effect while the program runs. - -\image sensors-static.png - -Statically registered backends may still exhibit some dynamic behaviour as the -QSensorBackendFactory is free to return 0 to indicate that a backend cannot be created. - -\section1 Dynamic Backend Registration - -While static registration is fine for most backends there are some situations where this is -problematic. - -The clearest example is backends that represent non-fixed hardware. As an example, lets consider -a game controller that is connected via Bluetooth. As there may be more than one game controller -in range of the phone, the program wants to record that a specific game controller should be used. -If the backend had been registered statically there would have been no unique information about -the controller. Instead, the registration is delayed until the controller is seen. - -\image sensors-dynamic.png - -\section1 Suggested Registration Policy - -A backend for fixed hardware should be registered immediately. Applications can see that the -sensor can be used. - -A backend for remote hardware should not be registered immediately. Applications can see that -the sensor cannot be used. When the remote hardware becomes available the backend should be -registered. Applications can see that the sensor is now available. - -If it is necessary to return 0 from a factory for a backend that was registered, the backend -should be unregistered. Applications can see that the sensor is no longer available. If the -factory can create the backend again it should be registered. Applications can see that the -sensor is available again. - -When the underlying hardware is no longer available, the backend should be deregistered. -Existing instances of the backend should report error states to the application but should -handle the situation gracefully. - -*/ - -/*! -\page qml-sensors.html -\title Sensors QML Plugin -\brief A QML plugin for the QtMobility Project Sensors API. - -\section1 Overview - -The identifying string for this component is \e {"QtMobility.sensors"}. -Use this in the QML \e {import} statement. - -The Sensors QML Plugin registers the C++ Sensors classes directly to the QML environment. -This causes some limitations due to the use of types that do not work in the QML environment. -See \l{Sensors QML Limitations}{below} for a list of the known limitations. - -See \l Sensors for more information about the Sensors API. - -\section1 Sensors QML Limitations - -The following limitations affect the Sensors QML bindings for Qt Mobility 1.1 and 1.2. - -\list 1 -\o The QSensor::sensorid property cannot be set because QML does not support QByteArray. - This means that it is not possible to specify a particular sensor when two or more have - been registered with the same type. -\o The QSensor::availableDataRates property cannot be used because QML does not support \l qrangelist. -\o The QSensor::outputRanges property cannot be used because QML does not support \l qoutputrangelist. -\o The QLightSensor::fieldOfView property cannot be used because QML cannot access dynamic properties. -\o The QMagnetometer::returnGeoValues property cannot be used because QML cannot access dynamic properties. -\o The QRotationSensor::hasZ property cannot be used because QML cannot access dynamic properties. -\o The QTapSensor::returnDoubleTapEvents property cannot be used because QML cannot access dynamic properties. -\endlist - -\section1 QML Sensor Elements - -These elements represent specific types of sensors. - -\annotatedlist qml-sensors_type - -\section1 QML Reading Elements - -The data from a sensor comes through a reading class. - -\annotatedlist qml-sensors_reading - -*/ - -/*! -\page meego-integration-notes.html -\title MeeGo Integration Notes -\ingroup sensors_backend_topics - -\section1 MeeGo Integration Notes - -The implementation of the API builds on top of the MeeGo Sensor Framework -that provides all the sensors specified in 1.2 API version. - -\section2 Available sensors - -If HW sensor is missing, the configuration file "Sensors.conf" -must be updated and sensor removed. The file -has the following format: - -\code -[Default] -QAccelerometer=meego.accelerometer -QAmbientLightSensor=meego.als -\endcode - -It lists sensor types and type's default implementation by giving the sensor id. -If the type is omitted then the backend does not support it in this device; this -gives a way of controlling and differentiating the supported sensor set. - -*/ - +\section1 QML Elements +The new QtSensor API provides a bundle of QML Elements. +Read the \l {qml-sensors5.html} +{Sensors QML Plugin for Qt 5 reference Documentation} for more information. +QtSensorsExample diff --git a/examples/sensors/qmlqtsensors5/Button.qml b/examples/sensors/qmlqtsensors5/Button.qml new file mode 100644 index 00000000..4e9c74c2 --- /dev/null +++ b/examples/sensors/qmlqtsensors5/Button.qml @@ -0,0 +1,34 @@ +import QtQuick 2.0 + +Rectangle { + id: button + width: 100 + height: 20 + property alias text: t.text + property bool checked + signal clicked + property color checkColor; + property color unCheckColor; + border.width: 1 + radius: 2 + + Text{ + x: 0 + id: t + anchors.fill: button + } + + MouseArea{ + anchors.fill: button + onClicked: { + setCheck(!button.checked); + button.clicked(); + } + } + + function setCheck(val) + { + checked = val; + button.color = (button.checked == true ? checkColor : unCheckColor); + } +} diff --git a/examples/sensors/qmlqtsensors5/SelectionButton.qml b/examples/sensors/qmlqtsensors5/SelectionButton.qml new file mode 100644 index 00000000..e258d5e1 --- /dev/null +++ b/examples/sensors/qmlqtsensors5/SelectionButton.qml @@ -0,0 +1,37 @@ +import QtQuick 2.0 + +Rectangle { + id: button + width: 100 + height: 25 + property alias text: t.text + property bool checked + signal clicked + + Image{ + id: image + x: 0 + width: 15 + height: 15 + source: (button.checked == true ? "checked.gif" : "unchecked.gif") + } + + Text{ + x: image.x + image.width + 10 + id: t + } + + MouseArea{ + anchors.fill: button + onClicked: { + setCheck(true); + button.clicked(); + } + } + + function setCheck(val) + { + checked = val; + image.source = (button.checked == true ? "checked.gif" : "unchecked.gif"); + } +} diff --git a/examples/sensors/qmlqtsensors5/checked.gif b/examples/sensors/qmlqtsensors5/checked.gif new file mode 100644 index 00000000..a4216f2c Binary files /dev/null and b/examples/sensors/qmlqtsensors5/checked.gif differ diff --git a/examples/sensors/qmlqtsensors5/icon.png b/examples/sensors/qmlqtsensors5/icon.png new file mode 100755 index 00000000..27657129 Binary files /dev/null and b/examples/sensors/qmlqtsensors5/icon.png differ diff --git a/examples/sensors/qmlqtsensors5/info.json b/examples/sensors/qmlqtsensors5/info.json new file mode 100644 index 00000000..70eef76d --- /dev/null +++ b/examples/sensors/qmlqtsensors5/info.json @@ -0,0 +1,14 @@ +{ + "info-version": "1.0", + "dict": { + "Category": "application", + "Runtime": "qml", + "DisplayName": "Sensors2", + "Subcategory": "utility", + "MainQML": "main.qml", + "Version": "1.0", + "Identifier": "com.noklab.nrcc.qmlsensors2.demo", + "Summary": "QML Sensors2 demo", + "Author": "Qt" + } +} diff --git a/examples/sensors/qmlqtsensors5/main.qml b/examples/sensors/qmlqtsensors5/main.qml new file mode 100644 index 00000000..113c10b2 --- /dev/null +++ b/examples/sensors/qmlqtsensors5/main.qml @@ -0,0 +1,290 @@ +//Import the declarative plugins +import QtQuick 2.0 +import Qt.QtSensors 5.0 + +/* Layout + tiltrect + / +------------------------------/ +| @ Facing Up <-------------------- selButtonFacingUp +| O Left Up <-------------------- selButtonLeftUp +| O Top Down <-------------------- selButtonTopDown +| O Face Down <-------------------- selButtonFaceDown +| O Right Up <-------------------- selButtonRightUp +| O Top Up <-------------------- selButtonTopUp +| --------- +| |degree | <-------------------- useRadian +| --------- +| X Rotation: 0 <------------------ xrottext +| Y Rotation: 0 <------------------ yrottext +| --------- +| |start | <-------------------- tiltStart +| --------- ablrect +------------------------------ / +------------------------------/ +| Ambient light: - <--------------- abltext +| --------- +| |start | <-------------------- ablStart +| --------- proxirect +------------------------------ / +------------------------------/ +| Proximity: false <--------------- proxitext +| --------- +| |start | <-------------------- proxiStart +| --------- +------------------------------ + +*/ + +Rectangle { + width: 320 + height: 480 + + Rectangle { + id: tiltrect + x: 2 + y: 22 + width: 315 + height: 270 + border.width: 1 + + TiltSensor { + id: tilt + radian: false + measureFrom: TiltSensor.FaceUp + running: false + } + + SelectionButton{ + id: selButtonFacingUp + x: 5 + y: 20 + checked: true + text: "Facing Up" + onClicked:{ + selButtonLeftUp.setCheck(false); + selButtonTopDown.setCheck(false); + selButtonFaceDown.setCheck(false); + selButtonRightUp.setCheck(false); + selButtonTopUp.setCheck(false); + tilt.measureFrom=TiltSensor.FaceUp; + } + } + SelectionButton{ + id: selButtonLeftUp + x: 5 + y: 45 + checked: false + text: "Left Up" + onClicked:{ + selButtonFacingUp.setCheck(false); + selButtonTopDown.setCheck(false); + selButtonFaceDown.setCheck(false); + selButtonRightUp.setCheck(false); + selButtonTopUp.setCheck(false); + tilt.measureFrom=TiltSensor.LeftUp; + } + } + SelectionButton{ + id: selButtonTopDown + x: 5 + y: 70 + checked: false + text: "Top Down" + onClicked:{ + selButtonFacingUp.setCheck(false); + selButtonLeftUp.setCheck(false); + selButtonFaceDown.setCheck(false); + selButtonRightUp.setCheck(false); + selButtonTopUp.setCheck(false); + tilt.measureFrom=TiltSensor.TopDown; + } + } + SelectionButton{ + id: selButtonFaceDown + x: 5 + y: 95 + checked: false + text: "Face Down" + onClicked:{ + selButtonFacingUp.setCheck(false); + selButtonLeftUp.setCheck(false); + selButtonTopDown.setCheck(false); + selButtonRightUp.setCheck(false); + selButtonTopUp.setCheck(false); + tilt.measureFrom=TiltSensor.FaceDown; + } + } + SelectionButton{ + id: selButtonRightUp + x: 5 + y: 120 + checked: false + text: "Right Up" + onClicked:{ + selButtonFacingUp.setCheck(false); + selButtonLeftUp.setCheck(false); + selButtonTopDown.setCheck(false); + selButtonFaceDown.setCheck(false); + selButtonTopUp.setCheck(false); + tilt.measureFrom=TiltSensor.RightUp; + } + } + SelectionButton{ + id: selButtonTopUp + x: 5 + y: 145 + checked: false + text: "Top Up" + onClicked:{ + selButtonFacingUp.setCheck(false); + selButtonLeftUp.setCheck(false); + selButtonTopDown.setCheck(false); + selButtonFaceDown.setCheck(false); + selButtonRightUp.setCheck(false); + tilt.measureFrom=TiltSensor.TopUp; + } + } + + Button{ + id: useRadian + x: 5 + y: 170 + text: "degree" + checkColor: "lightblue" + unCheckColor: "lightyellow" + checked: tilt.radian + color: "lightyellow" + + onClicked:{ + tilt.radian = useRadian.checked; + if (useRadian.checked) + useRadian.text = "radian"; + else + useRadian.text = "degree"; + } + } + + Text { + id: xrottext + x:5 + y:195 + text: "X Rotation: " + tilt.xRotation + } + Text { + id: yrottext + x:5 + y:220 + text: "Y Rotation: " + tilt.yRotation + } + Button{ + id: tiltStart + x: 5 + y: 245 + text: "start" + checkColor: "lightblue" + unCheckColor: "lightyellow" + checked: tilt.running + color: "lightyellow" + + onClicked:{ + tilt.running = tiltStart.checked; + if (tiltStart.checked) + tiltStart.text = "running"; + else + tiltStart.text = "stopped"; + } + } + } + + Rectangle { + id: ablrect + x: 2 + y: tiltrect.y + tiltrect.height + 10 + width: 315 + height: 70 + border.width: 1 + + AmbientLightSensor { + id: abl + running: false + onLightLevelChanged:{ + if (abl.lightLevel == AmbientLightSensor.Undefined) + abltext.text = "Ambient light: Undefined"; + else if (abl.lightLevel == AmbientLightSensor.Dark) + abltext.text = "Ambient light: Dark"; + else if (abl.lightLevel == AmbientLightSensor.Twilight) + abltext.text = "Ambient light: Twilight"; + else if (abl.lightLevel == AmbientLightSensor.Light) + abltext.text = "Ambient light: Light"; + else if (abl.lightLevel == AmbientLightSensor.Bright) + abltext.text = "Ambient light: Bright"; + else if (abl.lightLevel == AmbientLightSensor.Sunny) + abltext.text = "Ambient light: Sunny"; + } + } + Text { + id: abltext + x: 5 + y: 10 + text: "Ambient light: -" + } + Button{ + id: ablStart + x: 5 + y: 35 + text: "start" + checkColor: "lightblue" + unCheckColor: "lightyellow" + checked: abl.running + color: "lightyellow" + + onClicked:{ + abl.running = ablStart.checked; + if (ablStart.checked) + ablStart.text = "running"; + else + ablStart.text = "stopped"; + } + } + } + + Rectangle { + id: proxirect + x: 2 + y: ablrect.y + ablrect.height + 10 + width: 315 + height: 70 + border.width: 1 + + ProximitySensor { + id: proxi + running: true + } + Text { + id: proxitext + x: 5 + y: 10 + text: "Proximity: " + proxi.close + } + Button{ + id: proxiStart + x: 5 + y: 35 + text: "start" + checkColor: "lightblue" + unCheckColor: "lightyellow" + checked: proxi.running + color: "lightyellow" + + onClicked:{ + proxi.running = proxiStart.checked; + if (proxiStart.checked) + proxiStart.text = "running"; + else + proxiStart.text = "stopped"; + } + } + } +} + diff --git a/examples/sensors/qmlqtsensors5/qmlqtsensors5.qmlproject b/examples/sensors/qmlqtsensors5/qmlqtsensors5.qmlproject new file mode 100644 index 00000000..2218c43d --- /dev/null +++ b/examples/sensors/qmlqtsensors5/qmlqtsensors5.qmlproject @@ -0,0 +1,20 @@ +/* File generated by Qt Creator, version 2.2.0 */ + +import QmlProject 1.1 + +Project { + mainFile: "main.qml" + + /* Include .qml, .js, and image files from current directory and subdirectories */ + QmlFiles { + directory: "." + } + JavaScriptFiles { + directory: "." + } + ImageFiles { + directory: "." + } + /* List of plugin directories passed to QML runtime */ + // importPaths: [ "../exampleplugin" ] +} diff --git a/examples/sensors/qmlqtsensors5/unchecked.gif b/examples/sensors/qmlqtsensors5/unchecked.gif new file mode 100644 index 00000000..ffb651df Binary files /dev/null and b/examples/sensors/qmlqtsensors5/unchecked.gif differ diff --git a/src/imports/imports.pro b/src/imports/imports.pro index a68f6a5e..6115652e 100644 --- a/src/imports/imports.pro +++ b/src/imports/imports.pro @@ -1,4 +1,5 @@ TEMPLATE = subdirs SUBDIRS += sensors +SUBDIRS += sensors2 diff --git a/src/imports/sensors/sensors.cpp b/src/imports/sensors/sensors.cpp index ea0f076a..0d4394c7 100644 --- a/src/imports/sensors/sensors.cpp +++ b/src/imports/sensors/sensors.cpp @@ -63,14 +63,14 @@ class QSensorsDeclarativeModule : public QDeclarativeExtensionPlugin public: virtual void registerTypes(const char *uri) { - char const * const package = "Qt.sensors"; + char const * const package = "QtMobility.sensors"; if (QLatin1String(uri) != QLatin1String(package)) return; int major; int minor; - // Register the 1.0 interfaces + // Register the 1.2 interfaces major = 1; - minor = 0; + minor = 2; qmlRegisterUncreatableType(package, major, minor, "Sensor", QLatin1String("Cannot create Sensor")); qmlRegisterUncreatableType(package, major, minor, "SensorReading", QLatin1String("Cannot create SensorReading")); qmlRegisterType (package, major, minor, "Accelerometer"); @@ -109,6 +109,7 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara /*! \qmlclass Sensor QSensor \ingroup qml-sensors_type + \inqmlmodule QtMobility.sensors 1 \brief The Sensor element serves as a base type for sensors. The Sensor element serves as a base type for sensors. @@ -122,25 +123,25 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara */ /*! - \qmlproperty int Sensor::dataRate + \qmlproperty int QtMobility.sensors1::Sensor::dataRate Sets the rate at which data is returned by the sensor. Please see QSensor::dataRate for information about this property. */ /*! - \qmlproperty bool Sensor::active + \qmlproperty bool QtMobility.sensors1::Sensor::active Starts or stops the sensor. Please see QSensor::active for information about this property. */ /*! - \qmlproperty SensorReading Sensor::reading + \qmlproperty SensorReading QtMobility.sensors1::Sensor::reading Holds the most recent sensor reading. Please see QSensor::reading for information about this property. */ /*! - \qmlsignal Sensor::onReadingChanged() + \qmlsignal QtMobility.sensors1::Sensor::onReadingChanged() Called when the reading object changes. Please see QSensor::readingChanged() for information about this signal. */ @@ -148,6 +149,7 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara /*! \qmlclass SensorReading QSensorReading \ingroup qml-sensors_reading + \inqmlmodule QtMobility.sensors 1 \brief The SensorReading element serves as a base type for sensor readings. The SensorReading element serves as a base type for sensor readings. @@ -159,7 +161,7 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara */ /*! - \qmlproperty quint64 SensorReading::timestamp + \qmlproperty quint64 QtMobility.sensors1::SensorReading::timestamp A timestamp for the reading. Please see QSensorReading::timestamp for information about this property. */ @@ -167,6 +169,7 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara /*! \qmlclass Accelerometer QAccelerometer \ingroup qml-sensors_type + \inqmlmodule QtMobility.sensors 1 \inherits Sensor \brief The Accelerometer element reports on linear acceleration along the X, Y and Z axes. @@ -181,13 +184,13 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara */ /*! - \qmlproperty AccelerometerReading Accelerometer::reading + \qmlproperty AccelerometerReading QtMobility.sensors1::Accelerometer::reading Holds the most recent accelerometer reading. Please see QSensor::reading for information about this property. */ /*! - \qmlsignal Accelerometer::onReadingChanged() + \qmlsignal QtMobility.sensors1::Accelerometer::onReadingChanged() Called when the reading object changes. Please see QSensor::readingChanged() for information about this signal. */ @@ -195,6 +198,7 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara /*! \qmlclass AccelerometerReading QAccelerometerReading \ingroup qml-sensors_reading + \inqmlmodule QtMobility.sensors 1 \inherits SensorReading \brief The AccelerometerReading element holds the most recent Accelerometer reading. @@ -207,23 +211,24 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara */ /*! - \qmlproperty qreal AccelerometerReading::x + \qmlproperty qreal QtMobility.sensors1::AccelerometerReading::x Please see QAccelerometerReading::x for information about this property. */ /*! - \qmlproperty qreal AccelerometerReading::y + \qmlproperty qreal QtMobility.sensors1::AccelerometerReading::y Please see QAccelerometerReading::y for information about this property. */ /*! - \qmlproperty qreal AccelerometerReading::z + \qmlproperty qreal QtMobility.sensors1::AccelerometerReading::z Please see QAccelerometerReading::z for information about this property. */ /*! \qmlclass AmbientLightSensor QAmbientLightSensor \ingroup qml-sensors_type + \inqmlmodule QtMobility.sensors 1 \inherits Sensor \brief The AmbientLightSensor element repors on ambient lighting conditions. @@ -236,13 +241,13 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara */ /*! - \qmlproperty AmbientLightReading AmbientLightSensor::reading + \qmlproperty AmbientLightReading QtMobility.sensors1::AmbientLightSensor::reading Holds the most recent ambient light reading. Please see QSensor::reading for information about this property. */ /*! - \qmlsignal AmbientLightSensor::onReadingChanged() + \qmlsignal QtMobility.sensors1::AmbientLightSensor::onReadingChanged() Called when the reading object changes. Please see QSensor::readingChanged() for information about this signal. */ @@ -250,6 +255,7 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara /*! \qmlclass AmbientLightReading QAmbientLightReading \ingroup qml-sensors_reading + \inqmlmodule QtMobility.sensors 1 \inherits SensorReading \brief The AmbientLightReading element holds the most AmbientLightSensor reading. @@ -262,7 +268,7 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara */ /*! - \qmlproperty QAmbientLightReading::LightLevel AmbientLightReading::lightLevel + \qmlproperty QAmbientLightReading::LightLevel QtMobility.sensors1::AmbientLightReading::lightLevel Please see QAmbientLightReading::lightLevel for information about this property. LightLevel constants are exposed through the AmbientLightReading class. @@ -279,6 +285,7 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara /*! \qmlclass Compass QCompass \ingroup qml-sensors_type + \inqmlmodule QtMobility.sensors 1 \inherits Sensor \brief The Compass element reports on heading using magnetic north as a reference. @@ -291,13 +298,13 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara */ /*! - \qmlproperty CompassReading Compass::reading + \qmlproperty CompassReading QtMobility.sensors1::Compass::reading Holds the most recent compass reading. Please see QSensor::reading for information about this property. */ /*! - \qmlsignal Compass::onReadingChanged() + \qmlsignal QtMobility.sensors1::Compass::onReadingChanged() Called when the reading object changes. Please see QSensor::readingChanged() for information about this signal. */ @@ -305,6 +312,7 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara /*! \qmlclass CompassReading QCompassReading \ingroup qml-sensors_reading + \inqmlmodule QtMobility.sensors 1 \inherits SensorReading \brief The CompassReading element holds the most recent Compass reading. @@ -317,18 +325,19 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara */ /*! - \qmlproperty qreal CompassReading::azimuth + \qmlproperty qreal QtMobility.sensors1::CompassReading::azimuth Please see QCompassReading::azimuth for information about this property. */ /*! - \qmlproperty qreal CompassReading::calibrationLevel + \qmlproperty qreal QtMobility.sensors1::CompassReading::calibrationLevel Please see QCompassReading::calibrationLevel for information about this property. */ /*! \qmlclass Magnetometer QMagnetometer \ingroup qml-sensors_type + \inqmlmodule QtMobility.sensors 1 \inherits Sensor \brief The Magnetometer element reports on magnetic field strength along the Z, Y and Z axes. @@ -343,13 +352,13 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara */ /*! - \qmlproperty MagnetometerReading Magnetometer::reading + \qmlproperty MagnetometerReading QtMobility.sensors1::Magnetometer::reading Holds the most recent magnetometer reading. Please see QSensor::reading for information about this property. */ /*! - \qmlsignal Magnetometer::onReadingChanged() + \qmlsignal QtMobility.sensors1::Magnetometer::onReadingChanged() Called when the reading object changes. Please see QSensor::readingChanged() for information about this signal. */ @@ -357,6 +366,7 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara /*! \qmlclass MagnetometerReading QMagnetometerReading \ingroup qml-sensors_reading + \inqmlmodule QtMobility.sensors 1 \inherits SensorReading \brief The MagnetometerReading element holds the most recent Magnetometer reading. @@ -369,28 +379,29 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara */ /*! - \qmlproperty qreal MagnetometerReading::x + \qmlproperty qreal QtMobility.sensors1::MagnetometerReading::x Please see QMagnetometerReading::x for information about this property. */ /*! - \qmlproperty qreal MagnetometerReading::y + \qmlproperty qreal QtMobility.sensors1::MagnetometerReading::y Please see QMagnetometerReading::y for information about this property. */ /*! - \qmlproperty qreal MagnetometerReading::z + \qmlproperty qreal QtMobility.sensors1::MagnetometerReading::z Please see QMagnetometerReading::z for information about this property. */ /*! - \qmlproperty qreal MagnetometerReading::calibrationLevel + \qmlproperty qreal QtMobility.sensors1::MagnetometerReading::calibrationLevel Please see QMagnetometerReading::calibrationLevel for information about this property. */ /*! \qmlclass OrientationSensor QOrientationSensor \ingroup qml-sensors_type + \inqmlmodule QtMobility.sensors 1 \inherits Sensor \brief The OrientationSensor element reports device orientation. @@ -403,13 +414,13 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara */ /*! - \qmlproperty OrientationReading OrientationSensor::reading + \qmlproperty OrientationReading QtMobility.sensors1::OrientationSensor::reading Holds the most recent orientation reading. Please see QSensor::reading for information about this property. */ /*! - \qmlsignal OrientationSensor::onReadingChanged() + \qmlsignal QtMobility.sensors1::OrientationSensor::onReadingChanged() Called when the reading object changes. Please see QSensor::readingChanged() for information about this signal. */ @@ -417,6 +428,7 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara /*! \qmlclass OrientationReading QOrientationReading \ingroup qml-sensors_reading + \inqmlmodule QtMobility.sensors 1 \inherits SensorReading \brief The OrientationReading element holds the most recent OrientationSensor reading. @@ -429,7 +441,7 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara */ /*! - \qmlproperty QOrientationReading::Orientation OrientationReading::orientation + \qmlproperty QOrientationReading::Orientation QtMobility.sensors1::OrientationReading::orientation Please see QOrientationReading::orientation for information about this property. Orientation constants are exposed through the OrientationReading class. @@ -446,6 +458,7 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara /*! \qmlclass ProximitySensor QProximitySensor \ingroup qml-sensors_type + \inqmlmodule QtMobility.sensors 1 \inherits Sensor \brief The ProximitySensor element reports on object proximity. @@ -458,13 +471,13 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara */ /*! - \qmlproperty ProximityReading ProximitySensor::reading + \qmlproperty ProximityReading QtMobility.sensors1::ProximitySensor::reading Holds the most recent proximity reading. Please see QSensor::reading for information about this property. */ /*! - \qmlsignal ProximitySensor::onReadingChanged() + \qmlsignal QtMobility.sensors1::ProximitySensor::onReadingChanged() Called when the reading object changes. Please see QSensor::readingChanged() for information about this signal. */ @@ -472,6 +485,7 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara /*! \qmlclass ProximityReading QProximityReading \ingroup qml-sensors_reading + \inqmlmodule QtMobility.sensors 1 \inherits SensorReading \brief The ProximityReading element holds the most recent ProximitySensor reading. @@ -484,13 +498,14 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara */ /*! - \qmlproperty bool ProximityReading::close + \qmlproperty bool QtMobility.sensors1::ProximityReading::close Please see QProximityReading::close for information about this property. */ /*! \qmlclass RotationSensor QRotationSensor \ingroup qml-sensors_type + \inqmlmodule QtMobility.sensors 1 \inherits Sensor \brief The RotationSensor element reports on device rotation around the X, Y and Z axes. @@ -505,13 +520,13 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara */ /*! - \qmlproperty RotationReading RotationSensor::reading + \qmlproperty RotationReading QtMobility.sensors1::RotationSensor::reading Holds the most recent rotation reading. Please see QSensor::reading for information about this property. */ /*! - \qmlsignal RotationSensor::onReadingChanged() + \qmlsignal QtMobility.sensors1::RotationSensor::onReadingChanged() Called when the reading object changes. Please see QSensor::readingChanged() for information about this signal. */ @@ -519,6 +534,7 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara /*! \qmlclass RotationReading QRotationReading \ingroup qml-sensors_reading + \inqmlmodule QtMobility.sensors 1 \inherits SensorReading \brief The RotationReading element holds the most recent RotationSensor reading. @@ -531,23 +547,24 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara */ /*! - \qmlproperty qreal RotationReading::x + \qmlproperty qreal QtMobility.sensors1::RotationReading::x Please see QRotationReading::x for information about this property. */ /*! - \qmlproperty qreal RotationReading::y + \qmlproperty qreal QtMobility.sensors1::RotationReading::y Please see QRotationReading::y for information about this property. */ /*! - \qmlproperty qreal RotationReading::z + \qmlproperty qreal QtMobility.sensors1::RotationReading::z Please see QRotationReading::z for information about this property. */ /*! \qmlclass TapSensor QTapSensor \ingroup qml-sensors_type + \inqmlmodule QtMobility.sensors 1 \inherits Sensor \brief The TapSensor element reports tap and double tap events along the X, Y and Z axes. @@ -562,13 +579,13 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara */ /*! - \qmlproperty TapReading TapSensor::reading + \qmlproperty TapReading QtMobility.sensors1::TapSensor::reading Holds the most recent tap sensor reading. Please see QSensor::reading for information about this property. */ /*! - \qmlsignal TapSensor::onReadingChanged() + \qmlsignal QtMobility.sensors1::TapSensor::onReadingChanged() Called when the reading object changes. Please see QSensor::readingChanged() for information about this signal. */ @@ -576,6 +593,7 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara /*! \qmlclass TapReading QTapReading \ingroup qml-sensors_reading + \inqmlmodule QtMobility.sensors 1 \inherits SensorReading \brief The TapReading element holds the most recent TapSensor reading. @@ -588,12 +606,12 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara */ /*! - \qmlproperty bool TapReading::doubleTap + \qmlproperty bool QtMobility.sensors1::TapReading::doubleTap Please see QTapReading::doubleTap for information about this property. */ /*! - \qmlproperty QTapReading::TapDirection TapReading::tapDirection + \qmlproperty QTapReading::TapDirection QtMobility.sensors1::TapReading::tapDirection Please see QTapReading::tapDirection for information about this property. TapDirection constants are exposed through the TapReading class. @@ -610,6 +628,7 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara /*! \qmlclass LightSensor QLightSensor \ingroup qml-sensors_type + \inqmlmodule QtMobility.sensors 1 \inherits Sensor \brief The LightSensor element reports on light levels using LUX. @@ -622,13 +641,13 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara */ /*! - \qmlproperty LightReading LightSensor::reading + \qmlproperty LightReading QtMobility.sensors1::LightSensor::reading Holds the most recent light sensor reading. Please see QSensor::reading for information about this property. */ /*! - \qmlsignal LightSensor::onReadingChanged() + \qmlsignal QtMobility.sensors1::LightSensor::onReadingChanged() Called when the reading object changes. Please see QSensor::readingChanged() for information about this signal. */ @@ -636,6 +655,7 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara /*! \qmlclass LightReading QLightReading \ingroup qml-sensors_reading + \inqmlmodule QtMobility.sensors 1 \inherits SensorReading \brief The LightReading element holds the most recent LightSensor reading. @@ -648,13 +668,14 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara */ /*! - \qmlproperty qreal LightReading::lux + \qmlproperty qreal QtMobility.sensors1::LightReading::lux Please see QLightReading::lux for information about this property. */ /*! \qmlclass Gyroscope QGyroscope \ingroup qml-sensors_type + \inqmlmodule QtMobility.sensors 1 \inherits Sensor \brief The Gyroscope element reports on rotational acceleration around the X, Y and Z axes. @@ -666,13 +687,13 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara */ /*! - \qmlproperty GyroscopeReading Gyroscope::reading + \qmlproperty GyroscopeReading QtMobility.sensors1::Gyroscope::reading Holds the most recent gyroscope reading. Please see QSensor::reading for information about this property. */ /*! - \qmlsignal Gyroscope::onReadingChanged() + \qmlsignal QtMobility.sensors1::Gyroscope::onReadingChanged() Called when the reading object changes. Please see QSensor::readingChanged() for information about this signal. */ @@ -680,6 +701,7 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara /*! \qmlclass GyroscopeReading QGyroscopeReading \ingroup qml-sensors_reading + \inqmlmodule QtMobility.sensors 1 \inherits SensorReading \brief The GyroscopeReading element holds the most recent Gyroscope reading. @@ -692,17 +714,17 @@ Q_EXPORT_PLUGIN2(qsensorsdeclarativemodule, QT_PREPEND_NAMESPACE(QSensorsDeclara */ /*! - \qmlproperty qreal GyroscopeReading::x + \qmlproperty qreal QtMobility.sensors1::GyroscopeReading::x Please see QGyroscopeReading::x for information about this property. */ /*! - \qmlproperty qreal GyroscopeReading::y + \qmlproperty qreal QtMobility.sensors1::GyroscopeReading::y Please see QGyroscopeReading::y for information about this property. */ /*! - \qmlproperty qreal GyroscopeReading::z + \qmlproperty qreal QtMobility.sensors1::GyroscopeReading::z Please see QGyroscopeReading::z for information about this property. */ diff --git a/src/imports/sensors2/qmldir b/src/imports/sensors2/qmldir new file mode 100644 index 00000000..14c82f3b --- /dev/null +++ b/src/imports/sensors2/qmldir @@ -0,0 +1 @@ +plugin declarative_qtsensors5 diff --git a/src/imports/sensors2/qsensor2ambientlight.cpp b/src/imports/sensors2/qsensor2ambientlight.cpp new file mode 100644 index 00000000..e2a99510 --- /dev/null +++ b/src/imports/sensors2/qsensor2ambientlight.cpp @@ -0,0 +1,149 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qsensor2ambientlight.h" +#include + +QT_BEGIN_NAMESPACE + +/*! + \qmlclass AmbientLightSensor QSensor2AmbientLight + \inqmlmodule QtSensors 5 + \ingroup qml-QtSensors5 + \since QtSensors 5.0 + \brief The AmbientLightSensor element provide an easy access to determine the ambient light by using the ambient light sensor. + + This element is part of the \bold{QtSensors 5} module. + + \target lightLevelenum + \section1 Enums + \section2 AmbientLightSensor::LighLevel + + This enum describes the ambient light levels. + + \table + \row + \o AmbientLightSensor::Undefined + \o Ambient light not defined. + \row + \o AmbientLightSensor::Dark + \o Ambient light is dark. + \row + \o AmbientLightSensor::Twilight + \o Ambient light is twilight. + \row + \o AmbientLightSensor::Light + \o Ambient light is light. + \row + \o AmbientLightSensor::Bright + \o Ambient light is bright. + \row + \o AmbientLightSensor::Sunny + \o Ambient light is sunny. + \endtable +*/ +QSensor2AmbientLight::QSensor2AmbientLight(QObject* parent) + : QObject(parent) + , _lightLevel(QSensor2AmbientLight::Undefined) +{ + _ambientLight = new QAmbientLightSensor(this); + _ambientLight->addFilter(this); +} + + +QSensor2AmbientLight::~QSensor2AmbientLight() +{ +} + +/*! + \qmlproperty bool QtSensors5::AmbientLightSensor::running + Holds the identication if the sensor runs or not. +*/ +/*! + \qmlsignal QtSensors5::AmbientLightSensor::onRunningChanged() + This signal is emitted whenever the value of the property running has been changed. +*/ +bool QSensor2AmbientLight::running() +{ + return _ambientLight->isActive(); +} + +void QSensor2AmbientLight::setRunning(bool val) +{ + bool active = running(); + if (active != val){ + if (val){ + bool ret = _ambientLight->start(); + if (!ret) + qWarning() << "couldn't start the sensor."; + } + else + _ambientLight->stop(); + emit runningChanged(); + } +} + +/*! + \qmlproperty AmbientLightSensor::LightLevel QtSensors5::AmbientLightSensor::lightLevel + Holds the ambient light level. + \sa {lightLevelenum} {AmbientLightSensor::LighLevel} +*/ +/*! + \qmlsignal QtSensors5::AmbientLightSensor::onLightLevelChanged() + This signal is emitted whenever the value of the property lightLevel has been changed. +*/ + +QSensor2AmbientLight::LightLevel QSensor2AmbientLight::lightLevel() +{ + return _lightLevel; +} + +bool QSensor2AmbientLight::filter(QAmbientLightReading *reading) +{ + QSensor2AmbientLight::LightLevel lv = (QSensor2AmbientLight::LightLevel)reading->lightLevel(); + if (lv != _lightLevel){ + _lightLevel = lv; + emit lightLevelChanged(); + } + return false; +} + +QT_END_NAMESPACE diff --git a/src/imports/sensors2/qsensor2ambientlight.h b/src/imports/sensors2/qsensor2ambientlight.h new file mode 100644 index 00000000..5b9a516a --- /dev/null +++ b/src/imports/sensors2/qsensor2ambientlight.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QSENSOR2AMBIENTLIGHT_H +#define QSENSOR2AMBIENTLIGHT_H + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QSensor2AmbientLight : public QObject, public QAmbientLightFilter +{ + Q_OBJECT + Q_ENUMS(LightLevel) + Q_PROPERTY(LightLevel lightLevel READ lightLevel NOTIFY lightLevelChanged) + Q_PROPERTY(bool running READ running WRITE setRunning NOTIFY runningChanged) + +public: + QSensor2AmbientLight(QObject* parent = 0); + virtual ~QSensor2AmbientLight(); + + enum LightLevel { + Undefined = 0, + Dark, + Twilight, + Light, + Bright, + Sunny + }; + +Q_SIGNALS: + void lightLevelChanged(); + void runningChanged(); + +private: + // Override of QAmbientLightFilter::filter(QAmbientLightReading*) + bool filter(QAmbientLightReading *reading); + LightLevel lightLevel(); + bool running(); + void setRunning(bool val); + + QAmbientLightSensor* _ambientLight; + LightLevel _lightLevel; +}; + +QML_DECLARE_TYPE(QT_PREPEND_NAMESPACE(QSensor2AmbientLight)) + +QT_END_NAMESPACE + + +#endif // QSENSOR2AMBIENTLIGHT_H diff --git a/src/imports/sensors2/qsensor2proximity.cpp b/src/imports/sensors2/qsensor2proximity.cpp new file mode 100644 index 00000000..3d49124c --- /dev/null +++ b/src/imports/sensors2/qsensor2proximity.cpp @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qsensor2proximity.h" +#include + +QT_BEGIN_NAMESPACE + +/*! + \qmlclass ProximitySensor QSensor2Proximity + \inqmlmodule QtSensors 5 + \ingroup qml-QtSensors5 + \since QtSensors 5.0 + \brief The ProximitySensor element provide an easy access to determine if the proximity of the mobile user by using the proximity sensor. + + This element is part of the \bold{QtSensors 5} module. +*/ + +QSensor2Proximity::QSensor2Proximity(QObject* parent) + : QObject(parent) + , _close(false) +{ + _proximity = new QProximitySensor(this); + _proximity->addFilter(this); +} + +QSensor2Proximity::~QSensor2Proximity() +{ +} + +/*! + \qmlproperty bool QtSensors5::ProximitySensor::running + Holds the identication if the sensor runs or not. +*/ +/*! + \qmlsignal QtSensors5::ProximitySensor::onRunningChanged() + This signal is emitted whenever the value of the property running has been changed. +*/ +bool QSensor2Proximity::running() +{ + return _proximity->isActive(); +} + +void QSensor2Proximity::setRunning(bool val) +{ + bool active = running(); + if (active != val){ + if (val){ + bool ret = _proximity->start(); + if (!ret) + qWarning() << "couldn't start the sensor."; + } + else + _proximity->stop(); + emit runningChanged(); + } +} + +/*! + \qmlproperty bool QtSensors5::ProximitySensor::close + Holds the proximity from the user to the device. +*/ +/*! + \qmlsignal QtSensors5::ProximitySensor::onCloseChanged() + This signal is emitted whenever the value of the close property has been changed. +*/ +bool QSensor2Proximity::close() +{ + return _close; +} + +bool QSensor2Proximity::filter(QProximityReading *reading) +{ + bool cl = reading->close(); + if (_close != cl){ + _close = cl; + emit closeChanged(); + } + + return false; +} + +QT_END_NAMESPACE diff --git a/src/imports/sensors2/qsensor2proximity.h b/src/imports/sensors2/qsensor2proximity.h new file mode 100644 index 00000000..d0de3fa2 --- /dev/null +++ b/src/imports/sensors2/qsensor2proximity.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QSENSOR2PROXIMITY_H +#define QSENSOR2PROXIMITY_H + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QSensor2Proximity : public QObject, public QProximityFilter +{ + Q_OBJECT + Q_PROPERTY(bool close READ close NOTIFY closeChanged) + Q_PROPERTY(bool running READ running WRITE setRunning NOTIFY runningChanged) + +public: + QSensor2Proximity(QObject* parent = 0); + virtual ~QSensor2Proximity(); + +Q_SIGNALS: + void closeChanged(); + void runningChanged(); + +private: + // Override of QProximityFilter::filter(QProximityReading*) + bool filter(QProximityReading *reading); + bool close(); + bool running(); + void setRunning(bool val); + +private: + QProximitySensor* _proximity; + bool _close; +}; + +QML_DECLARE_TYPE(QT_PREPEND_NAMESPACE(QSensor2Proximity)) + +QT_END_NAMESPACE + + +#endif // QSENSOR2PROXIMITY_H diff --git a/src/imports/sensors2/qsensor2tilt.cpp b/src/imports/sensors2/qsensor2tilt.cpp new file mode 100644 index 00000000..03251909 --- /dev/null +++ b/src/imports/sensors2/qsensor2tilt.cpp @@ -0,0 +1,365 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qsensor2tilt.h" +#include +#include +#include + +QT_BEGIN_NAMESPACE + +/*! + \qmlclass TiltSensor QSensor2Tilt + \inqmlmodule QtSensors 5 + \ingroup qml-QtSensors5 + \since QtSensors 5.0 + \brief The TiltSensor element provides tilt datas from x and y rotation of the device using the accelerometer sensor. + + This element is part of the \bold{QtSensors 5} module. + + \target tiltreferenceenum + \section1 Enums + \section2 TiltSensor::TiltReference + + This enum describes the orientation of the device. + + \table + \row + \o TiltSensor::TopUp + \o The top of the device points up + \o + \image TopUp.gif + \row + \o TiltSensor::TopDown + \o The top of the device points down + \o + \image TopDown.gif + \row + \o TiltSensor::LeftUp + \o The left site of the device points up + \o + \image LeftUp.gif + \row + \o TiltSensor::RightUp + \o The right site of the device points up + \o + \image RightUp.gif + \row + \o TiltSensor::FaceUp + \o The screen of the device points up + \o + \image FaceUp.gif + \row + \o TiltSensor::FaceDown + \o The screen of the device points down + \o + \image FaceDown.gif + \endtable + +*/ +QSensor2Tilt::QSensor2Tilt(QObject* parent) + : QObject(parent) + , _measureFrom(QSensor2Tilt::FaceUp) + , _yRotation(0) + , _xRotation(0) + , _useRadian(true) +{ + _accel = new QAccelerometer(this); + _accel->addFilter(this); +} + +QSensor2Tilt::~QSensor2Tilt() +{ +} + +/*! + \qmlproperty bool QtSensors5::TiltSensor::dataRate + Holds the data rate that the sensor should be run at. +*/ +/*! + \qmlsignal QtSensors5::TiltSensor::onDataRateChanged() + This signal is emitted whenever the value of the property dataRate has been changed. +*/ +int QSensor2Tilt::dataRate() +{ + return _accel->dataRate(); +} + +void QSensor2Tilt::setDataRate(int val) +{ + if (val != dataRate()){ + _accel->setDataRate(val); + emit dataRateChanged(); + } +} + +/*! + \qmlproperty bool QtSensors5::TiltSensor::running + Holds the identication if the sensor runs or not. +*/ +/*! + \qmlsignal QtSensors5::TiltSensor::onRunningChanged() + This signal is emitted whenever the value of the property running has been changed. +*/ +bool QSensor2Tilt::running() +{ + return _accel->isActive(); +} + +void QSensor2Tilt::setRunning(bool val) +{ + bool active = running(); + if (active != val){ + if (val){ + bool ret = _accel->start(); + if (!ret) + qWarning() << "couldn't start the sensor."; + } + else + _accel->stop(); + emit runningChanged(); + } +} + +/*! + \qmlproperty QSensor2Tilt::TiltReference QtSensors5::TiltSensor::measureFrom + Holds the orientation in which the rotation should be calculated. + \sa {tiltreferenceenum} {TiltReference::TiltReference} +*/ +/*! + \qmlsignal QtSensors5::TiltSensor::onMeasureFromChanged() + This signal is emitted whenever the value of the property measureFrom has been changed. +*/ +QSensor2Tilt::TiltReference QSensor2Tilt::measureFrom() +{ + return _measureFrom; +} + +void QSensor2Tilt::setMeasureFrom(QSensor2Tilt::TiltReference val) +{ + if (val != _measureFrom){ + _measureFrom = val; + emit measureFromChanged(); + } +} + +/*! + \qmlproperty bool QtSensors5::TiltSensor::radian + Holds the unit of the rotation. True is rad otherwise deg. true = report values in radians. false = report values in degrees. +*/ +bool QSensor2Tilt::radian() +{ + return _useRadian; +} + +void QSensor2Tilt::setRadian(bool val) +{ + _useRadian = val; +} + + +/*! + \qmlproperty float QtSensors5::TiltSensor::yRotation + Holds the rotation arround the y axis. + + \table + \row + \o + \image YAngle.gif + \o + \image YAngleNegative.gif + \endtable +*/ +/*! + \qmlsignal QtSensors5::TiltSensor::onYRotationChanged() + This signal is emitted whenever the value of the property yRotation has been changed. +*/ +float QSensor2Tilt::yRotation() +{ + return _yRotation; +} + +/*! + \qmlproperty float QtSensors5::TiltSensor::xRotation + Holds the rotation arround the x axis. + \table + \row + \o + \image XAngle.gif + \o + \image XAngleNegative.gif + \endtable +*/ +/*! + \qmlsignal QtSensors5::TiltSensor::onXRotationChanged() + This signal is emitted whenever the value of the property XRotation has been changed. +*/ +float QSensor2Tilt::xRotation() +{ + return _xRotation; +} + +/* + Angle between Ground and X + | Ax | + pitch = arctan| ----------------------- | + | sqrt(Ay * Ay + Az * Az)| +*/ +inline float calcPitch(double Ax, double Ay, double Az) +{ + errno = 0; + float ret = (float)-atan(Ax / (sqrt(Ay * Ay + Az * Az))); + if (errno == EDOM){ + ret = 0.0; + errno = 0; + } + return ret; +} + +/* + Angle between Ground and Y + | Ay | + pitch = arctan| ----------------------- | + | sqrt(Ax * Ax + Az * Az)| +*/ +inline float calcRoll(double Ax, double Ay, double Az) +{ + errno = 0; + float ret = (float)atan(Ay / (sqrt(Ax * Ax + Az * Az))); + if (errno == EDOM){ + ret = 0.0; + errno = 0; + } + return ret; +} + +bool QSensor2Tilt::filter(QAccelerometerReading* reading) +{ + /* + z y + | / + |/___ x + */ + + int x = reading->x(); + int y = reading->y(); + int z = reading->z(); + float xrot = 0; + float yrot = 0; + + switch (_measureFrom) + { + case QSensor2Tilt::FaceUp: + /* + y + | => Ax = x, Ay = y, Az = z + |___ x + */ + yrot = calcPitch(x, y, z); + xrot = calcRoll(x, y, z); + break; + case QSensor2Tilt::LeftUp: + /* + z + | => Ax = y, Ay = z, Az = x + |___ y + */ + yrot = calcPitch(y, z, x); + xrot = -calcRoll(y, z, x); + break; + case QSensor2Tilt::TopDown: + /* + z + | => Ax = -x, Ay = z, Az = y + |___ -x + */ + yrot = -calcPitch(x, z, y); + xrot = -calcRoll(x, z, y); + break; + case QSensor2Tilt::FaceDown: + /* + -y + | => Ax = x, Ay = -y, Az = -z + |___ x + */ + yrot = calcPitch(-x, -y, z); + xrot = -calcRoll(-x, -y, z); + break; + case QSensor2Tilt::RightUp: + /* + z + | => Ax = -y, Ay = z, Az = -x + |___ -y + */ + yrot = calcPitch(-y, z, -x); + xrot = -calcRoll(-y, z, -x); + break; + case QSensor2Tilt::TopUp: + /* + z + | => Ax = x, Ay = z, Az = -y + |___ x + */ + yrot = calcPitch(x, z, -y); + xrot = -calcRoll(x, z, -y); + break; + } + + + + if (!_useRadian){ + yrot = 180 * yrot / M_PI; + xrot = 180 * xrot / M_PI; + } + + if (xrot != _xRotation){ + _xRotation = xrot; + emit xRotationChanged(); + } + if (yrot != _yRotation){ + _yRotation = yrot; + emit yRotationChanged(); + } + + return false; +} + +QT_END_NAMESPACE diff --git a/src/imports/sensors2/qsensor2tilt.h b/src/imports/sensors2/qsensor2tilt.h new file mode 100644 index 00000000..23f27271 --- /dev/null +++ b/src/imports/sensors2/qsensor2tilt.h @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QSEONSOR2TILT_H +#define QSEONSOR2TILT_H + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QSensor2Tilt : public QObject, public QAccelerometerFilter +{ + Q_OBJECT + Q_ENUMS(TiltReference) + Q_PROPERTY(TiltReference measureFrom READ measureFrom WRITE setMeasureFrom NOTIFY measureFromChanged) + Q_PROPERTY(float yRotation READ yRotation NOTIFY yRotationChanged) + Q_PROPERTY(float xRotation READ xRotation NOTIFY xRotationChanged) + Q_PROPERTY(bool radian READ radian WRITE setRadian) + Q_PROPERTY(int dataRate READ dataRate WRITE setDataRate NOTIFY dataRateChanged) + Q_PROPERTY(bool running READ running WRITE setRunning NOTIFY runningChanged) + +public: + QSensor2Tilt(QObject* parent = 0); + virtual ~QSensor2Tilt(); + + enum TiltReference{ + TopUp = 0, + TopDown, + LeftUp, + RightUp, + FaceUp, + FaceDown + }; + +Q_SIGNALS: + void measureFromChanged(); + void yRotationChanged(); + void xRotationChanged(); + void dataRateChanged(); + void runningChanged(); + +private: + // Override of QAcclerometerFilter::filter(QAccelerometerReading*) + bool filter(QAccelerometerReading* reading); + + TiltReference measureFrom(); + void setMeasureFrom(TiltReference val); + float yRotation(); + float xRotation(); + bool radian(); + void setRadian(bool val); + int dataRate(); + void setDataRate(int val); + bool running(); + void setRunning(bool val); + + QAccelerometer* _accel; + TiltReference _measureFrom; + float _yRotation; + float _xRotation; + bool _useRadian; + bool _init; +}; + +QML_DECLARE_TYPE(QT_PREPEND_NAMESPACE(QSensor2Tilt)) + +QT_END_NAMESPACE + +#endif // QSEONSOR2TILT_H diff --git a/src/imports/sensors2/qsensors2import.pri b/src/imports/sensors2/qsensors2import.pri new file mode 100644 index 00000000..d5cfeffc --- /dev/null +++ b/src/imports/sensors2/qsensors2import.pri @@ -0,0 +1,38 @@ +load(qt_module) + +symbian:load(qt_plugin) +TEMPLATE = lib +CONFIG += qt plugin + +win32|mac:!wince*:!win32-msvc:!macx-xcode:CONFIG += debug_and_release + +isEmpty(TARGETPATH) { + error("qimportbase.pri: You must provide a TARGETPATH!") +} +isEmpty(TARGET) { + error("qimportbase.pri: You must provide a TARGET!") +} + +QMLDIRFILE = $${_PRO_FILE_PWD_}/qmldir +copy2build.input = QMLDIRFILE +copy2build.output = $$QT.sensors.imports/$$TARGETPATH/qmldir +!contains(TEMPLATE_PREFIX, vc):copy2build.variable_out = PRE_TARGETDEPS +copy2build.commands = $$QMAKE_COPY ${QMAKE_FILE_IN} ${QMAKE_FILE_OUT} +copy2build.name = COPY ${QMAKE_FILE_IN} +copy2build.CONFIG += no_link +# `clean' should leave the build in a runnable state, which means it shouldn't delete qmldir +copy2build.CONFIG += no_clean +QMAKE_EXTRA_COMPILERS += copy2build + +TARGET = $$qtLibraryTarget($$TARGET) +contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols + +load(qt_targets) + +wince*:LIBS += $$QMAKE_LIBS_GUI + +symbian: { + TARGET.EPOCALLOWDLLDATA=1 + TARGET.CAPABILITY = All -Tcb + load(armcc_warnings) +} diff --git a/src/imports/sensors2/sensors2.cpp b/src/imports/sensors2/sensors2.cpp new file mode 100644 index 00000000..9d79863d --- /dev/null +++ b/src/imports/sensors2/sensors2.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include "qsensor2ambientlight.h" +#include "qsensor2proximity.h" +#include "qsensor2tilt.h" +#include + +QT_BEGIN_NAMESPACE + +class QSensors2DeclarativeModule : public QDeclarativeExtensionPlugin +{ + Q_OBJECT +public: + virtual void registerTypes(const char *uri) + { + qDebug() << "QSensors2DeclarativeModule::registerTypes(const char *uri)"; + + Q_ASSERT(QLatin1String(uri) == QLatin1String("Qt.QtSensors")); + qmlRegisterType(uri, 5, 0, "TiltSensor"); + qmlRegisterType(uri, 5, 0, "AmbientLightSensor"); + qmlRegisterType(uri, 5, 0, "ProximitySensor"); + } +}; + +QT_END_NAMESPACE + +#include "sensors2.moc" + +Q_EXPORT_PLUGIN2(qsensors2declarativemodule, QT_PREPEND_NAMESPACE(QSensors2DeclarativeModule)) + + diff --git a/src/imports/sensors2/sensors2.pro b/src/imports/sensors2/sensors2.pro new file mode 100644 index 00000000..a80446b3 --- /dev/null +++ b/src/imports/sensors2/sensors2.pro @@ -0,0 +1,39 @@ +TARGET = declarative_qtsensors5 +TARGETPATH = Qt/QtSensors + +include(qsensors2import.pri) + +QT += declarative sensors + +load(qt_plugin) + +SOURCES += sensors2.cpp \ + qsensor2ambientlight.cpp \ + qsensor2proximity.cpp \ + qsensor2tilt.cpp + +HEADERS += qsensor2ambientlight.h \ + qsensor2proximity.h \ + qsensor2tilt.h + +DESTDIR = $$QT.sensors.imports/$$TARGETPATH +target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH + +qmldir.files += $$PWD/qmldir +qmldir.path += $$[QT_INSTALL_IMPORTS]/$$TARGETPATH + +INSTALLS += target qmldir + +symbian { + # In Symbian, a library should enjoy _largest_ possible capability set. + TARGET.CAPABILITY = ALL -TCB + # Allow writable DLL data + TARGET.EPOCALLOWDLLDATA = 1 + # Target UID, makes every Symbian app unique + TARGET.UID3 = 0x20021324 + # Specifies what files shall be deployed: the plugin itself and the qmldir file. + importFiles.sources = $$DESTDIR/declarative_sensors$${QT_LIBINFIX}.dll qmldir + importFiles.path = $$QT_IMPORTS_BASE_DIR/$$TARGETPATH + DEPLOYMENT = importFiles + } + diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index b303c70b..ce22928f 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -1,4 +1,4 @@ TEMPLATE = subdirs SUBDIRS += qsensor - +SUBDIRS += sensors2qmlapi diff --git a/tests/auto/sensors2qmlapi/qbackends.h b/tests/auto/sensors2qmlapi/qbackends.h new file mode 100644 index 00000000..01bfa36a --- /dev/null +++ b/tests/auto/sensors2qmlapi/qbackends.h @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef BACKENDS_H +#define BACKENDS_H + +#include "qdeclaccelerometer.h" +#include "qdeclambientlightsensor.h" +#include "qdeclproximitysensor.h" +#include +#include + + +class TestSensorPlugin : public QObject, + public QSensorPluginInterface, + public QSensorChangesInterface, + public QSensorBackendFactory +{ + Q_OBJECT + Q_INTERFACES(QSensorPluginInterface QSensorChangesInterface) +public: + void registerSensors() + { + QSensorManager::registerBackend("QAccelerometer", "QAccelerometer", this); + QSensorManager::registerBackend("QAmbientLightSensor", "QAmbientLightSensor", this); + QSensorManager::registerBackend("QProximitySensor", "QProximitySensor", this); + } + + void sensorsChanged() + { + } + + QSensorBackend *createBackend(QSensor *sensor) + { + if (sensor->identifier() == "QAccelerometer") { + if (TestSensorPlugin::stAccel != 0) + return TestSensorPlugin::stAccel; + else + TestSensorPlugin::stAccel = new QDeclAccelerometer(sensor); + return createBackend(sensor); + } + else if (sensor->identifier() == "QAmbientLightSensor") { + if (TestSensorPlugin::stAbl != 0) + return TestSensorPlugin::stAbl; + else + TestSensorPlugin::stAbl = new QDeclAmbientLightSensor(sensor); + return createBackend(sensor); + } + else if (sensor->identifier() == "QProximitySensor") { + if (TestSensorPlugin::stProxi != 0) + return TestSensorPlugin::stProxi; + else + TestSensorPlugin::stProxi = new QDeclProximitySensor(sensor); + return createBackend(sensor); + } + + qWarning() << "Can't create backend" << sensor->identifier(); + return 0; + } +public: + static QDeclAccelerometer* stAccel; + static QDeclAmbientLightSensor* stAbl; + static QDeclProximitySensor* stProxi; +}; + +#endif + diff --git a/tests/auto/sensors2qmlapi/qdeclaccelerometer.h b/tests/auto/sensors2qmlapi/qdeclaccelerometer.h new file mode 100644 index 00000000..5842e01f --- /dev/null +++ b/tests/auto/sensors2qmlapi/qdeclaccelerometer.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLACCELEROMETER_H +#define QDECLACCELEROMETER_H + +#include +#include "qaccelerometer.h" + +class QDeclAccelerometer : public QSensorBackend +{ + Q_OBJECT +public: + explicit QDeclAccelerometer(QSensor *sensor) + : QSensorBackend(sensor) + , _active(false) + , _sensor(sensor) + { + } + virtual ~QDeclAccelerometer() {} + + void start() { _active = true; } + void stop() { _active = false; } + bool isActive() { return _active; } + + void test(int x, int y, int z) + { + if (sensor()->filters().count() > 0){ + QAccelerometerFilter* af = (QAccelerometerFilter*)sensor()->filters().at(0); + reader.setX((qreal)x); + reader.setY((qreal)y); + reader.setZ((qreal)z); + af->filter(&reader); + } + } +private: + bool _active; + QSensor* _sensor; + QAccelerometerReading reader; +}; +#endif + diff --git a/tests/auto/sensors2qmlapi/qdeclambientlightsensor.h b/tests/auto/sensors2qmlapi/qdeclambientlightsensor.h new file mode 100644 index 00000000..603ff1fb --- /dev/null +++ b/tests/auto/sensors2qmlapi/qdeclambientlightsensor.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLAMBIENTLIGHTSENSOR_H +#define QDECLAMBIENTLIGHTSENSOR_H + +#include +#include "./../../../src/imports/sensors2/qsensor2ambientlight.h" + +class QDeclAmbientLightSensor : public QSensorBackend +{ + Q_OBJECT +public: + explicit QDeclAmbientLightSensor(QSensor *sensor) + : QSensorBackend(sensor) + , _active(false) + , _sensor(sensor) + { + } + virtual ~QDeclAmbientLightSensor() {} + + void start() { _active = true; } + void stop() { _active = false; } + bool isActive() { return _active; } + + void test(QSensor2AmbientLight::LightLevel lv) + { + if (sensor()->filters().count() > 0){ + QAmbientLightFilter* af = (QAmbientLightFilter*)sensor()->filters().at(0); + reader.setLightLevel((QAmbientLightReading::LightLevel)lv); + af->filter(&reader); + } + } +private: + bool _active; + QSensor* _sensor; + QAmbientLightReading reader; +}; + +#endif + diff --git a/tests/auto/sensors2qmlapi/qdeclproximitysensor.h b/tests/auto/sensors2qmlapi/qdeclproximitysensor.h new file mode 100644 index 00000000..987a177d --- /dev/null +++ b/tests/auto/sensors2qmlapi/qdeclproximitysensor.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLPROXIMITYSENSOR_H +#define QDECLPROXIMITYSENSOR_H + +#include +#include "qproximitysensor.h" + +class QDeclProximitySensor : public QSensorBackend +{ + Q_OBJECT +public: + explicit QDeclProximitySensor(QSensor *sensor) + : QSensorBackend(sensor) + , _active(false) + , _sensor(sensor) + { + } + virtual ~QDeclProximitySensor() {} + + void start() { _active = true; } + void stop() { _active = false; } + bool isActive() { return _active; } + + void test(bool val) + { + if (sensor()->filters().count() > 0){ + QProximityFilter* af = (QProximityFilter*)sensor()->filters().at(0); + reader.setClose(val); + af->filter(&reader); + } + } +private: + bool _active; + QSensor* _sensor; + QProximityReading reader; +}; +#endif + diff --git a/tests/auto/sensors2qmlapi/sensors2qmlapi.pro b/tests/auto/sensors2qmlapi/sensors2qmlapi.pro new file mode 100644 index 00000000..acd8951b --- /dev/null +++ b/tests/auto/sensors2qmlapi/sensors2qmlapi.pro @@ -0,0 +1,20 @@ +TEMPLATE = app +TARGET = tst_sensors2qmlapi + +CONFIG += testcase +QT = core testlib sensors-private declarative +INCLUDEPATH += ./ +DEPENDPATH += ./ + +SOURCES += tst_sensors2qmlapi.cpp \ + ./../../../src/imports/sensors2/qsensor2ambientlight.cpp \ + ./../../../src/imports/sensors2/qsensor2proximity.cpp \ + ./../../../src/imports/sensors2/qsensor2tilt.cpp + +HEADERS += qdeclaccelerometer.h \ + qdeclambientlightsensor.h \ + qdeclproximitysensor.h \ + qbackends.h \ + ./../../../src/imports/sensors2/qsensor2ambientlight.h \ + ./../../../src/imports/sensors2/qsensor2proximity.h \ + ./../../../src/imports/sensors2/qsensor2tilt.h diff --git a/tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp b/tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp new file mode 100644 index 00000000..a80b7263 --- /dev/null +++ b/tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp @@ -0,0 +1,270 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtSensors middleware. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include "../../../src/imports/sensors2/qsensor2ambientlight.h" +#include "../../../src/imports/sensors2/qsensor2proximity.h" +#include "../../../src/imports/sensors2/qsensor2tilt.h" +#include "qbackends.h" +#include "qsensormanager.h" + +QT_USE_NAMESPACE +QDeclAccelerometer* TestSensorPlugin::stAccel = 0; +QDeclAmbientLightSensor* TestSensorPlugin::stAbl = 0; +QDeclProximitySensor* TestSensorPlugin::stProxi = 0; + +Q_SENSORS_EXPORT void sensors_unit_test_hook(int index); + +class tst_Sensors2QMLAPI : public QObject +{ + Q_OBJECT + +private slots: + void initTestCase(); + void testTilt_data(); + void testTilt(); + void testTilt_receivedSignalsCount(); + void testProximity(); + void testAmbientLight(); + +protected: + TestSensorPlugin _plugin; + QSensor2Tilt* _tilt; +}; + +void tst_Sensors2QMLAPI::initTestCase() +{ + sensors_unit_test_hook(0); // change some flags the library uses + _plugin.registerSensors(); + _tilt = 0; +} + +void tst_Sensors2QMLAPI::testProximity() +{ + QSensor2Proximity prox; + QSignalSpy spy(&prox, SIGNAL(runningChanged())); + prox.setProperty("running", QVariant(true)); + QCOMPARE(spy.count() , 1); + + spy.clear(); + prox.setProperty("running", QVariant(true)); + QCOMPARE(spy.count() , 0); + + TestSensorPlugin plugin; + QDeclProximitySensor* proxi = plugin.stProxi; + + qDebug() << "Check close = true"; + proxi->test(true); + QVERIFY((bool)prox.property("close").toBool() == true); + + qDebug() << "Check close = false"; + QSignalSpy spy1(&prox, SIGNAL(closeChanged())); + proxi->test(false); + QCOMPARE(spy1.count() , 1); + QVERIFY((bool)prox.property("close").toBool() == false); + + spy1.clear(); + proxi->test(false); + QCOMPARE(spy1.count() , 0); + prox.setProperty("running", QVariant(false)); +} + +void tst_Sensors2QMLAPI::testAmbientLight() +{ + QSensor2AmbientLight als; + QSignalSpy spy(&als, SIGNAL(runningChanged())); + als.setProperty("running", QVariant(true)); + QCOMPARE(spy.count() , 1); + + spy.clear(); + als.setProperty("running", QVariant(true)); + QCOMPARE(spy.count() , 0); + + TestSensorPlugin plugin; + QDeclAmbientLightSensor* abl = plugin.stAbl; + + for (int en = 5; en >= 0; en--){ + QString enumname = ""; + switch (en) + { + case 0: enumname = "Undefined"; break; + case 1: enumname = "Dark"; break; + case 2: enumname = "Twilight"; break; + case 3: enumname = "Light"; break; + case 4: enumname = "Bright"; break; + case 5: enumname = "Sunny"; break; + } + qDebug() << "Check " << enumname; + QSignalSpy spy1(&als, SIGNAL(lightLevelChanged())); + abl->test((QSensor2AmbientLight::LightLevel)en); + QCOMPARE(spy1.count() , 1); + QVERIFY((int)als.property("lightLevel").toInt() == en); + + spy1.clear(); + abl->test((QSensor2AmbientLight::LightLevel)en); + QCOMPARE(spy1.count() , 0); + } + als.setProperty("running", QVariant(false)); +} + +void tst_Sensors2QMLAPI::testTilt_data() +{ + QTest::addColumn("pos"); + QTest::addColumn("x"); + QTest::addColumn("y"); + QTest::addColumn("z"); + QTest::addColumn("xRotation"); + QTest::addColumn("yRotation"); + + QTest::newRow("TopUp001") << (int)QSensor2Tilt::TopUp << 0 << 0 << 1 << -90 << 0; + QTest::newRow("TopDown001") << (int)QSensor2Tilt::TopDown << 0 << 0 << 1 << -90 << 0; + QTest::newRow("LeftUp001") << (int)QSensor2Tilt::LeftUp << 0 << 0 << 1 << -90 << 0; + QTest::newRow("RightUp001") << (int)QSensor2Tilt::RightUp << 0 << 0 << 1 << -90 << 0; + QTest::newRow("FaceUp001") << (int)QSensor2Tilt::FaceUp << 0 << 0 << 1 << 0 << 0; + QTest::newRow("FaceDown001") << (int)QSensor2Tilt::FaceDown << 0 << 0 << 1 << 0 << 0; + + QTest::newRow("TopUp010") << (int)QSensor2Tilt::TopUp << 0 << 1 << 0 << 0 << 0; + QTest::newRow("TopDown010") << (int)QSensor2Tilt::TopDown << 0 << 1 << 0 << 0 << 0; + QTest::newRow("LeftUp010") << (int)QSensor2Tilt::LeftUp << 0 << 1 << 0 << 0 << -90; + QTest::newRow("RightUp010") << (int)QSensor2Tilt::RightUp << 0 << 1 << 0 << 0 << 90; + QTest::newRow("FaceUp010") << (int)QSensor2Tilt::FaceUp << 0 << 1 << 0 << 90 << 0; + QTest::newRow("FaceDown010") << (int)QSensor2Tilt::FaceDown << 0 << 1 << 0 << 90 << 0; + + QTest::newRow("TopUp100") << (int)QSensor2Tilt::TopUp << 1 << 0 << 0 << 0 << -90; + QTest::newRow("TopDown100") << (int)QSensor2Tilt::TopDown << 1 << 0 << 0 << 0 << 90; + QTest::newRow("LeftUp100") << (int)QSensor2Tilt::LeftUp << 1 << 0 << 0 << 0 << 0; + QTest::newRow("RightUp100") << (int)QSensor2Tilt::RightUp << 1 << 0 << 0 << 0 << 0; + QTest::newRow("FaceUp100") << (int)QSensor2Tilt::FaceUp << 1 << 0 << 0 << 0 << -90; + QTest::newRow("FaceDown100") << (int)QSensor2Tilt::FaceDown << 1 << 0 << 0 << 0 << 90; + + QTest::newRow("TopUp101") << (int)QSensor2Tilt::TopUp << 1 << 0 << 1 << -45 << -45; + QTest::newRow("TopDown101") << (int)QSensor2Tilt::TopDown << 1 << 0 << 1 << -45 << 45; + QTest::newRow("LeftUp101") << (int)QSensor2Tilt::LeftUp << 1 << 0 << 1 << -45 << 0; + QTest::newRow("RightUp101") << (int)QSensor2Tilt::RightUp << 1 << 0 << 1 << -45 << 0; + QTest::newRow("FaceUp101") << (int)QSensor2Tilt::FaceUp << 1 << 0 << 1 << 0 << -45; + QTest::newRow("FaceDown101") << (int)QSensor2Tilt::FaceDown << 1 << 0 << 1 << 0 << 45; + + QTest::newRow("TopUp110") << (int)QSensor2Tilt::TopUp << 1 << 1 << 0 << 0 << -45; + QTest::newRow("TopDown110") << (int)QSensor2Tilt::TopDown << 1 << 1 << 0 << 0 << 45; + QTest::newRow("LeftUp110") << (int)QSensor2Tilt::LeftUp << 1 << 1 << 0 << 0 << -45; + QTest::newRow("RightUp110") << (int)QSensor2Tilt::RightUp << 1 << 1 << 0 << 0 << 45; + QTest::newRow("FaceUp110") << (int)QSensor2Tilt::FaceUp << 1 << 1 << 0 << 45 << -45; + QTest::newRow("FaceDown110") << (int)QSensor2Tilt::FaceDown << 1 << 1 << 0 << 45 << 45; + + QTest::newRow("TopUp011") << (int)QSensor2Tilt::TopUp << 0 << 1 << 1 << -45 << 0; + QTest::newRow("TopDown011") << (int)QSensor2Tilt::TopDown << 0 << 1 << 1 << -45 << 0; + QTest::newRow("LeftUp011") << (int)QSensor2Tilt::LeftUp << 0 << 1 << 1 << -45 << -45; + QTest::newRow("RightUp011") << (int)QSensor2Tilt::RightUp << 0 << 1 << 1 << -45 << 45; + QTest::newRow("FaceUp011") << (int)QSensor2Tilt::FaceUp << 0 << 1 << 1 << 45 << 0; + QTest::newRow("FaceDown011") << (int)QSensor2Tilt::FaceDown << 0 << 1 << 1 << 45 << 0; +} + +int xrotch = 0; +int yrotch = 0; +int datarate = 10; +void tst_Sensors2QMLAPI::testTilt() +{ + QFETCH(int, pos); + QFETCH(int, x); + QFETCH(int, y); + QFETCH(int, z); + QFETCH(int, xRotation); + QFETCH(int, yRotation); + + qDebug() << "check pos: " << pos << " x: " << x << " y: " << y << " z: " << z << " xRot: " << xRotation << " yRot: " << yRotation; + + if (!_tilt) + _tilt = new QSensor2Tilt(this); + + QSignalSpy spy(_tilt, SIGNAL(runningChanged())); + _tilt->setProperty("running", QVariant(true)); + QCOMPARE(spy.count() , 1); + + spy.clear(); + _tilt->setProperty("running", QVariant(true)); + QCOMPARE(spy.count() , 0); + + _tilt->setProperty("radian", QVariant(false)); + + QSignalSpy spymf(_tilt, SIGNAL(measureFromChanged())); + _tilt->setProperty("measureFrom", QVariant(pos)); + QVERIFY((int)_tilt->property("measureFrom").toInt() == pos); + QCOMPARE(spymf.count() , 1); + spymf.clear(); + _tilt->setProperty("measureFrom", QVariant(pos)); + QCOMPARE(spymf.count() , 0); + + QDeclAccelerometer* accel = _plugin.stAccel; + + QSignalSpy spyxrot(_tilt, SIGNAL(xRotationChanged())); + QSignalSpy spyyrot(_tilt, SIGNAL(yRotationChanged())); + accel->test(x,y,z); + xrotch += spyxrot.count(); + yrotch += spyyrot.count(); + + QCOMPARE(xRotation, (int)_tilt->property("xRotation").toFloat()); + QCOMPARE(yRotation, (int)_tilt->property("yRotation").toFloat()); + + spy.clear(); + _tilt->setProperty("running", QVariant(false)); + QCOMPARE(spy.count() , 1); + spy.clear(); + _tilt->setProperty("running", QVariant(false)); + QCOMPARE(spy.count() , 0); + + datarate++; + QSignalSpy spydr(_tilt, SIGNAL(dataRateChanged())); + _tilt->setProperty("dataRate", QVariant(datarate)); + QCOMPARE(spydr.count() , 1); +} + +void tst_Sensors2QMLAPI::testTilt_receivedSignalsCount() +{ + qDebug() << "Check xRotation changed: " << xrotch; + QCOMPARE(xrotch , 9); + qDebug() << "Check yRotation changed: " << yrotch; + QCOMPARE(yrotch , 23); +} + +QTEST_MAIN(tst_Sensors2QMLAPI) +#include "tst_sensors2qmlapi.moc" -- cgit v1.2.3