summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/plugins.pro2
-rw-r--r--src/plugins/sensors/dummy/dummy.pri9
-rw-r--r--src/plugins/sensors/dummy/dummy.pro15
-rw-r--r--src/plugins/sensors/dummy/dummyaccelerometer.cpp65
-rw-r--r--src/plugins/sensors/dummy/dummyaccelerometer.h61
-rw-r--r--src/plugins/sensors/dummy/dummycommon.cpp116
-rw-r--r--src/plugins/sensors/dummy/dummycommon.h65
-rw-r--r--src/plugins/sensors/dummy/dummylightsensor.cpp65
-rw-r--r--src/plugins/sensors/dummy/dummylightsensor.h61
-rw-r--r--src/plugins/sensors/dummy/main.cpp79
-rw-r--r--src/plugins/sensors/generic/generic.pri9
-rw-r--r--src/plugins/sensors/generic/generic.pro24
-rw-r--r--src/plugins/sensors/generic/genericalssensor.cpp151
-rw-r--r--src/plugins/sensors/generic/genericalssensor.h67
-rw-r--r--src/plugins/sensors/generic/genericorientationsensor.cpp98
-rw-r--r--src/plugins/sensors/generic/genericorientationsensor.h67
-rw-r--r--src/plugins/sensors/generic/genericrotationsensor.cpp115
-rw-r--r--src/plugins/sensors/generic/genericrotationsensor.h69
-rw-r--r--src/plugins/sensors/generic/main.cpp100
-rw-r--r--src/plugins/sensors/sensors.pro5
-rw-r--r--src/plugins/sensors/simulator/main.cpp102
-rw-r--r--src/plugins/sensors/simulator/qsensordata_simulator.cpp128
-rw-r--r--src/plugins/sensors/simulator/qsensordata_simulator_p.h116
-rw-r--r--src/plugins/sensors/simulator/simulator.pri19
-rw-r--r--src/plugins/sensors/simulator/simulator.pro19
-rw-r--r--src/plugins/sensors/simulator/simulatoraccelerometer.cpp74
-rw-r--r--src/plugins/sensors/simulator/simulatoraccelerometer.h61
-rw-r--r--src/plugins/sensors/simulator/simulatorambientlightsensor.cpp70
-rw-r--r--src/plugins/sensors/simulator/simulatorambientlightsensor.h61
-rw-r--r--src/plugins/sensors/simulator/simulatorcommon.cpp200
-rw-r--r--src/plugins/sensors/simulator/simulatorcommon.h104
-rw-r--r--src/plugins/sensors/simulator/simulatorcompass.cpp72
-rw-r--r--src/plugins/sensors/simulator/simulatorcompass.h61
-rw-r--r--src/plugins/sensors/simulator/simulatorlightsensor.cpp70
-rw-r--r--src/plugins/sensors/simulator/simulatorlightsensor.h61
-rw-r--r--src/plugins/sensors/simulator/simulatormagnetometer.cpp76
-rw-r--r--src/plugins/sensors/simulator/simulatormagnetometer.h61
-rw-r--r--src/plugins/sensors/simulator/simulatorproximitysensor.cpp70
-rw-r--r--src/plugins/sensors/simulator/simulatorproximitysensor.h61
39 files changed, 2729 insertions, 0 deletions
diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro
new file mode 100644
index 00000000..234bd799
--- /dev/null
+++ b/src/plugins/plugins.pro
@@ -0,0 +1,2 @@
+TEMPLATE = subdirs
+SUBDIRS += sensors
diff --git a/src/plugins/sensors/dummy/dummy.pri b/src/plugins/sensors/dummy/dummy.pri
new file mode 100644
index 00000000..502081c7
--- /dev/null
+++ b/src/plugins/sensors/dummy/dummy.pri
@@ -0,0 +1,9 @@
+HEADERS += dummycommon.h\
+ dummyaccelerometer.h\
+ dummylightsensor.h\
+
+SOURCES += dummycommon.cpp\
+ dummyaccelerometer.cpp\
+ dummylightsensor.cpp\
+ main.cpp\
+
diff --git a/src/plugins/sensors/dummy/dummy.pro b/src/plugins/sensors/dummy/dummy.pro
new file mode 100644
index 00000000..3ccfad69
--- /dev/null
+++ b/src/plugins/sensors/dummy/dummy.pro
@@ -0,0 +1,15 @@
+load(qt_module)
+
+TARGET = qtsensors_dummy
+QT += sensors core
+
+load(qt_plugin)
+
+DESTDIR = $$QT.sensors.plugins/sensors
+
+include(dummy.pri)
+
+unix:LIBS+=-lrt
+
+target.path += $$[QT_INSTALL_PLUGINS]/sensors
+INSTALLS += target
diff --git a/src/plugins/sensors/dummy/dummyaccelerometer.cpp b/src/plugins/sensors/dummy/dummyaccelerometer.cpp
new file mode 100644
index 00000000..5db80f52
--- /dev/null
+++ b/src/plugins/sensors/dummy/dummyaccelerometer.cpp
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** 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 "dummyaccelerometer.h"
+#include <QDebug>
+#include <QtGlobal>
+
+char const * const dummyaccelerometer::id("dummy.accelerometer");
+
+dummyaccelerometer::dummyaccelerometer(QSensor *sensor)
+ : dummycommon(sensor)
+{
+ setReading<QAccelerometerReading>(&m_reading);
+ addDataRate(100, 100); // 100Hz
+}
+
+void dummyaccelerometer::poll()
+{
+ m_reading.setTimestamp(getTimestamp());
+ // Your average desktop computer doesn't move :)
+ m_reading.setX(0);
+ m_reading.setY(9.8); // facing the user, gravity goes here
+ m_reading.setZ(0);
+
+ newReadingAvailable();
+}
+
diff --git a/src/plugins/sensors/dummy/dummyaccelerometer.h b/src/plugins/sensors/dummy/dummyaccelerometer.h
new file mode 100644
index 00000000..2293d53e
--- /dev/null
+++ b/src/plugins/sensors/dummy/dummyaccelerometer.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** 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 DUMMYACCELEROMETER_H
+#define DUMMYACCELEROMETER_H
+
+#include "dummycommon.h"
+#include <qaccelerometer.h>
+
+class dummyaccelerometer : public dummycommon
+{
+public:
+ static char const * const id;
+
+ dummyaccelerometer(QSensor *sensor);
+
+ void poll();
+private:
+ QAccelerometerReading m_reading;
+};
+
+#endif
+
diff --git a/src/plugins/sensors/dummy/dummycommon.cpp b/src/plugins/sensors/dummy/dummycommon.cpp
new file mode 100644
index 00000000..643342d4
--- /dev/null
+++ b/src/plugins/sensors/dummy/dummycommon.cpp
@@ -0,0 +1,116 @@
+/****************************************************************************
+**
+** 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 "dummycommon.h"
+
+#ifdef Q_OS_WINCE
+#include <windows.h>
+// WINCE has <time.h> but using clock() gives a link error because
+// the function isn't actually implemented.
+#else
+#include <time.h>
+#endif
+
+dummycommon::dummycommon(QSensor *sensor)
+ : QSensorBackend(sensor)
+ , m_timerid(0)
+{
+}
+
+void dummycommon::start()
+{
+ if (m_timerid)
+ return;
+
+ int dataRate = sensor()->dataRate();
+ if (dataRate == 0) {
+ if (sensor()->availableDataRates().count())
+ // Use the first available rate when -1 is chosen
+ dataRate = sensor()->availableDataRates().first().first;
+ else
+ dataRate = 1;
+ }
+
+ int interval = 1000 / dataRate;
+
+ if (interval)
+ m_timerid = startTimer(interval);
+}
+
+void dummycommon::stop()
+{
+ if (m_timerid) {
+ killTimer(m_timerid);
+ m_timerid = 0;
+ }
+}
+
+void dummycommon::timerEvent(QTimerEvent * /*event*/)
+{
+ poll();
+}
+
+quint64 dummycommon::getTimestamp()
+{
+#ifdef Q_OS_WINCE
+ // This implementation is based on code found here:
+ // http://social.msdn.microsoft.com/Forums/en/vssmartdevicesnative/thread/74870c6c-76c5-454c-8533-812cfca585f8
+ HANDLE currentThread = GetCurrentThread();
+ FILETIME creationTime, exitTime, kernalTime, userTime;
+ GetThreadTimes(currentThread, &creationTime, &exitTime, &kernalTime, &userTime);
+
+ ULARGE_INTEGER uli;
+ uli.LowPart = userTime.dwLowDateTime;
+ uli.HighPart = userTime.dwHighDateTime;
+ ULONGLONG systemTimeInMS = uli.QuadPart/10000;
+ return static_cast<quint64>(systemTimeInMS);
+#else
+ struct timespec tv;
+ int ok;
+
+ ok = clock_gettime(CLOCK_MONOTONIC, &tv);
+ Q_ASSERT(ok == 0);
+
+ quint64 result = (tv.tv_sec * 1000000ULL) + (tv.tv_nsec * 0.001); // scale to microseconds
+ return result;
+#endif
+}
+
diff --git a/src/plugins/sensors/dummy/dummycommon.h b/src/plugins/sensors/dummy/dummycommon.h
new file mode 100644
index 00000000..e0a0e025
--- /dev/null
+++ b/src/plugins/sensors/dummy/dummycommon.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** 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 DUMMYCOMMON_H
+#define DUMMYCOMMON_H
+
+#include <qsensorbackend.h>
+
+class dummycommon : public QSensorBackend
+{
+public:
+ dummycommon(QSensor *sensor);
+
+ void start();
+ void stop();
+ virtual void poll() = 0;
+ void timerEvent(QTimerEvent * /*event*/);
+
+protected:
+ quint64 getTimestamp();
+
+private:
+ int m_timerid;
+};
+
+#endif
+
diff --git a/src/plugins/sensors/dummy/dummylightsensor.cpp b/src/plugins/sensors/dummy/dummylightsensor.cpp
new file mode 100644
index 00000000..a4bc6fe8
--- /dev/null
+++ b/src/plugins/sensors/dummy/dummylightsensor.cpp
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** 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 "dummylightsensor.h"
+#include <QDebug>
+#include <QtGlobal>
+
+char const * const dummylightsensor::id("dummy.lightsensor");
+
+dummylightsensor::dummylightsensor(QSensor *sensor)
+ : dummycommon(sensor)
+{
+ setReading<QAmbientLightReading>(&m_reading);
+ addDataRate(100,100);
+}
+
+void dummylightsensor::poll()
+{
+ m_reading.setTimestamp(getTimestamp());
+ if ((qrand() % 100) == 0)
+ m_reading.setLightLevel(QAmbientLightReading::Dark);
+ else
+ m_reading.setLightLevel(QAmbientLightReading::Light);
+
+ newReadingAvailable();
+}
+
diff --git a/src/plugins/sensors/dummy/dummylightsensor.h b/src/plugins/sensors/dummy/dummylightsensor.h
new file mode 100644
index 00000000..ba5be132
--- /dev/null
+++ b/src/plugins/sensors/dummy/dummylightsensor.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** 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 DUMMYLIGHTSENSOR_H
+#define DUMMYLIGHTSENSOR_H
+
+#include "dummycommon.h"
+#include <qambientlightsensor.h>
+
+class dummylightsensor : public dummycommon
+{
+public:
+ static char const * const id;
+
+ dummylightsensor(QSensor *sensor);
+
+ void poll();
+private:
+ QAmbientLightReading m_reading;
+};
+
+#endif
+
diff --git a/src/plugins/sensors/dummy/main.cpp b/src/plugins/sensors/dummy/main.cpp
new file mode 100644
index 00000000..b074a0eb
--- /dev/null
+++ b/src/plugins/sensors/dummy/main.cpp
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** 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 "dummyaccelerometer.h"
+#include "dummylightsensor.h"
+#include <qsensorplugin.h>
+#include <qsensorbackend.h>
+#include <qsensormanager.h>
+#include <QFile>
+#include <QDebug>
+
+class dummySensorPlugin : public QObject, public QSensorPluginInterface, public QSensorBackendFactory
+{
+ Q_OBJECT
+ Q_INTERFACES(QSensorPluginInterface)
+public:
+ void registerSensors()
+ {
+ qDebug() << "loaded the dummy plugin";
+ QSensorManager::registerBackend(QAccelerometer::type, dummyaccelerometer::id, this);
+ QSensorManager::registerBackend(QAmbientLightSensor::type, dummylightsensor::id, this);
+ }
+
+ QSensorBackend *createBackend(QSensor *sensor)
+ {
+ if (sensor->identifier() == dummyaccelerometer::id) {
+ return new dummyaccelerometer(sensor);
+ }
+
+ if (sensor->identifier() == dummylightsensor::id) {
+ return new dummylightsensor(sensor);
+ }
+
+ return 0;
+ }
+};
+
+Q_EXPORT_PLUGIN2(qtsensors_dummy, dummySensorPlugin)
+
+#include "main.moc"
+
diff --git a/src/plugins/sensors/generic/generic.pri b/src/plugins/sensors/generic/generic.pri
new file mode 100644
index 00000000..69efdc06
--- /dev/null
+++ b/src/plugins/sensors/generic/generic.pri
@@ -0,0 +1,9 @@
+HEADERS += genericorientationsensor.h\
+ genericrotationsensor.h\
+ genericalssensor.h
+
+SOURCES += genericorientationsensor.cpp\
+ main.cpp\
+ genericrotationsensor.cpp\
+ genericalssensor.cpp
+
diff --git a/src/plugins/sensors/generic/generic.pro b/src/plugins/sensors/generic/generic.pro
new file mode 100644
index 00000000..3d9e9cc4
--- /dev/null
+++ b/src/plugins/sensors/generic/generic.pro
@@ -0,0 +1,24 @@
+load(qt_module)
+
+TARGET = qtsensors_generic
+QT = core sensors
+
+load(qt_plugin)
+
+DESTDIR = $$QT.sensors.plugins/sensors
+
+include(generic.pri)
+
+
+symbian {
+ TARGET.EPOCALLOWDLLDATA = 1
+ TARGET.UID3 = 0x2002BFC3
+ TARGET.CAPABILITY = ALL -TCB
+
+ pluginDep.sources = $${TARGET}.dll
+ pluginDep.path = $${QT_PLUGINS_BASE_DIR}/$${PLUGIN_TYPE}
+ DEPLOYMENT += pluginDep
+}
+
+target.path += $$[QT_INSTALL_PLUGINS]/sensors
+INSTALLS += target
diff --git a/src/plugins/sensors/generic/genericalssensor.cpp b/src/plugins/sensors/generic/genericalssensor.cpp
new file mode 100644
index 00000000..48229966
--- /dev/null
+++ b/src/plugins/sensors/generic/genericalssensor.cpp
@@ -0,0 +1,151 @@
+/****************************************************************************
+**
+** 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 "genericalssensor.h"
+#include <QDebug>
+
+char const * const genericalssensor::id("generic.als");
+
+genericalssensor::genericalssensor(QSensor *sensor)
+ : QSensorBackend(sensor)
+{
+ lightSensor = new QLightSensor(this);
+ lightSensor->addFilter(this);
+ lightSensor->connectToBackend();
+
+ setReading<QAmbientLightReading>(&m_reading);
+ setDataRates(lightSensor);
+}
+
+void genericalssensor::start()
+{
+ lightSensor->setDataRate(sensor()->dataRate());
+ lightSensor->start();
+ if (!lightSensor->isActive())
+ sensorStopped();
+ if (lightSensor->isBusy())
+ sensorBusy();
+}
+
+void genericalssensor::stop()
+{
+ lightSensor->stop();
+}
+
+struct lux_limit {
+ int min;
+ int max;
+};
+
+// Defines the min and max lux values that a given level has.
+// These are used to add histeresis to the sensor.
+// If the previous level is below a level, the lux must be at or above the minimum.
+// If the previous level is above a level, the lux muyt be at or below the maximum.
+static lux_limit limits[] = {
+ { 0, 0 }, // Undefined (not used)
+ { 0, 5 }, // Dark
+ { 10, 50 }, // Twilight
+ { 100, 200 }, // Light
+ { 500, 2000 }, // Bright
+ { 5000, 0 } // Sunny
+};
+
+#if 0
+// Used for debugging
+static QString light_level(int level)
+{
+ switch (level) {
+ case 1:
+ return QLatin1String("Dark");
+ case 2:
+ return QLatin1String("Twilight");
+ case 3:
+ return QLatin1String("Light");
+ case 4:
+ return QLatin1String("Bright");
+ case 5:
+ return QLatin1String("Sunny");
+ default:
+ return QLatin1String("Undefined");
+ }
+}
+#endif
+
+bool genericalssensor::filter(QLightReading *reading)
+{
+ // It's unweildly dealing with these constants so make some
+ // local aliases that are shorter. This makes the code below
+ // much easier to read.
+ enum {
+ Undefined = QAmbientLightReading::Undefined,
+ Dark = QAmbientLightReading::Dark,
+ Twilight = QAmbientLightReading::Twilight,
+ Light = QAmbientLightReading::Light,
+ Bright = QAmbientLightReading::Bright,
+ Sunny = QAmbientLightReading::Sunny
+ };
+
+ int lightLevel = m_reading.lightLevel();
+ qreal lux = reading->lux();
+
+ // Check for change direction to allow for histeresis
+ if (lightLevel < Sunny && lux >= limits[Sunny ].min) lightLevel = Sunny;
+ else if (lightLevel < Bright && lux >= limits[Bright ].min) lightLevel = Bright;
+ else if (lightLevel < Light && lux >= limits[Light ].min) lightLevel = Light;
+ else if (lightLevel < Twilight && lux >= limits[Twilight].min) lightLevel = Twilight;
+ else if (lightLevel < Dark && lux >= limits[Dark ].min) lightLevel = Dark;
+ else if (lightLevel > Dark && lux <= limits[Dark ].max) lightLevel = Dark;
+ else if (lightLevel > Twilight && lux <= limits[Twilight].max) lightLevel = Twilight;
+ else if (lightLevel > Light && lux <= limits[Light ].max) lightLevel = Light;
+ else if (lightLevel > Bright && lux <= limits[Bright ].max) lightLevel = Bright;
+
+ //qDebug() << "lightLevel" << light_level(lightLevel) << "lux" << lux;
+
+ if (static_cast<int>(m_reading.lightLevel()) != lightLevel || m_reading.timestamp() == 0) {
+ m_reading.setTimestamp(reading->timestamp());
+ m_reading.setLightLevel(static_cast<QAmbientLightReading::LightLevel>(lightLevel));
+
+ newReadingAvailable();
+ }
+
+ return false;
+}
+
diff --git a/src/plugins/sensors/generic/genericalssensor.h b/src/plugins/sensors/generic/genericalssensor.h
new file mode 100644
index 00000000..fae005d8
--- /dev/null
+++ b/src/plugins/sensors/generic/genericalssensor.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** 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 GENERICALSSENSOR_H
+#define GENERICALSSENSOR_H
+
+#include <qsensorbackend.h>
+#include <qlightsensor.h>
+#include <qambientlightsensor.h>
+
+class genericalssensor : public QSensorBackend, public QLightFilter
+{
+public:
+ static char const * const id;
+
+ genericalssensor(QSensor *sensor);
+
+ void start();
+ void stop();
+
+ bool filter(QLightReading *reading);
+
+private:
+ QAmbientLightReading m_reading;
+ QLightSensor *lightSensor;
+};
+
+#endif
+
diff --git a/src/plugins/sensors/generic/genericorientationsensor.cpp b/src/plugins/sensors/generic/genericorientationsensor.cpp
new file mode 100644
index 00000000..3716047c
--- /dev/null
+++ b/src/plugins/sensors/generic/genericorientationsensor.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 "genericorientationsensor.h"
+#include <QDebug>
+
+char const * const genericorientationsensor::id("generic.orientation");
+
+genericorientationsensor::genericorientationsensor(QSensor *sensor)
+ : QSensorBackend(sensor)
+{
+ accelerometer = new QAccelerometer(this);
+ accelerometer->addFilter(this);
+ accelerometer->connectToBackend();
+
+ setReading<QOrientationReading>(&m_reading);
+ setDataRates(accelerometer);
+}
+
+void genericorientationsensor::start()
+{
+ accelerometer->setDataRate(sensor()->dataRate());
+ accelerometer->start();
+ if (!accelerometer->isActive())
+ sensorStopped();
+ if (accelerometer->isBusy())
+ sensorBusy();
+}
+
+void genericorientationsensor::stop()
+{
+ accelerometer->stop();
+}
+
+bool genericorientationsensor::filter(QAccelerometerReading *reading)
+{
+ QOrientationReading::Orientation o = m_reading.orientation();
+
+ if (reading->y() > 7.35)
+ o = QOrientationReading::TopUp;
+ else if (reading->y() < -7.35)
+ o = QOrientationReading::TopDown;
+ else if (reading->x() > 7.35)
+ o = QOrientationReading::RightUp;
+ else if (reading->x() < -7.35)
+ o = QOrientationReading::LeftUp;
+ else if (reading->z() > 7.35)
+ o = QOrientationReading::FaceUp;
+ else if (reading->z() < -7.35)
+ o = QOrientationReading::FaceDown;
+
+ if (o != m_reading.orientation() || m_reading.timestamp() == 0) {
+ m_reading.setTimestamp(reading->timestamp());
+ m_reading.setOrientation(o);
+ newReadingAvailable();
+ }
+
+ return false;
+}
+
diff --git a/src/plugins/sensors/generic/genericorientationsensor.h b/src/plugins/sensors/generic/genericorientationsensor.h
new file mode 100644
index 00000000..b66925de
--- /dev/null
+++ b/src/plugins/sensors/generic/genericorientationsensor.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** 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 GENERICORIENTATIONSENSOR_H
+#define GENERICORIENTATIONSENSOR_H
+
+#include <qsensorbackend.h>
+#include <qorientationsensor.h>
+#include <qaccelerometer.h>
+
+class genericorientationsensor : public QSensorBackend, public QAccelerometerFilter
+{
+public:
+ static char const * const id;
+
+ genericorientationsensor(QSensor *sensor);
+
+ void start();
+ void stop();
+
+ bool filter(QAccelerometerReading *reading);
+
+private:
+ QOrientationReading m_reading;
+ QAccelerometer *accelerometer;
+};
+
+#endif
+
diff --git a/src/plugins/sensors/generic/genericrotationsensor.cpp b/src/plugins/sensors/generic/genericrotationsensor.cpp
new file mode 100644
index 00000000..4c735c10
--- /dev/null
+++ b/src/plugins/sensors/generic/genericrotationsensor.cpp
@@ -0,0 +1,115 @@
+/****************************************************************************
+**
+** 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 "genericrotationsensor.h"
+#include <QDebug>
+#include <qmath.h>
+
+#define RADIANS_TO_DEGREES 57.2957795
+
+char const * const genericrotationsensor::id("generic.rotation");
+
+genericrotationsensor::genericrotationsensor(QSensor *sensor)
+ : QSensorBackend(sensor)
+{
+ accelerometer = new QAccelerometer(this);
+ accelerometer->addFilter(this);
+ accelerometer->connectToBackend();
+
+ setReading<QRotationReading>(&m_reading);
+ setDataRates(accelerometer);
+
+ sensor->setProperty("hasZ", false);
+}
+
+void genericrotationsensor::start()
+{
+ accelerometer->setDataRate(sensor()->dataRate());
+ accelerometer->start();
+ if (!accelerometer->isActive())
+ sensorStopped();
+ if (accelerometer->isBusy())
+ sensorBusy();
+}
+
+void genericrotationsensor::stop()
+{
+ accelerometer->stop();
+}
+
+bool genericrotationsensor::filter(QSensorReading *reading)
+{
+ QAccelerometerReading *ar = qobject_cast<QAccelerometerReading*>(reading);
+ qreal pitch = 0;
+ qreal roll = 0;
+
+ qreal x = ar->x();
+ qreal y = ar->y();
+ qreal z = ar->z();
+
+ // Note that the formula used come from this document:
+ // http://www.freescale.com/files/sensors/doc/app_note/AN3461.pdf
+ pitch = qAtan(y / sqrt(x*x + z*z)) * RADIANS_TO_DEGREES;
+ roll = qAtan(x / sqrt(y*y + z*z)) * RADIANS_TO_DEGREES;
+ // Roll is a left-handed rotation but we need right-handed rotation
+ roll = -roll;
+
+ // We need to fix up roll to the (-180,180] range required.
+ // Check for negative theta values and apply an offset as required.
+ // Note that theta is defined as the angle of the Z axis relative
+ // to gravity (see referenced document). It's negative when the
+ // face of the device points downward.
+ qreal theta = qAtan(sqrt(x*x + y*y) / z) * RADIANS_TO_DEGREES;
+ if (theta < 0) {
+ if (roll > 0)
+ roll = 180 - roll;
+ else
+ roll = -180 - roll;
+ }
+
+ m_reading.setTimestamp(ar->timestamp());
+ m_reading.setX(pitch);
+ m_reading.setY(roll);
+ m_reading.setZ(0);
+ newReadingAvailable();
+ return false;
+}
+
diff --git a/src/plugins/sensors/generic/genericrotationsensor.h b/src/plugins/sensors/generic/genericrotationsensor.h
new file mode 100644
index 00000000..bf2731df
--- /dev/null
+++ b/src/plugins/sensors/generic/genericrotationsensor.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** 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 GENERICROTATIONSENSOR_H
+#define GENERICROTATIONSENSOR_H
+
+#include <qsensorbackend.h>
+#include <qrotationsensor.h>
+#include <qaccelerometer.h>
+#include <qmagnetometer.h>
+
+class genericrotationsensor : public QSensorBackend, public QSensorFilter
+{
+public:
+ static char const * const id;
+
+ genericrotationsensor(QSensor *sensor);
+
+ void start();
+ void stop();
+
+ bool filter(QSensorReading *reading);
+
+private:
+ QRotationReading m_reading;
+ QAccelerometer *accelerometer;
+ QMagnetometer *magnetometer;
+};
+
+#endif
+
diff --git a/src/plugins/sensors/generic/main.cpp b/src/plugins/sensors/generic/main.cpp
new file mode 100644
index 00000000..26bb0e80
--- /dev/null
+++ b/src/plugins/sensors/generic/main.cpp
@@ -0,0 +1,100 @@
+/****************************************************************************
+**
+** 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 "genericorientationsensor.h"
+#include "genericrotationsensor.h"
+#include "genericalssensor.h"
+#include <qsensorplugin.h>
+#include <qsensorbackend.h>
+#include <qsensormanager.h>
+#include <QFile>
+#include <QDebug>
+
+class genericSensorPlugin : public QObject, public QSensorPluginInterface, public QSensorChangesInterface, public QSensorBackendFactory
+{
+ Q_OBJECT
+ Q_INTERFACES(QSensorPluginInterface QSensorChangesInterface)
+public:
+ void registerSensors()
+ {
+ qDebug() << "loaded the Generic plugin";
+ // Nothing to register here
+ }
+
+ void sensorsChanged()
+ {
+ if (!QSensor::defaultSensorForType(QAccelerometer::type).isEmpty()) {
+ // There is an accelerometer available. Register the backends
+ if (!QSensorManager::isBackendRegistered(QOrientationSensor::type, genericorientationsensor::id))
+ QSensorManager::registerBackend(QOrientationSensor::type, genericorientationsensor::id, this);
+ if (!QSensorManager::isBackendRegistered(QRotationSensor::type, genericrotationsensor::id))
+ QSensorManager::registerBackend(QRotationSensor::type, genericrotationsensor::id, this);
+ if (!QSensorManager::isBackendRegistered(QAmbientLightSensor::type, genericalssensor::id))
+ QSensorManager::registerBackend(QAmbientLightSensor::type, genericalssensor::id, this);
+ } else {
+ if (QSensorManager::isBackendRegistered(QOrientationSensor::type, genericorientationsensor::id))
+ QSensorManager::unregisterBackend(QOrientationSensor::type, genericorientationsensor::id);
+ if (QSensorManager::isBackendRegistered(QRotationSensor::type, genericrotationsensor::id))
+ QSensorManager::unregisterBackend(QRotationSensor::type, genericrotationsensor::id);
+ if (QSensorManager::isBackendRegistered(QAmbientLightSensor::type, genericalssensor::id))
+ QSensorManager::unregisterBackend(QAmbientLightSensor::type, genericalssensor::id);
+ }
+ }
+
+ QSensorBackend *createBackend(QSensor *sensor)
+ {
+ if (sensor->identifier() == genericorientationsensor::id)
+ return new genericorientationsensor(sensor);
+
+ if (sensor->identifier() == genericrotationsensor::id)
+ return new genericrotationsensor(sensor);
+
+ if (sensor->identifier() == genericalssensor::id)
+ return new genericalssensor(sensor);
+
+ return 0;
+ }
+};
+
+Q_EXPORT_PLUGIN2(qtsensors_generic, genericSensorPlugin)
+
+#include "main.moc"
+
diff --git a/src/plugins/sensors/sensors.pro b/src/plugins/sensors/sensors.pro
new file mode 100644
index 00000000..f3d3525c
--- /dev/null
+++ b/src/plugins/sensors/sensors.pro
@@ -0,0 +1,5 @@
+TEMPLATE = subdirs
+
+SUBDIRS += dummy generic
+#simulator: SUBDIRS += simulator
+
diff --git a/src/plugins/sensors/simulator/main.cpp b/src/plugins/sensors/simulator/main.cpp
new file mode 100644
index 00000000..be932ad9
--- /dev/null
+++ b/src/plugins/sensors/simulator/main.cpp
@@ -0,0 +1,102 @@
+/****************************************************************************
+**
+** 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 "simulatoraccelerometer.h"
+#include "simulatorambientlightsensor.h"
+#include "simulatorlightsensor.h"
+#include "simulatorcompass.h"
+#include "simulatorproximitysensor.h"
+#include "simulatormagnetometer.h"
+#include <qsensorplugin.h>
+#include <qsensorbackend.h>
+#include <qsensormanager.h>
+#include <QFile>
+#include <QDebug>
+
+class SimulatorSensorPlugin : public QObject, public QSensorPluginInterface, public QSensorBackendFactory
+{
+ Q_OBJECT
+ Q_INTERFACES(QSensorPluginInterface)
+public:
+ void registerSensors()
+ {
+ QSensorManager::registerBackend(QAccelerometer::type, SimulatorAccelerometer::id, this);
+ QSensorManager::registerBackend(QAmbientLightSensor::type, SimulatorAmbientLightSensor::id, this);
+ QSensorManager::registerBackend(QLightSensor::type, SimulatorLightSensor::id, this);
+ QSensorManager::registerBackend(QCompass::type, SimulatorCompass::id, this);
+ QSensorManager::registerBackend(QProximitySensor::type, SimulatorProximitySensor::id, this);
+ QSensorManager::registerBackend(QMagnetometer::type, SimulatorMagnetometer::id, this);
+ }
+
+ QSensorBackend *createBackend(QSensor *sensor)
+ {
+ if (sensor->identifier() == SimulatorAccelerometer::id) {
+ return new SimulatorAccelerometer(sensor);
+ }
+
+ if (sensor->identifier() == SimulatorAmbientLightSensor::id) {
+ return new SimulatorAmbientLightSensor(sensor);
+ }
+
+ if (sensor->identifier() == SimulatorLightSensor::id) {
+ return new SimulatorLightSensor(sensor);
+ }
+
+ if (sensor->identifier() == SimulatorProximitySensor::id) {
+ return new SimulatorProximitySensor(sensor);
+ }
+
+ if (sensor->identifier() == SimulatorCompass::id) {
+ return new SimulatorCompass(sensor);
+ }
+
+ if (sensor->identifier() == SimulatorMagnetometer::id) {
+ return new SimulatorMagnetometer(sensor);
+ }
+
+ return 0;
+ }
+};
+
+Q_EXPORT_PLUGIN2(libsensors_simulator, SimulatorSensorPlugin)
+
+#include "main.moc"
+
diff --git a/src/plugins/sensors/simulator/qsensordata_simulator.cpp b/src/plugins/sensors/simulator/qsensordata_simulator.cpp
new file mode 100644
index 00000000..205a3335
--- /dev/null
+++ b/src/plugins/sensors/simulator/qsensordata_simulator.cpp
@@ -0,0 +1,128 @@
+/****************************************************************************
+**
+** 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 "qsensordata_simulator_p.h"
+
+#include <QtCore/QDataStream>
+
+void qt_registerSensorTypes()
+{
+ qRegisterMetaTypeStreamOperators<QAmbientLightReadingData>("QtMobility::QAmbientLightReadingData");
+ qRegisterMetaTypeStreamOperators<QLightReadingData>("QtMobility::QLightReadingData");
+ qRegisterMetaTypeStreamOperators<QAccelerometerReadingData>("QtMobility::QAccelerometerReadingData");
+ qRegisterMetaTypeStreamOperators<QCompassReadingData>("QtMobility::QCompassReadingData");
+ qRegisterMetaTypeStreamOperators<QProximityReadingData>("QtMobility::QProximityReadingData");
+ qRegisterMetaTypeStreamOperators<QMagnetometerReadingData>("QtMobility::QMagnetometerReadingData");
+}
+
+QDataStream &operator<<(QDataStream &out, const QAmbientLightReadingData &s)
+{
+ out << static_cast<qint32>(s.lightLevel) << s.timestamp;
+ return out;
+}
+
+QDataStream &operator>>(QDataStream &in, QAmbientLightReadingData &s)
+{
+ qint32 lightLevel;
+ in >> lightLevel >> s.timestamp;
+ s.lightLevel = static_cast<QAmbientLightReading::LightLevel>(lightLevel);
+ return in;
+}
+
+QDataStream &operator<<(QDataStream &out, const QLightReadingData &s)
+{
+ out << s.lux << s.timestamp;
+ return out;
+}
+
+QDataStream &operator>>(QDataStream &in, QLightReadingData &s)
+{
+ in >> s.lux >> s.timestamp;
+ return in;
+}
+
+QDataStream &operator<<(QDataStream &out, const QAccelerometerReadingData &s)
+{
+ out << s.x << s.y << s.z << s.timestamp;
+ return out;
+}
+
+QDataStream &operator>>(QDataStream &in, QAccelerometerReadingData &s)
+{
+ in >> s.x >> s.y >> s.z >> s.timestamp;
+ return in;
+}
+
+QDataStream &operator<<(QDataStream &out, const QCompassReadingData &s)
+{
+ out << s.azimuth << s.calibrationLevel << s.timestamp;
+ return out;
+}
+
+QDataStream &operator>>(QDataStream &in, QCompassReadingData &s)
+{
+ in >> s.azimuth >> s.calibrationLevel >> s.timestamp;
+ return in;
+}
+
+QDataStream &operator<<(QDataStream &out, const QProximityReadingData &s)
+{
+ out << s.close << s.timestamp;
+ return out;
+}
+
+QDataStream &operator>>(QDataStream &in, QProximityReadingData &s)
+{
+ in >> s.close >> s.timestamp;
+ return in;
+}
+
+QDataStream &operator<<(QDataStream &out, const QMagnetometerReadingData &s)
+{
+ out << s.x << s.y << s.z << s.calibrationLevel << s.timestamp;
+ return out;
+}
+
+QDataStream &operator>>(QDataStream &in, QMagnetometerReadingData &s)
+{
+ in >> s.x >> s.y >> s.z >> s.calibrationLevel >> s.timestamp;
+ return in;
+}
diff --git a/src/plugins/sensors/simulator/qsensordata_simulator_p.h b/src/plugins/sensors/simulator/qsensordata_simulator_p.h
new file mode 100644
index 00000000..ca15ceb0
--- /dev/null
+++ b/src/plugins/sensors/simulator/qsensordata_simulator_p.h
@@ -0,0 +1,116 @@
+/****************************************************************************
+**
+** 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 QSENSORDATA_SIMULATOR_P_H
+#define QSENSORDATA_SIMULATOR_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 <qambientlightsensor.h>
+#include <QtCore/QMetaType>
+#include <QtCore/QDateTime>
+
+QT_BEGIN_HEADER
+
+struct QAmbientLightReadingData
+{
+ QAmbientLightReading::LightLevel lightLevel;
+ QDateTime timestamp;
+};
+
+struct QLightReadingData
+{
+ double lux;
+ QDateTime timestamp;
+};
+
+struct QAccelerometerReadingData
+{
+ double x;
+ double y;
+ double z;
+ QDateTime timestamp;
+};
+
+struct QMagnetometerReadingData
+{
+ double x;
+ double y;
+ double z;
+ double calibrationLevel;
+ QDateTime timestamp;
+};
+
+struct QCompassReadingData
+{
+ double azimuth;
+ double calibrationLevel;
+ QDateTime timestamp;
+};
+
+struct QProximityReadingData
+{
+ bool close;
+ QDateTime timestamp;
+};
+
+void qt_registerSensorTypes();
+
+
+Q_DECLARE_METATYPE(QAmbientLightReadingData)
+Q_DECLARE_METATYPE(QLightReadingData)
+Q_DECLARE_METATYPE(QAccelerometerReadingData)
+Q_DECLARE_METATYPE(QMagnetometerReadingData)
+Q_DECLARE_METATYPE(QCompassReadingData)
+Q_DECLARE_METATYPE(QProximityReadingData)
+
+QT_END_HEADER
+
+#endif // QSENSORDATA_SIMULATOR_P_H
diff --git a/src/plugins/sensors/simulator/simulator.pri b/src/plugins/sensors/simulator/simulator.pri
new file mode 100644
index 00000000..bdce2b4a
--- /dev/null
+++ b/src/plugins/sensors/simulator/simulator.pri
@@ -0,0 +1,19 @@
+HEADERS += simulatorcommon.h\
+ simulatoraccelerometer.h\
+ simulatorambientlightsensor.h\
+ simulatorlightsensor.h\
+ simulatorcompass.h\
+ simulatorproximitysensor.h\
+ simulatormagnetometer.h\
+ qsensordata_simulator_p.h
+
+SOURCES += simulatorcommon.cpp\
+ simulatoraccelerometer.cpp\
+ simulatorambientlightsensor.cpp\
+ simulatorlightsensor.cpp\
+ simulatorcompass.cpp\
+ simulatorproximitysensor.cpp\
+ simulatormagnetometer.cpp\
+ qsensordata_simulator.cpp\
+ main.cpp
+
diff --git a/src/plugins/sensors/simulator/simulator.pro b/src/plugins/sensors/simulator/simulator.pro
new file mode 100644
index 00000000..18f515b1
--- /dev/null
+++ b/src/plugins/sensors/simulator/simulator.pro
@@ -0,0 +1,19 @@
+load(qt_module)
+
+include(simulator.pri)
+
+TARGET = qtsensors_simulator
+load(qt_plugin)
+
+DESTDIR = $$QT.sensors.plugins/sensors
+
+#TODO what is the simulator called in Qt 5?
+#qtAddLibrary(QtMobilitySimulator)
+
+symbian:TARGET.EPOCALLOWDLLDATA = 1
+
+QT=core gui network sensors
+
+target.path += $$[QT_INSTALL_PLUGINS]/sensors
+INSTALLS += target
+
diff --git a/src/plugins/sensors/simulator/simulatoraccelerometer.cpp b/src/plugins/sensors/simulator/simulatoraccelerometer.cpp
new file mode 100644
index 00000000..c1eb0f20
--- /dev/null
+++ b/src/plugins/sensors/simulator/simulatoraccelerometer.cpp
@@ -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$
+**
+****************************************************************************/
+
+#include "simulatoraccelerometer.h"
+#include <QDebug>
+#include <QtGlobal>
+
+const char *SimulatorAccelerometer::id("Simulator.Accelerometer");
+
+SimulatorAccelerometer::SimulatorAccelerometer(QSensor *sensor)
+ : SimulatorCommon(sensor)
+{
+ setReading<QAccelerometerReading>(&m_reading);
+}
+
+void SimulatorAccelerometer::poll()
+{
+ QtMobility::QAccelerometerReadingData data = get_qtAccelerometerData();
+ qtimestamp newTimestamp;
+ if (!data.timestamp.isValid())
+ newTimestamp = QDateTime::currentDateTime().toTime_t();
+ else
+ newTimestamp = data.timestamp.toTime_t();
+ if (m_reading.timestamp() != newTimestamp
+ || m_reading.x() != data.x
+ || m_reading.y() != data.y
+ || m_reading.z() != data.z) {
+ m_reading.setTimestamp(newTimestamp);
+ m_reading.setX(data.x);
+ m_reading.setY(data.y);
+ m_reading.setZ(data.z);
+
+ newReadingAvailable();
+ }
+}
+
diff --git a/src/plugins/sensors/simulator/simulatoraccelerometer.h b/src/plugins/sensors/simulator/simulatoraccelerometer.h
new file mode 100644
index 00000000..9c78508d
--- /dev/null
+++ b/src/plugins/sensors/simulator/simulatoraccelerometer.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** 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 SIMULATORACCELEROMETER_H
+#define SIMULATORACCELEROMETER_H
+
+#include "simulatorcommon.h"
+#include <qaccelerometer.h>
+
+class SimulatorAccelerometer : public SimulatorCommon
+{
+public:
+ static const char *id;
+
+ SimulatorAccelerometer(QSensor *sensor);
+
+ void poll();
+private:
+ QAccelerometerReading m_reading;
+};
+
+#endif
+
diff --git a/src/plugins/sensors/simulator/simulatorambientlightsensor.cpp b/src/plugins/sensors/simulator/simulatorambientlightsensor.cpp
new file mode 100644
index 00000000..d23412da
--- /dev/null
+++ b/src/plugins/sensors/simulator/simulatorambientlightsensor.cpp
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** 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 "simulatorambientlightsensor.h"
+#include <QDebug>
+#include <QtGlobal>
+
+const char *SimulatorAmbientLightSensor::id("Simulator.AmbientLightSensor");
+
+SimulatorAmbientLightSensor::SimulatorAmbientLightSensor(QSensor *sensor)
+ : SimulatorCommon(sensor)
+{
+ setReading<QAmbientLightReading>(&m_reading);
+}
+
+void SimulatorAmbientLightSensor::poll()
+{
+ QAmbientLightReadingData data = get_qtAmbientLightData();
+ qtimestamp newTimestamp;
+ if (!data.timestamp.isValid())
+ newTimestamp = QDateTime::currentDateTime().toTime_t();
+ else
+ newTimestamp = data.timestamp.toTime_t();
+ if (m_reading.timestamp() != newTimestamp
+ || m_reading.lightLevel() != data.lightLevel) {
+ m_reading.setTimestamp(newTimestamp);
+ m_reading.setLightLevel(data.lightLevel);
+
+ newReadingAvailable();
+ }
+}
+
diff --git a/src/plugins/sensors/simulator/simulatorambientlightsensor.h b/src/plugins/sensors/simulator/simulatorambientlightsensor.h
new file mode 100644
index 00000000..441f3ed2
--- /dev/null
+++ b/src/plugins/sensors/simulator/simulatorambientlightsensor.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** 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 SIMULATORAMBIENTLIGHTSENSOR_H
+#define SIMULATORAMBIENTLIGHTSENSOR_H
+
+#include "simulatorcommon.h"
+#include <qambientlightsensor.h>
+
+class SimulatorAmbientLightSensor : public SimulatorCommon
+{
+public:
+ static const char *id;
+
+ SimulatorAmbientLightSensor(QSensor *sensor);
+
+ void poll();
+private:
+ QAmbientLightReading m_reading;
+};
+
+#endif
+
diff --git a/src/plugins/sensors/simulator/simulatorcommon.cpp b/src/plugins/sensors/simulator/simulatorcommon.cpp
new file mode 100644
index 00000000..c7c46ed0
--- /dev/null
+++ b/src/plugins/sensors/simulator/simulatorcommon.cpp
@@ -0,0 +1,200 @@
+/****************************************************************************
+**
+** 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 "simulatorcommon.h"
+#include "qsensordata_simulator_p.h"
+#include "mobilitysimulatorglobal.h"
+#include <mobilityconnection_p.h>
+
+#include <private/qsimulatordata_p.h>
+
+#include <QtNetwork/QLocalSocket>
+
+using namespace QtSimulatorPrivate;
+
+Q_GLOBAL_STATIC(QAmbientLightReadingData, qtAmbientLightData)
+Q_GLOBAL_STATIC(QLightReadingData, qtLightData)
+Q_GLOBAL_STATIC(QAccelerometerReadingData, qtAccelerometerData)
+Q_GLOBAL_STATIC(QMagnetometerReadingData, qtMagnetometerData)
+Q_GLOBAL_STATIC(QCompassReadingData, qtCompassData)
+Q_GLOBAL_STATIC(QProximityReadingData, qtProximityData)
+
+namespace Simulator
+{
+ SensorsConnection::SensorsConnection(MobilityConnection *mobilityCon)
+ : QObject(mobilityCon)
+ , mConnection(mobilityCon)
+ , mInitialDataReceived(false)
+ {
+ qt_registerSensorTypes();
+ mobilityCon->addMessageHandler(this);
+ }
+
+
+ void SensorsConnection::getInitialData()
+ {
+ RemoteMetacall<void>::call(mConnection->sendSocket(), NoSync, "setRequestsSensors");
+
+ while (!mInitialDataReceived) {
+ mConnection->receiveSocket()->waitForReadyRead(100);
+ mConnection->onReadyRead();
+ }
+ }
+
+ void SensorsConnection::initialSensorsDataSent()
+ {
+ mInitialDataReceived = true;
+ }
+
+ void SensorsConnection::setAmbientLightData(const QAmbientLightReadingData &data)
+ {
+ *qtAmbientLightData() = data;
+ }
+
+ void SensorsConnection::setLightData(const QLightReadingData &data)
+ {
+ *qtLightData() = data;
+ }
+
+ void SensorsConnection::setAccelerometerData(const QAccelerometerReadingData &data)
+ {
+ *qtAccelerometerData() = data;
+ }
+
+ void SensorsConnection::setMagnetometerData(const QMagnetometerReadingData &data)
+ {
+ *qtMagnetometerData() = data;
+ }
+
+ void SensorsConnection::setCompassData(const QCompassReadingData &data)
+ {
+ *qtCompassData() = data;
+ }
+
+ void SensorsConnection::setProximityData(const QProximityReadingData &data)
+ {
+ *qtProximityData() = data;
+ }
+} // namespace
+
+void ensureSimulatorConnection()
+{
+ using namespace Simulator;
+
+ static bool connected = false;
+ if (connected)
+ return;
+
+ connected = true;
+ MobilityConnection *connection = MobilityConnection::instance();
+ SensorsConnection *sensorsConnection = new SensorsConnection(connection);
+ sensorsConnection->getInitialData();
+}
+
+SimulatorCommon::SimulatorCommon(QSensor *sensor)
+ : QSensorBackend(sensor)
+ , m_timerid(0)
+{
+ addDataRate(1, 100);
+ sensor->setDataRate(20);
+ ensureSimulatorConnection();
+}
+
+void SimulatorCommon::start()
+{
+ if (m_timerid)
+ return;
+
+ int rate = sensor()->dataRate();
+ if (rate == 0)
+ rate = 20;
+ int interval = 1000 / rate;
+ if (interval < 0)
+ interval = 1000;
+
+ if (interval)
+ m_timerid = startTimer(interval);
+}
+
+void SimulatorCommon::stop()
+{
+ if (m_timerid) {
+ killTimer(m_timerid);
+ m_timerid = 0;
+ }
+}
+
+void SimulatorCommon::timerEvent(QTimerEvent * /*event*/)
+{
+ poll();
+}
+
+QAccelerometerReadingData get_qtAccelerometerData()
+{
+ return *qtAccelerometerData();
+}
+
+QMagnetometerReadingData get_qtMagnetometerData()
+{
+ return *qtMagnetometerData();
+}
+
+QAmbientLightReadingData get_qtAmbientLightData()
+{
+ return *qtAmbientLightData();
+}
+
+QLightReadingData get_qtLightData()
+{
+ return *qtLightData();
+}
+
+QCompassReadingData get_qtCompassData()
+{
+ return *qtCompassData();
+}
+
+QProximityReadingData get_qtProximityData()
+{
+ return *qtProximityData();
+}
+
+#include "moc_simulatorcommon.cpp"
diff --git a/src/plugins/sensors/simulator/simulatorcommon.h b/src/plugins/sensors/simulator/simulatorcommon.h
new file mode 100644
index 00000000..312a95de
--- /dev/null
+++ b/src/plugins/sensors/simulator/simulatorcommon.h
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** 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 SIMULATORCOMMON_H
+#define SIMULATORCOMMON_H
+
+#include <qsensorbackend.h>
+#include "qsensordata_simulator_p.h"
+
+QT_BEGIN_HEADER
+
+class QTimer;
+
+namespace Simulator
+{
+ class MobilityConnection;
+
+ class SensorsConnection : public QObject
+ {
+ Q_OBJECT
+ public:
+ SensorsConnection(MobilityConnection *mobilityCon);
+ virtual ~SensorsConnection() {}
+
+ void getInitialData();
+
+ private slots:
+ void setAmbientLightData(const QtMobility::QAmbientLightReadingData &);
+ void setLightData(const QtMobility::QLightReadingData &);
+ void setAccelerometerData(const QtMobility::QAccelerometerReadingData &);
+ void setMagnetometerData(const QtMobility::QMagnetometerReadingData &);
+ void setCompassData(const QtMobility::QCompassReadingData &);
+ void setProximityData(const QtMobility::QProximityReadingData &);
+ void initialSensorsDataSent();
+
+ private:
+ MobilityConnection *mConnection;
+ bool mInitialDataReceived;
+ };
+} // end namespace Simulator
+
+class SimulatorCommon : public QSensorBackend
+{
+public:
+ SimulatorCommon(QSensor *sensor);
+
+ void start();
+ void stop();
+ virtual void poll() = 0;
+ void timerEvent(QTimerEvent * /*event*/);
+
+private:
+ int m_timerid;
+};
+
+QAccelerometerReadingData get_qtAccelerometerData();
+QMagnetometerReadingData get_qtMagnetometerData();
+QAmbientLightReadingData get_qtAmbientLightData();
+QLightReadingData get_qtLightData();
+QCompassReadingData get_qtCompassData();
+QProximityReadingData get_qtProximityData();
+
+QT_END_HEADER
+
+#endif
+
diff --git a/src/plugins/sensors/simulator/simulatorcompass.cpp b/src/plugins/sensors/simulator/simulatorcompass.cpp
new file mode 100644
index 00000000..d6a2cccd
--- /dev/null
+++ b/src/plugins/sensors/simulator/simulatorcompass.cpp
@@ -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$
+**
+****************************************************************************/
+
+#include "simulatorcompass.h"
+#include <QDebug>
+#include <QtGlobal>
+
+const char *SimulatorCompass::id("Simulator.Compass");
+
+SimulatorCompass::SimulatorCompass(QSensor *sensor)
+ : SimulatorCommon(sensor)
+{
+ setReading<QCompassReading>(&m_reading);
+}
+
+void SimulatorCompass::poll()
+{
+ QtMobility::QCompassReadingData data = get_qtCompassData();
+ qtimestamp newTimestamp;
+ if (!data.timestamp.isValid())
+ newTimestamp = QDateTime::currentDateTime().toTime_t();
+ else
+ newTimestamp = data.timestamp.toTime_t();
+ if (m_reading.timestamp() != newTimestamp
+ || m_reading.azimuth() != data.azimuth
+ || m_reading.calibrationLevel() != data.calibrationLevel) {
+ m_reading.setTimestamp(newTimestamp);
+ m_reading.setAzimuth(data.azimuth);
+ m_reading.setCalibrationLevel(data.calibrationLevel);
+
+ newReadingAvailable();
+ }
+}
+
diff --git a/src/plugins/sensors/simulator/simulatorcompass.h b/src/plugins/sensors/simulator/simulatorcompass.h
new file mode 100644
index 00000000..4ad3a059
--- /dev/null
+++ b/src/plugins/sensors/simulator/simulatorcompass.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** 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 SIMULATORCOMPASS_H
+#define SIMULATORCOMPASS_H
+
+#include "simulatorcommon.h"
+#include <qcompass.h>
+
+class SimulatorCompass : public SimulatorCommon
+{
+public:
+ static const char *id;
+
+ SimulatorCompass(QSensor *sensor);
+
+ void poll();
+private:
+ QCompassReading m_reading;
+};
+
+#endif
+
diff --git a/src/plugins/sensors/simulator/simulatorlightsensor.cpp b/src/plugins/sensors/simulator/simulatorlightsensor.cpp
new file mode 100644
index 00000000..9cce94dd
--- /dev/null
+++ b/src/plugins/sensors/simulator/simulatorlightsensor.cpp
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** 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 "simulatorlightsensor.h"
+#include <QDebug>
+#include <QtGlobal>
+
+const char *SimulatorLightSensor::id("Simulator.LightSensor");
+
+SimulatorLightSensor::SimulatorLightSensor(QSensor *sensor)
+ : SimulatorCommon(sensor)
+{
+ setReading<QLightReading>(&m_reading);
+}
+
+void SimulatorLightSensor::poll()
+{
+ QLightReadingData data = get_qtLightData();
+ qtimestamp newTimestamp;
+ if (!data.timestamp.isValid())
+ newTimestamp = QDateTime::currentDateTime().toTime_t();
+ else
+ newTimestamp = data.timestamp.toTime_t();
+ if (m_reading.timestamp() != newTimestamp
+ || m_reading.lux() != data.lux) {
+ m_reading.setTimestamp(newTimestamp);
+ m_reading.setLux(data.lux);
+
+ newReadingAvailable();
+ }
+}
+
diff --git a/src/plugins/sensors/simulator/simulatorlightsensor.h b/src/plugins/sensors/simulator/simulatorlightsensor.h
new file mode 100644
index 00000000..acd44c0b
--- /dev/null
+++ b/src/plugins/sensors/simulator/simulatorlightsensor.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** 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 SIMULATORLIGHTSENSOR_H
+#define SIMULATORLIGHTSENSOR_H
+
+#include "simulatorcommon.h"
+#include <qlightsensor.h>
+
+class SimulatorLightSensor : public SimulatorCommon
+{
+public:
+ static const char *id;
+
+ SimulatorLightSensor(QSensor *sensor);
+
+ void poll();
+private:
+ QLightReading m_reading;
+};
+
+#endif
+
diff --git a/src/plugins/sensors/simulator/simulatormagnetometer.cpp b/src/plugins/sensors/simulator/simulatormagnetometer.cpp
new file mode 100644
index 00000000..ab0ba5d0
--- /dev/null
+++ b/src/plugins/sensors/simulator/simulatormagnetometer.cpp
@@ -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$
+**
+****************************************************************************/
+
+#include "simulatormagnetometer.h"
+#include <QDebug>
+#include <QtGlobal>
+
+const char *SimulatorMagnetometer::id("Simulator.Magnetometer");
+
+SimulatorMagnetometer::SimulatorMagnetometer(QSensor *sensor)
+ : SimulatorCommon(sensor)
+{
+ setReading<QMagnetometerReading>(&m_reading);
+}
+
+void SimulatorMagnetometer::poll()
+{
+ QtMobility::QMagnetometerReadingData data = get_qtMagnetometerData();
+ qtimestamp newTimestamp;
+ if (!data.timestamp.isValid())
+ newTimestamp = QDateTime::currentDateTime().toTime_t();
+ else
+ newTimestamp = data.timestamp.toTime_t();
+ if (m_reading.timestamp() != newTimestamp
+ || m_reading.x() != data.x
+ || m_reading.y() != data.y
+ || m_reading.z() != data.z
+ || m_reading.calibrationLevel() != data.calibrationLevel) {
+ m_reading.setTimestamp(newTimestamp);
+ m_reading.setX(data.x);
+ m_reading.setY(data.y);
+ m_reading.setZ(data.z);
+ m_reading.setCalibrationLevel(data.calibrationLevel);
+
+ newReadingAvailable();
+ }
+}
+
diff --git a/src/plugins/sensors/simulator/simulatormagnetometer.h b/src/plugins/sensors/simulator/simulatormagnetometer.h
new file mode 100644
index 00000000..6cf75122
--- /dev/null
+++ b/src/plugins/sensors/simulator/simulatormagnetometer.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** 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 SIMULATORMAGNETOMETER_H
+#define SIMULATORMAGNETOMETER_H
+
+#include "simulatorcommon.h"
+#include <qmagnetometer.h>
+
+class SimulatorMagnetometer : public SimulatorCommon
+{
+public:
+ static const char *id;
+
+ SimulatorMagnetometer(QSensor *sensor);
+
+ void poll();
+private:
+ QMagnetometerReading m_reading;
+};
+
+#endif
+
diff --git a/src/plugins/sensors/simulator/simulatorproximitysensor.cpp b/src/plugins/sensors/simulator/simulatorproximitysensor.cpp
new file mode 100644
index 00000000..44b99269
--- /dev/null
+++ b/src/plugins/sensors/simulator/simulatorproximitysensor.cpp
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** 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 "simulatorproximitysensor.h"
+#include <QDebug>
+#include <QtGlobal>
+
+const char *SimulatorProximitySensor::id("Simulator.ProximitySensor");
+
+SimulatorProximitySensor::SimulatorProximitySensor(QSensor *sensor)
+ : SimulatorCommon(sensor)
+{
+ setReading<QProximityReading>(&m_reading);
+}
+
+void SimulatorProximitySensor::poll()
+{
+ QtMobility::QProximityReadingData data = get_qtProximityData();
+ qtimestamp newTimestamp;
+ if (!data.timestamp.isValid())
+ newTimestamp = QDateTime::currentDateTime().toTime_t();
+ else
+ newTimestamp = data.timestamp.toTime_t();
+ if (m_reading.timestamp() != newTimestamp
+ || m_reading.close() != data.close) {
+ m_reading.setTimestamp(newTimestamp);
+ m_reading.setClose(data.close);
+
+ newReadingAvailable();
+ }
+}
+
diff --git a/src/plugins/sensors/simulator/simulatorproximitysensor.h b/src/plugins/sensors/simulator/simulatorproximitysensor.h
new file mode 100644
index 00000000..5b2a1777
--- /dev/null
+++ b/src/plugins/sensors/simulator/simulatorproximitysensor.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** 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 SIMULATORPROXIMITYSENSOR_H
+#define SIMULATORPROXIMITYSENSOR_H
+
+#include "simulatorcommon.h"
+#include <qproximitysensor.h>
+
+class SimulatorProximitySensor : public SimulatorCommon
+{
+public:
+ static const char *id;
+
+ SimulatorProximitySensor(QSensor *sensor);
+
+ void poll();
+private:
+ QProximityReading m_reading;
+};
+
+#endif
+