From fe2a949996e1e93f0824f4e49b423b4b57090a72 Mon Sep 17 00:00:00 2001 From: Lorn Potter Date: Wed, 6 Mar 2013 03:45:47 +1000 Subject: add sensorfw based sensor plugin ported from qtmobility. Change-Id: Ia4ee6e2b7ecbc441c5f6605f1bbabfec22ddcd09 Reviewed-by: Lorn Potter --- src/plugins/sensors/sensorfw/Sensors.conf | 11 ++ src/plugins/sensors/sensorfw/main.cpp | 109 ++++++++++++ src/plugins/sensors/sensorfw/plugin.json | 1 + src/plugins/sensors/sensorfw/sensorfw.pri | 26 +++ src/plugins/sensors/sensorfw/sensorfw.pro | 17 ++ .../sensors/sensorfw/sensorfwaccelerometer.cpp | 91 ++++++++++ .../sensors/sensorfw/sensorfwaccelerometer.h | 74 ++++++++ src/plugins/sensors/sensorfw/sensorfwals.cpp | 111 ++++++++++++ src/plugins/sensors/sensorfw/sensorfwals.h | 75 ++++++++ src/plugins/sensors/sensorfw/sensorfwcompass.cpp | 80 +++++++++ src/plugins/sensors/sensorfw/sensorfwcompass.h | 70 ++++++++ src/plugins/sensors/sensorfw/sensorfwgyroscope.cpp | 90 ++++++++++ src/plugins/sensors/sensorfw/sensorfwgyroscope.h | 78 +++++++++ .../sensors/sensorfw/sensorfwirproximitysensor.cpp | 81 +++++++++ .../sensors/sensorfw/sensorfwirproximitysensor.h | 71 ++++++++ .../sensors/sensorfw/sensorfwlightsensor.cpp | 71 ++++++++ src/plugins/sensors/sensorfw/sensorfwlightsensor.h | 72 ++++++++ .../sensors/sensorfw/sensorfwmagnetometer.cpp | 98 +++++++++++ .../sensors/sensorfw/sensorfwmagnetometer.h | 79 +++++++++ .../sensors/sensorfw/sensorfworientationsensor.cpp | 98 +++++++++++ .../sensors/sensorfw/sensorfworientationsensor.h | 74 ++++++++ .../sensors/sensorfw/sensorfwproximitysensor.cpp | 87 ++++++++++ .../sensors/sensorfw/sensorfwproximitysensor.h | 75 ++++++++ .../sensors/sensorfw/sensorfwrotationsensor.cpp | 79 +++++++++ .../sensors/sensorfw/sensorfwrotationsensor.h | 75 ++++++++ .../sensors/sensorfw/sensorfwsensorbase.cpp | 189 +++++++++++++++++++++ src/plugins/sensors/sensorfw/sensorfwsensorbase.h | 170 ++++++++++++++++++ src/plugins/sensors/sensorfw/sensorfwtapsensor.cpp | 110 ++++++++++++ src/plugins/sensors/sensorfw/sensorfwtapsensor.h | 73 ++++++++ src/plugins/sensors/sensors.pro | 12 +- src/sensors/doc/src/compatmap.qdoc | 14 +- src/sensors/doc/src/qtsensors.qdoc | 3 + src/sensors/doc/src/sensorfwbackend.qdoc | 39 +++++ 33 files changed, 2400 insertions(+), 3 deletions(-) create mode 100644 src/plugins/sensors/sensorfw/Sensors.conf create mode 100644 src/plugins/sensors/sensorfw/main.cpp create mode 100644 src/plugins/sensors/sensorfw/plugin.json create mode 100644 src/plugins/sensors/sensorfw/sensorfw.pri create mode 100644 src/plugins/sensors/sensorfw/sensorfw.pro create mode 100644 src/plugins/sensors/sensorfw/sensorfwaccelerometer.cpp create mode 100644 src/plugins/sensors/sensorfw/sensorfwaccelerometer.h create mode 100644 src/plugins/sensors/sensorfw/sensorfwals.cpp create mode 100644 src/plugins/sensors/sensorfw/sensorfwals.h create mode 100644 src/plugins/sensors/sensorfw/sensorfwcompass.cpp create mode 100644 src/plugins/sensors/sensorfw/sensorfwcompass.h create mode 100644 src/plugins/sensors/sensorfw/sensorfwgyroscope.cpp create mode 100644 src/plugins/sensors/sensorfw/sensorfwgyroscope.h create mode 100644 src/plugins/sensors/sensorfw/sensorfwirproximitysensor.cpp create mode 100644 src/plugins/sensors/sensorfw/sensorfwirproximitysensor.h create mode 100644 src/plugins/sensors/sensorfw/sensorfwlightsensor.cpp create mode 100644 src/plugins/sensors/sensorfw/sensorfwlightsensor.h create mode 100644 src/plugins/sensors/sensorfw/sensorfwmagnetometer.cpp create mode 100644 src/plugins/sensors/sensorfw/sensorfwmagnetometer.h create mode 100644 src/plugins/sensors/sensorfw/sensorfworientationsensor.cpp create mode 100644 src/plugins/sensors/sensorfw/sensorfworientationsensor.h create mode 100644 src/plugins/sensors/sensorfw/sensorfwproximitysensor.cpp create mode 100644 src/plugins/sensors/sensorfw/sensorfwproximitysensor.h create mode 100644 src/plugins/sensors/sensorfw/sensorfwrotationsensor.cpp create mode 100644 src/plugins/sensors/sensorfw/sensorfwrotationsensor.h create mode 100644 src/plugins/sensors/sensorfw/sensorfwsensorbase.cpp create mode 100644 src/plugins/sensors/sensorfw/sensorfwsensorbase.h create mode 100644 src/plugins/sensors/sensorfw/sensorfwtapsensor.cpp create mode 100644 src/plugins/sensors/sensorfw/sensorfwtapsensor.h create mode 100644 src/sensors/doc/src/sensorfwbackend.qdoc (limited to 'src') diff --git a/src/plugins/sensors/sensorfw/Sensors.conf b/src/plugins/sensors/sensorfw/Sensors.conf new file mode 100644 index 00000000..a003f12c --- /dev/null +++ b/src/plugins/sensors/sensorfw/Sensors.conf @@ -0,0 +1,11 @@ +[Default] +QAccelerometer=sensorfw.accelerometer +QAmbientLightSensor=sensorfw.als +QCompass=sensorfw.compass +QMagnetometer=sensorfw.magnetometer +QOrientationSensor=sensorfw.orientationsensor +QProximitySensor=sensorfw.proximitysensor +QRotationSensor=sensorfw.rotationsensor +QTapSensor=sensorfw.tapsensor +QLightSensor=sensorfw.lightsensor +QIRProximitySensor=sensorfw.irproximitysensor diff --git a/src/plugins/sensors/sensorfw/main.cpp b/src/plugins/sensors/sensorfw/main.cpp new file mode 100644 index 00000000..f12a193e --- /dev/null +++ b/src/plugins/sensors/sensorfw/main.cpp @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sensorfwaccelerometer.h" +#include "sensorfwals.h" +#include "sensorfwcompass.h" +#include "sensorfwmagnetometer.h" +#include "sensorfworientationsensor.h" +#include "sensorfwproximitysensor.h" +#include "sensorfwirproximitysensor.h" +#include "sensorfwrotationsensor.h" +#include "sensorfwtapsensor.h" +#include "sensorfwgyroscope.h" +#include "sensorfwlightsensor.h" + +#include +#include +#include +#include +#include + +class sensorfwSensorPlugin : public QObject, public QSensorPluginInterface, public QSensorBackendFactory +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "com.qt-project.Qt.QSensorPluginInterface/1.0" FILE "plugin.json") + Q_INTERFACES(QSensorPluginInterface) + +public: + + void registerSensors() + { + // if no default - no support either, uses Sensors.conf + QSettings settings(QSettings::SystemScope, QLatin1String("QtProject"), QLatin1String("Sensors")); + settings.beginGroup(QLatin1String("Default")); + QStringList keys = settings.allKeys(); + for (int i=0,l=keys.size(); iidentifier() == sensorfwaccelerometer::id) + return new sensorfwaccelerometer(sensor); + if (sensor->identifier() == Sensorfwals::id) + return new Sensorfwals(sensor); + if (sensor->identifier() == SensorfwCompass::id) + return new SensorfwCompass(sensor); + if (sensor->identifier() == SensorfwMagnetometer::id) + return new SensorfwMagnetometer(sensor); + if (sensor->identifier() == SensorfwOrientationSensor::id) + return new SensorfwOrientationSensor(sensor); + if (sensor->identifier() == SensorfwProximitySensor::id) + return new SensorfwProximitySensor(sensor); + if (sensor->identifier() == SensorfwRotationSensor::id) + return new SensorfwRotationSensor(sensor); + if (sensor->identifier() == SensorfwTapSensor::id) + return new SensorfwTapSensor(sensor); + if (sensor->identifier() == SensorfwGyroscope::id) + return new SensorfwGyroscope(sensor); + if (sensor->identifier() == SensorfwLightSensor::id) + return new SensorfwLightSensor(sensor); + if (sensor->identifier() == SensorfwIrProximitySensor::id) + return new SensorfwIrProximitySensor(sensor); + return 0; + } +}; + +#include "main.moc" diff --git a/src/plugins/sensors/sensorfw/plugin.json b/src/plugins/sensors/sensorfw/plugin.json new file mode 100644 index 00000000..8a55b3ae --- /dev/null +++ b/src/plugins/sensors/sensorfw/plugin.json @@ -0,0 +1 @@ +{ "Keys": [ "notused" ] } diff --git a/src/plugins/sensors/sensorfw/sensorfw.pri b/src/plugins/sensors/sensorfw/sensorfw.pri new file mode 100644 index 00000000..31d7254c --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfw.pri @@ -0,0 +1,26 @@ +HEADERS += sensorfwsensorbase.h \ + sensorfwaccelerometer.h \ + sensorfwals.h \ + sensorfwcompass.h \ + sensorfwgyroscope.h \ + sensorfwmagnetometer.h \ + sensorfworientationsensor.h \ + sensorfwproximitysensor.h \ + sensorfwrotationsensor.h \ + sensorfwtapsensor.h \ + sensorfwlightsensor.h \ + sensorfwirproximitysensor.h + +SOURCES += sensorfwsensorbase.cpp \ + sensorfwaccelerometer.cpp \ + sensorfwals.cpp \ + sensorfwcompass.cpp \ + sensorfwgyroscope.cpp \ + sensorfwmagnetometer.cpp \ + sensorfworientationsensor.cpp \ + sensorfwproximitysensor.cpp \ + sensorfwirproximitysensor.cpp \ + sensorfwrotationsensor.cpp \ + sensorfwtapsensor.cpp \ + sensorfwlightsensor.cpp \ + main.cpp diff --git a/src/plugins/sensors/sensorfw/sensorfw.pro b/src/plugins/sensors/sensorfw/sensorfw.pro new file mode 100644 index 00000000..8d67c81f --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfw.pro @@ -0,0 +1,17 @@ +TARGET = qtsensors_sensorfw +QT = core sensors network + +PLUGIN_TYPE = sensors +load(qt_plugin) + +include(sensorfw.pri) + + +CONFIG += link_pkgconfig +PKGCONFIG += sensord + +CONFIGFILES.files = Sensors.conf +CONFIGFILES.path = /etc/xdg/QtProject/ +INSTALLS += CONFIGFILES + +OTHER_FILES = plugin.json diff --git a/src/plugins/sensors/sensorfw/sensorfwaccelerometer.cpp b/src/plugins/sensors/sensorfw/sensorfwaccelerometer.cpp new file mode 100644 index 00000000..ddbaa9c6 --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwaccelerometer.cpp @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sensorfwaccelerometer.h" + +char const * const sensorfwaccelerometer::id("sensorfw.accelerometer"); +bool sensorfwaccelerometer::m_initDone = false; + +sensorfwaccelerometer::sensorfwaccelerometer(QSensor *sensor) + : SensorfwSensorBase(sensor) +{ + initSensor(m_initDone); + setDescription(QLatin1String("x, y, and z axes accelerations in m/s^2")); + setRanges(GRAVITY_EARTH_THOUSANDTH); + setReading(&m_reading); +} + +void sensorfwaccelerometer::slotDataAvailable(const XYZ& data) +{ + // Convert from milli-Gs to meters per second per second + // Using 1 G = 9.80665 m/s^2 + m_reading.setX(-data.x() * GRAVITY_EARTH_THOUSANDTH); + m_reading.setY(-data.y() * GRAVITY_EARTH_THOUSANDTH); + m_reading.setZ(-data.z() * GRAVITY_EARTH_THOUSANDTH); + m_reading.setTimestamp(data.XYZData().timestamp_); + newReadingAvailable(); +} + +void sensorfwaccelerometer::slotFrameAvailable(const QVector& frame) +{ + for (int i=0, l=frame.size(); i& )),this, SLOT(slotFrameAvailable(const QVector& ))); +} + + +QString sensorfwaccelerometer::sensorName() const +{ + return "accelerometersensor"; +} + + +qreal sensorfwaccelerometer::correctionFactor() const +{ + return GRAVITY_EARTH_THOUSANDTH; +} diff --git a/src/plugins/sensors/sensorfw/sensorfwaccelerometer.h b/src/plugins/sensors/sensorfw/sensorfwaccelerometer.h new file mode 100644 index 00000000..1c94aae3 --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwaccelerometer.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef SENSORFWACCELEROMETER_H +#define SENSORFWACCELEROMETER_H + +#include "sensorfwsensorbase.h" +#include + +#include +#include + + + +class sensorfwaccelerometer : public SensorfwSensorBase +{ + Q_OBJECT + +public: + static char const * const id; + sensorfwaccelerometer(QSensor *sensor); +protected: + virtual bool doConnect(); + virtual QString sensorName() const; + virtual qreal correctionFactor() const; + + +private: + QAccelerometerReading m_reading; + static bool m_initDone; + +private slots: + void slotDataAvailable(const XYZ& data); + void slotFrameAvailable(const QVector&); +}; + +#endif diff --git a/src/plugins/sensors/sensorfw/sensorfwals.cpp b/src/plugins/sensors/sensorfw/sensorfwals.cpp new file mode 100644 index 00000000..811da77f --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwals.cpp @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include "sensorfwals.h" + +char const * const Sensorfwals::id("sensorfw.als"); +bool Sensorfwals::m_initDone = false; + +Sensorfwals::Sensorfwals(QSensor *sensor) + : SensorfwSensorBase(sensor) +{ + initSensor(m_initDone); + setReading(&m_reading); + // metadata + setDescription(QLatin1String("ambient light intensity given as 5 pre-defined levels")); + addOutputRange(0, 5, 1); + addDataRate(10,10); +} + +void Sensorfwals::start() +{ + if (m_sensorInterface) { + Unsigned data(((ALSSensorChannelInterface*)m_sensorInterface)->lux()); + m_reading.setLightLevel(getLightLevel(data.x())); + m_reading.setTimestamp(data.UnsignedData().timestamp_); + newReadingAvailable(); + } + SensorfwSensorBase::start(); +} + + +void Sensorfwals::slotDataAvailable(const Unsigned& data) +{ + QAmbientLightReading::LightLevel level = getLightLevel(data.x()); + if (level != m_reading.lightLevel()) { + m_reading.setLightLevel(level); + m_reading.setTimestamp(data.UnsignedData().timestamp_); + newReadingAvailable(); + } +} + +bool Sensorfwals::doConnect() +{ + return QObject::connect(m_sensorInterface, SIGNAL(ALSChanged(const Unsigned&)), + this, SLOT(slotDataAvailable(const Unsigned&))); +} + + +QString Sensorfwals::sensorName() const +{ + return "alssensor"; +} + + +QAmbientLightReading::LightLevel Sensorfwals::getLightLevel(int lux) +{ + // Convert from integer to fixed levels + if (lux < 0) { + return QAmbientLightReading::Undefined; + } else if (lux < 10) { + return QAmbientLightReading::Dark; + } else if (lux < 50) { + return QAmbientLightReading::Twilight; + } else if (lux < 100) { + return QAmbientLightReading::Light; + } else if (lux < 150) { + return QAmbientLightReading::Bright; + } else { + return QAmbientLightReading::Sunny; + } + +} diff --git a/src/plugins/sensors/sensorfw/sensorfwals.h b/src/plugins/sensors/sensorfw/sensorfwals.h new file mode 100644 index 00000000..ba7c9af1 --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwals.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SENSORFWALS_H +#define SENSORFWALS_H + +#include "sensorfwsensorbase.h" +#include + +#include +#include + + + +class Sensorfwals : public SensorfwSensorBase +{ + Q_OBJECT + +public: + static char const * const id; + Sensorfwals(QSensor *sensor); +protected: + virtual bool doConnect(); + virtual QString sensorName() const; + virtual void start(); + + +private: + QAmbientLightReading m_reading; + static bool m_initDone; +private slots: + void slotDataAvailable(const Unsigned& data); + static QAmbientLightReading::LightLevel getLightLevel(int lux); + +}; + +#endif diff --git a/src/plugins/sensors/sensorfw/sensorfwcompass.cpp b/src/plugins/sensors/sensorfw/sensorfwcompass.cpp new file mode 100644 index 00000000..00741a1f --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwcompass.cpp @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include "sensorfwcompass.h" + +char const * const SensorfwCompass::id("sensorfw.compass"); +bool SensorfwCompass::m_initDone = false; + +SensorfwCompass::SensorfwCompass(QSensor *sensor) + : SensorfwSensorBase(sensor) +{ + initSensor(m_initDone); + setReading(&m_reading); +} + +void SensorfwCompass::slotDataAvailable(const Compass& data) +{ + // The scale for level is [0,3], where 3 is the best + // Qt: Measured as a value from 0 to 1 with higher values being better. + m_reading.setCalibrationLevel(((float) data.level()) / 3.0); + + // The scale for degrees from sensord is [0,359] + // Value can be directly used as azimuth + m_reading.setAzimuth(data.degrees()); + + m_reading.setTimestamp(data.data().timestamp_); + newReadingAvailable(); +} + + +bool SensorfwCompass::doConnect() +{ + return QObject::connect(m_sensorInterface, SIGNAL(dataAvailable(const Compass&)), + this, SLOT(slotDataAvailable(const Compass&))); +} + +QString SensorfwCompass::sensorName() const +{ + return "compasssensor"; +} + diff --git a/src/plugins/sensors/sensorfw/sensorfwcompass.h b/src/plugins/sensors/sensorfw/sensorfwcompass.h new file mode 100644 index 00000000..e54c348e --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwcompass.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef SENSORFWCOMPASS_H +#define SENSORFWCOMPASS_H + +#include "sensorfwsensorbase.h" +#include + +#include +#include + + + +class SensorfwCompass : public SensorfwSensorBase +{ + Q_OBJECT + +public: + static char const * const id; + SensorfwCompass(QSensor *sensor); +protected: + virtual bool doConnect(); + virtual QString sensorName() const; + +private: + QCompassReading m_reading; + static bool m_initDone; +private slots: + void slotDataAvailable(const Compass& data); +}; + +#endif diff --git a/src/plugins/sensors/sensorfw/sensorfwgyroscope.cpp b/src/plugins/sensors/sensorfw/sensorfwgyroscope.cpp new file mode 100644 index 00000000..238993ac --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwgyroscope.cpp @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sensorfwgyroscope.h" + +char const * const SensorfwGyroscope::id("sensorfw.gyroscope"); +const float SensorfwGyroscope::MILLI = 0.001; +bool SensorfwGyroscope::m_initDone = false; + +SensorfwGyroscope::SensorfwGyroscope(QSensor *sensor) + : SensorfwSensorBase(sensor) +{ + initSensor(m_initDone); + setDescription(QLatin1String("angular velocities around x, y, and z axis in degrees per second")); + setRanges(MILLI); + setReading(&m_reading); + addDataRate(10, 10); + addDataRate(50, 50); +} + +void SensorfwGyroscope::slotDataAvailable(const XYZ& data) +{ + m_reading.setX((qreal)(data.x()*MILLI)); + m_reading.setY((qreal)(data.y()*MILLI)); + m_reading.setZ((qreal)(data.z()*MILLI)); + m_reading.setTimestamp(data.XYZData().timestamp_); + newReadingAvailable(); +} + +void SensorfwGyroscope::slotFrameAvailable(const QVector& frame) +{ + for (int i=0, l=frame.size(); i& )),this, SLOT(slotFrameAvailable(const QVector& ))); +} + +QString SensorfwGyroscope::sensorName() const +{ + return "gyroscopesensor"; +} + +qreal SensorfwGyroscope::correctionFactor() const +{ + return MILLI; +} diff --git a/src/plugins/sensors/sensorfw/sensorfwgyroscope.h b/src/plugins/sensors/sensorfw/sensorfwgyroscope.h new file mode 100644 index 00000000..e982c809 --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwgyroscope.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#ifndef SENSORFWGYROSCOPE_H +#define SENSORFWGYROSCOPE_H + +#include "sensorfwsensorbase.h" +#include +#include +#include + + + + +class SensorfwGyroscope : public SensorfwSensorBase +{ + Q_OBJECT + +public: + static char const * const id; + SensorfwGyroscope(QSensor *sensor); +protected: + virtual bool doConnect(); + virtual QString sensorName() const; + virtual qreal correctionFactor() const; + + +private: + QGyroscopeReading m_reading; + static bool m_initDone; + static const float MILLI; +private slots: + void slotDataAvailable(const XYZ& data); + void slotFrameAvailable(const QVector&); + +}; + + +#endif // sensorfwGYROSCOPE_H diff --git a/src/plugins/sensors/sensorfw/sensorfwirproximitysensor.cpp b/src/plugins/sensors/sensorfw/sensorfwirproximitysensor.cpp new file mode 100644 index 00000000..865d3760 --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwirproximitysensor.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sensorfwirproximitysensor.h" +#define RM680_PS "/dev/bh1770glc_ps" + +char const * const SensorfwIrProximitySensor::id("sensorfw.irproximitysensor"); +bool SensorfwIrProximitySensor::m_initDone = false; + + + +SensorfwIrProximitySensor::SensorfwIrProximitySensor(QSensor *sensor) + : SensorfwSensorBase(sensor) +{ + initSensor(m_initDone); + setReading(&m_reading); + setDescription(QLatin1String("reflectance as percentage (%) of maximum")); + addOutputRange(0, 100, 1); + addDataRate(10,10); + rangeMax = QFile::exists(RM680_PS)?255:1023; +} + +void SensorfwIrProximitySensor::slotDataAvailable(const Proximity& proximity) +{ + m_reading.setReflectance((float)proximity.reflectance()*100 / rangeMax); + m_reading.setTimestamp(proximity.UnsignedData().timestamp_); + newReadingAvailable(); +} + + +bool SensorfwIrProximitySensor::doConnect() +{ + return QObject::connect(m_sensorInterface, SIGNAL(reflectanceDataAvailable(const Proximity&)), + this, SLOT(slotDataAvailable(const Proximity&))); +} + + +QString SensorfwIrProximitySensor::sensorName() const +{ + return "proximitysensor"; +} + + diff --git a/src/plugins/sensors/sensorfw/sensorfwirproximitysensor.h b/src/plugins/sensors/sensorfw/sensorfwirproximitysensor.h new file mode 100644 index 00000000..c729f595 --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwirproximitysensor.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SENSORFWIRPROXIMITYSENSOR_H +#define SENSORFWIRPROXIMITYSENSOR_H + +#include "sensorfwsensorbase.h" +#include +#include + + +class SensorfwIrProximitySensor : public SensorfwSensorBase +{ + Q_OBJECT + +public: + static char const * const id; + + SensorfwIrProximitySensor(QSensor *sensor); +protected: + virtual bool doConnect(); + virtual QString sensorName() const; + +private: + QIRProximityReading m_reading; + static bool m_initDone; + int rangeMax; + +private slots: + void slotDataAvailable(const Proximity& proximity); +}; + +#endif diff --git a/src/plugins/sensors/sensorfw/sensorfwlightsensor.cpp b/src/plugins/sensors/sensorfw/sensorfwlightsensor.cpp new file mode 100644 index 00000000..b49e7b2d --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwlightsensor.cpp @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sensorfwlightsensor.h" + +char const * const SensorfwLightSensor::id("sensorfw.lightsensor"); +bool SensorfwLightSensor::m_initDone = false; + +SensorfwLightSensor::SensorfwLightSensor(QSensor *sensor) + : SensorfwSensorBase(sensor) +{ + initSensor(m_initDone); + setReading(&m_reading); +} + +void SensorfwLightSensor::slotDataAvailable(const Unsigned& data) +{ + m_reading.setLux(data.x()); + m_reading.setTimestamp(data.UnsignedData().timestamp_); + newReadingAvailable(); +} + +bool SensorfwLightSensor::doConnect() +{ + return QObject::connect(m_sensorInterface, SIGNAL(ALSChanged(const Unsigned&)), + this, SLOT(slotDataAvailable(const Unsigned&))); +} + + +QString SensorfwLightSensor::sensorName() const +{ + return "alssensor"; +} diff --git a/src/plugins/sensors/sensorfw/sensorfwlightsensor.h b/src/plugins/sensors/sensorfw/sensorfwlightsensor.h new file mode 100644 index 00000000..83591fae --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwlightsensor.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#ifndef SENSORFWLIGHTSENSOR_H +#define SENSORFWLIGHTSENSOR_H + +#include "sensorfwsensorbase.h" +#include + +#include +#include + + + +class SensorfwLightSensor : public SensorfwSensorBase +{ + Q_OBJECT + +public: + static char const * const id; + SensorfwLightSensor(QSensor *sensor); +protected: + virtual bool doConnect(); + virtual QString sensorName() const; + +private: + QLightReading m_reading; + static bool m_initDone; +private slots: + void slotDataAvailable(const Unsigned& data); +}; + +#endif diff --git a/src/plugins/sensors/sensorfw/sensorfwmagnetometer.cpp b/src/plugins/sensors/sensorfw/sensorfwmagnetometer.cpp new file mode 100644 index 00000000..9778b95c --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwmagnetometer.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sensorfwmagnetometer.h" + +char const * const SensorfwMagnetometer::id("sensorfw.magnetometer"); +bool SensorfwMagnetometer::m_initDone = false; +const float SensorfwMagnetometer::NANO = 0.000000001; + + +SensorfwMagnetometer::SensorfwMagnetometer(QSensor *sensor) + : SensorfwSensorBase(sensor) +{ + initSensor(m_initDone); + setDescription(QLatin1String("magnetic flux density in teslas (T)")); + setRanges(NANO); + setReading(&m_reading); +} + +void SensorfwMagnetometer::start() +{ + m_isGeoMagnetometer = sensor()->returnGeoValues(); + SensorfwSensorBase::start(); +} + +void SensorfwMagnetometer::slotDataAvailable(const MagneticField& data) +{ + //nanoTeslas given, divide with 10^9 to get Teslas + m_reading.setX( NANO * (m_isGeoMagnetometer?data.x():data.rx())); + m_reading.setY( NANO * (m_isGeoMagnetometer?data.y():data.ry())); + m_reading.setZ( NANO * (m_isGeoMagnetometer?data.z():data.rz())); + m_reading.setCalibrationLevel( m_isGeoMagnetometer?((float) data.level()) / 3.0 :1); + m_reading.setTimestamp(data.timestamp()); + newReadingAvailable(); +} + + +void SensorfwMagnetometer::slotFrameAvailable(const QVector& frame) +{ + for (int i=0, l=frame.size(); i& )),this, SLOT(slotFrameAvailable(const QVector& ))); +} + +QString SensorfwMagnetometer::sensorName() const +{ + return "magnetometersensor"; +} + +qreal SensorfwMagnetometer::correctionFactor() const +{ + return SensorfwMagnetometer::NANO; +} diff --git a/src/plugins/sensors/sensorfw/sensorfwmagnetometer.h b/src/plugins/sensors/sensorfw/sensorfwmagnetometer.h new file mode 100644 index 00000000..dff70c09 --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwmagnetometer.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SENSORFWMAGNETOMETER_H +#define SENSORFWMAGNETOMETER_H + +#include "sensorfwsensorbase.h" +#include + +#include +#include + + + +class SensorfwMagnetometer : public SensorfwSensorBase +{ + Q_OBJECT + +public: + static char const * const id; + SensorfwMagnetometer(QSensor *sensor); +protected: + virtual bool doConnect(); + virtual void start(); + virtual QString sensorName() const; + virtual qreal correctionFactor() const; + + +private: + static const float NANO; + QMagnetometerReading m_reading; + static bool m_initDone; + bool m_isGeoMagnetometer; + +private slots: + void slotDataAvailable(const MagneticField& data); + void slotFrameAvailable(const QVector&); + +}; + +#endif diff --git a/src/plugins/sensors/sensorfw/sensorfworientationsensor.cpp b/src/plugins/sensors/sensorfw/sensorfworientationsensor.cpp new file mode 100644 index 00000000..09dfb0eb --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfworientationsensor.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sensorfworientationsensor.h" + +#include + +char const * const SensorfwOrientationSensor::id("sensorfw.orientationsensor"); +bool SensorfwOrientationSensor::m_initDone = false; + +SensorfwOrientationSensor::SensorfwOrientationSensor(QSensor *sensor) + : SensorfwSensorBase(sensor) +{ + initSensor(m_initDone); + setReading(&m_reading); +} + + +void SensorfwOrientationSensor::start() +{ + if (m_sensorInterface) { + Unsigned data(((OrientationSensorChannelInterface*)m_sensorInterface)->orientation()); + m_reading.setOrientation(SensorfwOrientationSensor::getOrientation(data.x())); + m_reading.setTimestamp(data.UnsignedData().timestamp_); + newReadingAvailable(); + } + SensorfwSensorBase::start(); +} + + +void SensorfwOrientationSensor::slotDataAvailable(const Unsigned& data) +{ + m_reading.setOrientation(SensorfwOrientationSensor::getOrientation(data.x())); + m_reading.setTimestamp(data.UnsignedData().timestamp_); + newReadingAvailable(); +} + +bool SensorfwOrientationSensor::doConnect() +{ + return QObject::connect(m_sensorInterface, SIGNAL(orientationChanged(const Unsigned&)), + this, SLOT(slotDataAvailable(const Unsigned&))); +} + +QString SensorfwOrientationSensor::sensorName() const +{ + return "orientationsensor"; +} + +QOrientationReading::Orientation SensorfwOrientationSensor::getOrientation(int orientation) +{ + switch (orientation) { + case PoseData::BottomDown: return QOrientationReading::TopUp; + case PoseData::BottomUp: return QOrientationReading::TopDown; + case PoseData::LeftUp: return QOrientationReading::LeftUp; + case PoseData::RightUp: return QOrientationReading::RightUp; + case PoseData::FaceUp: return QOrientationReading::FaceUp; + case PoseData::FaceDown: return QOrientationReading::FaceDown; + } + return QOrientationReading::Undefined; +} diff --git a/src/plugins/sensors/sensorfw/sensorfworientationsensor.h b/src/plugins/sensors/sensorfw/sensorfworientationsensor.h new file mode 100644 index 00000000..496939ce --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfworientationsensor.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SENSORFWORIENTATIONSENSOR_H +#define SENSORFWORIENTATIONSENSOR_H + +#include "sensorfwsensorbase.h" +#include + +#include +#include + + + +class SensorfwOrientationSensor : public SensorfwSensorBase +{ + Q_OBJECT + +public: + static char const * const id; + SensorfwOrientationSensor(QSensor *sensor); +protected: + virtual bool doConnect(); + virtual QString sensorName() const; + virtual void start(); + +private: + QOrientationReading m_reading; + static QOrientationReading::Orientation getOrientation(int orientation); + static bool m_initDone; + +private slots: + void slotDataAvailable(const Unsigned& orientation); +}; + +#endif diff --git a/src/plugins/sensors/sensorfw/sensorfwproximitysensor.cpp b/src/plugins/sensors/sensorfw/sensorfwproximitysensor.cpp new file mode 100644 index 00000000..4602a9a1 --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwproximitysensor.cpp @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sensorfwproximitysensor.h" + +char const * const SensorfwProximitySensor::id("sensorfw.proximitysensor"); +bool SensorfwProximitySensor::m_initDone = false; + +SensorfwProximitySensor::SensorfwProximitySensor(QSensor *sensor) + : SensorfwSensorBase(sensor), m_exClose(false) +{ + initSensor(m_initDone); + setReading(&m_reading); + addDataRate(10,10); //TODO: fix this when we know better +} + +void SensorfwProximitySensor::start() +{ + if (m_sensorInterface) { + Unsigned data(((ProximitySensorChannelInterface*)m_sensorInterface)->proximity()); + m_reading.setClose(data.x()? true: false); + m_reading.setTimestamp(data.UnsignedData().timestamp_); + newReadingAvailable(); + } + SensorfwSensorBase::start(); +} + + +void SensorfwProximitySensor::slotDataAvailable(const Unsigned& data) +{ + bool close = data.x()? true: false; + if (close == m_exClose) return; + m_reading.setClose(close); + m_reading.setTimestamp(data.UnsignedData().timestamp_); + newReadingAvailable(); + m_exClose = close; +} + +bool SensorfwProximitySensor::doConnect() +{ + return (QObject::connect(m_sensorInterface, SIGNAL(dataAvailable(const Unsigned&)), + this, SLOT(slotDataAvailable(const Unsigned&)))); +} + + +QString SensorfwProximitySensor::sensorName() const +{ + return "proximitysensor"; +} diff --git a/src/plugins/sensors/sensorfw/sensorfwproximitysensor.h b/src/plugins/sensors/sensorfw/sensorfwproximitysensor.h new file mode 100644 index 00000000..91800c2e --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwproximitysensor.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SENSORFWPROXIMITYSENSOR_H +#define SENSORFWPROXIMITYSENSOR_H + +#include "sensorfwsensorbase.h" +#include + +#include +#include + + + +class SensorfwProximitySensor : public SensorfwSensorBase +{ + Q_OBJECT + +public: + static char const * const id; + SensorfwProximitySensor(QSensor *sensor); +protected: + virtual bool doConnect(); + virtual QString sensorName() const; + virtual void start(); + + +private: + QProximityReading m_reading; + static bool m_initDone; + bool m_exClose; + +private slots: + void slotDataAvailable(const Unsigned& data); +}; + +#endif diff --git a/src/plugins/sensors/sensorfw/sensorfwrotationsensor.cpp b/src/plugins/sensors/sensorfw/sensorfwrotationsensor.cpp new file mode 100644 index 00000000..d5774022 --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwrotationsensor.cpp @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sensorfwrotationsensor.h" + +char const * const SensorfwRotationSensor::id("sensorfw.rotationsensor"); +bool SensorfwRotationSensor::m_initDone = false; + +SensorfwRotationSensor::SensorfwRotationSensor(QSensor *sensor) + : SensorfwSensorBase(sensor) +{ + initSensor(m_initDone); + setReading(&m_reading); + sensor()->setHasZ(true); +} + +void SensorfwRotationSensor::slotDataAvailable(const XYZ& data) +{ + m_reading.setFromEuler(data.x(),data.y(),data.z()); + m_reading.setTimestamp(data.XYZData().timestamp_); + newReadingAvailable(); +} + +void SensorfwRotationSensor::slotFrameAvailable(const QVector& frame) +{ + for (int i=0, l=frame.size(); i& )),this, SLOT(slotFrameAvailable(const QVector& ))); +} + +QString SensorfwRotationSensor::sensorName() const +{ + return "rotationsensor"; +} diff --git a/src/plugins/sensors/sensorfw/sensorfwrotationsensor.h b/src/plugins/sensors/sensorfw/sensorfwrotationsensor.h new file mode 100644 index 00000000..5b5556df --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwrotationsensor.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#ifndef SENSORFWROTATION_H +#define SENSORFWROTATION_H + +#include "sensorfwsensorbase.h" +#include + +#include +#include + + + +class SensorfwRotationSensor : public SensorfwSensorBase +{ + Q_OBJECT + +public: + static char const * const id; + SensorfwRotationSensor(QSensor *sensor); +protected: + virtual bool doConnect(); + virtual QString sensorName() const; + +private: + QRotationReading m_reading; + static bool m_initDone; + +private slots: + void slotDataAvailable(const XYZ& data); + void slotFrameAvailable(const QVector&); + +}; + +#endif diff --git a/src/plugins/sensors/sensorfw/sensorfwsensorbase.cpp b/src/plugins/sensors/sensorfw/sensorfwsensorbase.cpp new file mode 100644 index 00000000..85968e22 --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwsensorbase.cpp @@ -0,0 +1,189 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sensorfwsensorbase.h" + + +SensorManagerInterface* SensorfwSensorBase::m_remoteSensorManager = 0; + +//According to wikipedia link http://en.wikipedia.org/wiki/Standard_gravity +//const float sensorfwsensorbase::GRAVITY_EARTH = 9.812865328; +const float SensorfwSensorBase::GRAVITY_EARTH_THOUSANDTH = 0.009812865328; +const int SensorfwSensorBase::KErrNotFound=-1; +const int SensorfwSensorBase::KErrInUse=-14; +QStringList SensorfwSensorBase::m_bufferingSensors = QStringList() + <<"sensorfw.accelerometer"<<"sensorfw.magnetometer" + <<"sensorfw.gyroscope"<<"sensorfw.rotationsensor"; + +SensorfwSensorBase::SensorfwSensorBase(QSensor *sensor) + : QSensorBackend(sensor), m_sensorInterface(0), m_bufferSize(-1), m_prevOutputRange(0), m_efficientBufferSize(1), m_maxBufferSize(1) +{ + if (!m_remoteSensorManager) + m_remoteSensorManager = &SensorManagerInterface::instance(); +} + +SensorfwSensorBase::~SensorfwSensorBase() +{ + if (m_sensorInterface) { + stop(); + delete m_sensorInterface, m_sensorInterface = 0; + } +} + +void SensorfwSensorBase::start() +{ + if (m_sensorInterface) { + // dataRate + QByteArray type = sensor()->type(); + if (type != QTapSensor::type() && type != QProximitySensor::type()) { + int dataRate = sensor()->dataRate(); + int interval = dataRate > 0 ? 1000 / dataRate : 0; + // for testing maximum speed + //interval = 1; + //dataRate = 1000; + m_sensorInterface->setInterval(interval); + } + + // outputRange + int currentRange = sensor()->outputRange(); + int l = sensor()->outputRanges().size(); + if (l > 1) { + if (currentRange != m_prevOutputRange) { +//#ifdef Q_WS_MAEMO_6 + bool isOk = m_sensorInterface->setDataRangeIndex(currentRange); //NOTE THAT THE CHANGE MIGHT NOT SUCCEED, FIRST COME FIRST SERVED + if (!isOk) sensorError(KErrInUse); + else m_prevOutputRange = currentRange; +//#else +// // TODO: remove when sensord integrated, in sensorfw env there is a delay +// qoutputrange range = sensor()->outputRanges().at(currentRange); +// qreal correction = 1/correctionFactor(); +// DataRange range1(range.minimum*correction, range.maximum*correction, range.accuracy*correction); +// m_sensorInterface->requestDataRange(range1); +// m_prevOutputRange = currentRange; +//#endif + } + } + + // always on + bool alwaysOn = sensor()->isAlwaysOn(); + m_sensorInterface->setStandbyOverride(alwaysOn); + + // connects after buffering checks + doConnectAfterCheck(); + + int returnCode = m_sensorInterface->start().error().type(); + if (returnCode == 0) return; + qWarning() << "m_sensorInterface did not start, error code:" << returnCode; + } + sensorStopped(); +} + +void SensorfwSensorBase::stop() +{ + if (m_sensorInterface) m_sensorInterface->stop(); +} + +void SensorfwSensorBase::setRanges(qreal correctionFactor) +{ + if (!m_sensorInterface) return; + + QList ranges = m_sensorInterface->getAvailableDataRanges(); + + for (int i = 0, l = ranges.size(); i < l; i++) { + DataRange range = ranges.at(i); + qreal rangeMin = range.min * correctionFactor; + qreal rangeMax = range.max * correctionFactor; + qreal resolution = range.resolution * correctionFactor; + addOutputRange(rangeMin, rangeMax, resolution); + } +} + + +bool SensorfwSensorBase::doConnectAfterCheck() +{ + if (!m_sensorInterface) return false; + + // buffer size + int size = bufferSize(); + if (size == m_bufferSize) return true; + + if (m_bufferingSensors.contains(sensor()->identifier())) + m_sensorInterface->setBufferSize(size); + else + size = 1; + + // if multiple->single or single->multiple or if uninitialized + if ((m_bufferSize > 1 && size == 1) || (m_bufferSize == 1 && size > 1) || m_bufferSize == -1) { + m_bufferSize = size; + disconnect(this); + if (!doConnect()) { + qWarning() << "Unable to connect "<< sensorName(); + return false; + } + return true; + } + m_bufferSize = size; + return true; +} + +int SensorfwSensorBase::bufferSize() const +{ + int bufferSize = sensor()->bufferSize(); + if (bufferSize == 1) + return 1; + + // otherwise check validit + if (bufferSize < 1) { + qWarning() << "bufferSize cannot be " << bufferSize << ", must be a positive number >= 1"; + return 1; + } + if (bufferSize > m_maxBufferSize) { + qWarning() << "bufferSize cannot be " << bufferSize << ", MAX value is " << m_maxBufferSize; + return m_maxBufferSize; + } + return bufferSize; +} + +qreal SensorfwSensorBase::correctionFactor() const +{ + return 1; +} + diff --git a/src/plugins/sensors/sensorfw/sensorfwsensorbase.h b/src/plugins/sensors/sensorfw/sensorfwsensorbase.h new file mode 100644 index 00000000..78a6c14f --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwsensorbase.h @@ -0,0 +1,170 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#ifndef SENSORFWSENSORBASE_H +#define SENSORFWSENSORBASE_H + +#include +#include +#include + +class SensorfwSensorBase : public QSensorBackend +{ +public: + SensorfwSensorBase(QSensor *sensor); + virtual ~SensorfwSensorBase(); + + +protected: + virtual bool doConnect()=0; + virtual void start(); + virtual void stop(); + + static const float GRAVITY_EARTH; + static const float GRAVITY_EARTH_THOUSANDTH; //for speed + static const int KErrNotFound; + static const int KErrInUse; + static QStringList m_bufferingSensors; + + void setRanges(qreal correctionFactor=1); + virtual QString sensorName() const=0; + + template + void initSensor(bool &initDone) + { + + const QString name = sensorName(); + + if (!initDone) { + if (!m_remoteSensorManager->loadPlugin(name)) { + sensorError(KErrNotFound); + return; + } + m_remoteSensorManager->registerSensorInterface(name); + } + m_sensorInterface = T::controlInterface(name); + if (!m_sensorInterface) { + m_sensorInterface = const_cast(T::listenInterface(name)); + } + if (!m_sensorInterface) { + sensorError(KErrNotFound); + return; + } + if (!m_sensorInterface) { + sensorError(KErrNotFound); + return; + } + + initDone = true; + + //metadata + QList intervals = m_sensorInterface->getAvailableIntervals(); + + for (int i = 0, l = intervals.size(); i < l; i++) { + qreal intervalMax = ((DataRange)(intervals.at(i))).max; + qreal intervalMin =((DataRange)(intervals.at(i))).min; + + if (intervalMin == 0 && intervalMax == 0) { + // 0 interval has different meanings in e.g. magge/acce + // magge -> best-effort + // acce -> lowest possible + // in Qt API setting 0 means default + continue; + } + + qreal rateMin = intervalMax < 1 ? 1 : 1 / intervalMax * 1000; + rateMin = rateMin < 1 ? 1 : rateMin; + + intervalMin = intervalMin < 1 ? 10: intervalMin; // do not divide with 0 + qreal rateMax = 1 / intervalMin * 1000; + addDataRate(rateMin, rateMax); + } + + //bufferSizes + if (m_bufferingSensors.contains(sensor()->identifier())) { + + IntegerRangeList sizes = m_sensorInterface->getAvailableBufferSizes(); + int l = sizes.size(); + for (int i = 0; i < l; i++) { + int second = sizes.at(i).second; + m_maxBufferSize = second > m_bufferSize ? second : m_maxBufferSize; + } + m_maxBufferSize = m_maxBufferSize < 0 ? 1 : m_maxBufferSize; + //SensorFW guarantees to provide the most efficient size first + //TODO: remove from comments + //m_efficientBufferSize = m_sensorInterface->hwBuffering()? (l>0?sizes.at(0).first:1) : 1; + } + else + m_maxBufferSize = 1; + + sensor()->setMaxBufferSize(m_maxBufferSize); + sensor()->efficientBufferSize(m_efficientBufferSize); + + QByteArray type = sensor()->type(); + if (type == QAmbientLightSensor::type()) return; // SensorFW returns lux values, plugin enumerated values + if (type == QIRProximitySensor::type()) return; // SensorFW returns raw reflectance values, plugin % of max reflectance + if (name == "accelerometersensor") return; // SensorFW returns milliGs, plugin m/s^2 + if (name == "magnetometersensor") return; // SensorFW returns nanoTeslas, plugin Teslas + if (name == "gyroscopesensor") return; // SensorFW returns DSPs, plugin milliDSPs + + setDescription(m_sensorInterface->description()); + + if (name == "tapsensor") return; + setRanges(); + }; + + + AbstractSensorChannelInterface* m_sensorInterface; + int m_bufferSize; + int bufferSize() const; + virtual qreal correctionFactor() const; + +private: + + static SensorManagerInterface* m_remoteSensorManager; + int m_prevOutputRange; + bool doConnectAfterCheck(); + int m_efficientBufferSize, m_maxBufferSize; + +}; + +#endif diff --git a/src/plugins/sensors/sensorfw/sensorfwtapsensor.cpp b/src/plugins/sensors/sensorfw/sensorfwtapsensor.cpp new file mode 100644 index 00000000..c945ac11 --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwtapsensor.cpp @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sensorfwtapsensor.h" + +char const * const SensorfwTapSensor::id("sensorfw.tapsensor"); +bool SensorfwTapSensor::m_initDone = false; + +SensorfwTapSensor::SensorfwTapSensor(QSensor *sensor) + : SensorfwSensorBase(sensor), m_isOnceStarted(false) +{ + initSensor(m_initDone); + setReading(&m_reading); + addOutputRange(QTapReading::Undefined, QTapReading::Z_Both, 1); + addDataRate(10,10); //TODO: fix this when we know better +} + + +void SensorfwTapSensor::start() +{ + bool b = sensor()->returnDoubleTapEvents(); + bool isDoubleTapSensor = m_isDoubleTapSensor; + if (!b) { + sensor()->setReturnDoubleTapEvents(true); //by default doubles + m_isDoubleTapSensor = true; + } + else m_isDoubleTapSensor = b; + + if (!m_isOnceStarted || (m_isOnceStarted && isDoubleTapSensor != m_isDoubleTapSensor)) + ((TapSensorChannelInterface*)m_sensorInterface)-> + setTapType(m_isDoubleTapSensor?TapSensorChannelInterface::Double:TapSensorChannelInterface::Single); + + SensorfwSensorBase::start(); + // Set tap type (single/double) + m_reading.setDoubleTap(m_isDoubleTapSensor); + m_isOnceStarted = true; +} + + +void SensorfwTapSensor::slotDataAvailable(const Tap& data) +{ + // Set tap direction + QTapReading::TapDirection o; + switch (data.direction()) { + case TapData::X: o = QTapReading::X_Both; break; + case TapData::Y: o = QTapReading::Y_Both; break; + case TapData::Z: o = QTapReading::Z_Both; break; + case TapData::LeftRight: o = QTapReading::X_Pos; break; + case TapData::RightLeft: o = QTapReading::X_Neg; break; + case TapData::TopBottom: o = QTapReading::Z_Neg; break; + case TapData::BottomTop: o = QTapReading::Z_Pos; break; + case TapData::FaceBack: o = QTapReading::Y_Pos; break; + case TapData::BackFace: o = QTapReading::Y_Neg; break; + default: o = QTapReading::Undefined; + } + m_reading.setTapDirection(o); + m_reading.setTimestamp(data.tapData().timestamp_); + newReadingAvailable(); +} + + +bool SensorfwTapSensor::doConnect() +{ + return QObject::connect(m_sensorInterface, SIGNAL(dataAvailable(const Tap&)), + this, SLOT(slotDataAvailable(const Tap&))); +} + + +QString SensorfwTapSensor::sensorName() const +{ + return "tapsensor"; +} diff --git a/src/plugins/sensors/sensorfw/sensorfwtapsensor.h b/src/plugins/sensors/sensorfw/sensorfwtapsensor.h new file mode 100644 index 00000000..6df3bcfb --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwtapsensor.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef SENSORFWTAPSENSOR_H +#define SENSORFWTAPSENSOR_H + +#include "sensorfwsensorbase.h" +#include + +#include +#include + + + +class SensorfwTapSensor : public SensorfwSensorBase +{ + Q_OBJECT + +public: + static char const * const id; + SensorfwTapSensor(QSensor *sensor); +protected: + virtual bool doConnect(); + virtual void start(); + virtual QString sensorName() const; + +private: + QTapReading m_reading; + static bool m_initDone; + bool m_isDoubleTapSensor; + bool m_isOnceStarted; +private slots: + void slotDataAvailable(const Tap&); +}; + +#endif diff --git a/src/plugins/sensors/sensors.pro b/src/plugins/sensors/sensors.pro index 3822dafc..ef15f133 100644 --- a/src/plugins/sensors/sensors.pro +++ b/src/plugins/sensors/sensors.pro @@ -4,8 +4,14 @@ TEMPLATE = subdirs # of these. This reduces compile time and plugin loading time. blackberry { isEmpty(SENSORS_PLUGINS): SENSORS_PLUGINS = blackberry generic -} else: android { - SENSORS_PLUGINS = android generic +} + +android { + isEmpty(SENSORS_PLUGINS): SENSORS_PLUGINS = android generic +} + +sensorfw { + isEmpty(SENSORS_PLUGINS): SENSORS_PLUGINS = sensorfw generic } isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, dummy):SUBDIRS += dummy @@ -14,3 +20,5 @@ isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, simulator):simulator:SUBDIRS isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, blackberry):blackberry:SUBDIRS += blackberry isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, linux):linux:SUBDIRS += linux isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, android):android:SUBDIRS += android +isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, sensorfw):sensorfw:SUBDIRS += sensorfw + diff --git a/src/sensors/doc/src/compatmap.qdoc b/src/sensors/doc/src/compatmap.qdoc index 8fe24adc..a40a7a00 100644 --- a/src/sensors/doc/src/compatmap.qdoc +++ b/src/sensors/doc/src/compatmap.qdoc @@ -57,6 +57,7 @@ Android Linux Generic + Sensorfw Accelerometer @@ -64,6 +65,7 @@ + Altimeter @@ -78,6 +80,7 @@ + Ambient Temperature Sensor @@ -92,6 +95,7 @@ + Gyroscope @@ -99,6 +103,7 @@ + Holster Sensor @@ -120,6 +125,7 @@ + Magnetometer @@ -127,6 +133,7 @@ + Orientation Sensor @@ -134,6 +141,7 @@ + Pressure Sensor @@ -148,6 +156,7 @@ + Rotation Sensor @@ -155,6 +164,7 @@ + Tap Sensor @@ -169,13 +179,15 @@ + Sensor Gestures - 1) + + diff --git a/src/sensors/doc/src/qtsensors.qdoc b/src/sensors/doc/src/qtsensors.qdoc index 61286733..9213371d 100644 --- a/src/sensors/doc/src/qtsensors.qdoc +++ b/src/sensors/doc/src/qtsensors.qdoc @@ -112,6 +112,9 @@ \row \li \l {Generic Backend}{Generic Backend} \li Information about the generic sensor backend. + \row + \li \l {Sensorfw Backend}{Sensorfw Backend} + \li Information about the Sensorfw sensor backend. \endtable */ diff --git a/src/sensors/doc/src/sensorfwbackend.qdoc b/src/sensors/doc/src/sensorfwbackend.qdoc new file mode 100644 index 00000000..fcfbb5d8 --- /dev/null +++ b/src/sensors/doc/src/sensorfwbackend.qdoc @@ -0,0 +1,39 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Jolla Mobile +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \page senorfwbackend.html + \title Sensorfw Backend + \brief Information about the Sensorfw sensor backend + + The Sensorfw sensor backend requires the Sensorfw and sensor daemon. Sensorfw was originally used in MeeGo, and is available + from http://meego.gitorious.org/meego-middleware/sensorfw + + To compile the sensorfw backend, you need sensorfw installed and run qmake with CONFIG+=sensorfw + +*/ + -- cgit v1.2.3