summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore263
-rw-r--r--modules/qt_sensors.pri17
-rw-r--r--qtsensors.pro5
-rwxr-xr-xsrc/sensors/make_sensor.pl287
-rw-r--r--src/sensors/qaccelerometer.cpp194
-rw-r--r--src/sensors/qaccelerometer.h90
-rw-r--r--src/sensors/qaccelerometer_p.h76
-rw-r--r--src/sensors/qambientlightsensor.cpp170
-rw-r--r--src/sensors/qambientlightsensor.h92
-rw-r--r--src/sensors/qambientlightsensor_p.h72
-rw-r--r--src/sensors/qcompass.cpp180
-rw-r--r--src/sensors/qcompass.h86
-rw-r--r--src/sensors/qcompass_p.h74
-rw-r--r--src/sensors/qgyroscope.cpp192
-rw-r--r--src/sensors/qgyroscope.h90
-rw-r--r--src/sensors/qgyroscope_p.h76
-rw-r--r--src/sensors/qlightsensor.cpp152
-rw-r--r--src/sensors/qlightsensor.h85
-rw-r--r--src/sensors/qlightsensor_p.h74
-rw-r--r--src/sensors/qmagnetometer.cpp243
-rw-r--r--src/sensors/qmagnetometer.h97
-rw-r--r--src/sensors/qmagnetometer_p.h78
-rw-r--r--src/sensors/qmobilitypluginsearch.h172
-rw-r--r--src/sensors/qorientationsensor.cpp193
-rw-r--r--src/sensors/qorientationsensor.h93
-rw-r--r--src/sensors/qorientationsensor_p.h72
-rw-r--r--src/sensors/qproximitysensor.cpp149
-rw-r--r--src/sensors/qproximitysensor.h82
-rw-r--r--src/sensors/qproximitysensor_p.h72
-rw-r--r--src/sensors/qrotationsensor.cpp238
-rw-r--r--src/sensors/qrotationsensor.h93
-rw-r--r--src/sensors/qrotationsensor_p.h76
-rw-r--r--src/sensors/qsensor.cpp982
-rw-r--r--src/sensors/qsensor.h251
-rw-r--r--src/sensors/qsensor_p.h119
-rw-r--r--src/sensors/qsensorbackend.cpp326
-rw-r--r--src/sensors/qsensorbackend.h94
-rw-r--r--src/sensors/qsensormanager.cpp498
-rw-r--r--src/sensors/qsensormanager.h108
-rw-r--r--src/sensors/qsensorplugin.cpp98
-rw-r--r--src/sensors/qsensorplugin.h73
-rw-r--r--src/sensors/qsensorpluginloader.cpp102
-rw-r--r--src/sensors/qsensorpluginloader_p.h81
-rw-r--r--src/sensors/qtapsensor.cpp247
-rw-r--r--src/sensors/qtapsensor.h106
-rw-r--r--src/sensors/qtapsensor_p.h74
-rw-r--r--src/sensors/sensorlog_p.h83
-rw-r--r--src/sensors/sensors.pro77
-rw-r--r--src/src.pro3
-rw-r--r--sync.profile26
50 files changed, 7281 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..33334ca
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,263 @@
+# This file is used to ignore files which are generated in the Qt build system
+# ----------------------------------------------------------------------------
+
+examples/*/*/*
+!examples/*/*/*[.]*
+!examples/*/*/README
+examples/*/*/*[.]app
+!examples/declarative/*
+!examples/tutorials/*
+!examples/tutorials/*/*
+!examples/ja_JP/*/*
+demos/*/*
+!demos/spectrum/*
+demos/spectrum/bin
+!demos/*/*[.]*
+demos/*/*[.]app
+!demos/declarative/*
+config.tests/*/*/*
+!config.tests/*/*/*[.]*
+config.tests/*/*/*[.]app
+
+callgrind.out.*
+pcviewer.cfg
+*~
+*.a
+*.la
+*.core
+*.moc
+*.o
+*.obj
+*.orig
+*.swp
+*.rej
+*.so
+*.pbxuser
+*.mode1
+*.mode1v3
+*_pch.h.cpp
+*_resource.rc
+.#*
+*.*#
+core
+.qmake.cache
+.qmake.vars
+*.prl
+tags
+.DS_Store
+*.debug
+Makefile*
+!qmake/Makefile.win32*
+!qmake/Makefile.unix
+*.prl
+*.app
+*.pro.user
+*.qmlproject.user
+*.gcov
+bin/Qt*.dll
+bin/assistant*
+bin/designer*
+bin/dumpcpp*
+bin/idc*
+bin/linguist*
+bin/lrelease*
+bin/lupdate*
+bin/lconvert*
+bin/moc*
+bin/makeqpf*
+bin/pixeltool*
+bin/qmake*
+bin/qdoc3*
+bin/qt3to4*
+bin/qtdemo*
+bin/qttracereplay*
+bin/rcc*
+bin/uic*
+bin/patternist*
+bin/phonon*
+bin/qcollectiongenerator*
+bin/qdbus*
+bin/qhelpconverter*
+bin/qhelpgenerator*
+bin/qtconfig*
+bin/xmlpatterns*
+bin/cetest*
+bin/collectiongenerator
+bin/helpconverter
+bin/helpgenerator
+bin/kmap2qmap*
+bin/qlalr*
+bin/qmlconv*
+bin/qmldebugger*
+bin/qml*
+bin/qttracereplay*
+configure.cache
+config.status
+mkspecs/default
+mkspecs/qconfig.pri
+moc_*.cpp
+qmake/qmake.exe
+qmake/Makefile.bak
+src/corelib/global/qconfig.cpp
+src/corelib/global/qconfig.h
+src/corelib/global/qconfig.h.qmake
+ui_*.h
+tests/auto/qprocess/test*/*.exe
+tests/auto/qtcpsocket/stressTest/*.exe
+tests/auto/qprocess/fileWriterProcess/*.exe
+tests/auto/qmake/testdata/quotedfilenames/*.exe
+tests/auto/compilerwarnings/*.exe
+tests/auto/qmake/testdata/quotedfilenames/test.cpp
+tests/auto/qprocess/fileWriterProcess.txt
+.com.apple.timemachine.supported
+tests/auto/qlibrary/libmylib.so*
+tests/auto/qresourceengine/runtime_resource.rcc
+tools/qtestlib/chart/chart*
+tools/qtestlib/updater/updater*
+tools/activeqt/testcon/testcon.tlb
+translations/*.qm
+translations/*_untranslated.ts
+qrc_*.cpp
+
+src/sensors/qtsensorsversion.h
+
+# Test generated files
+QObject.log
+tst_*
+!tst_*.*
+tst_*.log
+tst_*.debug
+tst_*~
+
+# xemacs temporary files
+*.flc
+
+# Vim temporary files
+.*.swp
+
+# Visual Studio generated files
+*.ib_pdb_index
+*.idb
+*.ilk
+*.pdb
+*.sln
+*.suo
+*.vcproj
+*vcproj.*.*.user
+*.ncb
+*.vcxproj
+*.vcxproj.filters
+*.vcxproj.user
+
+# MinGW generated files
+*.Debug
+*.Release
+
+# WebKit temp files
+src/3rdparty/webkit/WebCore/mocinclude.tmp
+src/3rdparty/webkit/includes.txt
+src/3rdparty/webkit/includes2.txt
+
+# Symlinks generated by configure
+tools/qvfb/qvfbhdr.h
+tools/qvfb/qlock_p.h
+tools/qvfb/qlock.cpp
+tools/qvfb/qwssignalhandler.cpp
+tools/qvfb/qwssignalhandler_p.h
+.DS_Store
+.pch
+.rcc
+*.app
+config.status
+config.tests/unix/cups/cups
+config.tests/unix/getaddrinfo/getaddrinfo
+config.tests/unix/getifaddrs/getifaddrs
+config.tests/unix/iconv/iconv
+config.tests/unix/ipv6/ipv6
+config.tests/unix/ipv6ifname/ipv6ifname
+config.tests/unix/largefile/largefile
+config.tests/unix/nis/nis
+config.tests/unix/odbc/odbc
+config.tests/unix/openssl/openssl
+config.tests/unix/stl/stl
+config.tests/unix/zlib/zlib
+config.tests/unix/3dnow/3dnow
+config.tests/unix/mmx/mmx
+config.tests/unix/sse/sse
+config.tests/unix/sse2/sse2
+
+
+
+# Directories to ignore
+# ---------------------
+
+debug
+examples/tools/plugandpaint/plugins
+include/*
+include/*/*
+lib/*
+!lib/fonts
+!lib/README
+plugins/*/*
+release
+tmp
+doc-build
+doc/html/*
+doc/qch
+doc-build
+.rcc
+.pch
+.metadata
+
+# Symbian build system generated files
+# ---------------------
+
+ABLD.BAT
+bld.inf*
+*.mmp
+*.mk
+*.rss
+*.loc
+!s60main.rss
+*.pkg
+plugin_commonu.def
+*.qtplugin
+*.sis
+*.sisx
+*.lst
+*.exe
+*.mif
+*.rsc
+*.sym
+*.lib
+
+# runonphone crash dumps
+d_exc_*.txt
+d_exc_*.stk
+
+# Generated by abldfast.bat from devtools.
+.abldsteps.*
+
+# Carbide project files
+# ---------------------
+.project
+.cproject
+.make.cache
+*.d
+
+qtc-debugging-helper
+src/corelib/lib
+src/network/lib
+src/xml/lib/
+
+.pc/
+
+# INTEGRITY generated files
+*.gpj
+*.int
+*.ael
+*.dla
+*.dnm
+*.dep
+*.map
+work
diff --git a/modules/qt_sensors.pri b/modules/qt_sensors.pri
new file mode 100644
index 0000000..f8e388e
--- /dev/null
+++ b/modules/qt_sensors.pri
@@ -0,0 +1,17 @@
+QT.sensors.VERSION = 5.0.0
+QT.sensors.MAJOR_VERSION = 5
+QT.sensors.MINOR_VERSION = 0
+QT.sensors.PATCH_VERSION = 0
+
+QT.sensors.name = QtSensors
+QT.sensors.bins = $$QT_MODULE_BIN_BASE
+QT.sensors.includes = $$QT_MODULE_INCLUDE_BASE $$QT_MODULE_INCLUDE_BASE/QtSensors
+QT.sensors.private_includes = $$QT_MODULE_INCLUDE_BASE/QtSensors/private
+QT.sensors.sources = $$QT_MODULE_BASE/src/sensors
+QT.sensors.libs = $$QT_MODULE_LIB_BASE
+QT.sensors.plugins = $$QT_MODULE_PLUGIN_BASE
+QT.sensors.imports = $$QT_MODULE_IMPORT_BASE
+QT.sensors.depends = gui sql network
+QT.sensors.DEFINES = QT_SENSORS_LIB
+
+QT_CONFIG += sensors
diff --git a/qtsensors.pro b/qtsensors.pro
index 9671085..1623616 100644
--- a/qtsensors.pro
+++ b/qtsensors.pro
@@ -1 +1,6 @@
TEMPLATE = subdirs
+
+module_qtsensors_src.subdir = src
+module_qtsensors_src.target = module-qtsensors-src
+
+SUBDIRS += module_qtsensors_src
diff --git a/src/sensors/make_sensor.pl b/src/sensors/make_sensor.pl
new file mode 100755
index 0000000..cc699ea
--- /dev/null
+++ b/src/sensors/make_sensor.pl
@@ -0,0 +1,287 @@
+#!/usr/bin/perl
+#############################################################################
+##
+## 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 Qt Mobility Components.
+##
+## $QT_BEGIN_LICENSE:LGPL$
+## 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 Lesser General Public License Usage
+## Alternatively, this file may be used under the terms of the GNU Lesser
+## General Public License version 2.1 as published by the Free Software
+## Foundation and appearing in the file LICENSE.LGPL included in the
+## packaging of this file. Please review the following information to
+## ensure the GNU Lesser General Public License version 2.1 requirements
+## will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+##
+## In addition, as a special exception, 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.
+##
+## If you have questions regarding the use of this file, please contact
+## Nokia at qt-info@nokia.com.
+##
+##
+##
+##
+##
+##
+##
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+use strict;
+use warnings;
+
+use Carp;
+local $Carp::CarpLevel;# = 1;
+
+my $sensor = get_arg();
+my $sensorbase = $sensor;
+$sensorbase =~ s/Sensor$//;
+my $reading = $sensorbase.'Reading';
+my $reading_private = $reading.'Private';
+my $filter = $sensorbase.'Filter';
+
+my $filebase;
+eval {
+ $filebase = get_arg();
+};
+if ($@) {
+ $filebase = lc($sensor);
+}
+
+my $pheader = $filebase."_p.h";
+my $header = $filebase.".h";
+my $source = $filebase.".cpp";
+
+my $pguard = uc($pheader);
+$pguard =~ s/\./_/g;
+
+my $guard = uc($header);
+$guard =~ s/\./_/g;
+
+if (! -e $pheader) {
+ print "Creating $pheader\n";
+ open OUT, ">$pheader" or die $!;
+ print OUT '
+#ifndef '.$pguard.'
+#define '.$pguard.'
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+QT_BEGIN_NAMESPACE
+
+class '.$reading_private.'
+{
+public:
+ '.$reading_private.'()
+ : myprop(0)
+ {
+ }
+
+ /*
+ * Note that this class is copied so you may need to implement
+ * a copy constructor if you have complex types or pointers
+ * as values.
+ */
+
+ qreal myprop;
+};
+
+QT_END_NAMESPACE
+
+#endif
+';
+ close OUT;
+}
+
+if (! -e $header) {
+ print "Creating $header\n";
+ open OUT, ">$header" or die $!;
+ print OUT '
+#ifndef '.$guard.'
+#define '.$guard.'
+
+#include <qsensor.h>
+
+QT_BEGIN_NAMESPACE
+
+class '.$reading_private.';
+
+class Q_SENSORS_EXPORT '.$reading.' : public QSensorReading
+{
+ Q_OBJECT
+ Q_PROPERTY(qreal myprop READ myprop)
+ DECLARE_READING('.$reading.')
+public:
+ qreal myprop() const;
+ void setMyprop(qreal myprop);
+};
+
+class Q_SENSORS_EXPORT '.$filter.' : public QSensorFilter
+{
+public:
+ virtual bool filter('.$reading.' *reading) = 0;
+private:
+ bool filter(QSensorReading *reading) { return filter(static_cast<'.$reading.'*>(reading)); }
+};
+
+class Q_SENSORS_EXPORT '.$sensor.' : public QSensor
+{
+ Q_OBJECT
+public:
+ explicit '.$sensor.'(QObject *parent = 0) : QSensor('.$sensor.'::type, parent) {}
+ virtual ~'.$sensor.'() {}
+ '.$reading.' *reading() const { return static_cast<'.$reading.'*>(QSensor::reading()); }
+ static char const * const type;
+};
+
+QT_END_NAMESPACE
+
+#endif
+';
+ close OUT;
+}
+
+if (! -e $source) {
+ print "Creating $source\n";
+ open OUT, ">$source" or die $!;
+ print OUT '
+#include <'.$header.'>
+#include "'.$pheader.'"
+
+QT_BEGIN_NAMESPACE
+
+IMPLEMENT_READING('.$reading.')
+
+/*!
+ \class '.$reading.'
+ \ingroup sensors_reading
+ \inmodule QtSensors
+
+ \brief The '.$reading.' class holds readings from the [X] sensor.
+
+ [Fill this out]
+
+ \section2 '.$reading.' Units
+
+ [Fill this out]
+*/
+
+/*!
+ \property '.$reading.'::myprop
+ \brief [what does it hold?]
+
+ [What are the units?]
+ \sa {'.$reading.' Units}
+*/
+
+qreal '.$reading.'::myprop() const
+{
+ return d->myprop;
+}
+
+/*!
+ Sets [what?] to \a myprop.
+*/
+void '.$reading.'::setMyprop(qreal myprop)
+{
+ d->myprop = myprop;
+}
+
+// =====================================================================
+
+/*!
+ \class '.$filter.'
+ \ingroup sensors_filter
+ \inmodule QtSensors
+
+ \brief The '.$filter.' class is a convenience wrapper around QSensorFilter.
+
+ The only difference is that the filter() method features a pointer to '.$reading.'
+ instead of QSensorReading.
+*/
+
+/*!
+ \fn '.$filter.'::filter('.$reading.' *reading)
+
+ Called when \a reading changes. Returns false to prevent the reading from propagating.
+
+ \sa QSensorFilter::filter()
+*/
+
+char const * const '.$sensor.'::type("'.$sensor.'");
+
+/*!
+ \class '.$sensor.'
+ \ingroup sensors_type
+ \inmodule QtSensors
+
+ \brief The '.$sensor.' class is a convenience wrapper around QSensor.
+
+ The only behavioural difference is that this class sets the type properly.
+
+ This class also features a reading() function that returns a '.$reading.' instead of a QSensorReading.
+
+ For details about how the sensor works, see \l '.$reading.'.
+
+ \sa '.$reading.'
+*/
+
+/*!
+ \fn '.$sensor.'::'.$sensor.'(QObject *parent)
+
+ Construct the sensor as a child of \a parent.
+*/
+
+/*!
+ \fn '.$sensor.'::~'.$sensor.'()
+
+ Destroy the sensor. Stops the sensor if it has not already been stopped.
+*/
+
+/*!
+ \fn '.$sensor.'::reading() const
+
+ Returns the reading class for this sensor.
+
+ \sa QSensor::reading()
+*/
+
+#include "moc_'.$source.'"
+QT_END_NAMESPACE
+';
+ close OUT;
+}
+
+exit 0;
+
+
+sub get_arg
+{
+ if (scalar(@ARGV) == 0) {
+ croak "Missing arg(s)";
+ }
+ return shift(@ARGV);
+}
+
diff --git a/src/sensors/qaccelerometer.cpp b/src/sensors/qaccelerometer.cpp
new file mode 100644
index 0000000..e90becd
--- /dev/null
+++ b/src/sensors/qaccelerometer.cpp
@@ -0,0 +1,194 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qaccelerometer.h"
+#include "qaccelerometer_p.h"
+
+QT_BEGIN_NAMESPACE
+
+IMPLEMENT_READING(QAccelerometerReading)
+
+/*!
+ \class QAccelerometerReading
+ \ingroup sensors_reading
+ \inmodule QtSensors
+ \since 1.0
+
+ \brief The QAccelerometerReading class reports on linear acceleration
+ along the X, Y and Z axes.
+
+ \section2 QAccelerometerReading Units
+ The scale of the values is meters per second squared.
+ The axes are arranged as follows.
+
+ \image sensors-coordinates2.jpg
+
+ A monoblock device sitting at rest, face up on a desk will experience
+ a force of approximately 9.8 on the Z axis (ie. towards the roof).
+ This is the proper acceleration the device experiences relative to
+ freefall.
+*/
+
+/*!
+ \property QAccelerometerReading::x
+ \brief the acceleration on the X axis.
+
+ The scale of the values is meters per second squared.
+ \sa {QAccelerometerReading Units}
+*/
+
+qreal QAccelerometerReading::x() const
+{
+ return d->x;
+}
+
+/*!
+ Sets the acceleration on the X axis to \a x.
+*/
+void QAccelerometerReading::setX(qreal x)
+{
+ d->x = x;
+}
+
+/*!
+ \property QAccelerometerReading::y
+ \brief the acceleration on the Y axis.
+
+ The scale of the values is meters per second squared.
+ \sa {QAccelerometerReading Units}
+*/
+
+qreal QAccelerometerReading::y() const
+{
+ return d->y;
+}
+
+/*!
+ Sets the acceleration on the Y axis to \a y.
+*/
+void QAccelerometerReading::setY(qreal y)
+{
+ d->y = y;
+}
+
+/*!
+ \property QAccelerometerReading::z
+ \brief the acceleration on the Z axis.
+
+ The scale of the values is meters per second squared.
+ \sa {QAccelerometerReading Units}
+*/
+
+qreal QAccelerometerReading::z() const
+{
+ return d->z;
+}
+
+/*!
+ Sets the acceleration on the Z axis to \a z.
+*/
+void QAccelerometerReading::setZ(qreal z)
+{
+ d->z = z;
+}
+
+// =====================================================================
+
+/*!
+ \class QAccelerometerFilter
+ \ingroup sensors_filter
+ \inmodule QtSensors
+
+ \brief The QAccelerometerFilter class is a convenience wrapper around QSensorFilter.
+
+ The only difference is that the filter() method features a pointer to QAccelerometerReading
+ instead of QSensorReading.
+*/
+
+/*!
+ \fn QAccelerometerFilter::filter(QAccelerometerReading *reading)
+
+ Called when \a reading changes. Returns false to prevent the reading from propagating.
+
+ \sa QSensorFilter::filter()
+*/
+
+char const * const QAccelerometer::type("QAccelerometer");
+
+/*!
+ \class QAccelerometer
+ \ingroup sensors_type
+ \inmodule QtSensors
+
+ \brief The QAccelerometer class is a convenience wrapper around QSensor.
+
+ The only behavioural difference is that this class sets the type properly.
+
+ This class also features a reading() function that returns a QAccelerometerReading instead of a QSensorReading.
+
+ For details about how the sensor works, see \l QAccelerometerReading.
+
+ \sa QAccelerometerReading
+*/
+
+/*!
+ \fn QAccelerometer::QAccelerometer(QObject *parent)
+
+ Construct the sensor as a child of \a parent.
+*/
+
+/*!
+ \fn QAccelerometer::~QAccelerometer()
+
+ Destroy the sensor. Stops the sensor if it has not already been stopped.
+*/
+
+/*!
+ \fn QAccelerometer::reading() const
+
+ Returns the reading class for this sensor.
+
+ \sa QSensor::reading()
+*/
+
+#include "moc_qaccelerometer.cpp"
+QT_END_NAMESPACE
+
diff --git a/src/sensors/qaccelerometer.h b/src/sensors/qaccelerometer.h
new file mode 100644
index 0000000..141dfd3
--- /dev/null
+++ b/src/sensors/qaccelerometer.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QACCELEROMETER_H
+#define QACCELEROMETER_H
+
+#include "qsensor.h"
+
+QT_BEGIN_NAMESPACE
+
+class QAccelerometerReadingPrivate;
+
+class Q_SENSORS_EXPORT QAccelerometerReading : public QSensorReading
+{
+ Q_OBJECT
+ Q_PROPERTY(qreal x READ x)
+ Q_PROPERTY(qreal y READ y)
+ Q_PROPERTY(qreal z READ z)
+ DECLARE_READING(QAccelerometerReading)
+public:
+ qreal x() const;
+ void setX(qreal x);
+
+ qreal y() const;
+ void setY(qreal y);
+
+ qreal z() const;
+ void setZ(qreal z);
+};
+
+class Q_SENSORS_EXPORT QAccelerometerFilter : public QSensorFilter
+{
+public:
+ virtual bool filter(QAccelerometerReading *reading) = 0;
+private:
+ bool filter(QSensorReading *reading) { return filter(static_cast<QAccelerometerReading*>(reading)); }
+};
+
+class Q_SENSORS_EXPORT QAccelerometer : public QSensor
+{
+ Q_OBJECT
+public:
+ explicit QAccelerometer(QObject *parent = 0) : QSensor(QAccelerometer::type, parent) {}
+ virtual ~QAccelerometer() {}
+ QAccelerometerReading *reading() const { return static_cast<QAccelerometerReading*>(QSensor::reading()); }
+ static char const * const type;
+};
+
+QT_END_NAMESPACE
+
+#endif
+
diff --git a/src/sensors/qaccelerometer_p.h b/src/sensors/qaccelerometer_p.h
new file mode 100644
index 0000000..6c1cb0b
--- /dev/null
+++ b/src/sensors/qaccelerometer_p.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QACCELEROMETER_P_H
+#define QACCELEROMETER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+QT_BEGIN_NAMESPACE
+
+class QAccelerometerReadingPrivate
+{
+public:
+ QAccelerometerReadingPrivate()
+ : x(0)
+ , y(0)
+ , z(0)
+ {
+ }
+
+ qreal x;
+ qreal y;
+ qreal z;
+};
+
+QT_END_NAMESPACE
+
+#endif
+
diff --git a/src/sensors/qambientlightsensor.cpp b/src/sensors/qambientlightsensor.cpp
new file mode 100644
index 0000000..212872f
--- /dev/null
+++ b/src/sensors/qambientlightsensor.cpp
@@ -0,0 +1,170 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qambientlightsensor.h"
+#include "qambientlightsensor_p.h"
+
+QT_BEGIN_NAMESPACE
+
+IMPLEMENT_READING(QAmbientLightReading)
+
+/*!
+ \class QAmbientLightReading
+ \ingroup sensors_reading
+ \inmodule QtSensors
+ \since 1.0
+
+ \brief The QAmbientLightReading class represents one reading from the
+ ambient light sensor.
+
+ \section2 QAmbientLightReading Units
+ The ambient light sensor returns the intensity of the ambient light
+ using the pre-defined values found in the QAmbientLightReading::LightLevel
+ enum.
+*/
+
+/*!
+ \enum QAmbientLightReading::LightLevel
+
+ This enum represents the ambient light level.
+
+ \value Undefined The light level is unknown.
+ \value Dark It is dark.
+ \value Twilight It is moderately dark.
+ \value Light It is light (eg. internal lights).
+ \value Bright It is bright (eg. shade).
+ \value Sunny It is very bright (eg. direct sunlight).
+*/
+
+/*!
+ \property QAmbientLightReading::lightLevel
+ \brief the ambient light level.
+
+ The value represents the ambient light and comes from QAmbientLightReading::LightLevel.
+ \sa {QAmbientLightReading Units}
+*/
+
+QAmbientLightReading::LightLevel QAmbientLightReading::lightLevel() const
+{
+ return static_cast<LightLevel>(d->lightLevel);
+}
+
+/*!
+ Sets the ambient light level to \a lightLevel.
+*/
+void QAmbientLightReading::setLightLevel(QAmbientLightReading::LightLevel lightLevel)
+{
+ switch (lightLevel) {
+ case Dark:
+ case Twilight:
+ case Light:
+ case Bright:
+ case Sunny:
+ d->lightLevel = lightLevel;
+ break;
+ default:
+ d->lightLevel = Undefined;
+ break;
+ }
+}
+
+// =====================================================================
+
+/*!
+ \class QAmbientLightFilter
+ \ingroup sensors_filter
+ \inmodule QtSensors
+
+ \brief The QAmbientLightFilter class is a convenience wrapper around QSensorFilter.
+
+ The only difference is that the filter() method features a pointer to QAmbientLightReading
+ instead of QSensorReading.
+*/
+
+/*!
+ \fn QAmbientLightFilter::filter(QAmbientLightReading *reading)
+
+ Called when \a reading changes. Returns false to prevent the reading from propagating.
+
+ \sa QSensorFilter::filter()
+*/
+
+char const * const QAmbientLightSensor::type("QAmbientLightSensor");
+
+/*!
+ \class QAmbientLightSensor
+ \ingroup sensors_type
+ \inmodule QtSensors
+
+ \brief The QAmbientLightSensor class is a convenience wrapper around QSensor.
+
+ The only behavioural difference is that this class sets the type properly.
+
+ This class also features a reading() function that returns a QAmbientLightReading instead of a QSensorReading.
+
+ For details about how the sensor works, see \l QAmbientLightReading.
+
+ \sa QAmbientLightReading
+*/
+
+/*!
+ \fn QAmbientLightSensor::QAmbientLightSensor(QObject *parent)
+
+ Construct the sensor as a child of \a parent.
+*/
+
+/*!
+ \fn QAmbientLightSensor::~QAmbientLightSensor()
+
+ Destroy the sensor. Stops the sensor if it has not already been stopped.
+*/
+
+/*!
+ \fn QAmbientLightSensor::reading() const
+
+ Returns the reading class for this sensor.
+
+ \sa QSensor::reading()
+*/
+
+#include "moc_qambientlightsensor.cpp"
+QT_END_NAMESPACE
+
diff --git a/src/sensors/qambientlightsensor.h b/src/sensors/qambientlightsensor.h
new file mode 100644
index 0000000..8c48b84
--- /dev/null
+++ b/src/sensors/qambientlightsensor.h
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QAMBIENTLIGHTSENSOR_H
+#define QAMBIENTLIGHTSENSOR_H
+
+#include "qsensor.h"
+
+QT_BEGIN_NAMESPACE
+
+class QAmbientLightReadingPrivate;
+
+class Q_SENSORS_EXPORT QAmbientLightReading : public QSensorReading
+{
+ Q_OBJECT
+ Q_ENUMS(LightLevel)
+ Q_PROPERTY(LightLevel lightLevel READ lightLevel)
+ DECLARE_READING(QAmbientLightReading)
+public:
+ enum LightLevel {
+ Undefined = 0,
+ Dark,
+ Twilight,
+ Light,
+ Bright,
+ Sunny
+ };
+
+ LightLevel lightLevel() const;
+ void setLightLevel(LightLevel lightLevel);
+};
+
+class Q_SENSORS_EXPORT QAmbientLightFilter : public QSensorFilter
+{
+public:
+ virtual bool filter(QAmbientLightReading *reading) = 0;
+private:
+ bool filter(QSensorReading *reading) { return filter(static_cast<QAmbientLightReading*>(reading)); }
+};
+
+class Q_SENSORS_EXPORT QAmbientLightSensor : public QSensor
+{
+ Q_OBJECT
+public:
+ explicit QAmbientLightSensor(QObject *parent = 0) : QSensor(QAmbientLightSensor::type, parent) {}
+ virtual ~QAmbientLightSensor() {}
+ QAmbientLightReading *reading() const { return static_cast<QAmbientLightReading*>(QSensor::reading()); }
+ static char const * const type;
+};
+
+QT_END_NAMESPACE
+
+#endif
+
diff --git a/src/sensors/qambientlightsensor_p.h b/src/sensors/qambientlightsensor_p.h
new file mode 100644
index 0000000..e7fdb3a
--- /dev/null
+++ b/src/sensors/qambientlightsensor_p.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QAMBIENTLIGHTSENSOR_P_H
+#define QAMBIENTLIGHTSENSOR_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+QT_BEGIN_NAMESPACE
+
+class QAmbientLightReadingPrivate
+{
+public:
+ QAmbientLightReadingPrivate()
+ : lightLevel(0)
+ {
+ }
+
+ int lightLevel;
+};
+
+QT_END_NAMESPACE
+
+#endif
+
diff --git a/src/sensors/qcompass.cpp b/src/sensors/qcompass.cpp
new file mode 100644
index 0000000..e55fe61
--- /dev/null
+++ b/src/sensors/qcompass.cpp
@@ -0,0 +1,180 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qcompass.h"
+#include "qcompass_p.h"
+
+QT_BEGIN_NAMESPACE
+
+IMPLEMENT_READING(QCompassReading)
+
+/*!
+ \class QCompassReading
+ \ingroup sensors_reading
+ \inmodule QtSensors
+ \since 1.0
+
+ \brief The QCompassReading class represents one reading from a
+ compass.
+
+ \section2 QCompassReading Units
+ The compass returns the azimuth of the device as degrees from
+ magnetic north in a clockwise direction based on the top of the UI.
+ There is also a value to indicate the calibration status of the device.
+ If the device is not calibrated the azimuth may not be accurate.
+
+ Digital compasses are susceptible to magnetic interference and may need
+ calibration after being placed near anything that emits a magnetic force.
+ Accuracy of the compass can be affected by any ferrous materials that are nearby.
+
+ The calibration status of the device is measured as a number from 0 to 1.
+ A value of 1 is the highest level that the device can support and 0 is
+ the worst.
+ \sa {http://wiki.forum.nokia.com/index.php/CS001671_-_Calibrating_the_magnetometer_sensor}{CS001671 - Calibrating the magnetometer sensor}
+*/
+
+/*!
+ \property QCompassReading::azimuth
+ \brief the azimuth of the device.
+
+ Measured in degrees from magnetic north in a clockwise direction based
+ the top of the UI.
+ \sa {QCompassReading Units}
+*/
+
+qreal QCompassReading::azimuth() const
+{
+ return d->azimuth;
+}
+
+/*!
+ Sets the \a azimuth of the device.
+
+ \sa {QCompassReading Units}
+*/
+void QCompassReading::setAzimuth(qreal azimuth)
+{
+ d->azimuth = azimuth;
+}
+
+/*!
+ \property QCompassReading::calibrationLevel
+ \brief the calibration level of the reading.
+
+ Measured as a value from 0 to 1 with higher values being better.
+ \sa {QCompassReading Units}, {http://wiki.forum.nokia.com/index.php/CS001671_-_Calibrating_the_magnetometer_sensor}{CS001671 - Calibrating the magnetometer sensor}
+*/
+
+qreal QCompassReading::calibrationLevel() const
+{
+ return d->calibrationLevel;
+}
+
+/*!
+ Sets the calibration level of the reading to \a calibrationLevel.
+*/
+void QCompassReading::setCalibrationLevel(qreal calibrationLevel)
+{
+ d->calibrationLevel = calibrationLevel;
+}
+
+// =====================================================================
+
+/*!
+ \class QCompassFilter
+ \ingroup sensors_filter
+ \inmodule QtSensors
+
+ \brief The QCompassFilter class is a convenience wrapper around QSensorFilter.
+
+ The only difference is that the filter() method features a pointer to QCompassReading
+ instead of QSensorReading.
+*/
+
+/*!
+ \fn QCompassFilter::filter(QCompassReading *reading)
+
+ Called when \a reading changes. Returns false to prevent the reading from propagating.
+
+ \sa QSensorFilter::filter()
+*/
+
+char const * const QCompass::type("QCompass");
+
+/*!
+ \class QCompass
+ \ingroup sensors_type
+ \inmodule QtSensors
+
+ \brief The QCompass class is a convenience wrapper around QSensor.
+
+ The only behavioural difference is that this class sets the type properly.
+
+ This class also features a reading() function that returns a QCompassReading instead of a QSensorReading.
+
+ For details about how the sensor works, see \l QCompassReading.
+
+ \sa QCompassReading
+*/
+
+/*!
+ \fn QCompass::QCompass(QObject *parent)
+
+ Construct the sensor as a child of \a parent.
+*/
+
+/*!
+ \fn QCompass::~QCompass()
+
+ Destroy the sensor. Stops the sensor if it has not already been stopped.
+*/
+
+/*!
+ \fn QCompass::reading() const
+
+ Returns the reading class for this sensor.
+
+ \sa QSensor::reading()
+*/
+
+#include "moc_qcompass.cpp"
+QT_END_NAMESPACE
+
diff --git a/src/sensors/qcompass.h b/src/sensors/qcompass.h
new file mode 100644
index 0000000..4ff4b46
--- /dev/null
+++ b/src/sensors/qcompass.h
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QCOMPASS_H
+#define QCOMPASS_H
+
+#include "qsensor.h"
+
+QT_BEGIN_NAMESPACE
+
+class QCompassReadingPrivate;
+
+class Q_SENSORS_EXPORT QCompassReading : public QSensorReading
+{
+ Q_OBJECT
+ Q_PROPERTY(qreal azimuth READ azimuth)
+ Q_PROPERTY(qreal calibrationLevel READ calibrationLevel)
+ DECLARE_READING(QCompassReading)
+public:
+ qreal azimuth() const;
+ void setAzimuth(qreal azimuth);
+
+ qreal calibrationLevel() const;
+ void setCalibrationLevel(qreal calibrationLevel);
+};
+
+class Q_SENSORS_EXPORT QCompassFilter : public QSensorFilter
+{
+public:
+ virtual bool filter(QCompassReading *reading) = 0;
+private:
+ bool filter(QSensorReading *reading) { return filter(static_cast<QCompassReading*>(reading)); }
+};
+
+class Q_SENSORS_EXPORT QCompass : public QSensor
+{
+ Q_OBJECT
+public:
+ explicit QCompass(QObject *parent = 0) : QSensor(QCompass::type, parent) {}
+ virtual ~QCompass() {}
+ QCompassReading *reading() const { return static_cast<QCompassReading*>(QSensor::reading()); }
+ static char const * const type;
+};
+
+QT_END_NAMESPACE
+
+#endif
+
diff --git a/src/sensors/qcompass_p.h b/src/sensors/qcompass_p.h
new file mode 100644
index 0000000..8f1d51c
--- /dev/null
+++ b/src/sensors/qcompass_p.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QCOMPASS_P_H
+#define QCOMPASS_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+QT_BEGIN_NAMESPACE
+
+class QCompassReadingPrivate
+{
+public:
+ QCompassReadingPrivate()
+ : azimuth(0)
+ , calibrationLevel(0)
+ {
+ }
+
+ qreal azimuth;
+ qreal calibrationLevel;
+};
+
+QT_END_NAMESPACE
+
+#endif
+
diff --git a/src/sensors/qgyroscope.cpp b/src/sensors/qgyroscope.cpp
new file mode 100644
index 0000000..52959c1
--- /dev/null
+++ b/src/sensors/qgyroscope.cpp
@@ -0,0 +1,192 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qgyroscope.h"
+#include "qgyroscope_p.h"
+
+QT_BEGIN_NAMESPACE
+
+IMPLEMENT_READING(QGyroscopeReading)
+
+/*!
+ \class QGyroscopeReading
+ \ingroup sensors_reading
+ \inmodule QtSensors
+ \since 1.2
+
+ \brief The QGyroscopeReading class represents one reading from the
+ gyroscope sensor.
+
+ \section2 QGyroscopeReading Units
+
+ The reading contains 3 values, measured in degrees per second that define
+ the movement of the device around the x, y and z axes. Unlike QRotationReading,
+ the values represent the current angular velocity rather than a fixed rotation.
+ The measurements are in degrees per second.
+
+ \image sensors-coordinates3.jpg
+*/
+
+/*!
+ \property QGyroscopeReading::x
+ \brief the angular velocity around the x axis.
+
+ Measured as degrees per second.
+ \sa {QGyroscopeReading Units}
+*/
+
+qreal QGyroscopeReading::x() const
+{
+ return d->x;
+}
+
+/*!
+ Sets the angular velocity around the x axis to \a x.
+*/
+void QGyroscopeReading::setX(qreal x)
+{
+ d->x = x;
+}
+
+/*!
+ \property QGyroscopeReading::y
+ \brief the angular velocity around the y axis.
+
+ Measured as degrees per second.
+ \sa {QGyroscopeReading Units}
+*/
+
+qreal QGyroscopeReading::y() const
+{
+ return d->y;
+}
+
+/*!
+ Sets the angular velocity around the y axis to \a y.
+*/
+void QGyroscopeReading::setY(qreal y)
+{
+ d->y = y;
+}
+
+/*!
+ \property QGyroscopeReading::z
+ \brief the angular velocity around the z axis.
+
+ Measured as degrees per second.
+ \sa {QGyroscopeReading Units}
+*/
+
+qreal QGyroscopeReading::z() const
+{
+ return d->z;
+}
+
+/*!
+ Sets the angular velocity around the z axis to \a z.
+*/
+void QGyroscopeReading::setZ(qreal z)
+{
+ d->z = z;
+}
+
+// =====================================================================
+
+/*!
+ \class QGyroscopeFilter
+ \ingroup sensors_filter
+ \inmodule QtSensors
+
+ \brief The QGyroscopeFilter class is a convenience wrapper around QSensorFilter.
+
+ The only difference is that the filter() method features a pointer to QGyroscopeReading
+ instead of QSensorReading.
+*/
+
+/*!
+ \fn QGyroscopeFilter::filter(QGyroscopeReading *reading)
+
+ Called when \a reading changes. Returns false to prevent the reading from propagating.
+
+ \sa QSensorFilter::filter()
+*/
+
+char const * const QGyroscope::type("QGyroscope");
+
+/*!
+ \class QGyroscope
+ \ingroup sensors_type
+ \inmodule QtSensors
+
+ \brief The QGyroscope class is a convenience wrapper around QSensor.
+
+ The only behavioural difference is that this class sets the type properly.
+
+ This class also features a reading() function that returns a QGyroscopeReading instead of a QSensorReading.
+
+ For details about how the sensor works, see \l QGyroscopeReading.
+
+ \sa QGyroscopeReading
+*/
+
+/*!
+ \fn QGyroscope::QGyroscope(QObject *parent)
+
+ Construct the sensor as a child of \a parent.
+*/
+
+/*!
+ \fn QGyroscope::~QGyroscope()
+
+ Destroy the sensor. Stops the sensor if it has not already been stopped.
+*/
+
+/*!
+ \fn QGyroscope::reading() const
+
+ Returns the reading class for this sensor.
+
+ \sa QSensor::reading()
+*/
+
+#include "moc_qgyroscope.cpp"
+QT_END_NAMESPACE
+
diff --git a/src/sensors/qgyroscope.h b/src/sensors/qgyroscope.h
new file mode 100644
index 0000000..e6fd037
--- /dev/null
+++ b/src/sensors/qgyroscope.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QGYROSCOPE_H
+#define QGYROSCOPE_H
+
+#include "qsensor.h"
+
+QT_BEGIN_NAMESPACE
+
+class QGyroscopeReadingPrivate;
+
+class Q_SENSORS_EXPORT QGyroscopeReading : public QSensorReading
+{
+ Q_OBJECT
+ Q_PROPERTY(qreal x READ x)
+ Q_PROPERTY(qreal y READ y)
+ Q_PROPERTY(qreal z READ z)
+ DECLARE_READING(QGyroscopeReading)
+public:
+ qreal x() const;
+ void setX(qreal x);
+
+ qreal y() const;
+ void setY(qreal y);
+
+ qreal z() const;
+ void setZ(qreal z);
+};
+
+class Q_SENSORS_EXPORT QGyroscopeFilter : public QSensorFilter
+{
+public:
+ virtual bool filter(QGyroscopeReading *reading) = 0;
+private:
+ bool filter(QSensorReading *reading) { return filter(static_cast<QGyroscopeReading*>(reading)); }
+};
+
+class Q_SENSORS_EXPORT QGyroscope : public QSensor
+{
+ Q_OBJECT
+public:
+ explicit QGyroscope(QObject *parent = 0) : QSensor(QGyroscope::type, parent) {}
+ virtual ~QGyroscope() {}
+ QGyroscopeReading *reading() const { return static_cast<QGyroscopeReading*>(QSensor::reading()); }
+ static char const * const type;
+};
+
+QT_END_NAMESPACE
+
+#endif
+
diff --git a/src/sensors/qgyroscope_p.h b/src/sensors/qgyroscope_p.h
new file mode 100644
index 0000000..3861d80
--- /dev/null
+++ b/src/sensors/qgyroscope_p.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QGYROSCOPE_P_H
+#define QGYROSCOPE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+QT_BEGIN_NAMESPACE
+
+class QGyroscopeReadingPrivate
+{
+public:
+ QGyroscopeReadingPrivate()
+ : x(0)
+ , y(0)
+ , z(0)
+ {
+ }
+
+ qreal x;
+ qreal y;
+ qreal z;
+};
+
+QT_END_NAMESPACE
+
+#endif
+
diff --git a/src/sensors/qlightsensor.cpp b/src/sensors/qlightsensor.cpp
new file mode 100644
index 0000000..61c7199
--- /dev/null
+++ b/src/sensors/qlightsensor.cpp
@@ -0,0 +1,152 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qlightsensor.h"
+#include "qlightsensor_p.h"
+
+QT_BEGIN_NAMESPACE
+
+IMPLEMENT_READING(QLightReading)
+
+/*!
+ \class QLightReading
+ \ingroup sensors_reading
+
+ \since 1.2
+
+ \preliminary
+ \brief The QLightReading class represents one reading from the
+ light sensor.
+
+ \section2 QLightReading Units
+ The light sensor returns the intensity of the light in lux.
+*/
+
+/*!
+ \property QLightReading::lux
+ \brief the light level.
+
+ Measured as lux.
+ \sa {QLightReading Units}
+*/
+
+qreal QLightReading::lux() const
+{
+ return d->lux;
+}
+
+/*!
+ Sets the light level to \a lux.
+*/
+void QLightReading::setLux(qreal lux)
+{
+ d->lux = lux;
+}
+
+// =====================================================================
+
+/*!
+ \class QLightFilter
+ \ingroup sensors_filter
+
+ \preliminary
+ \brief The QLightFilter class is a convenience wrapper around QSensorFilter.
+
+ The only difference is that the filter() method features a pointer to QLightReading
+ instead of QSensorReading.
+*/
+
+/*!
+ \fn QLightFilter::filter(QLightReading *reading)
+
+ Called when \a reading changes. Returns false to prevent the reading from propagating.
+
+ \sa QSensorFilter::filter()
+*/
+
+char const * const QLightSensor::type("QLightSensor");
+
+/*!
+ \class QLightSensor
+ \ingroup sensors_type
+
+ \preliminary
+ \brief The QLightSensor class is a convenience wrapper around QSensor.
+
+ The only behavioural difference is that this class sets the type properly.
+
+ This class also features a reading() function that returns a QLightReading instead of a QSensorReading.
+
+ For details about how the sensor works, see \l QLightReading.
+
+ \sa QLightReading
+*/
+
+/*!
+ \fn QLightSensor::QLightSensor(QObject *parent)
+
+ Construct the sensor as a child of \a parent.
+*/
+
+/*!
+ \fn QLightSensor::~QLightSensor()
+
+ Destroy the sensor. Stops the sensor if it has not already been stopped.
+*/
+
+/*!
+ \fn QLightSensor::reading() const
+
+ Returns the reading class for this sensor.
+
+ \sa QSensor::reading()
+*/
+
+/*!
+ \property QLightSensor::fieldOfView
+ \brief a value indicating the field of view.
+
+ This is an angle that represents the field of view of the sensor.
+*/
+
+#include "moc_qlightsensor.cpp"
+QT_END_NAMESPACE
+
diff --git a/src/sensors/qlightsensor.h b/src/sensors/qlightsensor.h
new file mode 100644
index 0000000..6b618db
--- /dev/null
+++ b/src/sensors/qlightsensor.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QLIGHTSENSOR_H
+#define QLIGHTSENSOR_H
+
+#include "qsensor.h"
+
+QT_BEGIN_NAMESPACE
+
+class QLightReadingPrivate;
+
+class Q_SENSORS_EXPORT QLightReading : public QSensorReading
+{
+ Q_OBJECT
+ Q_PROPERTY(qreal lux READ lux)
+ DECLARE_READING(QLightReading)
+public:
+ qreal lux() const;
+ void setLux(qreal lux);
+};
+
+class Q_SENSORS_EXPORT QLightFilter : public QSensorFilter
+{
+public:
+ virtual bool filter(QLightReading *reading) = 0;
+private:
+ bool filter(QSensorReading *reading) { return filter(static_cast<QLightReading*>(reading)); }
+};
+
+class Q_SENSORS_EXPORT QLightSensor : public QSensor
+{
+ Q_OBJECT
+#ifdef Q_QDOC
+ Q_PROPERTY(qreal fieldOfView)
+#endif
+public:
+ explicit QLightSensor(QObject *parent = 0) : QSensor(QLightSensor::type, parent) {}
+ virtual ~QLightSensor() {}
+ QLightReading *reading() const { return static_cast<QLightReading*>(QSensor::reading()); }
+ static char const * const type;
+};
+
+QT_END_NAMESPACE
+
+#endif
+
diff --git a/src/sensors/qlightsensor_p.h b/src/sensors/qlightsensor_p.h
new file mode 100644
index 0000000..3b204e9
--- /dev/null
+++ b/src/sensors/qlightsensor_p.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QLIGHTSENSOR_P_H
+#define QLIGHTSENSOR_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qsensor_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QLightReadingPrivate : public QSensorReadingPrivate
+{
+public:
+ QLightReadingPrivate()
+ : lux(0)
+ {
+ }
+
+ qreal lux;
+};
+
+QT_END_NAMESPACE
+
+#endif
+
diff --git a/src/sensors/qmagnetometer.cpp b/src/sensors/qmagnetometer.cpp
new file mode 100644
index 0000000..c499f58
--- /dev/null
+++ b/src/sensors/qmagnetometer.cpp
@@ -0,0 +1,243 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qmagnetometer.h"
+#include "qmagnetometer_p.h"
+
+QT_BEGIN_NAMESPACE
+
+IMPLEMENT_READING(QMagnetometerReading)
+
+/*!
+ \class QMagnetometerReading
+ \ingroup sensors_reading
+ \inmodule QtSensors
+ \since 1.0
+
+ \brief The QMagnetometerReading class represents one reading from the
+ magnetometer.
+
+ \section2 QMagnetometerReading Units
+ The magnetometer returns magnetic flux density values along 3 axes.
+ The scale of the values is teslas. The axes are arranged as follows.
+
+ \image sensors-coordinates2.jpg
+
+ The magnetometer can report on either raw magnetic flux values or geomagnetic flux values.
+ By default it returns raw magnetic flux values. The QMagnetometer::returnGeoValues property
+ must be set to return geomagnetic flux values.
+
+ The primary difference between raw and geomagnetic values is that extra processing
+ is done to eliminate local magnetic interference from the geomagnetic values so they
+ represent only the effect of the Earth's magnetic field. This process is not perfect
+ and the accuracy of each reading may change.
+
+ The image below shows the difference between geomagnetic (on the left) and raw (on the right)
+ readings for a phone that is being subjected to magnetic interference.
+
+ \image sensors-geo-vs-raw-magnetism.jpg
+
+ The accuracy of each reading is measured as a number from 0 to 1.
+ A value of 1 is the highest level that the device can support and 0 is
+ the worst.
+ \sa {http://wiki.forum.nokia.com/index.php/CS001671_-_Calibrating_the_magnetometer_sensor}{CS001671 - Calibrating the magnetometer sensor}
+*/
+
+/*!
+ \property QMagnetometerReading::x
+ \brief the raw magnetic flux density on the X axis.
+
+ Measured as telsas.
+ \sa {QMagnetometerReading Units}
+*/
+
+qreal QMagnetometerReading::x() const
+{
+ return d->x;
+}
+
+/*!
+ Sets the raw magnetic flux density on the X axis to \a x.
+*/
+void QMagnetometerReading::setX(qreal x)
+{
+ d->x = x;
+}
+
+/*!
+ \property QMagnetometerReading::y
+ \brief the raw magnetic flux density on the Y axis.
+
+ Measured as telsas.
+ \sa {QMagnetometerReading Units}
+*/
+
+qreal QMagnetometerReading::y() const
+{
+ return d->y;
+}
+
+/*!
+ Sets the raw magnetic flux density on the Y axis to \a y.
+*/
+void QMagnetometerReading::setY(qreal y)
+{
+ d->y = y;
+}
+
+/*!
+ \property QMagnetometerReading::z
+ \brief the raw magnetic flux density on the Z axis.
+
+ Measured as telsas.
+ \sa {QMagnetometerReading Units}
+*/
+
+qreal QMagnetometerReading::z() const
+{
+ return d->z;
+}
+
+/*!
+ Sets the raw magnetic flux density on the Z axis to \a z.
+*/
+void QMagnetometerReading::setZ(qreal z)
+{
+ d->z = z;
+}
+
+/*!
+ \property QMagnetometerReading::calibrationLevel
+ \brief the accuracy of the reading.
+
+ Measured as a value from 0 to 1 with higher values being better.
+
+ Note that this only changes when measuring geomagnetic flux density.
+ Raw magnetic flux readings will always have a value of 1.
+ \sa {QMagnetometerReading Units}, {http://wiki.forum.nokia.com/index.php/CS001671_-_Calibrating_the_magnetometer_sensor}{CS001671 - Calibrating the magnetometer sensor}
+*/
+
+qreal QMagnetometerReading::calibrationLevel() const
+{
+ return d->calibrationLevel;
+}
+
+/*!
+ Sets the accuracy of the reading to \a calibrationLevel.
+*/
+void QMagnetometerReading::setCalibrationLevel(qreal calibrationLevel)
+{
+ d->calibrationLevel = calibrationLevel;
+}
+
+// =====================================================================
+
+/*!
+ \class QMagnetometerFilter
+ \ingroup sensors_filter
+ \inmodule QtSensors
+
+ \brief The QMagnetometerFilter class is a convenience wrapper around QSensorFilter.
+
+ The only difference is that the filter() method features a pointer to QMagnetometerReading
+ instead of QSensorReading.
+*/
+
+/*!
+ \fn QMagnetometerFilter::filter(QMagnetometerReading *reading)
+
+ Called when \a reading changes. Returns false to prevent the reading from propagating.
+
+ \sa QSensorFilter::filter()
+*/
+
+char const * const QMagnetometer::type("QMagnetometer");
+
+/*!
+ \class QMagnetometer
+ \ingroup sensors_type
+ \inmodule QtSensors
+
+ \brief The QMagnetometer class is a convenience wrapper around QSensor.
+
+ The only behavioural difference is that this class sets the type properly.
+
+ This class also features a reading() function that returns a QMagnetometerReading instead of a QSensorReading.
+
+ For details about how the sensor works, see \l QMagnetometerReading.
+
+ \sa QMagnetometerReading
+*/
+
+/*!
+ \fn QMagnetometer::QMagnetometer(QObject *parent)
+
+ Construct the sensor as a child of \a parent.
+*/
+
+/*!
+ \fn QMagnetometer::~QMagnetometer()
+
+ Destroy the sensor. Stops the sensor if it has not already been stopped.
+*/
+
+/*!
+ \fn QMagnetometer::reading() const
+
+ Returns the reading class for this sensor.
+
+ \sa QSensor::reading()
+*/
+
+/*!
+ \property QMagnetometer::returnGeoValues
+ \brief a value indicating if geomagnetic values should be returned.
+
+ Set to true to return geomagnetic flux density.
+ Set to false (the default) to return raw magnetic flux density.
+
+ Note that you must access this property via QObject::property() and QObject::setProperty().
+ The property must be set before calling start().
+*/
+
+#include "moc_qmagnetometer.cpp"
+QT_END_NAMESPACE
+
diff --git a/src/sensors/qmagnetometer.h b/src/sensors/qmagnetometer.h
new file mode 100644
index 0000000..08d0847
--- /dev/null
+++ b/src/sensors/qmagnetometer.h
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QMAGNETOMETER_H
+#define QMAGNETOMETER_H
+
+#include "qsensor.h"
+
+QT_BEGIN_NAMESPACE
+
+class QMagnetometerReadingPrivate;
+
+class Q_SENSORS_EXPORT QMagnetometerReading : public QSensorReading
+{
+ Q_OBJECT
+ Q_PROPERTY(qreal x READ x)
+ Q_PROPERTY(qreal y READ y)
+ Q_PROPERTY(qreal z READ z)
+ Q_PROPERTY(qreal calibrationLevel READ calibrationLevel)
+ DECLARE_READING(QMagnetometerReading)
+public:
+ qreal x() const;
+ void setX(qreal x);
+
+ qreal y() const;
+ void setY(qreal y);
+
+ qreal z() const;
+ void setZ(qreal z);
+
+ qreal calibrationLevel() const;
+ void setCalibrationLevel(qreal calibrationLevel);
+};
+
+class Q_SENSORS_EXPORT QMagnetometerFilter : public QSensorFilter
+{
+public:
+ virtual bool filter(QMagnetometerReading *reading) = 0;
+private:
+ bool filter(QSensorReading *reading) { return filter(static_cast<QMagnetometerReading*>(reading)); }
+};
+
+class Q_SENSORS_EXPORT QMagnetometer : public QSensor
+{
+ Q_OBJECT
+#ifdef Q_QDOC
+ Q_PROPERTY(bool returnGeoValues)
+#endif
+public:
+ explicit QMagnetometer(QObject *parent = 0) : QSensor(QMagnetometer::type, parent) {}
+ virtual ~QMagnetometer() {}
+ QMagnetometerReading *reading() const { return static_cast<QMagnetometerReading*>(QSensor::reading()); }
+ static char const * const type;
+};
+
+QT_END_NAMESPACE
+
+#endif
+
diff --git a/src/sensors/qmagnetometer_p.h b/src/sensors/qmagnetometer_p.h
new file mode 100644
index 0000000..a8a5734
--- /dev/null
+++ b/src/sensors/qmagnetometer_p.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QMAGNETOMETER_P_H
+#define QMAGNETOMETER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+QT_BEGIN_NAMESPACE
+
+class QMagnetometerReadingPrivate
+{
+public:
+ QMagnetometerReadingPrivate()
+ : x(0)
+ , y(0)
+ , z(0)
+ , calibrationLevel(0)
+ {
+ }
+
+ qreal x;
+ qreal y;
+ qreal z;
+ qreal calibrationLevel;
+};
+
+QT_END_NAMESPACE
+
+#endif
+
diff --git a/src/sensors/qmobilitypluginsearch.h b/src/sensors/qmobilitypluginsearch.h
new file mode 100644
index 0000000..7485154
--- /dev/null
+++ b/src/sensors/qmobilitypluginsearch.h
@@ -0,0 +1,172 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef QMOBILITYPLUGINSEARCH_H
+#define QMOBILITYPLUGINSEARCH_H
+
+#include <QCoreApplication>
+#include <QStringList>
+#include <QDir>
+#include <QDebug>
+
+#if defined(Q_OS_SYMBIAN)
+# include <f32file.h>
+#endif
+
+QT_BEGIN_NAMESPACE
+
+#if defined(Q_OS_SYMBIAN)
+static inline bool qSymbian_CheckDir(const QDir& dir, RFs& rfs)
+{
+ bool pathFound = false;
+ // In Symbian, going cdUp() in a c:/private/<uid3>/ will result in *platsec* error at fileserver (requires AllFiles capability)
+ // Also, trying to cd() to a nonexistent directory causes *platsec* error. This does not cause functional harm, but should
+ // nevertheless be changed to use native Symbian methods to avoid unnecessary platsec warnings (as per qpluginloader.cpp).
+ // Use native Symbian code to check for directory existence, because checking
+ // for files from under non-existent protected dir like E:/private/<uid> using
+ // QDir::exists causes platform security violations on most apps.
+ QString nativePath = QDir::toNativeSeparators(dir.absolutePath());
+ TPtrC ptr = TPtrC16(static_cast<const TUint16*>(nativePath.utf16()), nativePath.length());
+ TUint attributes;
+ TInt err = rfs.Att(ptr, attributes);
+ if (err == KErrNone) {
+ // yes, the directory exists.
+ pathFound = true;
+ }
+ return pathFound;
+}
+#define CHECKDIR(dir) qSymbian_CheckDir(dir, rfs)
+#else
+#define CHECKDIR(dir) (dir).exists()
+#endif
+
+inline QStringList mobilityPlugins(const QString& plugintype)
+{
+#if !defined QT_NO_DEBUG
+ const bool showDebug = qgetenv("QT_DEBUG_PLUGINS").toInt() > 0;
+#endif
+
+ QStringList paths = QCoreApplication::libraryPaths();
+/*#ifdef QTM_PLUGIN_PATH
+ paths << QLatin1String(QTM_PLUGIN_PATH);
+#endif*/
+#if !defined QT_NO_DEBUG
+ if (showDebug)
+ qDebug() << "Plugin paths:" << paths;
+#endif
+
+#if defined(Q_OS_SYMBIAN)
+ RFs rfs;
+ qt_symbian_throwIfError(rfs.Connect());
+#endif
+
+ // Temp variable to avoid multiple identical paths
+ // (we don't convert the list to set first, because that loses the order)
+ QSet<QString> processed;
+
+ /* The list of discovered plugins */
+ QStringList plugins;
+
+ /* Enumerate our plugin paths */
+ for (int i=0; i < paths.count(); i++) {
+ if (processed.contains(paths.at(i)))
+ continue;
+ processed.insert(paths.at(i));
+ QDir pluginsDir(paths.at(i));
+ if (!CHECKDIR(pluginsDir))
+ continue;
+
+#if defined(Q_OS_WIN)
+ if (pluginsDir.dirName().toLower() == QLatin1String("debug") || pluginsDir.dirName().toLower() == QLatin1String("release"))
+ pluginsDir.cdUp();
+#elif defined(Q_OS_MAC)
+ if (pluginsDir.dirName() == QLatin1String("MacOS")) {
+ pluginsDir.cdUp();
+ pluginsDir.cdUp();
+ pluginsDir.cdUp();
+ }
+#endif
+
+ QString subdir(QLatin1String("plugins/"));
+ subdir += plugintype;
+ if (pluginsDir.path().endsWith(QLatin1String("/plugins"))
+ || pluginsDir.path().endsWith(QLatin1String("/plugins/")))
+ subdir = plugintype;
+
+ if (CHECKDIR(QDir(pluginsDir.filePath(subdir)))) {
+ pluginsDir.cd(subdir);
+ QStringList files = pluginsDir.entryList(QDir::Files);
+
+#if !defined QT_NO_DEBUG
+ if (showDebug)
+ qDebug() << "Looking for " << plugintype << " plugins in" << pluginsDir.path() << files;
+#endif
+
+ for (int j=0; j < files.count(); j++) {
+ plugins << pluginsDir.absoluteFilePath(files.at(j));
+ }
+ }
+ }
+
+ /* Add application path + plugintype */
+ QDir appldir(QCoreApplication::applicationDirPath());
+ if(appldir.cd(plugintype)){
+ if (!processed.contains(appldir.absolutePath())){
+ processed.insert(appldir.absolutePath());
+ QStringList files = appldir.entryList(QDir::Files);
+#if !defined QT_NO_DEBUG
+ if (showDebug)
+ qDebug() << "Looking for " << plugintype << " plugins in" << appldir.path() << files;
+#endif
+ for (int j=0; j < files.count(); j++) {
+ plugins << appldir.absoluteFilePath(files.at(j));
+ }
+ }
+ }
+
+#if defined(Q_OS_SYMBIAN)
+ rfs.Close();
+#endif
+ return plugins;
+}
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/sensors/qorientationsensor.cpp b/src/sensors/qorientationsensor.cpp
new file mode 100644
index 0000000..10632a3
--- /dev/null
+++ b/src/sensors/qorientationsensor.cpp
@@ -0,0 +1,193 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qorientationsensor.h"
+#include "qorientationsensor_p.h"
+
+QT_BEGIN_NAMESPACE
+
+IMPLEMENT_READING(QOrientationReading)
+
+/*!
+ \class QOrientationReading
+ \ingroup sensors_reading
+ \inmodule QtSensors
+ \since 1.0
+
+ \brief The QOrientationReading class represents one reading from the
+ orientation sensor.
+
+ The orientation sensor reports the orientation of the device. As it operates below
+ the UI level it does not report on or even know how the UI is rotated. Most importantly
+ this means that this sensor cannot be used to detect if a device is in portrait or
+ landscape mode.
+
+ This sensor is useful to detect that a particular side of the device is pointing up.
+
+ \section2 QOrientationReading Units
+ The orientation sensor returns the orientation of the device using
+ the pre-defined values found in the QOrientationReading::Orientation
+ enum.
+*/
+
+/*!
+ \enum QOrientationReading::Orientation
+
+ This enum represents the orientation of the device.
+
+ To explain the meaning of each value it is helpful to refer to the following diagram.
+
+ \image sensors-sides.jpg
+
+ The orientations are shown here in order: TopUp, TopDown, LeftUp, RightUp, FaceUp, FaceDown.
+
+ \image sensors-orientation.jpg
+
+ \value Undefined The orientation is unknown.
+ \value TopUp The Top edge of the device is pointing up.
+ \value TopDown The Top edge of the device is pointing down.
+ \value LeftUp The Left edge of the device is pointing up.
+ \value RightUp The Right edge of the device is pointing up.
+ \value FaceUp The Face of the device is pointing up.
+ \value FaceDown The Face of the device is pointing down.
+
+ It should be noted that the orientation sensor reports the orientation of the device
+ and not the UI. The orientation of the device will not change just because the UI is
+ rotated. This means this sensor cannot be used to detect if a device is in portrait
+ or landscape mode.
+*/
+
+/*!
+ \property QOrientationReading::orientation
+ \brief the orientation of the device.
+
+ The unit is an enumeration describing the orientation of the device.
+
+ \sa {QOrientationReading Units}
+*/
+
+QOrientationReading::Orientation QOrientationReading::orientation() const
+{
+ return static_cast<QOrientationReading::Orientation>(d->orientation);
+}
+
+/*!
+ Sets the \a orientation for the reading.
+*/
+void QOrientationReading::setOrientation(QOrientationReading::Orientation orientation)
+{
+ switch (orientation) {
+ case TopUp:
+ case TopDown:
+ case LeftUp:
+ case RightUp:
+ case FaceUp:
+ case FaceDown:
+ d->orientation = orientation;
+ break;
+ default:
+ d->orientation = Undefined;
+ break;
+ }
+}
+
+// =====================================================================
+
+/*!
+ \class QOrientationFilter
+ \ingroup sensors_filter
+ \inmodule QtSensors
+
+ \brief The QOrientationFilter class is a convenience wrapper around QSensorFilter.
+
+ The only difference is that the filter() method features a pointer to QOrientationReading
+ instead of QSensorReading.
+*/
+
+/*!
+ \fn QOrientationFilter::filter(QOrientationReading *reading)
+
+ Called when \a reading changes. Returns false to prevent the reading from propagating.
+
+ \sa QSensorFilter::filter()
+*/
+
+char const * const QOrientationSensor::type("QOrientationSensor");
+
+/*!
+ \class QOrientationSensor
+ \ingroup sensors_type
+ \inmodule QtSensors
+
+ \brief The QOrientationSensor class is a convenience wrapper around QSensor.
+
+ The only behavioural difference is that this class sets the type properly.
+
+ This class also features a reading() function that returns a QOrientationReading instead of a QSensorReading.
+
+ For details about how the sensor works, see \l QOrientationReading.
+
+ \sa QOrientationReading
+*/
+
+/*!
+ \fn QOrientationSensor::QOrientationSensor(QObject *parent)
+
+ Construct the sensor as a child of \a parent.
+*/
+
+/*!
+ \fn QOrientationSensor::~QOrientationSensor()
+
+ Destroy the sensor. Stops the sensor if it has not already been stopped.
+*/
+
+/*!
+ \fn QOrientationSensor::reading() const
+
+ Returns the reading class for this sensor.
+
+ \sa QSensor::reading()
+*/
+
+#include "moc_qorientationsensor.cpp"
+QT_END_NAMESPACE
+
diff --git a/src/sensors/qorientationsensor.h b/src/sensors/qorientationsensor.h
new file mode 100644
index 0000000..404d64c
--- /dev/null
+++ b/src/sensors/qorientationsensor.h
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QORIENTATIONSENSOR_H
+#define QORIENTATIONSENSOR_H
+
+#include "qsensor.h"
+
+QT_BEGIN_NAMESPACE
+
+class QOrientationReadingPrivate;
+
+class Q_SENSORS_EXPORT QOrientationReading : public QSensorReading
+{
+ Q_OBJECT
+ Q_ENUMS(Orientation)
+ Q_PROPERTY(Orientation orientation READ orientation)
+ DECLARE_READING(QOrientationReading)
+public:
+ enum Orientation {
+ Undefined = 0,
+ TopUp,
+ TopDown,
+ LeftUp,
+ RightUp,
+ FaceUp,
+ FaceDown,
+ };
+
+ Orientation orientation() const;
+ void setOrientation(Orientation orientation);
+};
+
+class Q_SENSORS_EXPORT QOrientationFilter : public QSensorFilter
+{
+public:
+ virtual bool filter(QOrientationReading *reading) = 0;
+private:
+ bool filter(QSensorReading *reading) { return filter(static_cast<QOrientationReading*>(reading)); }
+};
+
+class Q_SENSORS_EXPORT QOrientationSensor : public QSensor
+{
+ Q_OBJECT
+public:
+ explicit QOrientationSensor(QObject *parent = 0) : QSensor(QOrientationSensor::type, parent) {}
+ virtual ~QOrientationSensor() {}
+ QOrientationReading *reading() const { return static_cast<QOrientationReading*>(QSensor::reading()); }
+ static char const * const type;
+};
+
+QT_END_NAMESPACE
+
+#endif
+
diff --git a/src/sensors/qorientationsensor_p.h b/src/sensors/qorientationsensor_p.h
new file mode 100644
index 0000000..975d80e
--- /dev/null
+++ b/src/sensors/qorientationsensor_p.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QORIENTATIONSENSOR_P_H
+#define QORIENTATIONSENSOR_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+QT_BEGIN_NAMESPACE
+
+class QOrientationReadingPrivate
+{
+public:
+ QOrientationReadingPrivate()
+ : orientation(0)
+ {
+ }
+
+ int orientation;
+};
+
+QT_END_NAMESPACE
+
+#endif
+
diff --git a/src/sensors/qproximitysensor.cpp b/src/sensors/qproximitysensor.cpp
new file mode 100644
index 0000000..9f44efe
--- /dev/null
+++ b/src/sensors/qproximitysensor.cpp
@@ -0,0 +1,149 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qproximitysensor.h"
+#include "qproximitysensor_p.h"
+
+QT_BEGIN_NAMESPACE
+
+IMPLEMENT_READING(QProximityReading)
+
+/*!
+ \class QProximityReading
+ \ingroup sensors_reading
+ \inmodule QtSensors
+ \since 1.0
+
+ \brief The QProximityReading class represents one reading from the
+ proximity sensor.
+
+ \target QProximityReading_Units
+ The proximity sensor can only indicate if an object is close or not.
+
+ The distance at which an object is considered close is device-specific. This
+ distance may be available in the QSensor::outputRanges property.
+*/
+
+/*!
+ \property QProximityReading::close
+ \brief a value indicating if something is close.
+
+ Set to true if something is close.
+ Set to false is nothing is close.
+
+ \sa QProximityReading_Units
+*/
+
+bool QProximityReading::close() const
+{
+ return d->close;
+}
+
+/*!
+ Sets the close value to \a close.
+*/
+void QProximityReading::setClose(bool close)
+{
+ d->close = close;
+}
+
+// =====================================================================
+
+/*!
+ \class QProximityFilter
+ \ingroup sensors_filter
+ \inmodule QtSensors
+
+ \brief The QProximityFilter class is a convenience wrapper around QSensorFilter.
+
+ The only difference is that the filter() method features a pointer to QProximityReading
+ instead of QSensorReading.
+*/
+
+/*!
+ \fn QProximityFilter::filter(QProximityReading *reading)
+
+ Called when \a reading changes. Returns false to prevent the reading from propagating.
+
+ \sa QSensorFilter::filter()
+*/
+
+char const * const QProximitySensor::type("QProximitySensor");
+
+/*!
+ \class QProximitySensor
+ \ingroup sensors_type
+ \inmodule QtSensors
+
+ \brief The QProximitySensor class is a convenience wrapper around QSensor.
+
+ The only behavioural difference is that this class sets the type properly.
+
+ This class also features a reading() function that returns a QProximityReading instead of a QSensorReading.
+
+ For details about how the sensor works, see \l QProximityReading.
+
+ \sa QProximityReading
+*/
+
+/*!
+ \fn QProximitySensor::QProximitySensor(QObject *parent)
+
+ Construct the sensor as a child of \a parent.
+*/
+
+/*!
+ \fn QProximitySensor::~QProximitySensor()
+
+ Destroy the sensor. Stops the sensor if it has not already been stopped.
+*/
+
+/*!
+ \fn QProximitySensor::reading() const
+
+ Returns the reading class for this sensor.
+
+ \sa QSensor::reading()
+*/
+
+#include "moc_qproximitysensor.cpp"
+QT_END_NAMESPACE
+
diff --git a/src/sensors/qproximitysensor.h b/src/sensors/qproximitysensor.h
new file mode 100644
index 0000000..87b76a9
--- /dev/null
+++ b/src/sensors/qproximitysensor.h
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QPROXIMITYSENSOR_H
+#define QPROXIMITYSENSOR_H
+
+#include "qsensor.h"
+
+QT_BEGIN_NAMESPACE
+
+class QProximityReadingPrivate;
+
+class Q_SENSORS_EXPORT QProximityReading : public QSensorReading
+{
+ Q_OBJECT
+ Q_PROPERTY(bool close READ close)
+ DECLARE_READING(QProximityReading)
+public:
+ bool close() const;
+ void setClose(bool close);
+};
+
+class Q_SENSORS_EXPORT QProximityFilter : public QSensorFilter
+{
+public:
+ virtual bool filter(QProximityReading *reading) = 0;
+private:
+ bool filter(QSensorReading *reading) { return filter(static_cast<QProximityReading*>(reading)); }
+};
+
+class Q_SENSORS_EXPORT QProximitySensor : public QSensor
+{
+ Q_OBJECT
+public:
+ explicit QProximitySensor(QObject *parent = 0) : QSensor(QProximitySensor::type, parent) {}
+ virtual ~QProximitySensor() {}
+ QProximityReading *reading() const { return static_cast<QProximityReading*>(QSensor::reading()); }
+ static char const * const type;
+};
+
+QT_END_NAMESPACE
+
+#endif
+
diff --git a/src/sensors/qproximitysensor_p.h b/src/sensors/qproximitysensor_p.h
new file mode 100644
index 0000000..fc6604c
--- /dev/null
+++ b/src/sensors/qproximitysensor_p.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QPROXIMITYSENSOR_P_H
+#define QPROXIMITYSENSOR_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+QT_BEGIN_NAMESPACE
+
+class QProximityReadingPrivate
+{
+public:
+ QProximityReadingPrivate()
+ : close(false)
+ {
+ }
+
+ bool close;
+};
+
+QT_END_NAMESPACE
+
+#endif
+
diff --git a/src/sensors/qrotationsensor.cpp b/src/sensors/qrotationsensor.cpp
new file mode 100644
index 0000000..8269202
--- /dev/null
+++ b/src/sensors/qrotationsensor.cpp
@@ -0,0 +1,238 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qrotationsensor.h"
+#include "qrotationsensor_p.h"
+
+QT_BEGIN_NAMESPACE
+
+IMPLEMENT_READING(QRotationReading)
+
+/*!
+ \class QRotationReading
+ \ingroup sensors_reading
+ \inmodule QtSensors
+ \since 1.0
+
+ \brief The QRotationReading class represents one reading from the
+ rotation sensor.
+
+ \section2 QRotationReading Units
+
+ The rotation reading contains 3 angles, measured in degrees that define
+ the orientation of the device in three-dimensional space. These angles
+ are similar to yaw, pitch and roll but are defined using only right hand
+ rotation with axes as defined by the right hand cartesian coordinate system.
+
+ \image sensors-rotation.jpg
+
+ The three angles are applied to the device in the following order.
+
+ \list
+ \o Right-handed rotation z (-180, 180]. Starting from the y-axis and
+ incrementing in the counter-clockwise direction.
+ \o Right-handed rotation x [-90, 90]. Starting from the new
+ (once-rotated) y-axis and incrementing towards the z-axis.
+ \o Right-handed rotation y (-180, 180]. Starting from the new
+ (twice-rotated) z-axis and incrementing towards the x-axis.
+ \endlist
+
+ Here is a visualization showing the order in which angles are applied.
+
+ \image sensors-rotation-anim.gif
+
+ The 0 point for the z angle is defined as a fixed, external entity and
+ is device-specific. While magnetic North is typically used as this
+ reference point it may not be. Do not attempt to compare values
+ for the z angle between devices or even on the same device if it has
+ moved a significant distance.
+
+ If the device cannot detect a fixed, external entity the z angle will
+ always be 0 and the QRotationSensor::hasZ property will be set to false.
+
+ The 0 point for the x and y angles are defined as when the x and y axes
+ of the device are oriented towards the horizon. Here is an example of
+ how the x value will change with device movement.
+
+ \image sensors-rotation2.jpg
+
+ Here is an example of how the y value will change with device movement.
+
+ \image sensors-rotation3.jpg
+
+ Note that when x is 90 or -90, values for z and y achieve rotation around
+ the same axis (due to the order of operations). In this case the y
+ rotation will be 0.
+*/
+
+/*!
+ \property QRotationReading::x
+ \brief the rotation around the x axis.
+
+ Measured as degrees.
+ \sa {QRotationReading Units}
+*/
+
+qreal QRotationReading::x() const
+{
+ return d->x;
+}
+
+/*!
+ Sets the rotation around the x axis to \a x.
+*/
+void QRotationReading::setX(qreal x)
+{
+ d->x = x;
+}
+
+/*!
+ \property QRotationReading::y
+ \brief the rotation around the y axis.
+
+ Measured as degrees.
+ \sa {QRotationReading Units}
+*/
+
+qreal QRotationReading::y() const
+{
+ return d->y;
+}
+
+/*!
+ Sets the rotation around the y axis to \a y.
+*/
+void QRotationReading::setY(qreal y)
+{
+ d->y = y;
+}
+
+/*!
+ \property QRotationReading::z
+ \brief the rotation around the z axis.
+
+ Measured as degrees.
+ \sa {QRotationReading Units}
+*/
+
+qreal QRotationReading::z() const
+{
+ return d->z;
+}
+
+/*!
+ Sets the rotation around the z axis to \a z.
+*/
+void QRotationReading::setZ(qreal z)
+{
+ d->z = z;
+}
+
+// =====================================================================
+
+/*!
+ \class QRotationFilter
+ \ingroup sensors_filter
+ \inmodule QtSensors
+
+ \brief The QRotationFilter class is a convenience wrapper around QSensorFilter.
+
+ The only difference is that the filter() method features a pointer to QRotationReading
+ instead of QSensorReading.
+*/
+
+/*!
+ \fn QRotationFilter::filter(QRotationReading *reading)
+
+ Called when \a reading changes. Returns false to prevent the reading from propagating.
+
+ \sa QSensorFilter::filter()
+*/
+
+char const * const QRotationSensor::type("QRotationSensor");
+
+/*!
+ \class QRotationSensor
+ \ingroup sensors_type
+ \inmodule QtSensors
+
+ \brief The QRotationSensor class is a convenience wrapper around QSensor.
+
+ The only behavioural difference is that this class sets the type properly.
+
+ This class also features a reading() function that returns a QRotationReading instead of a QSensorReading.
+
+ For details about how the sensor works, see \l QRotationReading.
+
+ \sa QRotationReading
+*/
+
+/*!
+ \fn QRotationSensor::QRotationSensor(QObject *parent)
+
+ Construct the sensor as a child of \a parent.
+*/
+
+/*!
+ \fn QRotationSensor::~QRotationSensor()
+
+ Destroy the sensor. Stops the sensor if it has not already been stopped.
+*/
+
+/*!
+ \fn QRotationSensor::reading() const
+
+ Returns the reading class for this sensor.
+
+ \sa QSensor::reading()
+*/
+
+/*!
+ \property QRotationSensor::hasZ
+ \brief a value indicating if the z angle is available.
+
+ Returns true if z is available.
+ Returns false if z is not available.
+*/
+
+#include "moc_qrotationsensor.cpp"
+QT_END_NAMESPACE
+
diff --git a/src/sensors/qrotationsensor.h b/src/sensors/qrotationsensor.h
new file mode 100644
index 0000000..501fb7c
--- /dev/null
+++ b/src/sensors/qrotationsensor.h
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QROTATIONSENSOR_H
+#define QROTATIONSENSOR_H
+
+#include "qsensor.h"
+
+QT_BEGIN_NAMESPACE
+
+class QRotationReadingPrivate;
+
+class Q_SENSORS_EXPORT QRotationReading : public QSensorReading
+{
+ Q_OBJECT
+ Q_PROPERTY(qreal x READ x)
+ Q_PROPERTY(qreal y READ y)
+ Q_PROPERTY(qreal z READ z)
+ DECLARE_READING(QRotationReading)
+public:
+ qreal x() const;
+ void setX(qreal x);
+
+ qreal y() const;
+ void setY(qreal y);
+
+ qreal z() const;
+ void setZ(qreal z);
+};
+
+class Q_SENSORS_EXPORT QRotationFilter : public QSensorFilter
+{
+public:
+ virtual bool filter(QRotationReading *reading) = 0;
+private:
+ bool filter(QSensorReading *reading) { return filter(static_cast<QRotationReading*>(reading)); }
+};
+
+class Q_SENSORS_EXPORT QRotationSensor : public QSensor
+{
+ Q_OBJECT
+#ifdef Q_QDOC
+ Q_PROPERTY(bool hasZ)
+#endif
+public:
+ explicit QRotationSensor(QObject *parent = 0) : QSensor(QRotationSensor::type, parent) {}
+ virtual ~QRotationSensor() {}
+ QRotationReading *reading() const { return static_cast<QRotationReading*>(QSensor::reading()); }
+ static char const * const type;
+};
+
+QT_END_NAMESPACE
+
+#endif
+
diff --git a/src/sensors/qrotationsensor_p.h b/src/sensors/qrotationsensor_p.h
new file mode 100644
index 0000000..7c8bd19
--- /dev/null
+++ b/src/sensors/qrotationsensor_p.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QROTATIONSENSOR_P_H
+#define QROTATIONSENSOR_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+QT_BEGIN_NAMESPACE
+
+class QRotationReadingPrivate
+{
+public:
+ QRotationReadingPrivate()
+ : x(0)
+ , y(0)
+ , z(0)
+ {
+ }
+
+ qreal x;
+ qreal y;
+ qreal z;
+};
+
+QT_END_NAMESPACE
+
+#endif
+
diff --git a/src/sensors/qsensor.cpp b/src/sensors/qsensor.cpp
new file mode 100644
index 0000000..28cbd20
--- /dev/null
+++ b/src/sensors/qsensor.cpp
@@ -0,0 +1,982 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsensor.h"
+#include "qsensor_p.h"
+#include "qsensorbackend.h"
+#include "qsensormanager.h"
+#include <QDebug>
+#include <QMetaProperty>
+#include <QTimer>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \typedef qtimestamp
+ \relates QSensor
+
+ Sensor timestamps are represented by this typedef which is a 64 bit unsigned integer.
+
+ Timestamps values are microseconds since a fixed point.
+ You can use timestamps to see how far apart two sensor readings are.
+
+ Note that sensor timestamps from different sensors may not be directly
+ comparable (as they may choose different fixed points for their reference).
+
+ \bold{Note that some platforms do not deliver timestamps correctly}.
+ Applications should be prepared for occasional issues that cause timestamps to jump
+ forwards or backwards. The \l{sensors-api.html#platform-notes}{platform notes} have
+ more details.
+*/
+
+/*!
+ \typedef qrange
+ \relates QSensor
+
+ This type is defined as a QPair.
+
+ \code
+ typedef QPair<int,int> qrange;
+ \endcode
+
+ \sa QPair, qrangelist, QSensor::availableDataRates
+*/
+
+/*!
+ \typedef qrangelist
+ \relates QSensor
+
+ This type is defined as a list of qrange values.
+
+ \code
+ typedef QList<qrange> qrangelist;
+ \endcode
+
+ \sa QList, qrange, QSensor::availableDataRates
+*/
+
+/*!
+ \class qoutputrange
+ \relates QSensor
+ \brief The qoutputrange class holds the specifics of an output range.
+
+ The class is defined as a simple struct.
+
+ \code
+ struct qoutputrange
+ {
+ qreal maximum;
+ qreal minimum;
+ qreal accuracy;
+ };
+ \endcode
+
+ Each output range specifies a minimum and maximum value as well as an accuracy value.
+ The accuracy value represents the resolution of the sensor. It is the smallest change
+ the sensor can detect and is expressed using the same units as the minimum and maximum.
+
+ Sensors must often trade off range for accuracy. To allow the user to determine which of
+ these are more important the sensor may offer several output ranges. One output
+ range may have reduced minimum and maximum values and increased sensitivity. Another output
+ range may have higher minimum and maximum values with reduced sensitivity. Note that higher
+ sensitivities will be represented by smaller accuracy values.
+
+ An example of this tradeoff can be seen by examining the LIS302DL accelerometer. It has only
+ 256 possible values to report with. These values are scaled so that they can represent either
+ -2G to +2G (with an accuracy value of 0.015G) or -8G to +8G (with an accuracy value of 0.06G).
+
+ \sa qoutputrangelist, QSensor::outputRanges
+*/
+
+/*!
+ \variable qoutputrange::maximum
+
+ This is the maximum value for this output range.
+ The units are defined by the sensor.
+*/
+
+/*!
+ \variable qoutputrange::minimum
+
+ This is the minimum value for this output range.
+ The units are defined by the sensor.
+*/
+
+/*!
+ \variable qoutputrange::accuracy
+
+ The accuracy value represents the resolution of the sensor. It is the smallest change
+ the sensor can detect and is expressed using the same units as the minimum and maximum.
+*/
+
+/*!
+ \typedef qoutputrangelist
+ \relates QSensor
+
+ This type is defined as a list of qoutputrange values.
+
+ \code
+ typedef QList<qoutputrange> qoutputrangelist;
+ \endcode
+
+ \sa QList, qoutputrange, QSensor::outputRanges
+*/
+
+// A bit of a hack to call qRegisterMetaType when the library is loaded.
+static int qtimestamp_id = qRegisterMetaType<qtimestamp>("qtimestamp");
+static int qrange_id = qRegisterMetaType<qrange>("qrange");
+static int qrangelist_id = qRegisterMetaType<qrangelist>("qrangelist");
+static int qoutputrangelist_id = qRegisterMetaType<qoutputrangelist>("qoutputrangelist");
+
+// =====================================================================
+
+/*!
+ \class QSensor
+ \ingroup sensors_main
+ \inmodule QtSensors
+
+ \brief The QSensor class represents a single hardware sensor.
+
+ The life cycle of a sensor is typically:
+
+ \list
+ \o Create a sub-class of QSensor 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
+
+ The sensor data is delivered via QSensorData and its sub-classes.
+
+ \sa QSensorReading
+*/
+
+/*!
+ Construct the \a type sensor as a child of \a parent.
+*/
+QSensor::QSensor(const QByteArray &type, QObject *parent)
+ : QObject(parent)
+ , d(new QSensorPrivate)
+{
+ d->type = type;
+ registerInstance(); // so the availableSensorsChanged() signal works
+}
+
+/*!
+ Destroy the sensor. Stops the sensor if it has not already been stopped.
+*/
+QSensor::~QSensor()
+{
+ stop();
+ Q_FOREACH (QSensorFilter *filter, d->filters)
+ filter->setSensor(0);
+ delete d->backend;
+ d->backend = 0;
+ // owned by the backend
+ d->device_reading = 0;
+ d->filter_reading = 0;
+ d->cache_reading = 0;
+}
+
+/*!
+ \property QSensor::connectedToBackend
+ \brief a value indicating if the sensor has connected to a backend.
+
+ A sensor that has not been connected to a backend cannot do anything useful.
+
+ Call the connectToBackend() method to force the sensor to connect to a backend
+ immediately. This is automatically called if you call start() so you only need
+ to do this if you need access to sensor properties (ie. to poll the sensor's
+ meta-data before you use it).
+*/
+
+bool QSensor::isConnectedToBackend() const
+{
+ return (d->backend != 0);
+}
+
+/*!
+ \property QSensor::sensorid
+ \brief the backend identifier for the sensor.
+
+ Note that the identifier is filled out automatically
+ when the sensor is connected to a backend. If you want
+ to connect a specific backend, you should call
+ setIdentifier() before connectToBackend().
+*/
+
+QByteArray QSensor::identifier() const
+{
+ return d->identifier;
+}
+
+void QSensor::setIdentifier(const QByteArray &identifier)
+{
+ if (isConnectedToBackend()) {
+ qWarning() << "ERROR: Cannot call QSensor::setIdentifier while connected to a backend!";
+ return;
+ }
+ d->identifier = identifier;
+}
+
+/*!
+ \property QSensor::type
+ \brief the type of the sensor.
+*/
+
+QByteArray QSensor::type() const
+{
+ return d->type;
+}
+
+/*!
+ Try to connect to a sensor backend.
+
+ Returns true if a suitable backend could be found, false otherwise.
+
+ The type must be set before calling this method if you are using QSensor directly.
+
+ \sa isConnectedToBackend()
+*/
+bool QSensor::connectToBackend()
+{
+ if (isConnectedToBackend())
+ return true;
+
+ d->backend = QSensorManager::createBackend(this);
+
+ // Reset the properties to their default values and re-set them now so
+ // that the logic we've put into the setters gets called.
+ if (d->dataRate != 0) {
+ int tmp = d->dataRate;
+ d->dataRate = 0;
+ setDataRate(tmp);
+ }
+ if (d->outputRange != -1) {
+ int tmp = d->outputRange;
+ d->outputRange = -1;
+ setOutputRange(tmp);
+ }
+
+ return isConnectedToBackend();
+}
+
+/*!
+ \property QSensor::busy
+ \brief a value to indicate if the sensor is busy.
+
+ Some sensors may be on the system but unavailable for use.
+ This function will return true if the sensor is busy. You
+ will not be able to start() the sensor.
+
+ Note that this function does not return true if you
+ are using the sensor, only if another process is using
+ the sensor.
+
+ \sa busyChanged()
+*/
+
+bool QSensor::isBusy() const
+{
+ return d->busy;
+}
+
+/*!
+ \fn QSensor::busyChanged()
+
+ This signal is emitted when the sensor is no longer busy.
+ This can be used to grab a sensor when it becomes available.
+
+ \code
+ sensor.start();
+ if (sensor.isBusy()) {
+ // need to wait for busyChanged signal and try again
+ }
+ \endcode
+*/
+
+/*!
+ \property QSensor::active
+ \brief a value to indicate if the sensor is active.
+
+ This is true if the sensor is active (returning values). This is false otherwise.
+
+ Note that setting this value to true will not have an immediate effect. Instead,
+ the sensor will be started once the event loop has been reached.
+*/
+void QSensor::setActive(bool active)
+{
+ if (active == isActive())
+ return;
+
+ if (active)
+ QTimer::singleShot(0, this, SLOT(start())); // delay ensures all properties have been set if using QML
+ else
+ stop();
+}
+
+bool QSensor::isActive() const
+{
+ return d->active;
+}
+
+/*!
+ \property QSensor::availableDataRates
+ \brief the data rates that the sensor supports.
+
+ This is a list of the data rates that the sensor supports.
+ Measured in Hertz.
+
+ Entries in the list can represent discrete rates or a
+ continuous range of rates.
+ A discrete rate is noted by having both values the same.
+
+ See the sensor_explorer example for an example of how to interpret and use
+ this information.
+
+ Note that this information is not mandatory as not all sensors have a rate at which
+ they run. In such cases, the list will be empty.
+
+ \sa QSensor::dataRate, qrangelist
+*/
+
+qrangelist QSensor::availableDataRates() const
+{
+ return d->availableDataRates;
+}
+
+/*!
+ \property QSensor::dataRate
+ \brief the data rate that the sensor should be run at.
+
+ Measured in Hertz.
+
+ The data rate is the maximum frequency at which the sensor can detect changes.
+
+ Setting this property is not portable and can cause conflicts with other
+ applications. Check with the sensor backend and platform documentation for
+ any policy regarding multiple applications requesting a data rate.
+
+ The default value (0) means that the app does not care what the data rate is.
+ Applications should consider using a timer-based poll of the current value or
+ ensure that the code that processes values can run very quickly as the platform
+ may provide updates hundreds of times each second.
+
+ This should be set before calling start() because the sensor may not
+ notice changes to this value while it is running.
+
+ Note that there is no mechanism to determine the current data rate in use by the
+ platform.
+
+ \sa QSensor::availableDataRates
+*/
+
+int QSensor::dataRate() const
+{
+ return d->dataRate;
+}
+
+void QSensor::setDataRate(int rate)
+{
+ if (rate == 0 || !isConnectedToBackend()) {
+ d->dataRate = rate;
+ return;
+ }
+ bool warn = true;
+ Q_FOREACH (const qrange &range, d->availableDataRates) {
+ if (rate >= range.first && rate <= range.second) {
+ warn = false;
+ d->dataRate = rate;
+ break;
+ }
+ }
+ if (warn) {
+ qWarning() << "setDataRate:" << rate << "is not supported by the sensor.";
+ }
+}
+
+/*!
+ Start retrieving values from the sensor.
+ Returns true if the sensor was started, false otherwise.
+
+ The sensor may fail to start for several reasons.
+
+ Once an application has started a sensor it must wait until the sensor receives a
+ new value before it can query the sensor's values. This is due to how the sensor
+ receives values from the system. Sensors do not (in general) poll for new values,
+ rather new values are pushed to the sensors as they happen.
+
+ For example, this code will not work as intended.
+
+ \badcode
+ sensor->start();
+ sensor->reading()->x(); // no data available
+ \endcode
+
+ To work correctly, the code that accesses the reading should ensure the
+ readingChanged() signal has been emitted.
+
+ \code
+ connect(sensor, SIGNAL(readingChanged()), this, SLOT(checkReading()));
+ sensor->start();
+ }
+ void MyClass::checkReading() {
+ sensor->reading()->x();
+ \endcode
+
+ \sa QSensor::busy
+*/
+bool QSensor::start()
+{
+ if (isActive())
+ return true;
+ if (!connectToBackend())
+ return false;
+ // Set these flags to their defaults
+ d->active = true;
+ d->busy = false;
+ // Backend will update the flags appropriately
+ d->backend->start();
+ Q_EMIT activeChanged();
+ return isActive();
+}
+
+/*!
+ Stop retrieving values from the sensor.
+
+ This releases the sensor so that other processes can use it.
+
+ \sa QSensor::busy
+*/
+void QSensor::stop()
+{
+ if (!isConnectedToBackend() || !isActive())
+ return;
+ d->active = false;
+ d->backend->stop();
+ Q_EMIT activeChanged();
+}
+
+/*!
+ \property QSensor::reading
+ \brief the reading class.
+
+ The reading class provides access to sensor readings. The reading object
+ is a volatile cache of the most recent sensor reading that has been received
+ so the application should process readings immediately or save the values
+ somewhere for later processing.
+
+ Note that this will return 0 until a sensor backend is connected to a backend.
+
+ Also note that readings are not immediately available after start() is called.
+ Applications must wait for the readingChanged() signal to be emitted.
+
+ \sa isConnectedToBackend(), start()
+*/
+
+QSensorReading *QSensor::reading() const
+{
+ return d->cache_reading;
+}
+
+/*!
+ Add a \a filter to the sensor.
+
+ The sensor does not take ownership of the filter.
+ QSensorFilter will inform the sensor if it is destroyed.
+
+ \sa QSensorFilter
+*/
+void QSensor::addFilter(QSensorFilter *filter)
+{
+ if (!filter) {
+ qWarning() << "addFilter: passed a null filter!";
+ return;
+ }
+ filter->setSensor(this);
+ d->filters << filter;
+}
+
+/*!
+ Remove \a filter from the sensor.
+
+ \sa QSensorFilter
+*/
+void QSensor::removeFilter(QSensorFilter *filter)
+{
+ if (!filter) {
+ qWarning() << "removeFilter: passed a null filter!";
+ return;
+ }
+ d->filters.removeOne(filter);
+ filter->setSensor(0);
+}
+
+/*!
+ Returns the filters currently attached to the sensor.
+
+ \sa QSensorFilter
+*/
+QList<QSensorFilter*> QSensor::filters() const
+{
+ return d->filters;
+}
+
+/*!
+ \fn QSensor::d_func() const
+ \internal
+*/
+
+/*!
+ \fn QSensor::readingChanged()
+
+ This signal is emitted when a new sensor reading is received.
+
+ The sensor reading can be found in the QSensor::reading property. Note that the
+ reading object is a volatile cache of the most recent sensor reading that has
+ been received so the application should process the reading immediately or
+ save the values somewhere for later processing.
+
+ Before this signal has been emitted for the first time, the reading object will
+ have uninitialized data.
+
+ \sa start()
+*/
+
+/*!
+ \fn QSensor::activeChanged()
+
+ This signal is emitted when the QSensor::active property has changed.
+
+ \sa QSensor::active
+*/
+
+/*!
+ \property QSensor::outputRanges
+ \brief a list of output ranges the sensor supports.
+
+ A sensor may have more than one output range. Typically this is done
+ to give a greater measurement range at the cost of lowering accuracy.
+
+ Note that this information is not mandatory. This information is typically only
+ available for sensors that have selectable output ranges (such as typical
+ accelerometers).
+
+ \sa QSensor::outputRange, qoutputrangelist
+*/
+
+qoutputrangelist QSensor::outputRanges() const
+{
+ return d->outputRanges;
+}
+
+/*!
+ \property QSensor::outputRange
+ \brief the output range in use by the sensor.
+
+ This value represents the index in the QSensor::outputRanges list to use.
+
+ Setting this property is not portable and can cause conflicts with other
+ applications. Check with the sensor backend and platform documentation for
+ any policy regarding multiple applications requesting an output range.
+
+ The default value (-1) means that the app does not care what the output range is.
+
+ Note that there is no mechanism to determine the current output range in use by the
+ platform.
+
+ \sa QSensor::outputRanges
+*/
+
+int QSensor::outputRange() const
+{
+ return d->outputRange;
+}
+
+void QSensor::setOutputRange(int index)
+{
+ if (index == -1 || !isConnectedToBackend()) {
+ d->outputRange = index;
+ return;
+ }
+ bool warn = true;
+ if (index >= 0 && index < d->outputRanges.count()) {
+ warn = false;
+ d->outputRange = index;
+ }
+ if (warn) {
+ qWarning() << "setOutputRange:" << index << "is not supported by the sensor.";
+ }
+}
+
+/*!
+ \property QSensor::description
+ \brief a descriptive string for the sensor.
+*/
+
+QString QSensor::description() const
+{
+ return d->description;
+}
+
+/*!
+ \property QSensor::error
+ \brief the last error code set on the sensor.
+
+ Note that error codes are sensor-specific.
+*/
+
+int QSensor::error() const
+{
+ return d->error;
+}
+
+/*!
+ \fn QSensor::sensorError(int error)
+
+ This signal is emitted when an \a error code is set on the sensor.
+ Note that some errors will cause the sensor to stop working.
+ You should call isActive() to determine if the sensor is still running.
+*/
+
+/*!
+ \fn QSensor::availableSensorsChanged()
+
+ This signal is emitted when the list of available sensors has changed.
+ The sensors available to a program will not generally change over time
+ however some of the avilable sensors may represent hardware that is not
+ permanently connected. For example, a game controller that is connected
+ via bluetooth would become available when it was on and would become
+ unavailable when it was off.
+
+ \sa QSensor::sensorTypes(), QSensor::sensorsForType()
+*/
+
+/*!
+ \property QSensor::maxBufferSize
+
+ The property holds the maximum buffer size.
+
+ Note that this may be undefined, in which case the sensor does not support any form of buffering.
+
+ \sa QSensor::bufferSize, QSensor::efficientBufferSize
+*/
+
+/*!
+ \property QSensor::efficientBufferSize
+
+ The property holds the most efficient buffer size. Normally this is 1 (which means
+ no particular size is most efficient). Some sensor drivers have a FIFO buffer which
+ makes it more efficient to deliver the FIFO's size worth of readings at one time.
+
+ Note that this may be undefined, in which case the sensor does not support any form of buffering.
+
+ \sa QSensor::bufferSize, QSensor::maxBufferSize
+*/
+
+/*!
+ \property QSensor::bufferSize
+
+ This property holds the size of the buffer. By default (and if the property
+ is left undefined), the buffer size is 1, which means no buffering.
+ If the maximum buffer size is 1 (or undefined), then buffering is not supported
+ by the sensor.
+
+ Setting bufferSize greater than maxBufferSize will cause maxBufferSize to be used.
+
+ Buffering is turned on when bufferSize is greater than 1. The sensor will collect
+ the requested number of samples and deliver them all to the application at one time.
+ They will be delivered to the application as a burst of changed readings so it is
+ particularly important that the application processes each reading immediately or
+ saves the values somewhere else.
+
+ If stop() is called when buffering is on-going, the partial buffer is not delivered.
+
+ When the sensor is started with buffering option, values are collected from that
+ moment onwards. There is no pre-existing buffer that can be utilized.
+
+ The buffer size can only be changed while the sensor is not active.
+
+ \sa QSensor::maxBufferSize, QSensor::efficientBufferSize
+*/
+
+// =====================================================================
+
+/*!
+ \class QSensorFilter
+ \ingroup sensors_main
+ \inmodule QtSensors
+
+ \brief The QSensorFilter class provides an efficient
+ callback facility for asynchronous notifications of
+ sensor changes.
+
+ Some sensors (eg. the accelerometer) are often accessed very frequently.
+ This may be slowed down by the use of signals and slots.
+ The QSensorFilter interface provides a more efficient way for the
+ sensor to notify your class that the sensor has changed.
+
+ Additionally, multiple filters can be added to a sensor. They are called
+ in order and each filter has the option to modify the values in the reading
+ or to suppress the reading altogether.
+
+ Note that the values in the class returned by QSensor::reading() will
+ not be updated until after the filters have been run.
+
+ \sa filter()
+*/
+
+/*!
+ \internal
+*/
+QSensorFilter::QSensorFilter()
+ : m_sensor(0)
+{
+}
+
+/*!
+ Notifies the attached sensor (if any) that the filter is being destroyed.
+*/
+QSensorFilter::~QSensorFilter()
+{
+ if (m_sensor)
+ m_sensor->removeFilter(this);
+}
+
+/*!
+ \fn QSensorFilter::filter(QSensorReading *reading)
+
+ This function is called when the sensor \a reading changes.
+
+ The filter can modify the reading.
+
+ Returns true to allow the next filter to receive the value.
+ If this is the last filter, returning true causes the signal
+ to be emitted and the value is stored in the sensor.
+
+ Returns false to drop the reading.
+*/
+
+/*!
+ \internal
+*/
+void QSensorFilter::setSensor(QSensor *sensor)
+{
+ m_sensor = sensor;
+}
+
+// =====================================================================
+
+/*!
+ \class QSensorReading
+ \ingroup sensors_main
+ \inmodule QtSensors
+
+ \brief The QSensorReading class holds the readings from the sensor.
+
+ Note that QSensorReading is not particularly useful by itself. The interesting
+ data for each sensor is defined in a sub-class of QSensorReading.
+*/
+
+/*!
+ \internal
+*/
+QSensorReading::QSensorReading(QObject *parent, QSensorReadingPrivate *_d)
+ : QObject(parent)
+ , d(_d?_d:new QSensorReadingPrivate)
+{
+}
+
+/*!
+ \internal
+*/
+QSensorReading::~QSensorReading()
+{
+}
+
+/*!
+ \property QSensorReading::timestamp
+ \brief the timestamp of the reading.
+
+ \sa qtimestamp
+*/
+
+/*!
+ Returns the timestamp of the reading.
+*/
+qtimestamp QSensorReading::timestamp() const
+{
+ return d->timestamp;
+}
+
+/*!
+ Sets the \a timestamp of the reading.
+*/
+void QSensorReading::setTimestamp(qtimestamp timestamp)
+{
+ d->timestamp = timestamp;
+}
+
+/*!
+ Returns the number of extra properties that the reading has.
+
+ Note that this does not count properties declared in QSensorReading.
+
+ As an example, this returns 3 for QAccelerometerReading because
+ there are 3 properties defined in that class.
+*/
+int QSensorReading::valueCount() const
+{
+ const QMetaObject *mo = metaObject();
+ return mo->propertyCount() - mo->propertyOffset();
+}
+
+/*!
+ Returns the value of the property at \a index.
+
+ Note that this function is slower than calling the data function directly.
+
+ Here is an example of getting a property via the different mechanisms available.
+
+ Accessing directly provides the best performance but requires compile-time knowledge
+ of the data you are accessing.
+
+ \code
+ QAccelerometerReading *reading = ...;
+ qreal x = reading->x();
+ \endcode
+
+ You can also access a property by name. To do this you must call QObject::property().
+
+ \code
+ qreal x = reading->property("x").value<qreal>();
+ \endcode
+
+ Finally, you can access values via numeric index.
+
+ \code
+ qreal x = reading->value(0).value<qreal>();
+ \endcode
+
+ Note that value() can only access properties declared with Q_PROPERTY() in sub-classes
+ of QSensorReading.
+
+ \sa valueCount(), QObject::property()
+*/
+QVariant QSensorReading::value(int index) const
+{
+ // get them meta-object
+ const QMetaObject *mo = metaObject();
+
+ // determine the index of the property we want
+ index += mo->propertyOffset();
+
+ // get the meta-property
+ QMetaProperty property = mo->property(index);
+
+ // read the property
+ return property.read(this);
+}
+
+/*!
+ \fn QSensorReading::copyValuesFrom(QSensorReading *other)
+ \internal
+
+ Copy values from other into this reading. Implemented by sub-classes
+ using the DECLARE_READING() and IMPLEMENT_READING() macros.
+
+ Note that this method should only be called by QSensorBackend.
+*/
+void QSensorReading::copyValuesFrom(QSensorReading *other)
+{
+ QSensorReadingPrivate *my_ptr = d.data();
+ QSensorReadingPrivate *other_ptr = other->d.data();
+ /* Do a direct copy of the private class */
+ *(my_ptr) = *(other_ptr);
+}
+
+/*!
+ \fn QSensorReading::d_ptr()
+ \internal
+ No longer used. Exists to keep the winscw build happy.
+*/
+
+/*!
+ \macro DECLARE_READING(classname)
+ \relates QSensorReading
+ \brief The DECLARE_READING macro adds some required methods to a reading class.
+
+ This macro should be used for all reading classes. Pass the \a classname of your reading class.
+
+ \code
+ class MyReading : public QSensorReading
+ {
+ Q_OBJECT
+ Q_PROPERTY(qreal myprop READ myprop)
+ DECLARE_READING(MyReading)
+ public:
+ qreal myprop() const;
+ vod setMyprop(qreal myprop);
+ };
+ \endcode
+
+ \sa IMPLEMENT_READING()
+*/
+
+/*!
+ \macro IMPLEMENT_READING(classname)
+ \relates QSensorReading
+ \brief The IMPLEMENT_READING macro implements the required methods for a reading class.
+
+ This macro should be used for all reading classes. It should be placed into a single compilation
+ unit (source file), not into a header file. Pass the \a classname of your reading class.
+
+ \code
+ IMPLEMENT_READING(MyReading)
+ \endcode
+
+ \sa DECLARE_READING()
+*/
+
+#include "moc_qsensor.cpp"
+QT_END_NAMESPACE
+
diff --git a/src/sensors/qsensor.h b/src/sensors/qsensor.h
new file mode 100644
index 0000000..613f82f
--- /dev/null
+++ b/src/sensors/qsensor.h
@@ -0,0 +1,251 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSENSOR_H
+#define QSENSOR_H
+
+#include <QtCore/QObject>
+#include <QtCore/QByteArray>
+#include <QtCore/QMetaType>
+#include <QtCore/QVariant>
+#include <QtCore/QPair>
+
+QT_BEGIN_NAMESPACE
+
+class QSensorPrivate;
+class QSensorBackend;
+class QSensorReading;
+class QSensorReadingPrivate;
+class QSensorFilter;
+
+#ifdef Q_QDOC
+typedef quint64 qtimestamp;
+#else
+class qtimestamp
+{
+public:
+ qtimestamp() : value() {}
+ qtimestamp(quint64 timestamp) : value(timestamp) {}
+ operator quint64() const { return value; }
+private:
+ quint64 value;
+};
+#endif
+
+typedef QPair<int,int> qrange;
+typedef QList<qrange> qrangelist;
+struct qoutputrange
+{
+ qreal minimum;
+ qreal maximum;
+ qreal accuracy;
+};
+typedef QList<qoutputrange> qoutputrangelist;
+
+class Q_SENSORS_EXPORT QSensor : public QObject
+{
+ friend class QSensorBackend;
+
+ Q_OBJECT
+ Q_PROPERTY(QByteArray sensorid READ identifier WRITE setIdentifier)
+ Q_PROPERTY(QByteArray type READ type)
+ Q_PROPERTY(bool connectedToBackend READ isConnectedToBackend)
+ Q_PROPERTY(qrangelist availableDataRates READ availableDataRates)
+ Q_PROPERTY(int dataRate READ dataRate WRITE setDataRate)
+ Q_PROPERTY(QSensorReading* reading READ reading NOTIFY readingChanged)
+ Q_PROPERTY(bool busy READ isBusy)
+ Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged)
+ Q_PROPERTY(qoutputrangelist outputRanges READ outputRanges)
+ Q_PROPERTY(int outputRange READ outputRange WRITE setOutputRange)
+ Q_PROPERTY(QString description READ description)
+ Q_PROPERTY(int error READ error NOTIFY sensorError)
+#ifdef Q_QDOC
+ Q_PROPERTY(int maxBufferSize)
+ Q_PROPERTY(int efficientBufferSize)
+ Q_PROPERTY(int bufferSize)
+#endif
+public:
+ explicit QSensor(const QByteArray &type, QObject *parent = 0);
+ virtual ~QSensor();
+
+ QByteArray identifier() const;
+ void setIdentifier(const QByteArray &identifier);
+
+ QByteArray type() const;
+
+ Q_INVOKABLE bool connectToBackend();
+ bool isConnectedToBackend() const;
+
+ bool isBusy() const;
+
+ void setActive(bool active);
+ bool isActive() const;
+
+ qrangelist availableDataRates() const;
+ int dataRate() const;
+ void setDataRate(int rate);
+
+ qoutputrangelist outputRanges() const;
+ int outputRange() const;
+ void setOutputRange(int index);
+
+ QString description() const;
+ int error() const;
+
+ // Filters modify the reading
+ void addFilter(QSensorFilter *filter);
+ void removeFilter(QSensorFilter *filter);
+ QList<QSensorFilter*> filters() const;
+
+ // The readings are exposed via this object
+ QSensorReading *reading() const;
+
+ // Information about available sensors
+ // These functions are implemented in qsensormanager.cpp
+ static QList<QByteArray> sensorTypes();
+ static QList<QByteArray> sensorsForType(const QByteArray &type);
+ static QByteArray defaultSensorForType(const QByteArray &type);
+
+public Q_SLOTS:
+ // Start receiving values from the sensor
+ bool start();
+
+ // Stop receiving values from the sensor
+ void stop();
+
+Q_SIGNALS:
+ void busyChanged();
+ void activeChanged();
+ void readingChanged();
+ void sensorError(int error);
+ void availableSensorsChanged();
+
+protected:
+ // called by the back end
+ QSensorPrivate *d_func() const { return d.data(); }
+
+private:
+ void registerInstance();
+
+ QScopedPointer<QSensorPrivate> d;
+ Q_DISABLE_COPY(QSensor)
+};
+
+class Q_SENSORS_EXPORT QSensorFilter
+{
+ friend class QSensor;
+public:
+ virtual bool filter(QSensorReading *reading) = 0;
+protected:
+ QSensorFilter();
+ ~QSensorFilter();
+ virtual void setSensor(QSensor *sensor);
+ QSensor *m_sensor;
+};
+
+class Q_SENSORS_EXPORT QSensorReading : public QObject
+{
+ friend class QSensorBackend;
+
+ Q_OBJECT
+ Q_PROPERTY(qtimestamp timestamp READ timestamp)
+public:
+ virtual ~QSensorReading();
+
+ qtimestamp timestamp() const;
+ void setTimestamp(qtimestamp timestamp);
+
+ // Access properties of sub-classes by numeric index
+ // For name-based access use QObject::property()
+ int valueCount() const;
+ QVariant value(int index) const;
+
+protected:
+ explicit QSensorReading(QObject *parent, QSensorReadingPrivate *d);
+ QScopedPointer<QSensorReadingPrivate> *d_ptr() { return &d; }
+ virtual void copyValuesFrom(QSensorReading *other);
+
+private:
+ QScopedPointer<QSensorReadingPrivate> d;
+ Q_DISABLE_COPY(QSensorReading)
+};
+
+#define DECLARE_READING(classname)\
+ DECLARE_READING_D(classname, classname ## Private)
+
+#define DECLARE_READING_D(classname, pclassname)\
+ public:\
+ classname(QObject *parent = 0);\
+ virtual ~classname();\
+ void copyValuesFrom(QSensorReading *other);\
+ private:\
+ QScopedPointer<pclassname> d;
+
+#define IMPLEMENT_READING(classname)\
+ IMPLEMENT_READING_D(classname, classname ## Private)
+
+#define IMPLEMENT_READING_D(classname, pclassname)\
+ classname::classname(QObject *parent)\
+ : QSensorReading(parent, 0)\
+ , d(new pclassname)\
+ {}\
+ classname::~classname() {}\
+ void classname::copyValuesFrom(QSensorReading *_other)\
+ {\
+ /* No need to verify types, only called by QSensorBackend */\
+ classname *other = static_cast<classname *>(_other);\
+ pclassname *my_ptr = d.data();\
+ pclassname *other_ptr = other->d.data();\
+ /* Do a direct copy of the private class */\
+ *(my_ptr) = *(other_ptr);\
+ /* We need to copy the parent too */\
+ QSensorReading::copyValuesFrom(_other);\
+ }
+
+
+Q_DECLARE_METATYPE(qtimestamp)
+Q_DECLARE_METATYPE(qrange)
+Q_DECLARE_METATYPE(qrangelist)
+Q_DECLARE_METATYPE(qoutputrangelist)
+
+QT_END_NAMESPACE
+#endif
+
diff --git a/src/sensors/qsensor_p.h b/src/sensors/qsensor_p.h
new file mode 100644
index 0000000..cd15952
--- /dev/null
+++ b/src/sensors/qsensor_p.h
@@ -0,0 +1,119 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSENSOR_P_H
+#define QSENSOR_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qsensor.h"
+
+QT_BEGIN_NAMESPACE
+
+typedef QList<QSensorFilter*> QFilterList;
+
+class QSensorPrivate
+{
+public:
+ QSensorPrivate()
+ : identifier()
+ , type()
+ , outputRange(-1)
+ , dataRate(0)
+ , backend(0)
+ , active(false)
+ , busy(false)
+ , device_reading(0)
+ , filter_reading(0)
+ , cache_reading(0)
+ , error(0)
+ {
+ }
+
+ // meta-data
+ QByteArray identifier;
+ QByteArray type;
+
+ QString description;
+
+ qoutputrangelist outputRanges;
+ int outputRange;
+
+ // policy
+ qrangelist availableDataRates;
+ int dataRate;
+
+ QSensorBackend *backend;
+ QFilterList filters;
+ bool active;
+ bool busy;
+ QSensorReading *device_reading;
+ QSensorReading *filter_reading;
+ QSensorReading *cache_reading;
+
+ int error;
+};
+
+class QSensorReadingPrivate
+{
+public:
+ QSensorReadingPrivate()
+ : timestamp(0)
+ {
+ }
+
+ // sensor data cache
+ qtimestamp timestamp;
+};
+
+QT_END_NAMESPACE
+
+#endif
+
diff --git a/src/sensors/qsensorbackend.cpp b/src/sensors/qsensorbackend.cpp
new file mode 100644
index 0000000..1aaf8b1
--- /dev/null
+++ b/src/sensors/qsensorbackend.cpp
@@ -0,0 +1,326 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsensorbackend.h"
+#include "qsensor_p.h"
+#include <QDebug>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QSensorBackend
+ \ingroup sensors_backend
+ \inmodule QtSensors
+ \since 1.0
+
+ \brief The QSensorBackend class is a sensor implementation.
+
+ Sensors on a device will be represented by sub-classes of
+ QSensorBackend.
+*/
+
+/*!
+ \internal
+*/
+QSensorBackend::QSensorBackend(QSensor *sensor)
+ : m_sensor(sensor)
+{
+}
+
+/*!
+ \internal
+*/
+QSensorBackend::~QSensorBackend()
+{
+}
+
+/*!
+ Notify the QSensor class that a new reading is available.
+*/
+void QSensorBackend::newReadingAvailable()
+{
+ QSensorPrivate *d = m_sensor->d_func();
+
+ // Copy the values from the device reading to the filter reading
+ d->filter_reading->copyValuesFrom(d->device_reading);
+
+ for (QFilterList::const_iterator it = d->filters.constBegin(); it != d->filters.constEnd(); ++it) {
+ QSensorFilter *filter = (*it);
+ if (!filter->filter(d->filter_reading))
+ return;
+ }
+
+ // Copy the values from the filter reading to the cached reading
+ d->cache_reading->copyValuesFrom(d->filter_reading);
+
+ Q_EMIT m_sensor->readingChanged();
+}
+
+/*!
+ \fn QSensorBackend::start()
+
+ Start reporting values.
+*/
+
+/*!
+ \fn QSensorBackend::stop()
+
+ Stop reporting values.
+*/
+
+/*!
+ If the backend has lost its reference to the reading
+ it can call this method to get the address.
+
+ Note that you will need to down-cast to the appropriate
+ type.
+
+ \sa setReading()
+*/
+QSensorReading *QSensorBackend::reading() const
+{
+ QSensorPrivate *d = m_sensor->d_func();
+ return d->device_reading;
+}
+
+/*!
+ \fn QSensorBackend::sensor() const
+
+ Returns the sensor front end associated with this backend.
+*/
+
+/*!
+ \fn QSensorBackend::setReading(T *reading)
+
+ This function is called to initialize the \a reading
+ classes used for a sensor.
+
+ If your backend has already allocated a reading you
+ should pass the address of this to the function.
+ Otherwise you should pass 0 and the function will
+ return the address of the reading your backend
+ should use when it wants to notify the sensor API
+ of new readings.
+
+ Note that this is a template function so it should
+ be called with the appropriate type.
+
+ \code
+ class MyBackend : public QSensorBackend
+ {
+ QAccelerometerReading m_reading;
+ public:
+ MyBackend(QSensor *sensor)
+ : QSensorBackend(sensor)
+ {
+ setReading<QAccelerometerReading>(&m_reading);
+ }
+
+ ...
+ \endcode
+
+ Note that this function must be called or you will
+ not be able to send readings to the front end.
+
+ If you do not wish to store the address of the reading
+ you may use the reading() method to get it again later.
+
+ \code
+ class MyBackend : public QSensorBackend
+ {
+ public:
+ MyBackend(QSensor *sensor)
+ : QSensorBackend(sensor)
+ {
+ setReading<QAccelerometerReading>(0);
+ }
+
+ void poll()
+ {
+ qtimestamp timestamp;
+ qreal x, y, z;
+ ...
+ QAccelerometerReading *reading = static_cast<QAccelerometerReading*>(reading());
+ reading->setTimestamp(timestamp);
+ reading->setX(x);
+ reading->setY(y);
+ reading->setZ(z);
+ }
+
+ ...
+ \endcode
+
+ \sa reading()
+*/
+
+/*!
+ \internal
+*/
+void QSensorBackend::setReadings(QSensorReading *device, QSensorReading *filter, QSensorReading *cache)
+{
+ QSensorPrivate *d = m_sensor->d_func();
+ d->device_reading = device;
+ d->filter_reading = filter;
+ d->cache_reading = cache;
+}
+
+/*!
+ Add a data rate (consisting of \a min and \a max values) for the sensor.
+
+ Note that this function should be called from the constructor so that the information
+ is available immediately.
+
+ \sa QSensor::availableDataRates
+*/
+void QSensorBackend::addDataRate(qreal min, qreal max)
+{
+ QSensorPrivate *d = m_sensor->d_func();
+ d->availableDataRates << qrange(min, max);
+}
+
+/*!
+ Set the data rates for the sensor based on \a otherSensor.
+
+ This is designed for sensors that are based on other sensors.
+
+ \code
+ setDataRates(otherSensor);
+ \endcode
+
+ Note that this function should be called from the constructor so that the information
+ is available immediately.
+
+ \sa QSensor::availableDataRates, addDataRate()
+*/
+void QSensorBackend::setDataRates(const QSensor *otherSensor)
+{
+ if (!otherSensor) {
+ qWarning() << "ERROR: Cannot call QSensorBackend::setDataRates with 0";
+ return;
+ }
+ if (otherSensor->identifier().isEmpty()) {
+ qWarning() << "ERROR: Cannot call QSensorBackend::setDataRates with an invalid sensor";
+ return;
+ }
+ QSensorPrivate *d = m_sensor->d_func();
+ d->availableDataRates = otherSensor->availableDataRates();
+ d->dataRate = otherSensor->dataRate();
+}
+
+/*!
+ Add an output range (consisting of \a min, \a max values and \a accuracy) for the sensor.
+
+ Note that this function should be called from the constructor so that the information
+ is available immediately.
+
+ \sa QSensor::outputRange, QSensor::outputRanges
+*/
+void QSensorBackend::addOutputRange(qreal min, qreal max, qreal accuracy)
+{
+ QSensorPrivate *d = m_sensor->d_func();
+
+ qoutputrange details = {min, max, accuracy};
+
+ d->outputRanges << details;
+}
+
+/*!
+ Set the \a description for the sensor.
+
+ Note that this function should be called from the constructor so that the information
+ is available immediately.
+*/
+void QSensorBackend::setDescription(const QString &description)
+{
+ QSensorPrivate *d = m_sensor->d_func();
+ d->description = description;
+}
+
+/*!
+ Inform the front end that the sensor has stopped.
+ This can be due to start() failing or for some
+ unexpected reason (eg. hardware failure).
+
+ Note that the front end must call QSensor::isActive() to see if
+ the sensor has stopped. If the sensor has stopped due to an error
+ the sensorError() function should be called to notify the class
+ of the error condition.
+*/
+void QSensorBackend::sensorStopped()
+{
+ QSensorPrivate *d = m_sensor->d_func();
+ d->active = false;
+}
+
+/*!
+ Inform the front end that the sensor is busy.
+ This implicitly calls sensorStopped() and
+ is typically called from start().
+
+ Note that the front end must call QSensor::isBusy() to see if
+ the sensor is busy. If the sensor has stopped due to an error
+ the sensorError() function should be called to notify the class
+ of the error condition.
+*/
+void QSensorBackend::sensorBusy()
+{
+ QSensorPrivate *d = m_sensor->d_func();
+ d->active = false;
+ d->busy = true;
+}
+
+/*!
+ Inform the front end that a sensor error occurred.
+ Note that this only reports an \a error code. It does
+ not stop the sensor.
+
+ \sa sensorStopped()
+*/
+void QSensorBackend::sensorError(int error)
+{
+ QSensorPrivate *d = m_sensor->d_func();
+ d->error = error;
+ Q_EMIT m_sensor->sensorError(error);
+}
+
+#include "moc_qsensorbackend.cpp"
+QT_END_NAMESPACE
+
diff --git a/src/sensors/qsensorbackend.h b/src/sensors/qsensorbackend.h
new file mode 100644
index 0000000..1d19e02
--- /dev/null
+++ b/src/sensors/qsensorbackend.h
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSENSORBACKEND_H
+#define QSENSORBACKEND_H
+
+#include "qsensor.h"
+#include "qsensormanager.h"
+
+QT_BEGIN_NAMESPACE
+
+class Q_SENSORS_EXPORT QSensorBackend : public QObject
+{
+ Q_OBJECT
+public:
+ QSensorBackend(QSensor *sensor);
+ virtual ~QSensorBackend();
+
+ virtual void start() = 0;
+ virtual void stop() = 0;
+
+ // used by the backend to set metadata properties
+ void addDataRate(qreal min, qreal max);
+ void setDataRates(const QSensor *otherSensor);
+ void addOutputRange(qreal min, qreal max, qreal accuracy);
+ void setDescription(const QString &description);
+
+ template <typename T>
+ T *setReading(T *reading)
+ {
+ if (!reading)
+ reading = new T(this);
+ setReadings(reading, new T(this), new T(this));
+ return reading;
+ }
+
+ QSensorReading *reading() const;
+ QSensor *sensor() const { return m_sensor; }
+
+ // used by the backend to inform us of events
+ void newReadingAvailable();
+ void sensorStopped();
+ void sensorBusy();
+ void sensorError(int error);
+
+private:
+ void setReadings(QSensorReading *device, QSensorReading *filter, QSensorReading *cache);
+
+ QSensor *m_sensor;
+ Q_DISABLE_COPY(QSensorBackend)
+};
+
+QT_END_NAMESPACE
+
+#endif
+
diff --git a/src/sensors/qsensormanager.cpp b/src/sensors/qsensormanager.cpp
new file mode 100644
index 0000000..c8cc1ce
--- /dev/null
+++ b/src/sensors/qsensormanager.cpp
@@ -0,0 +1,498 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsensormanager.h"
+#include <QDebug>
+#include "qsensorpluginloader_p.h"
+#include "qsensorplugin.h"
+#include <QSettings>
+#include "sensorlog_p.h"
+#include <QTimer>
+
+QT_BEGIN_NAMESPACE
+
+Q_GLOBAL_STATIC(QSensorPluginLoader, pluginLoader)
+
+typedef QHash<QByteArray,QSensorBackendFactory*> FactoryForIdentifierMap;
+typedef QHash<QByteArray,FactoryForIdentifierMap> BackendIdentifiersForTypeMap;
+
+class QSensorManagerPrivate : public QObject
+{
+ friend class QSensorManager;
+
+ Q_OBJECT
+public:
+ enum PluginLoadingState {
+ NotLoaded,
+ Loading,
+ Loaded
+ };
+ QSensorManagerPrivate()
+ : pluginLoadingState(NotLoaded)
+ , sensorsChanged(false)
+ {
+ }
+
+ PluginLoadingState pluginLoadingState;
+ void loadPlugins();
+
+ QList<CreatePluginFunc> staticRegistrations;
+
+ // Holds a mapping from type to available identifiers (and from there to the factory)
+ BackendIdentifiersForTypeMap backendsByType;
+
+ // Holds the first identifier for each type
+ QHash<QByteArray, QByteArray> firstIdentifierForType;
+
+ bool sensorsChanged;
+ QList<QSensorChangesInterface*> changeListeners;
+
+Q_SIGNALS:
+ void availableSensorsChanged();
+
+public Q_SLOTS:
+ void emitSensorsChanged()
+ {
+ static bool alreadyRunning = false;
+ if (pluginLoadingState != QSensorManagerPrivate::Loaded || alreadyRunning) {
+ // We're busy.
+ // Just note that a registration changed and exit.
+ // Someone up the call stack will deal with this.
+ sensorsChanged = true;
+ return;
+ }
+
+ // Set a flag so any recursive calls doesn't cause a loop.
+ alreadyRunning = true;
+
+ // Since one [un]registration may cause other [un]registrations and since
+ // the order in which we do things matters we just do a cascading update
+ // until things stop changing.
+ do {
+ sensorsChanged = false;
+ Q_FOREACH (QSensorChangesInterface *changes, changeListeners) {
+ changes->sensorsChanged();
+ }
+ } while (sensorsChanged);
+
+ // We're going away now so clear the flag
+ alreadyRunning = false;
+
+ // Notify the client of the changes
+ Q_EMIT availableSensorsChanged();
+ }
+};
+
+Q_GLOBAL_STATIC(QSensorManagerPrivate, sensorManagerPrivate)
+
+// The unit test needs to change the behaviour of the library. It does this
+// through an exported but undocumented function.
+static void initPlugin(QObject *plugin);
+static QSettings::Scope settings_scope = QSettings::SystemScope;
+static bool load_external_plugins = true;
+Q_SENSORS_EXPORT void sensors_unit_test_hook(int index)
+{
+ QSensorManagerPrivate *d = sensorManagerPrivate();
+
+ switch (index) {
+ case 0:
+ Q_ASSERT(d->pluginLoadingState == QSensorManagerPrivate::NotLoaded);
+ settings_scope = QSettings::UserScope;
+ load_external_plugins = false;
+ break;
+ case 1:
+ Q_ASSERT(load_external_plugins == false);
+ Q_ASSERT(d->pluginLoadingState == QSensorManagerPrivate::Loaded);
+ SENSORLOG() << "initializing plugins";
+ Q_FOREACH (QObject *plugin, pluginLoader()->plugins()) {
+ initPlugin(plugin);
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+static void initPlugin(QObject *o)
+{
+ if (!o) return;
+ QSensorManagerPrivate *d = sensorManagerPrivate();
+
+ QSensorChangesInterface *changes = qobject_cast<QSensorChangesInterface*>(o);
+ if (changes)
+ d->changeListeners << changes;
+
+ QSensorPluginInterface *plugin = qobject_cast<QSensorPluginInterface*>(o);
+ if (plugin)
+ plugin->registerSensors();
+}
+
+void QSensorManagerPrivate::loadPlugins()
+{
+ QSensorManagerPrivate *d = this;
+ if (d->pluginLoadingState != QSensorManagerPrivate::NotLoaded) return;
+ d->pluginLoadingState = QSensorManagerPrivate::Loading;
+
+ SENSORLOG() << "initializing legacy static plugins";
+ // Legacy static plugins
+ Q_FOREACH (CreatePluginFunc func, d->staticRegistrations) {
+ QSensorPluginInterface *plugin = func();
+ plugin->registerSensors();
+ }
+
+ SENSORLOG() << "initializing static plugins";
+ // Qt-style static plugins
+ Q_FOREACH (QObject *plugin, QPluginLoader::staticInstances()) {
+ initPlugin(plugin);
+ }
+
+ if (load_external_plugins) {
+ SENSORLOG() << "initializing plugins";
+ Q_FOREACH (QObject *plugin, pluginLoader()->plugins()) {
+ initPlugin(plugin);
+ }
+ }
+
+ d->pluginLoadingState = QSensorManagerPrivate::Loaded;
+
+ if (d->sensorsChanged) {
+ // Notify the app that the available sensor list has changed.
+ // This may cause recursive calls!
+ d->emitSensorsChanged();
+ }
+}
+
+// =====================================================================
+
+/*!
+ \class QSensorManager
+ \ingroup sensors_backend
+ \inmodule QtSensors
+ \since 1.0
+
+ \brief The QSensorManager class handles registration and creation of sensor backends.
+
+ Sensor plugins register backends using the registerBackend() function.
+
+ When QSensor::connectToBackend() is called, the createBackend() function will be called.
+*/
+
+/*!
+ Register a sensor for \a type. The \a identifier must be unique.
+
+ The \a factory will be asked to create instances of the backend.
+*/
+void QSensorManager::registerBackend(const QByteArray &type, const QByteArray &identifier, QSensorBackendFactory *factory)
+{
+ Q_ASSERT(type.count());
+ Q_ASSERT(identifier.count());
+ Q_ASSERT(factory);
+ QSensorManagerPrivate *d = sensorManagerPrivate();
+ if (!d->backendsByType.contains(type)) {
+ (void)d->backendsByType[type];
+ d->firstIdentifierForType[type] = identifier;
+ } else if (d->firstIdentifierForType[type].startsWith("generic.")) {
+ // Don't let a generic backend be the default when some other backend exists!
+ d->firstIdentifierForType[type] = identifier;
+ }
+ FactoryForIdentifierMap &factoryByIdentifier = d->backendsByType[type];
+ if (factoryByIdentifier.contains(identifier)) {
+ qWarning() << "A backend with type" << type << "and identifier" << identifier << "has already been registered!";
+ return;
+ }
+ SENSORLOG() << "registering backend for type" << type << "identifier" << identifier;// << "factory" << QString().sprintf("0x%08x", (unsigned int)factory);
+ factoryByIdentifier[identifier] = factory;
+
+ // Notify the app that the available sensor list has changed.
+ // This may cause recursive calls!
+ d->emitSensorsChanged();
+}
+
+/*!
+ Unregister the backend for \a type with \a identifier.
+
+ Note that this only prevents new instance of the backend from being created. It does not
+ invalidate the existing instances of the backend. The backend code should handle the
+ disappearance of the underlying hardware itself.
+*/
+void QSensorManager::unregisterBackend(const QByteArray &type, const QByteArray &identifier)
+{
+ QSensorManagerPrivate *d = sensorManagerPrivate();
+ if (!d->backendsByType.contains(type)) {
+ qWarning() << "No backends of type" << type << "are registered";
+ return;
+ }
+ FactoryForIdentifierMap &factoryByIdentifier = d->backendsByType[type];
+ if (!factoryByIdentifier.contains(identifier)) {
+ qWarning() << "Identifier" << identifier << "is not registered";
+ return;
+ }
+
+ (void)factoryByIdentifier.take(identifier); // we don't own this pointer anyway
+ if (d->firstIdentifierForType[type] == identifier) {
+ if (factoryByIdentifier.count()) {
+ d->firstIdentifierForType[type] = factoryByIdentifier.begin().key();
+ if (d->firstIdentifierForType[type].startsWith("generic.")) {
+ // Don't let a generic backend be the default when some other backend exists!
+ for (FactoryForIdentifierMap::const_iterator it = factoryByIdentifier.begin()++; it != factoryByIdentifier.end(); it++) {
+ const QByteArray &identifier(it.key());
+ if (!identifier.startsWith("generic.")) {
+ d->firstIdentifierForType[type] = identifier;
+ break;
+ }
+ }
+ }
+ } else {
+ (void)d->firstIdentifierForType.take(type);
+ }
+ }
+ if (!factoryByIdentifier.count())
+ (void)d->backendsByType.take(type);
+
+ // Notify the app that the available sensor list has changed.
+ // This may cause recursive calls!
+ d->emitSensorsChanged();
+}
+
+/*!
+ \internal
+*/
+void QSensorManager::registerStaticPlugin(CreatePluginFunc func)
+{
+ QSensorManagerPrivate *d = sensorManagerPrivate();
+ d->staticRegistrations.append(func);
+}
+
+/*!
+ Create a backend for \a sensor. Returns null if no suitable backend exists.
+*/
+QSensorBackend *QSensorManager::createBackend(QSensor *sensor)
+{
+ Q_ASSERT(sensor);
+
+ QSensorManagerPrivate *d = sensorManagerPrivate();
+ d->loadPlugins();
+
+ SENSORLOG() << "QSensorManager::createBackend" << "type" << sensor->type() << "identifier" << sensor->identifier();
+
+ if (!d->backendsByType.contains(sensor->type())) {
+ SENSORLOG() << "no backends of type" << sensor->type() << "have been registered.";
+ return 0;
+ }
+
+ const FactoryForIdentifierMap &factoryByIdentifier = d->backendsByType[sensor->type()];
+ QSensorBackendFactory *factory;
+ QSensorBackend *backend;
+
+ if (sensor->identifier().isEmpty()) {
+ QByteArray defaultIdentifier = QSensor::defaultSensorForType(sensor->type());
+ SENSORLOG() << "Trying the default" << defaultIdentifier;
+ // No identifier set, try the default
+ factory = factoryByIdentifier[defaultIdentifier];
+ //SENSORLOG() << "factory" << QString().sprintf("0x%08x", (unsigned int)factory);
+ sensor->setIdentifier(defaultIdentifier); // the factory requires this
+ backend = factory->createBackend(sensor);
+ if (backend) return backend; // Got it!
+
+ // The default failed to instantiate so try any other registered sensors for this type
+ Q_FOREACH (const QByteArray &identifier, factoryByIdentifier.keys()) {
+ SENSORLOG() << "Trying" << identifier;
+ if (identifier == defaultIdentifier) continue; // Don't do the default one again
+ factory = factoryByIdentifier[identifier];
+ //SENSORLOG() << "factory" << QString().sprintf("0x%08x", (unsigned int)factory);
+ sensor->setIdentifier(identifier); // the factory requires this
+ backend = factory->createBackend(sensor);
+ if (backend) return backend; // Got it!
+ }
+ SENSORLOG() << "FAILED";
+ sensor->setIdentifier(QByteArray()); // clear the identifier
+ } else {
+ if (!factoryByIdentifier.contains(sensor->identifier())) {
+ SENSORLOG() << "no backend with identifier" << sensor->identifier() << "for type" << sensor->type();
+ return 0;
+ }
+
+ // We were given an explicit identifier so don't substitute other backends if it fails to instantiate
+ factory = factoryByIdentifier[sensor->identifier()];
+ //SENSORLOG() << "factory" << QString().sprintf("0x%08x", (unsigned int)factory);
+ backend = factory->createBackend(sensor);
+ if (backend) return backend; // Got it!
+ }
+
+ SENSORLOG() << "no suitable backend found for requested identifier" << sensor->identifier() << "and type" << sensor->type();
+ return 0;
+}
+
+/*!
+ Returns true if the backend identified by \a type and \a identifier is registered.
+
+ This is a convenience method that helps out plugins doing dynamic registration.
+*/
+bool QSensorManager::isBackendRegistered(const QByteArray &type, const QByteArray &identifier)
+{
+ QSensorManagerPrivate *d = sensorManagerPrivate();
+ d->loadPlugins();
+
+ if (!d->backendsByType.contains(type))
+ return false;
+
+ const FactoryForIdentifierMap &factoryByIdentifier = d->backendsByType[type];
+ if (!factoryByIdentifier.contains(identifier))
+ return false;
+
+ return true;
+}
+
+// =====================================================================
+
+/*!
+ Returns a list of all sensor types.
+*/
+QList<QByteArray> QSensor::sensorTypes()
+{
+ QSensorManagerPrivate *d = sensorManagerPrivate();
+ d->loadPlugins();
+
+ return d->backendsByType.keys();
+}
+
+/*!
+ Returns a list of ids for each of the sensors for \a type.
+ If there are no sensors of that type available the list will be empty.
+*/
+QList<QByteArray> QSensor::sensorsForType(const QByteArray &type)
+{
+ QSensorManagerPrivate *d = sensorManagerPrivate();
+ d->loadPlugins();
+
+ // no sensors of that type exist
+ if (!d->backendsByType.contains(type))
+ return QList<QByteArray>();
+
+ return d->backendsByType[type].keys();
+}
+
+/*!
+ Returns the default sensor identifier for \a type.
+ This is set in a config file and can be overridden if required.
+ If no default is available the system will return the first registered
+ sensor for \a type.
+
+ 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}.
+
+ \sa {Determining the default sensor for a type}
+*/
+QByteArray QSensor::defaultSensorForType(const QByteArray &type)
+{
+ QSensorManagerPrivate *d = sensorManagerPrivate();
+ d->loadPlugins();
+
+ // no sensors of that type exist
+ if (!d->backendsByType.contains(type))
+ return QByteArray();
+
+ // The unit test needs to modify Sensors.conf but it can't access the system directory
+ QSettings settings(settings_scope, QLatin1String("Nokia"), QLatin1String("Sensors"));
+ QVariant value = settings.value(QString(QLatin1String("Default/%1")).arg(QString::fromLatin1(type)));
+ if (!value.isNull()) {
+ QByteArray defaultIdentifier = value.toByteArray();
+ if (d->backendsByType[type].contains(defaultIdentifier)) // Don't return a value that we can't use!
+ return defaultIdentifier;
+ }
+
+ // This is our fallback
+ return d->firstIdentifierForType[type];
+}
+
+void QSensor::registerInstance()
+{
+ QSensorManagerPrivate *d = sensorManagerPrivate();
+ connect(d, SIGNAL(availableSensorsChanged()), this, SIGNAL(availableSensorsChanged()));
+}
+
+// =====================================================================
+
+/*!
+ \class QSensorBackendFactory
+ \ingroup sensors_backend
+ \inmodule QtSensors
+
+ \brief The QSensorBackendFactory class instantiates instances of
+ QSensorBackend.
+
+ This interface must be implemented in order to register a sensor backend.
+
+ \sa {Creating a sensor plugin}
+*/
+
+/*!
+ \fn QSensorBackendFactory::~QSensorBackendFactory()
+ \internal
+*/
+
+/*!
+ \fn QSensorBackendFactory::createBackend(QSensor *sensor)
+
+ Instantiate a backend. If the factory handles multiple identifiers
+ it should check with the \a sensor to see which one is requested.
+
+ If the factory cannot create a backend it should return 0.
+*/
+
+/*!
+ \macro REGISTER_STATIC_PLUGIN(pluginname)
+ \relates QSensorManager
+
+ Registers a static plugin, \a pluginname.
+
+ Note that this macro relies on static initialization so it may not be appropriate
+ for use in a library and may not work on all platforms.
+
+ \sa {Creating a sensor plugin}
+*/
+
+#include "qsensormanager.moc"
+
+QT_END_NAMESPACE
+
diff --git a/src/sensors/qsensormanager.h b/src/sensors/qsensormanager.h
new file mode 100644
index 0000000..58e7fd5
--- /dev/null
+++ b/src/sensors/qsensormanager.h
@@ -0,0 +1,108 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSENSORMANAGER_H
+#define QSENSORMANAGER_H
+
+#include "qsensor.h"
+
+QT_BEGIN_NAMESPACE
+
+class QSensorBackend;
+class QSensorBackendFactory;
+class QSensorPluginInterface;
+
+typedef QSensorPluginInterface *(*CreatePluginFunc)();
+
+class Q_SENSORS_EXPORT QSensorManager
+{
+public:
+ // Register a backend (call this from a plugin)
+ static void registerBackend(const QByteArray &type, const QByteArray &identifier, QSensorBackendFactory *factory);
+ static void unregisterBackend(const QByteArray &type, const QByteArray &identifier);
+
+ static bool isBackendRegistered(const QByteArray &type, const QByteArray &identifier);
+
+ // Create a backend (uses the type and identifier set in the sensor)
+ static QSensorBackend *createBackend(QSensor *sensor);
+
+ // For static plugins
+ static void registerStaticPlugin(CreatePluginFunc func);
+};
+
+class Q_SENSORS_EXPORT QSensorBackendFactory
+{
+public:
+ virtual QSensorBackend *createBackend(QSensor *sensor) = 0;
+protected:
+ ~QSensorBackendFactory() {}
+};
+
+// The default is for legacy static plugins
+// This will change to Qt-style static plugins in 1.3
+#define REGISTER_STATIC_PLUGIN(pluginname) \
+ REGISTER_STATIC_PLUGIN_V1(pluginname)
+
+// Legacy static plugins have their own registration methods.
+// They can only register types. They cannot use the changes interface.
+#define REGISTER_STATIC_PLUGIN_V1(pluginname) \
+ static QSensorPluginInterface *create_static_plugin_ ## pluginname()\
+ {\
+ return new pluginname;\
+ }\
+ static bool side_effect_sensor_backend_ ## pluginname ()\
+ {\
+ QSensorManager::registerStaticPlugin(create_static_plugin_ ## pluginname);\
+ return false;\
+ }\
+ /* This assignment calls the function above */\
+ static bool dummy_sensor_backend_ ## pluginname = side_effect_sensor_backend_ ## pluginname();
+
+// Qt-style static plugins use macros from Qt.
+// They are handled just like regular plugins.
+#define REGISTER_STATIC_PLUGIN_V2(pluginname) \
+ QT_PREPEND_NAMESPACE(QObject) *qt_plugin_instance_##pluginname() Q_PLUGIN_INSTANCE(pluginname)\
+ Q_IMPORT_PLUGIN(pluginname)
+
+QT_END_NAMESPACE
+
+#endif
+
diff --git a/src/sensors/qsensorplugin.cpp b/src/sensors/qsensorplugin.cpp
new file mode 100644
index 0000000..f6e78c5
--- /dev/null
+++ b/src/sensors/qsensorplugin.cpp
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsensorplugin.h"
+
+/*!
+ \class QSensorPluginInterface
+ \ingroup sensors_backend
+ \inmodule QtSensors
+ \brief The QSensorPluginInterface class is the pure virtual interface to sensor plugins.
+ \since 1.0
+
+ The QSensorPluginInterface class is implemented in sensor plugins to register sensor
+ backends with QSensorManager.
+
+ \sa {Creating a sensor plugin}
+*/
+
+/*!
+ \fn QSensorPluginInterface::~QSensorPluginInterface()
+ \internal
+*/
+
+/*!
+ \fn QSensorPluginInterface::registerSensors()
+
+ This function is called when the plugin is loaded. The plugin should register
+ sensor backends by calling QSensorManager::registerBackend(). Any backends
+ that utilise other sensors should be registered in the
+ QSensorPluginInterface::sensorsChanged() method instead.
+
+ \sa {Creating a sensor plugin}
+*/
+
+/*!
+ \class QSensorChangesInterface
+ \ingroup sensors_backend
+ \inmodule QtSensors
+ \brief The QSensorChangesInterface class is the pure virtual interface to sensor plugins.
+
+ The QSensorChangesInterface class is implemented in sensor plugins to receive notification
+ that registered sensor backends have changed.
+
+ \sa {Creating a sensor plugin}
+*/
+
+/*!
+ \fn QSensorChangesInterface::~QSensorChangesInterface()
+ \internal
+*/
+/*!
+ \fn QSensorChangesInterface::sensorsChanged()
+
+ This function is called when the registered backends have changed.
+ Any backends that depend on the presence of other sensors should be
+ registered or unregistered in here.
+
+ \sa {Creating a sensor plugin}
+*/
+
diff --git a/src/sensors/qsensorplugin.h b/src/sensors/qsensorplugin.h
new file mode 100644
index 0000000..8a0fcd7
--- /dev/null
+++ b/src/sensors/qsensorplugin.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSENSORPLUGIN_H
+#define QSENSORPLUGIN_H
+
+#include <QtCore/qstringlist.h>
+#include <QtCore/qplugin.h>
+#include <QtCore/qfactoryinterface.h>
+
+QT_BEGIN_NAMESPACE
+class QSensorBackend;
+
+class Q_SENSORS_EXPORT QSensorPluginInterface
+{
+public:
+ virtual void registerSensors() = 0;
+protected:
+ ~QSensorPluginInterface() {}
+};
+
+class Q_SENSORS_EXPORT QSensorChangesInterface
+{
+public:
+ virtual void sensorsChanged() = 0;
+protected:
+ ~QSensorChangesInterface() {}
+};
+
+Q_DECLARE_INTERFACE(QSensorPluginInterface, "com.nokia.Qt.QSensorPluginInterface/1.0");
+Q_DECLARE_INTERFACE(QSensorChangesInterface, "com.nokia.Qt.QSensorChangesInterface/1.0");
+QT_END_NAMESPACE
+
+#endif
+
diff --git a/src/sensors/qsensorpluginloader.cpp b/src/sensors/qsensorpluginloader.cpp
new file mode 100644
index 0000000..ef46d39
--- /dev/null
+++ b/src/sensors/qsensorpluginloader.cpp
@@ -0,0 +1,102 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsensorpluginloader_p.h"
+#include <QtCore/qcoreapplication.h>
+#include <QtCore/qdir.h>
+#include <QtCore/qdebug.h>
+
+#include "qsensorplugin.h"
+#include "qmobilitypluginsearch.h"
+
+QT_BEGIN_NAMESPACE
+
+QSensorPluginLoader::QSensorPluginLoader()
+{
+ load();
+}
+
+QSensorPluginLoader::~QSensorPluginLoader()
+{
+ Q_FOREACH (QPluginLoader *loader, m_loaders) {
+ bool ok = loader->unload();
+ if (!ok) qWarning() << "Cannot unload" << loader->fileName();
+ delete loader;
+ }
+}
+
+QList<QObject*> QSensorPluginLoader::plugins() const
+{
+ return m_plugins;
+}
+
+void QSensorPluginLoader::load()
+{
+ if (!m_plugins.isEmpty())
+ return;
+
+ QStringList plugins = mobilityPlugins(QLatin1String("sensors"));
+
+ /* Now discover the dynamic plugins */
+ for (int i = 0; i < plugins.count(); i++) {
+ QPluginLoader *loader = new QPluginLoader(plugins.at(i));
+
+ QObject *o = loader->instance();
+ if (o != 0) {
+ QSensorPluginInterface *p = qobject_cast<QSensorPluginInterface*>(o);
+ if (p != 0) {
+ m_plugins << o;
+ m_loaders << loader;
+ } else {
+ loader->unload();
+ delete loader;
+ }
+
+ continue;
+ }
+ delete o;
+ loader->unload();
+ delete loader;
+ }
+}
+
+QT_END_NAMESPACE
+
diff --git a/src/sensors/qsensorpluginloader_p.h b/src/sensors/qsensorpluginloader_p.h
new file mode 100644
index 0000000..5272736
--- /dev/null
+++ b/src/sensors/qsensorpluginloader_p.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSENSORPLUGINLOADER_H
+#define QSENSORPLUGINLOADER_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/QObject>
+#include <QtCore/qstring.h>
+#include <QtCore/qlist.h>
+#include <QtCore/qpluginloader.h>
+
+QT_BEGIN_NAMESPACE
+
+class Q_AUTOTEST_EXPORT QSensorPluginLoader
+{
+public:
+ QSensorPluginLoader();
+ ~QSensorPluginLoader();
+
+ QList<QObject*> plugins() const;
+
+private:
+ void load();
+
+ QList<QObject*> m_plugins;
+ QList<QPluginLoader *> m_loaders;
+};
+
+QT_END_NAMESPACE
+
+#endif
+
diff --git a/src/sensors/qtapsensor.cpp b/src/sensors/qtapsensor.cpp
new file mode 100644
index 0000000..cabf170
--- /dev/null
+++ b/src/sensors/qtapsensor.cpp
@@ -0,0 +1,247 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qtapsensor.h"
+#include "qtapsensor_p.h"
+
+QT_BEGIN_NAMESPACE
+
+IMPLEMENT_READING(QTapReading)
+
+/*!
+ \class QTapReading
+ \ingroup sensors_reading
+ \inmodule QtSensors
+ \since 1.0
+
+ \brief The QTapReading class represents one reading from the
+ tap sensor.
+
+ \section2 QTapReading Units
+ The tap sensor registers tap events along the 3 axes that originate from the phone.
+ The axes are arranged as follows.
+
+ \image sensors-coordinates2.jpg
+
+ By default it returns only double tap events. The QTapSensor::returnDoubleTapEvents property
+ must be set to false to return individual tap events.
+*/
+
+/*!
+ \enum QTapReading::TapDirection
+
+ The tap direction is indicated using flags. Applications should check for the presence of
+ a particular flag as multiple flags may be set at once.
+
+ The X, Y and Z flags allow an app to check for taps along an axis without caring about the
+ direction.
+
+ \code
+ if (reading->tapDirection()&QTapReading::X) {
+ ...
+ }
+ \endcode
+
+ The *_Pos and *_Neg flags allow checking for taps in a specific direction. Note that some
+ devices cannot determine the direction of a tap and will set both the _Pos and _Neg flag for
+ the detected axis. Previous versions of the API did not allow this. Applications that check
+ for the _Pos and _Neg flags as values should be updated so they can work with all devices.
+
+ \oldcode
+ if (reading->tapDirection() == QTapReading::X_Pos) {
+ ...
+ }
+ \newcode
+ if (reading->tapDirection()&QTapReading::X_Pos) {
+ ...
+ }
+ \endcode
+
+ \value Undefined This value means that the direction is unknown.
+ \value X This flag is set if the tap was along the X axis.
+ \value Y This flag is set if the tap was along the Y axis.
+ \value Z This flag is set if the tap was along the Z axis.
+ \value X_Pos This flag is set if the tap was towards the positive X direction.
+ \value Y_Pos This flag is set if the tap was towards the positive Y direction.
+ \value Z_Pos This flag is set if the tap was towards the positive Z direction.
+ \value X_Neg This flag is set if the tap was towards the negative X direction.
+ \value Y_Neg This flag is set if the tap was towards the negative Y direction.
+ \value Z_Neg This flag is set if the tap was towards the negative Z direction.
+ \value X_Both Equivalent to \c{X_Pos|X_Neg}. Returned by devices that cannot detect the direction of a tap.
+ \value Y_Both Equivalent to \c{Y_Pos|Y_Neg}. Returned by devices that cannot detect the direction of a tap.
+ \value Z_Both Equivalent to \c{Z_Pos|Z_Neg}. Returned by devices that cannot detect the direction of a tap.
+*/
+
+/*!
+ \property QTapReading::tapDirection
+ \brief the direction of the tap.
+
+ \sa {QTapReading Units}
+*/
+
+QTapReading::TapDirection QTapReading::tapDirection() const
+{
+ return static_cast<QTapReading::TapDirection>(d->tapDirection);
+}
+
+/*!
+ Sets the tap direction to \a tapDirection.
+*/
+void QTapReading::setTapDirection(QTapReading::TapDirection tapDirection)
+{
+ switch (tapDirection) {
+ case X_Pos:
+ case Y_Pos:
+ case Z_Pos:
+ case X_Neg:
+ case Y_Neg:
+ case Z_Neg:
+ case X_Both:
+ case Y_Both:
+ case Z_Both:
+ d->tapDirection = tapDirection;
+ break;
+ default:
+ d->tapDirection = Undefined;
+ break;
+ }
+}
+
+/*!
+ \property QTapReading::doubleTap
+ \brief a value indicating if there was a single or double tap.
+
+ \list
+ \o true - double tap
+ \o false - single tap
+ \endlist
+ \sa {QTapReading Units}
+*/
+
+bool QTapReading::isDoubleTap() const
+{
+ return d->doubleTap;
+}
+
+/*!
+ Sets the double tap status of the reading to \a doubleTap.
+*/
+void QTapReading::setDoubleTap(bool doubleTap)
+{
+ d->doubleTap = doubleTap;
+}
+
+// =====================================================================
+
+/*!
+ \class QTapFilter
+ \ingroup sensors_filter
+ \inmodule QtSensors
+
+ \brief The QTapFilter class is a convenience wrapper around QSensorFilter.
+
+ The only difference is that the filter() method features a pointer to QTapReading
+ instead of QSensorReading.
+*/
+
+/*!
+ \fn QTapFilter::filter(QTapReading *reading)
+
+ Called when \a reading changes. Returns false to prevent the reading from propagating.
+
+ \sa QSensorFilter::filter()
+*/
+
+char const * const QTapSensor::type("QTapSensor");
+
+/*!
+ \class QTapSensor
+ \ingroup sensors_type
+ \inmodule QtSensors
+
+ \brief The QTapSensor class is a convenience wrapper around QSensor.
+
+ The only behavioural difference is that this class sets the type properly.
+
+ This class also features a reading() function that returns a QTapReading instead of a QSensorReading.
+
+ For details about how the sensor works, see \l QTapReading.
+
+ \sa QTapReading
+*/
+
+/*!
+ \fn QTapSensor::QTapSensor(QObject *parent)
+
+ Construct the sensor as a child of \a parent.
+*/
+
+/*!
+ \fn QTapSensor::~QTapSensor()
+
+ Destroy the sensor. Stops the sensor if it has not already been stopped.
+*/
+
+/*!
+ \fn QTapSensor::reading() const
+
+ Returns the reading class for this sensor.
+
+ \sa QSensor::reading()
+*/
+
+/*!
+ \property QTapSensor::returnDoubleTapEvents
+ \brief a value indicating if double tap events should be reported.
+
+ Set to true (the default) to have the sensor report only on double tap events.
+ Set to false to have the sensor report only on individual tap events.
+
+ It is not possible to have the sensor report both single and double tap events.
+ If both are needed the app should create 2 sensor objects.
+
+ Note that you must access this property via QObject::property() and QObject::setProperty().
+ The property must be set before calling start().
+*/
+
+#include "moc_qtapsensor.cpp"
+QT_END_NAMESPACE
+
diff --git a/src/sensors/qtapsensor.h b/src/sensors/qtapsensor.h
new file mode 100644
index 0000000..24a2119
--- /dev/null
+++ b/src/sensors/qtapsensor.h
@@ -0,0 +1,106 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QTAPSENSOR_H
+#define QTAPSENSOR_H
+
+#include "qsensor.h"
+
+QT_BEGIN_NAMESPACE
+
+class QTapReadingPrivate;
+
+class Q_SENSORS_EXPORT QTapReading : public QSensorReading
+{
+ Q_OBJECT
+ Q_ENUMS(TapDirection)
+ Q_PROPERTY(TapDirection tapDirection READ tapDirection)
+ Q_PROPERTY(bool doubleTap READ isDoubleTap)
+ DECLARE_READING(QTapReading)
+public:
+ enum TapDirection {
+ Undefined = 0,
+ X = 0x0001,
+ Y = 0x0002,
+ Z = 0x0004,
+ X_Pos = 0x0011,
+ Y_Pos = 0x0022,
+ Z_Pos = 0x0044,
+ X_Neg = 0x0101,
+ Y_Neg = 0x0202,
+ Z_Neg = 0x0404,
+ X_Both = 0x0111,
+ Y_Both = 0x0222,
+ Z_Both = 0x0444
+ };
+
+ TapDirection tapDirection() const;
+ void setTapDirection(TapDirection tapDirection);
+
+ bool isDoubleTap() const;
+ void setDoubleTap(bool doubleTap);
+};
+
+class Q_SENSORS_EXPORT QTapFilter : public QSensorFilter
+{
+public:
+ virtual bool filter(QTapReading *reading) = 0;
+private:
+ bool filter(QSensorReading *reading) { return filter(static_cast<QTapReading*>(reading)); }
+};
+
+class Q_SENSORS_EXPORT QTapSensor : public QSensor
+{
+ Q_OBJECT
+#ifdef Q_QDOC
+ Q_PROPERTY(bool returnDoubleTapEvents)
+#endif
+public:
+ explicit QTapSensor(QObject *parent = 0) : QSensor(QTapSensor::type, parent) {}
+ virtual ~QTapSensor() {}
+ QTapReading *reading() const { return static_cast<QTapReading*>(QSensor::reading()); }
+ static char const * const type;
+};
+
+QT_END_NAMESPACE
+
+#endif
+
diff --git a/src/sensors/qtapsensor_p.h b/src/sensors/qtapsensor_p.h
new file mode 100644
index 0000000..e321170
--- /dev/null
+++ b/src/sensors/qtapsensor_p.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QTAPSENSOR_P_H
+#define QTAPSENSOR_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+QT_BEGIN_NAMESPACE
+
+class QTapReadingPrivate
+{
+public:
+ QTapReadingPrivate()
+ : tapDirection(0)
+ , doubleTap(false)
+ {
+ }
+
+ int tapDirection;
+ bool doubleTap;
+};
+
+QT_END_NAMESPACE
+
+#endif
+
diff --git a/src/sensors/sensorlog_p.h b/src/sensors/sensorlog_p.h
new file mode 100644
index 0000000..f614cb4
--- /dev/null
+++ b/src/sensors/sensorlog_p.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSENSORLOG_P_H
+#define QSENSORLOG_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#ifdef ENABLE_RUNTIME_SENSORLOG
+
+static bool logEnabled()
+{
+ static int state = -1;
+
+ if (state == -1) {
+ QByteArray sensorlog = qgetenv("SENSORLOG");
+ if (sensorlog == "1")
+ state = 1;
+ else
+ state = 0;
+ }
+
+ return state;
+}
+
+#define SENSORLOG() if (!logEnabled()); else qDebug()
+
+#else
+
+// Do nothing (compiles to almost nothing)
+#define SENSORLOG() if (1); else qDebug()
+
+#endif
+
+#endif
+
diff --git a/src/sensors/sensors.pro b/src/sensors/sensors.pro
new file mode 100644
index 0000000..09456ef
--- /dev/null
+++ b/src/sensors/sensors.pro
@@ -0,0 +1,77 @@
+load(qt_module)
+
+TARGET = QtSensors
+QPRO_PWD = $$PWD
+
+CONFIG += module
+CONFIG += strict_flags
+CONFIG(debug,debug|release):DEFINES += ENABLE_RUNTIME_SENSORLOG
+
+MOUDLUE_PRI = ../../modules/qt_sensors.pri
+
+QT = core
+
+DEFINES += QT_BUILD_SENSORS_LIB QT_MAKEDLL
+
+include($$QT_SOURCE_TREE/src/qbase.pri)
+HEADERS += qtsensorsversion.h
+
+
+symbian {
+ TARGET.CAPABILITY = ALL -TCB
+ TARGET.UID3 = 0x2002BFC0
+
+ ### Sensors
+ # Main library
+ SENSORS_DEPLOYMENT.sources = QtSensors.dll
+ SENSORS_DEPLOYMENT.path = /sys/bin
+ DEPLOYMENT += SENSORS_DEPLOYMENT
+ LIBS += -lefsrv
+
+ # We break on Symbian^3 unless we have this include (normally obtained by linking to QtGui)
+ load(platform_paths)
+ INCLUDEPATH *= $$MW_LAYER_SYSTEMINCLUDE
+
+}
+
+
+#INCLUDEPATH += .
+#DEPENDPATH += .
+
+PUBLIC_HEADERS += \
+ qsensorbackend.h\
+ qsensormanager.h\
+ qsensorplugin.h\
+
+PRIVATE_HEADERS += \
+ qsensorpluginloader_p.h\
+ sensorlog_p.h\
+
+SOURCES += qsensorbackend.cpp\
+ qsensormanager.cpp\
+ qsensorplugin.cpp\
+ qsensorpluginloader.cpp\
+
+# 3 files per sensor (including QSensor)
+SENSORS=\
+ qsensor\
+ qaccelerometer\
+ qambientlightsensor\
+ qcompass\
+ qlightsensor\
+ qmagnetometer\
+ qorientationsensor\
+ qproximitysensor\
+ qrotationsensor\
+ qtapsensor\
+ qgyroscope\
+
+for(s,SENSORS) {
+ # Client API
+ PUBLIC_HEADERS += $${s}.h
+ SOURCES += $${s}.cpp
+ # Private header
+ PRIVATE_HEADERS += $${s}_p.h
+}
+
+HEADERS = $$PUBLIC_HEADERS $$PRIVATE_HEADERS
diff --git a/src/src.pro b/src/src.pro
new file mode 100644
index 0000000..afba897
--- /dev/null
+++ b/src/src.pro
@@ -0,0 +1,3 @@
+TEMPLATE = subdirs
+CONFIG+=ordered
+SUBDIRS += sensors
diff --git a/sync.profile b/sync.profile
new file mode 100644
index 0000000..e9f96a8
--- /dev/null
+++ b/sync.profile
@@ -0,0 +1,26 @@
+%modules = ( # path to module name map
+ "QtSensors" => "$basedir/src/sensors",
+);
+%moduleheaders = ( # restrict the module headers to those found in relative path
+);
+%classnames = (
+ "qtsensorsversion.h" => "QtSensorsVersion",
+);
+%mastercontent = (
+ "declarative" => "#include <QtDeclarative/qdeclarative.h>\n",
+);
+%modulepris = (
+ "QtSensors" => "$basedir/modules/qt_sensors.pri",
+);
+# Modules and programs, and their dependencies.
+# Each of the module version specifiers can take one of the following values:
+# - A specific Git revision.
+# - "LATEST_REVISION", to always test against the latest revision.
+# - "LATEST_RELEASE", to always test against the latest public release.
+# - "THIS_REPOSITORY", to indicate that the module is in this repository.
+%dependencies = (
+ "QtSensors" => {
+ "QtCore" => "0c637cb07ba3c9b353e7e483a209537485cc4e2a",
+ "QtDeclarative" => "0c637cb07ba3c9b353e7e483a209537485cc4e2a",
+ },
+);