diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2011-06-15 14:04:28 +1000 |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2011-06-15 14:04:28 +1000 |
commit | 65eeff39f1ded93ff48dbbd7058a6987f6642936 (patch) | |
tree | ccfa0c532e9c17b3e758cb991f42b702cb183816 | |
parent | c839f1340cfef41696647de9ee71edc2389452ce (diff) | |
parent | f4e111e25fd37c74cae3cf0d8d46a6b47e0337ce (diff) |
Merge branch 'master' of git://scm.dev.nokia.troll.no/qt/qtsensors-staging
* 'master' of git://scm.dev.nokia.troll.no/qt/qtsensors-staging:
Fix mac dependencies for dummy sensor plug-in.
honour configures -nomake examples/tests/demos flags in QtSensors
make MacOS compile
use MacOS specific monotonic time
Add dummy, generic and simulator backend
47 files changed, 3761 insertions, 2 deletions
diff --git a/qtsensors.pro b/qtsensors.pro index 16236164..f5040084 100644 --- a/qtsensors.pro +++ b/qtsensors.pro @@ -3,4 +3,12 @@ TEMPLATE = subdirs module_qtsensors_src.subdir = src module_qtsensors_src.target = module-qtsensors-src -SUBDIRS += module_qtsensors_src +module_qtsensors_tests.subdir = tests +module_qtsensors_tests.target = module-qtsensors-tests +module_qtsensors_tests.depends = module_qtsensors_src +!contains(QT_BUILD_PARTS,tests) { + module_qtsensors_tests.CONFIG = no_default_target no_default_install +} + +SUBDIRS += module_qtsensors_src \ + module_qtsensors_tests 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..b49c0be8 --- /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:!mac: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..1ead6703 --- /dev/null +++ b/src/plugins/sensors/dummy/dummycommon.cpp @@ -0,0 +1,136 @@ +/**************************************************************************** +** +** 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> +#ifdef Q_OS_MAC +#include <mach/mach_time.h> +#endif +#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(); +} + +#ifdef Q_OS_MAC +//taken from qelapsedtimer_mac.cpp +static mach_timebase_info_data_t info = {0,0}; +static qint64 absoluteToNSecs(qint64 cpuTime) +{ + if (info.denom == 0) + mach_timebase_info(&info); + qint64 nsecs = cpuTime * info.numer / info.denom; + return nsecs; +} +#endif + +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); +#elif defined(Q_OS_MAC) + uint64_t cpu_time = mach_absolute_time(); + uint64_t nsecs = absoluteToNSecs(cpu_time); + + quint64 result = (nsecs * 0.001); //scale to microseconds + return result; +#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 + diff --git a/src/src.pro b/src/src.pro index 770ca36b..fce5a40f 100644 --- a/src/src.pro +++ b/src/src.pro @@ -1,3 +1,3 @@ TEMPLATE = subdirs CONFIG+=ordered -SUBDIRS += sensors imports +SUBDIRS += sensors imports plugins diff --git a/tests/manual/sensor_explorer/explorer.cpp b/tests/manual/sensor_explorer/explorer.cpp new file mode 100644 index 00000000..31308379 --- /dev/null +++ b/tests/manual/sensor_explorer/explorer.cpp @@ -0,0 +1,444 @@ +/**************************************************************************** +** +** 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 examples of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "explorer.h" +#include <QTimer> +#include <QDebug> +#include <qsensor.h> +#include <QMetaObject> +#include <QMetaProperty> + +Explorer::Explorer(QWidget *parent) + : QMainWindow(parent) + , m_sensor(0) + , ignoreItemChanged(false) +{ + ui.setupUi(this); + // Clear out example data from the .ui file + ui.sensors->clear(); + clearSensorProperties(); + clearReading(); + + // Force types to be registered + (void)QSensor::sensorTypes(); + // Listen for changes to the registered types + QSensor *sensor = new QSensor(QByteArray(), this); + connect(sensor, SIGNAL(availableSensorsChanged()), this, SLOT(loadSensors())); +} + +Explorer::~Explorer() +{ +} + +void Explorer::loadSensors() +{ + qDebug() << "Explorer::loadSensors"; + + // Clear out anything that's in there now + ui.sensors->clear(); + + foreach (const QByteArray &type, QSensor::sensorTypes()) { + qDebug() << "Found type" << type; + foreach (const QByteArray &identifier, QSensor::sensorsForType(type)) { + qDebug() << "Found identifier" << identifier; + // Don't put in sensors we can't connect to + QSensor sensor(type); + sensor.setIdentifier(identifier); + if (!sensor.connectToBackend()) { + qDebug() << "Couldn't connect to" << identifier; + continue; + } + + qDebug() << "Adding identifier" << identifier; + QTreeWidgetItem *item = new QTreeWidgetItem(QStringList() << QString::fromLatin1(identifier)); + item->setData(0, Qt::UserRole, QString::fromLatin1(type)); + ui.sensors->addTopLevelItem(item); + } + } + + if (ui.sensors->topLevelItemCount() == 0) { + QTreeWidgetItem *item = new QTreeWidgetItem(QStringList() << tr("No Sensors Found")); + item->setData(0, Qt::UserRole, QString()); + ui.sensors->addTopLevelItem(item); + } + + ui.sensors->setCurrentItem(0); + ui.scrollArea->hide(); + + resizeSensors(); +} + +void Explorer::resizeSensors() +{ + ui.sensors->resizeColumnToContents(0); + int length = ui.sensors->header()->length() + 4; + ui.sensors->setFixedWidth(length); +} + +void Explorer::on_sensors_currentItemChanged() +{ + qDebug() << "Explorer::sensorSelected"; + + // Clear out anything that's in there now + if (m_sensor) { + delete m_sensor; + m_sensor = 0; + } + clearSensorProperties(); + clearReading(); + ui.scrollArea->hide(); + + // Check that we've selected an item + QTreeWidgetItem *item = ui.sensors->currentItem(); + if (!item) { + qWarning() << "Didn't select an item!"; + return; + } + + QByteArray type = item->data(0, Qt::UserRole).toString().toLatin1(); + QByteArray identifier = item->data(0, Qt::DisplayRole).toString().toLatin1(); + + if (type.isEmpty()) { + // Uh oh, there aren't any sensors. + // The user has clicked the dummy list entry so just ignore it. + return; + } + + // Connect to the sensor so we can probe it + m_sensor = new QSensor(type, this); + connect(m_sensor, SIGNAL(readingChanged()), this, SLOT(sensor_changed())); + m_sensor->setIdentifier(identifier); + if (!m_sensor->connectToBackend()) { + delete m_sensor; + m_sensor = 0; + qWarning() << "Can't connect to the sensor!"; + return; + } + + ui.scrollArea->show(); + loadSensorProperties(); + loadReading(); + + adjustTableColumns(ui.sensorprops); + adjustTableColumns(ui.reading); + QTimer::singleShot(100, this, SLOT(adjustSizes())); +} + +void Explorer::clearReading() +{ + ui.reading->setRowCount(0); +} + +void Explorer::loadReading() +{ + // Probe the reading using Qt's meta-object facilities + QSensorReading *reading = m_sensor->reading(); + const QMetaObject *mo = reading->metaObject(); + int firstProperty = QSensorReading::staticMetaObject.propertyOffset(); + + ui.reading->setRowCount(mo->propertyCount() - firstProperty); + + for (int i = firstProperty; i < mo->propertyCount(); ++i) { + int row = i - firstProperty; + QTableWidgetItem *index; + if (row == 0) + // timestamp is not available via index + index = new QTableWidgetItem(QLatin1String("N/A")); + else + index = new QTableWidgetItem(QVariant(row - 1).toString()); + QTableWidgetItem *prop = new QTableWidgetItem(mo->property(i).name()); + QString typeName = QLatin1String(mo->property(i).typeName()); + int crap = typeName.lastIndexOf("::"); + if (crap != -1) + typeName = typeName.mid(crap + 2); + QTableWidgetItem *type = new QTableWidgetItem(typeName); + QTableWidgetItem *value = new QTableWidgetItem(); + + index->setFlags(value->flags() ^ Qt::ItemIsEditable); + prop->setFlags(value->flags() ^ Qt::ItemIsEditable); + type->setFlags(value->flags() ^ Qt::ItemIsEditable); + value->setFlags(value->flags() ^ Qt::ItemIsEditable); + + ui.reading->setItem(row, 0, index); + ui.reading->setItem(row, 1, prop); + ui.reading->setItem(row, 2, type); + ui.reading->setItem(row, 3, value); + } +} + +void Explorer::clearSensorProperties() +{ + ui.sensorprops->setRowCount(0); +} + +void Explorer::loadSensorProperties() +{ + ignoreItemChanged = true; + + // Probe the sensor using Qt's meta-object facilities + const QMetaObject *mo = m_sensor->metaObject(); + int firstProperty = QSensor::staticMetaObject.propertyOffset(); + + int rows = mo->propertyCount() - firstProperty; + ui.sensorprops->setRowCount(rows); + + int offset = 0; + for (int i = firstProperty; i < mo->propertyCount(); ++i) { + int row = i - firstProperty - offset; + QLatin1String name(mo->property(i).name()); + if (name == "sensorid" || + //name == "type" || + name == "reading" || + name == "connected" || + name == "running" || + name == "supportsPolling") { + ++offset; + continue; + } + QTableWidgetItem *prop = new QTableWidgetItem(name); + QString typeName = QLatin1String(mo->property(i).typeName()); + int crap = typeName.lastIndexOf("::"); + if (crap != -1) + typeName = typeName.mid(crap + 2); + QTableWidgetItem *type = new QTableWidgetItem(typeName); + QVariant v = mo->property(i).read(m_sensor); + QString val; + if (typeName == "qrangelist") { + qrangelist rl = v.value<qrangelist>(); + QStringList out; + foreach (const qrange &r, rl) { + if (r.first == r.second) + out << QString("%1 Hz").arg(r.first); + else + out << QString("%1-%2 Hz").arg(r.first).arg(r.second); + } + val = out.join(", "); + } else if (typeName == "qoutputrangelist") { + qoutputrangelist rl = v.value<qoutputrangelist>(); + QStringList out; + foreach (const qoutputrange &r, rl) { + out << QString("(%1, %2) += %3").arg(r.minimum).arg(r.maximum).arg(r.accuracy); + } + val = out.join(", "); + } else { + val = v.toString(); + } + QTableWidgetItem *value = new QTableWidgetItem(val); + + prop->setFlags(value->flags() ^ Qt::ItemIsEditable); + type->setFlags(value->flags() ^ Qt::ItemIsEditable); + if (!mo->property(i).isWritable()) { + // clear the editable flag + value->setFlags(value->flags() ^ Qt::ItemIsEditable); + } + + ui.sensorprops->setItem(row, 0, prop); + ui.sensorprops->setItem(row, 1, type); + ui.sensorprops->setItem(row, 2, value); + } + + // We don't add all properties + ui.sensorprops->setRowCount(rows - offset); + + ignoreItemChanged = false; +} + +void Explorer::showEvent(QShowEvent *event) +{ + // Once we're visible, load the sensors + // (don't delay showing the UI while we load plugins, connect to backends, etc.) + QTimer::singleShot(0, this, SLOT(loadSensors())); + + QMainWindow::showEvent(event); +} + +// Resize columns to fit the space. +// This shouldn't be so hard! +void Explorer::adjustTableColumns(QTableWidget *table) +{ + if (table->rowCount() == 0) { + table->setFixedHeight(0); + return; + } + + // At least this is easy to do + table->resizeColumnsToContents(); + int length = table->verticalHeader()->length(); + length += (length / static_cast<qreal>(table->verticalHeader()->count())); // Add 1 more (the header itself) + table->setFixedHeight(length); + + int columns = table->columnCount(); + QList<int> width; + int suggestedWidth = 0; + for (int i = 0; i < columns; ++i) { + int cwidth = table->columnWidth(i); + width << cwidth; + suggestedWidth += cwidth; + } + + int actualWidth = table->size().width(); + //qDebug() << "suggestedWidth" << suggestedWidth << "actualWidth" << actualWidth; + + // We only scale the columns up, we don't scale down + if (actualWidth <= suggestedWidth) + return; + + qreal multiplier = actualWidth / static_cast<qreal>(suggestedWidth); + int currentSpace = 4; + for (int i = 0; i < columns; ++i) { + width[i] = multiplier * width[i]; + currentSpace += width[i]; + } + + // It ends up too big due to cell decorations or something. + // Make things smaller one pixel at a time in round robin fashion until we're good. + int i = 0; + while (currentSpace > actualWidth) { + --width[i]; + --currentSpace; + i = (i + 1) % columns; + } + + for (int i = 0; i < columns; ++i) { + table->setColumnWidth(i, width[i]); + } + + table->setMinimumWidth(suggestedWidth); +} + +void Explorer::adjustSizes() +{ + adjustTableColumns(ui.reading); + adjustTableColumns(ui.sensorprops); +} + +void Explorer::resizeEvent(QResizeEvent *event) +{ + resizeSensors(); + adjustSizes(); + + QMainWindow::resizeEvent(event); +} + +void Explorer::on_start_clicked() +{ + m_sensor->start(); + QTimer::singleShot(0, this, SLOT(loadSensorProperties())); +} + +void Explorer::on_stop_clicked() +{ + m_sensor->stop(); + QTimer::singleShot(0, this, SLOT(loadSensorProperties())); +} + +void Explorer::sensor_changed() +{ + QSensorReading *reading = m_sensor->reading(); + filter(reading); +} + +bool Explorer::filter(QSensorReading *reading) +{ + const QMetaObject *mo = reading->metaObject(); + int firstProperty = QSensorReading::staticMetaObject.propertyOffset(); + + for (int i = firstProperty; i < mo->propertyCount(); ++i) { + int row = i - firstProperty; + QString typeName = QLatin1String(mo->property(i).typeName()); + int crap = typeName.lastIndexOf("::"); + if (crap != -1) + typeName = typeName.mid(crap + 2); + QLatin1String name(mo->property(i).name()); + QTableWidgetItem *value = ui.reading->item(row, 3); + QVariant val = mo->property(i).read(reading); + if (typeName == "qtimestamp") { + value->setText(QString("%1").arg(val.value<qtimestamp>())); + } else if (typeName == "LightLevel") { + QString text; + switch (val.toInt()) { + case 1: + text = "Dark"; + break; + case 2: + text = "Twilight"; + break; + case 3: + text = "Light"; + break; + case 4: + text = "Bright"; + break; + case 5: + text = "Sunny"; + break; + default: + text = "Undefined"; + break; + } + value->setText(text); + } else { + value->setText(val.toString()); + } + } + + adjustTableColumns(ui.reading); + //QTimer::singleShot(0, this, SLOT(adjustSizes())); + + return false; +} + +void Explorer::on_sensorprops_itemChanged(QTableWidgetItem *item) +{ + if (ignoreItemChanged) + return; + if (!(item->flags() & Qt::ItemIsEditable)) + return; + + int row = item->row(); + QString name = ui.sensorprops->item(row, 0)->text(); + QVariant value = item->text(); + + qDebug() << "setProperty" << name << value; + m_sensor->setProperty(name.toLatin1().constData(), QVariant(value)); + + QTimer::singleShot(0, this, SLOT(loadSensorProperties())); +} + diff --git a/tests/manual/sensor_explorer/explorer.h b/tests/manual/sensor_explorer/explorer.h new file mode 100644 index 00000000..fdc3516b --- /dev/null +++ b/tests/manual/sensor_explorer/explorer.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** 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 examples of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef EXPLORER_H +#define EXPLORER_H + +#include <QMainWindow> +#include <ui_explorer.h> +#include <qsensor.h> + + +class Explorer : public QMainWindow, public QSensorFilter +{ + Q_OBJECT +public: + Explorer(QWidget *parent = 0); + ~Explorer(); + + bool filter(QSensorReading *reading); + +private slots: + void loadSensors(); + void on_sensors_currentItemChanged(); + void on_sensorprops_itemChanged(QTableWidgetItem *item); + void on_start_clicked(); + void on_stop_clicked(); + void sensor_changed(); + void adjustSizes(); + void loadSensorProperties(); + +private: + void showEvent(QShowEvent *event); + void resizeEvent(QResizeEvent *event); + + void clearReading(); + void loadReading(); + void clearSensorProperties(); + void adjustTableColumns(QTableWidget *table); + void resizeSensors(); + + Ui::Explorer ui; + QSensor *m_sensor; + bool ignoreItemChanged; +}; + +#endif + diff --git a/tests/manual/sensor_explorer/explorer.ui b/tests/manual/sensor_explorer/explorer.ui new file mode 100644 index 00000000..166e9c36 --- /dev/null +++ b/tests/manual/sensor_explorer/explorer.ui @@ -0,0 +1,406 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>Explorer</class> + <widget class="QMainWindow" name="Explorer"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>760</width> + <height>636</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Minimum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="windowTitle"> + <string>MainWindow</string> + </property> + <widget class="QWidget" name="centralwidget"> + <layout class="QVBoxLayout" name="verticalLayout_4"> + <property name="spacing"> + <number>9</number> + </property> + <item> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Sensors that were detected on the device are listed in the list on the left, grouped by type. The reading properties for the sensor will be presented on the right.</string> + </property> + <property name="textFormat"> + <enum>Qt::AutoText</enum> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QWidget" name="widget" native="true"> + <layout class="QHBoxLayout" name="horizontalLayout"> + <property name="spacing"> + <number>9</number> + </property> + <property name="margin"> + <number>0</number> + </property> + <item> + <widget class="QWidget" name="widget_2" native="true"> + <layout class="QVBoxLayout" name="verticalLayout"> + <property name="spacing"> + <number>9</number> + </property> + <property name="margin"> + <number>0</number> + </property> + <item> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Sensor</string> + </property> + <property name="buddy"> + <cstring>sensors</cstring> + </property> + </widget> + </item> + <item> + <widget class="QTreeWidget" name="sensors"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Expanding"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="alternatingRowColors"> + <bool>true</bool> + </property> + <property name="selectionBehavior"> + <enum>QAbstractItemView::SelectRows</enum> + </property> + <property name="rootIsDecorated"> + <bool>false</bool> + </property> + <property name="itemsExpandable"> + <bool>false</bool> + </property> + <property name="expandsOnDoubleClick"> + <bool>false</bool> + </property> + <attribute name="headerVisible"> + <bool>false</bool> + </attribute> + <attribute name="headerVisible"> + <bool>false</bool> + </attribute> + <column> + <property name="text"> + <string notr="true">Sensor</string> + </property> + </column> + <item> + <property name="text"> + <string notr="true">dummy.accelerometer</string> + </property> + </item> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QScrollArea" name="scrollArea"> + <property name="frameShape"> + <enum>QFrame::NoFrame</enum> + </property> + <property name="widgetResizable"> + <bool>true</bool> + </property> + <widget class="QWidget" name="scrollAreaWidgetContents"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>477</width> + <height>556</height> + </rect> + </property> + <layout class="QVBoxLayout" name="verticalLayout_5"> + <property name="spacing"> + <number>9</number> + </property> + <property name="margin"> + <number>0</number> + </property> + <item> + <widget class="QWidget" name="widget_4" native="true"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Minimum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <layout class="QVBoxLayout" name="verticalLayout_3"> + <property name="spacing"> + <number>9</number> + </property> + <property name="margin"> + <number>0</number> + </property> + <item> + <widget class="QLabel" name="label_4"> + <property name="text"> + <string>Sensor Properties</string> + </property> + </widget> + </item> + <item> + <widget class="QTableWidget" name="sensorprops"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Minimum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="verticalScrollBarPolicy"> + <enum>Qt::ScrollBarAlwaysOff</enum> + </property> + <property name="alternatingRowColors"> + <bool>true</bool> + </property> + <property name="columnCount"> + <number>3</number> + </property> + <attribute name="verticalHeaderVisible"> + <bool>false</bool> + </attribute> + <attribute name="verticalHeaderVisible"> + <bool>false</bool> + </attribute> + <row> + <property name="text"> + <string notr="true">1</string> + </property> + </row> + <column> + <property name="text"> + <string>Name</string> + </property> + </column> + <column> + <property name="text"> + <string>Type</string> + </property> + </column> + <column> + <property name="text"> + <string>Value</string> + </property> + </column> + <item row="0" column="0"> + <property name="text"> + <string notr="true">supportedIntervals</string> + </property> + </item> + <item row="0" column="1"> + <property name="text"> + <string notr="true">qrangelist</string> + </property> + </item> + <item row="0" column="2"> + <property name="text"> + <string/> + </property> + </item> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QWidget" name="widget_3" native="true"> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <property name="spacing"> + <number>9</number> + </property> + <property name="margin"> + <number>0</number> + </property> + <item> + <widget class="QPushButton" name="start"> + <property name="text"> + <string>start</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="stop"> + <property name="text"> + <string>stop</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QWidget" name="widget_5" native="true"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Minimum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <property name="spacing"> + <number>9</number> + </property> + <property name="margin"> + <number>0</number> + </property> + <item> + <widget class="QLabel" name="label_6"> + <property name="text"> + <string>Reading Properties</string> + </property> + </widget> + </item> + <item> + <widget class="QTableWidget" name="reading"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Minimum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="verticalScrollBarPolicy"> + <enum>Qt::ScrollBarAlwaysOff</enum> + </property> + <property name="alternatingRowColors"> + <bool>true</bool> + </property> + <property name="columnCount"> + <number>4</number> + </property> + <attribute name="verticalHeaderVisible"> + <bool>false</bool> + </attribute> + <attribute name="verticalHeaderVisible"> + <bool>false</bool> + </attribute> + <row> + <property name="text"> + <string notr="true">1</string> + </property> + </row> + <row> + <property name="text"> + <string notr="true">2</string> + </property> + </row> + <column> + <property name="text"> + <string>Index</string> + </property> + </column> + <column> + <property name="text"> + <string>Value</string> + </property> + </column> + <column> + <property name="text"> + <string>Type</string> + </property> + </column> + <column> + <property name="text"> + <string>Value</string> + </property> + </column> + <item row="0" column="0"> + <property name="text"> + <string notr="true">0</string> + </property> + </item> + <item row="0" column="1"> + <property name="text"> + <string notr="true">x</string> + </property> + </item> + <item row="0" column="2"> + <property name="text"> + <string notr="true">qreal</string> + </property> + </item> + <item row="0" column="3"> + <property name="text"> + <string>9.8</string> + </property> + </item> + <item row="1" column="0"> + <property name="text"> + <string notr="true">0</string> + </property> + </item> + <item row="1" column="1"> + <property name="text"> + <string notr="true">changeOfBeingEaten</string> + </property> + </item> + <item row="1" column="2"> + <property name="text"> + <string notr="true">bool</string> + </property> + </item> + <item row="1" column="3"> + <property name="text"> + <string>true</string> + </property> + </item> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>0</width> + <height>18</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + </widget> + </item> + </layout> + </widget> + </item> + </layout> + </widget> + <widget class="QStatusBar" name="statusbar"/> + </widget> + <resources/> + <connections/> +</ui> diff --git a/tests/manual/sensor_explorer/main.cpp b/tests/manual/sensor_explorer/main.cpp new file mode 100644 index 00000000..63ef1b9d --- /dev/null +++ b/tests/manual/sensor_explorer/main.cpp @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** 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 examples of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "explorer.h" + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + Explorer explorer; + explorer.show(); + return app.exec(); +} + diff --git a/tests/manual/sensor_explorer/sensor_explorer.pro b/tests/manual/sensor_explorer/sensor_explorer.pro new file mode 100644 index 00000000..fc273052 --- /dev/null +++ b/tests/manual/sensor_explorer/sensor_explorer.pro @@ -0,0 +1,16 @@ +TEMPLATE=app +TARGET=sensor_explorer + +QT = core gui sensors + +FORMS=\ + explorer.ui + +HEADERS=\ + explorer.h + +SOURCES=\ + explorer.cpp\ + main.cpp + + diff --git a/tests/tests.pro b/tests/tests.pro new file mode 100644 index 00000000..566e1725 --- /dev/null +++ b/tests/tests.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs + |