summaryrefslogtreecommitdiff
path: root/src/plugins/sensors/dummy
diff options
context:
space:
mode:
authorAlex <qt-info@nokia.com>2011-06-09 18:31:09 +1000
committerAlex <qt-info@nokia.com>2011-06-10 15:34:08 +1000
commit164e4f5813d8beb30ce8e1555f49f84b785c0d51 (patch)
tree5ee0569d239e50695f6ae4c3357b506ea16b1abb /src/plugins/sensors/dummy
parentca4eb890b701035dfd472e0fb9aab23a9733a01d (diff)
downloadqtsensors-164e4f5813d8beb30ce8e1555f49f84b785c0d51.tar.gz
Add dummy, generic and simulator backend
The Simulator backend is not working/tested at this stage as the simulator library is not available for Qt5 at this stage. In addtion the sensor_explorer test app was added for simple sensor testing.
Diffstat (limited to 'src/plugins/sensors/dummy')
-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
9 files changed, 536 insertions, 0 deletions
diff --git a/src/plugins/sensors/dummy/dummy.pri b/src/plugins/sensors/dummy/dummy.pri
new file mode 100644
index 0000000..502081c
--- /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 0000000..3ccfad6
--- /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 0000000..5db80f5
--- /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 0000000..2293d53
--- /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 0000000..643342d
--- /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 0000000..e0a0e02
--- /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 0000000..a4bc6fe
--- /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 0000000..ba5be13
--- /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 0000000..b074a0e
--- /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"
+