summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/sensors/maze/maze.qml2
-rw-r--r--examples/sensors/qmlqtsensors/qmlqtsensors.qml87
-rw-r--r--src/imports/sensors/plugins.qmltypes16
-rw-r--r--src/imports/sensors/qmlirproximitysensor.h1
-rw-r--r--src/imports/sensors/qmltiltsensor.cpp166
-rw-r--r--src/imports/sensors/qmltiltsensor.h94
-rw-r--r--src/imports/sensors/sensors.cpp29
-rw-r--r--src/imports/sensors/sensors.pro20
-rw-r--r--src/imports/sensors2/plugins.qmltypes10
-rw-r--r--src/imports/sensors2/qsensor2tilt.cpp64
-rw-r--r--src/imports/sensors2/qsensor2tilt.h14
-rw-r--r--src/plugins/sensors/generic/generic.pro6
-rw-r--r--src/plugins/sensors/generic/generictiltsensor.cpp181
-rw-r--r--src/plugins/sensors/generic/generictiltsensor.h83
-rw-r--r--src/plugins/sensors/generic/main.cpp2
-rw-r--r--src/sensors/qsensor.cpp8
-rw-r--r--src/sensors/qsensor.h1
-rw-r--r--src/sensors/qtiltsensor.cpp175
-rw-r--r--src/sensors/qtiltsensor.h95
-rw-r--r--src/sensors/qtiltsensor_p.h74
-rw-r--r--src/sensors/sensors.pro1
-rw-r--r--tests/auto/legacy_sensors/tst_legacy_sensors.cpp3
-rw-r--r--tests/auto/qsensor/test_backends.h5
-rw-r--r--tests/auto/qsensor/tst_qsensor.cpp5
-rw-r--r--tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp75
25 files changed, 962 insertions, 255 deletions
diff --git a/examples/sensors/maze/maze.qml b/examples/sensors/maze/maze.qml
index 46775056..46262877 100644
--- a/examples/sensors/maze/maze.qml
+++ b/examples/sensors/maze/maze.qml
@@ -173,9 +173,7 @@ ApplicationWindow {
//! [1]
TiltSensor{
id: tiltSensor
- unit: TiltSensor.Degrees
enabled: true
- accuracy: 5.0
}
//! [1]
diff --git a/examples/sensors/qmlqtsensors/qmlqtsensors.qml b/examples/sensors/qmlqtsensors/qmlqtsensors.qml
index fe21c4b4..d285cc94 100644
--- a/examples/sensors/qmlqtsensors/qmlqtsensors.qml
+++ b/examples/sensors/qmlqtsensors/qmlqtsensors.qml
@@ -102,7 +102,6 @@ ApplicationWindow {
height: 480
color: "transparent"
- property int accuracy: 1
property string speed: "Slow"
Text {
@@ -148,76 +147,12 @@ ApplicationWindow {
//! [1]
TiltSensor {
id: tilt
- unit: TiltSensor.Degrees
enabled: false
- accuracy: 1.0
speed: TiltSensor.Slow
}
//! [1]
Rectangle{
- id: accuracyRect
- anchors.top: labelTilt.bottom
- anchors.topMargin: 5
- anchors.left: mainWnd.left
- anchors.leftMargin: 5
- anchors.right: mainWnd.right
- anchors.rightMargin: mainWnd.width / 2
- height: 110
- color: "transparent"
-
- Text{
- id: textAccuracy
- anchors.top: accuracyRect.top
- anchors.left: accuracyRect.left
- text: "Accuracy"
- font.bold: true
- }
-
- Text{
- id: textAccuracyValue
- anchors.top: textAccuracy.bottom
- anchors.topMargin: 5
- anchors.left: accuracyHigher.left
- anchors.right: accuracyHigher.right
- text: mainWnd.accuracy
- verticalAlignment: Text.AlignVCenter
- }
-
- Button{
- id: accuracyLower
- anchors.top: textAccuracyValue.bottom
- anchors.left: accuracyRect.left
- height: 30
- width: 40
- text: "-"
-
- onClicked:{
- if (mainWnd.accuracy > 1){
- mainWnd.accuracy--;
- tilt.accuracy = mainWnd.accuracy;
- }
- }
- }
-
- Button{
- id: accuracyHigher
- anchors.top: textAccuracyValue.bottom
- anchors.left: accuracyLower.right
- height: 30
- width: 40
- text: "+"
-
- onClicked:{
- if (mainWnd.accuracy < 10){
- mainWnd.accuracy++;
- tilt.accuracy = mainWnd.accuracy;
- }
- }
- }
- }
-
- Rectangle{
id: speedRect
anchors.top: labelTilt.bottom
anchors.topMargin: 5
@@ -291,7 +226,7 @@ ApplicationWindow {
id: calibrate
anchors.left: mainWnd.left
anchors.leftMargin: 5
- anchors.top: accuracyRect.bottom
+ anchors.top: speedRect.bottom
height: 30
width: 80
text: "Calibrate"
@@ -302,22 +237,8 @@ ApplicationWindow {
}
Button{
- id: useRadian
- anchors.top: calibrate.bottom
- anchors.left: mainWnd.left
- anchors.leftMargin: 5
- height: 30
- width: 80
- text: (tilt !== null ? tilt.unit === TiltSensor.Radians ? "Degree" : "Radians" : "Degree")
-
- onClicked:{
- tilt.unit = (useRadian.text === "Radians" ? TiltSensor.Radians : TiltSensor.Degrees);
- }
- }
-
- Button{
id: tiltStart
- anchors.top: useRadian.bottom
+ anchors.top: calibrate.bottom
anchors.left: mainWnd.left
anchors.leftMargin: 5
height: 30
@@ -341,7 +262,7 @@ ApplicationWindow {
anchors.bottom: useRadian.bottom
verticalAlignment: Text.AlignVCenter
//! [3]
- text: "X Rotation: " + tilt.xRotation + (tilt.unit === TiltSensor.Radians ? " rad" : "°")
+ text: "X Rotation: " + tilt.xRotation + "°"
//! [3]
}
@@ -355,7 +276,7 @@ ApplicationWindow {
anchors.bottom: tiltStart.bottom
verticalAlignment: Text.AlignVCenter
//! [4]
- text: "Y Rotation: " + tilt.yRotation + (tilt.unit === TiltSensor.Radians ? " rad" : "°")
+ text: "Y Rotation: " + tilt.yRotation + "°"
//! [4]
}
diff --git a/src/imports/sensors/plugins.qmltypes b/src/imports/sensors/plugins.qmltypes
index 49c2e748..eecc3a93 100644
--- a/src/imports/sensors/plugins.qmltypes
+++ b/src/imports/sensors/plugins.qmltypes
@@ -495,5 +495,21 @@ Module {
Signal { name: "tapDirectionChanged"; type: "void" }
Signal { name: "isDoubleTapChanged"; type: "void" }
}
+ Component {
+ name: "QmlTiltSensor"
+ prototype: "QmlSensor"
+ exports: ["TiltSensor 1.3"]
+ }
+ Method { name: "calibrate"; type: "void" }
+ }
+ Component {
+ name: "QmlTiltSensorReading"
+ prototype: "QmlSensorReading"
+ exports: ["TiltReading 1.3"]
+ Property { name: "yRotation"; type: "double"; isReadonly: true }
+ Property { name: "xRotation"; type: "double"; isReadonly: true }
+ Signal { name: "yRotationChanged"; type: "void" }
+ Signal { name: "xRotationChanged"; type: "void" }
+ }
ModuleApi { version: 1.3; name: "QmlSensorGlobal" }
}
diff --git a/src/imports/sensors/qmlirproximitysensor.h b/src/imports/sensors/qmlirproximitysensor.h
index bf188d2a..2b2d4c49 100644
--- a/src/imports/sensors/qmlirproximitysensor.h
+++ b/src/imports/sensors/qmlirproximitysensor.h
@@ -56,7 +56,6 @@ public:
explicit QmlIRProximitySensor(QObject *parent = 0);
~QmlIRProximitySensor();
-
private:
QSensor *sensor() const Q_DECL_OVERRIDE;
QIRProximitySensor *m_sensor;
diff --git a/src/imports/sensors/qmltiltsensor.cpp b/src/imports/sensors/qmltiltsensor.cpp
new file mode 100644
index 00000000..26f6611d
--- /dev/null
+++ b/src/imports/sensors/qmltiltsensor.cpp
@@ -0,0 +1,166 @@
+/****************************************************************************
+**
+** 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 "qmltiltsensor.h"
+#include <QtSensors/qtiltsensor.h>
+
+QT_BEGIN_NAMESPACE
+QT_END_NAMESPACE
+
+/*!
+ \qmltype TiltSensor
+ \instantiates QmlTiltSensor
+ \ingroup qml-sensors_type
+ \inqmlmodule QtMobility.sensors 1.3
+ \since QtMobility.sensors 1.1
+ \inherits QtMobility.sensors1::Sensor
+ \brief The TiltSensor element reports tilt events
+ along the X and Y axes.
+
+ The TiltSensor element reports tilt events along the X and Y axes.
+
+ This element wraps the QTiltSensor class. Please see the documentation for
+ QTiltSensor for details.
+
+ \sa TiltReading
+*/
+
+QmlTiltSensor::QmlTiltSensor(QObject *parent)
+ : QmlSensor(parent)
+ , m_sensor(new QTiltSensor(this))
+{
+}
+
+QmlTiltSensor::~QmlTiltSensor()
+{
+}
+
+QmlSensorReading *QmlTiltSensor::createReading() const
+{
+ return new QmlTiltSensorReading(m_sensor);
+}
+
+QSensor *QmlTiltSensor::sensor() const
+{
+ return m_sensor;
+}
+
+/*!
+ \qmlmethod QtMobility.sensors1::TiltSensor::calibrate()
+ Calibrate the tilt sensor.
+
+ Please see QTiltSensor::calibrate() for information about this property.
+*/
+void QmlTiltSensor::calibrate()
+{
+ m_sensor->calibrate();
+}
+
+/*!
+ \qmltype TiltReading
+ \instantiates QmlTiltSensorReading
+ \ingroup qml-sensors_reading
+ \inqmlmodule QtMobility.sensors 1.3
+ \since QtMobility.sensors 1.1
+ \inherits QtMobility.sensors1::SensorReading
+ \brief The TiltReading element holds the most recent TiltSensor reading.
+
+ The TiltReading element holds the most recent TiltSensor reading.
+
+ This element wraps the QTiltReading class. Please see the documentation for
+ QTiltReading for details.
+
+ This element cannot be directly created.
+*/
+
+QmlTiltSensorReading::QmlTiltSensorReading(QTiltSensor *sensor)
+ : QmlSensorReading(sensor)
+ , m_sensor(sensor)
+{
+ update();
+}
+
+QmlTiltSensorReading::~QmlTiltSensorReading()
+{
+}
+
+/*!
+ \qmlproperty qreal QtMobility.sensors1::TiltReading::yRotation
+ This property holds the amount of tilt on the Y axis.
+
+ Please see QTiltReading::yRotation for information about this property.
+*/
+
+qreal QmlTiltSensorReading::yRotation() const
+{
+ return m_yRotation;
+}
+
+/*!
+ \qmlproperty qreal QtMobility.sensors1::TiltReading::xRotation
+ This property holds the amount of tilt on the X axis.
+
+ Please see QTiltReading::xRotation for information about this property.
+*/
+
+qreal QmlTiltSensorReading::xRotation() const
+{
+ return m_xRotation;
+}
+
+QSensorReading *QmlTiltSensorReading::reading() const
+{
+ return m_sensor->reading();
+}
+
+void QmlTiltSensorReading::readingUpdate()
+{
+ qreal tiltY = m_sensor->reading()->yRotation();
+ if (m_yRotation != tiltY) {
+ m_yRotation = tiltY;
+ Q_EMIT yRotationChanged();
+ }
+ qreal tiltX = m_sensor->reading()->xRotation();
+ if (m_xRotation != tiltX) {
+ m_xRotation = tiltX;
+ Q_EMIT xRotationChanged();
+ }
+}
diff --git a/src/imports/sensors/qmltiltsensor.h b/src/imports/sensors/qmltiltsensor.h
new file mode 100644
index 00000000..9afed564
--- /dev/null
+++ b/src/imports/sensors/qmltiltsensor.h
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** 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 QMLTILTSENSOR_H
+#define QMLTILTSENSOR_H
+
+#include "qmlsensor.h"
+#include <QtSensors/QTiltSensor>
+
+QT_BEGIN_HEADER
+QT_BEGIN_NAMESPACE
+
+class QTiltSensor;
+
+class QmlTiltSensor : public QmlSensor
+{
+ Q_OBJECT
+public:
+
+ explicit QmlTiltSensor(QObject *parent = 0);
+ ~QmlTiltSensor();
+ Q_INVOKABLE void calibrate();
+
+private:
+ QSensor *sensor() const Q_DECL_OVERRIDE;
+ QTiltSensor *m_sensor;
+ QmlSensorReading *createReading() const Q_DECL_OVERRIDE;
+};
+
+class QmlTiltSensorReading : public QmlSensorReading
+{
+ Q_OBJECT
+ Q_PROPERTY(qreal yRotation READ yRotation NOTIFY yRotationChanged)
+ Q_PROPERTY(qreal xRotation READ xRotation NOTIFY xRotationChanged)
+public:
+ explicit QmlTiltSensorReading(QTiltSensor *sensor);
+ ~QmlTiltSensorReading();
+
+ qreal yRotation() const;
+ qreal xRotation() const;
+
+Q_SIGNALS:
+ void yRotationChanged();
+ void xRotationChanged();
+
+private:
+ QSensorReading *reading() const Q_DECL_OVERRIDE;
+ void readingUpdate() Q_DECL_OVERRIDE;
+ QTiltSensor *m_sensor;
+ qreal m_yRotation;
+ qreal m_xRotation;
+};
+
+QT_END_NAMESPACE
+QT_END_HEADER
+#endif
diff --git a/src/imports/sensors/sensors.cpp b/src/imports/sensors/sensors.cpp
index e5f43835..9e425297 100644
--- a/src/imports/sensors/sensors.cpp
+++ b/src/imports/sensors/sensors.cpp
@@ -41,18 +41,20 @@
#include <QtQml/qqmlextensionplugin.h>
#include <QtQml/qqml.h>
+#include <QtSensors/QSensorManager>
-#include <qaccelerometer.h>
-#include <qambientlightsensor.h>
-#include <qcompass.h>
-#include <qmagnetometer.h>
-#include <qorientationsensor.h>
-#include <qproximitysensor.h>
-#include <qrotationsensor.h>
-#include <qtapsensor.h>
-#include <qlightsensor.h>
-#include <qgyroscope.h>
-#include <qirproximitysensor.h>
+#include <QtSensors/qaccelerometer.h>
+#include <QtSensors/qambientlightsensor.h>
+#include <QtSensors/qcompass.h>
+#include <QtSensors/qmagnetometer.h>
+#include <QtSensors/qorientationsensor.h>
+#include <QtSensors/qproximitysensor.h>
+#include <QtSensors/qrotationsensor.h>
+#include <QtSensors/qtapsensor.h>
+#include <QtSensors/qlightsensor.h>
+#include <QtSensors/qgyroscope.h>
+#include <QtSensors/qirproximitysensor.h>
+#include <QtSensors/qtiltsensor.h>
#include "qmlsensorglobal.h"
#include "qmlsensor.h"
@@ -67,6 +69,7 @@
#include "qmlproximitysensor.h"
#include "qmlrotationsensor.h"
#include "qmltapsensor.h"
+#include "qmltiltsensor.h"
QT_BEGIN_NAMESPACE
@@ -75,7 +78,7 @@ static QObject *global_object_13(QQmlEngine *, QJSEngine *)
return new QmlSensorGlobal;
}
-class QSensorsDeclarativeModule : public QQmlExtensionPlugin
+class QtSensorsDeclarativeModule : public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface" FILE "plugin.json")
@@ -164,6 +167,8 @@ public:
qmlRegisterUncreatableType<QmlRotationSensorReading >(package, major, minor, "RotationReading", QLatin1String("Cannot create RotationReading"));
qmlRegisterType <QmlTapSensor >(package, major, minor, "TapSensor");
qmlRegisterUncreatableType<QmlTapSensorReading >(package, major, minor, "TapReading", QLatin1String("Cannot create TapReading"));
+ qmlRegisterType <QmlTiltSensor >(package, major, minor, "TiltSensor");
+ qmlRegisterUncreatableType<QmlTiltSensorReading >(package, major, minor, "TiltReading", QLatin1String("Cannot create TiltReading"));
}
};
diff --git a/src/imports/sensors/sensors.pro b/src/imports/sensors/sensors.pro
index ac59fcde..89af5ead 100644
--- a/src/imports/sensors/sensors.pro
+++ b/src/imports/sensors/sensors.pro
@@ -3,7 +3,9 @@ TARGET = declarative_sensors
TARGETPATH = QtMobility/sensors
IMPORT_VERSION = 1.3 # Doesn't matter, as long as it's a valid version?!
-QT += qml sensors
+include(qsensorsimport.pri)
+
+QT += qml sensors sensors-private
HEADERS += \
qmlsensor.h \
@@ -19,7 +21,9 @@ HEADERS += \
qmlproximitysensor.h \
qmltapsensor.h \
qmlrotationsensor.h \
- qmlsensorglobal.h
+ qmlsensorglobal.h \
+ qmltiltsensor.h
+
SOURCES += sensors.cpp \
qmlsensor.cpp \
qmlsensorrange.cpp \
@@ -34,7 +38,17 @@ SOURCES += sensors.cpp \
qmlproximitysensor.cpp \
qmltapsensor.cpp \
qmlrotationsensor.cpp \
- qmlsensorglobal.cpp
+ qmlsensorglobal.cpp \
+ qmltiltsensor.cpp
+
+
+DESTDIR = $$QT.sensors.imports/$$TARGETPATH
+target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
+
+qmldir.files += $$PWD/qmldir $$PWD/plugin.qmltypes
+qmldir.path += $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
+
+INSTALLS += target qmldir
load(qml_plugin)
diff --git a/src/imports/sensors2/plugins.qmltypes b/src/imports/sensors2/plugins.qmltypes
index 97c9fe37..ea8b5260 100644
--- a/src/imports/sensors2/plugins.qmltypes
+++ b/src/imports/sensors2/plugins.qmltypes
@@ -56,13 +56,6 @@ Module {
prototype: "qsensor2common"
exports: ["TiltSensor 5.0"]
Enum {
- name: "Unit"
- values: {
- "Radians": 0,
- "Degrees": 1
- }
- }
- Enum {
name: "Speed"
values: {
"Slow": 0,
@@ -72,11 +65,8 @@ Module {
}
Property { name: "yRotation"; type: "double"; isReadonly: true }
Property { name: "xRotation"; type: "double"; isReadonly: true }
- Property { name: "unit"; type: "Unit" }
Property { name: "speed"; type: "Speed" }
- Property { name: "accuracy"; type: "double" }
Property { name: "settings"; type: "QByteArray" }
- Signal { name: "unitChanged"; type: "void" }
Signal { name: "yRotationChanged"; type: "void" }
Signal { name: "xRotationChanged"; type: "void" }
Signal { name: "speedChanged"; type: "void" }
diff --git a/src/imports/sensors2/qsensor2tilt.cpp b/src/imports/sensors2/qsensor2tilt.cpp
index 1314d6dc..85d39ce8 100644
--- a/src/imports/sensors2/qsensor2tilt.cpp
+++ b/src/imports/sensors2/qsensor2tilt.cpp
@@ -71,7 +71,6 @@ QSensor2Tilt::QSensor2Tilt(QObject* parent)
, _yRotation(0)
, _xRotation(0)
, _radAccuracy(M_PI / 180)
- , _unit(QSensor2Tilt::Radians)
, _pitch(0)
, _roll(0)
, _calibratedPitch(0)
@@ -199,32 +198,6 @@ void QSensor2Tilt::setEnabled(const bool val)
}
}
-/*!
- \target unit_property
- \qmlproperty enumeration QtSensors5::TiltSensor::unit
- Returns the unit of the rotation which can be one of:
- \table
- \row
- \li TiltSensor.Radians
- \li The unit of the rotation angle is radians.
- \row
- \li TiltSensor.Degrees
- \li The unit of the rotation angle is degrees.
- \endtable
-*/
-QSensor2Tilt::Unit QSensor2Tilt::unit()
-{
- return _unit;
-}
-
-void QSensor2Tilt::setUnit(const QSensor2Tilt::Unit val)
-{
- if (_unit != val){
- _unit = val;
- Q_EMIT unitChanged();
- }
-}
-
/*!
\qmlproperty real QtSensors5::TiltSensor::yRotation
@@ -240,10 +213,7 @@ void QSensor2Tilt::setUnit(const QSensor2Tilt::Unit val)
*/
qreal QSensor2Tilt::yRotation()
{
- if (_unit == QSensor2Tilt::Degrees)
- return _yRotation * 180 / M_PI;
-
- return _yRotation;
+ return _yRotation * 180 / M_PI;
}
/*!
@@ -259,10 +229,7 @@ qreal QSensor2Tilt::yRotation()
*/
qreal QSensor2Tilt::xRotation()
{
- if (_unit == QSensor2Tilt::Degrees)
- return _xRotation * 180 / M_PI;
-
- return _xRotation;
+ return _xRotation * 180 / M_PI;
}
/*
@@ -273,7 +240,7 @@ qreal QSensor2Tilt::xRotation()
*/
inline qreal calcPitch(double Ax, double Ay, double Az)
{
- return (float)-qAtan2(Ax, sqrt(Ay * Ay + Az * Az));
+ return -qAtan2(Ax, sqrt(Ay * Ay + Az * Az));
}
/*
@@ -284,7 +251,7 @@ inline qreal calcPitch(double Ax, double Ay, double Az)
*/
inline qreal calcRoll(double Ax, double Ay, double Az)
{
- return (float)qAtan2(Ay, (sqrt(Ax * Ax + Az * Az)));
+ return qAtan2(Ay, (sqrt(Ax * Ax + Az * Az)));
}
/*!
@@ -316,22 +283,16 @@ inline qreal calcRoll(double Ax, double Ay, double Az)
/*!
\qmlsignal QtSensors5::TiltSensor::tiltChanged(real deltaX, real deltaY)
This signal is emitted whenever the change from at leat one of the rotation values was higher than the accuracy.
- The angle value is based on the specified unit (Degree or Radian).
+ The angle value is based on degrees.
- \sa {QtSensors5::TiltSensor::unit}
*/
-qreal QSensor2Tilt::accuracy()
-{
- //return in degree
- return 180 * _radAccuracy / M_PI;
-}
-void QSensor2Tilt::setAccuracy(qreal val)
-{
- //save in rad to save convertion calc in filter function
- if (val <= 90 && val >= 0)
- _radAccuracy = M_PI * val / 180;
-}
+//void QSensor2Tilt::setAccuracy(qreal val)
+//{
+// //save in rad to save convertion calc in filter function
+// if (val <= 90 && val >= 0)
+// _radAccuracy = M_PI * val / 180;
+//}
/*!
\qmlmethod void QtSensors5::TiltSensor::calibrate()
@@ -440,10 +401,7 @@ bool QSensor2Tilt::filter(QAccelerometerReading* reading)
change = true;
}
if (change){
- if (_unit == QSensor2Tilt::Degrees)
Q_EMIT tiltChanged(dxrot * 180 / M_PI, dyrot * 180 / M_PI);
- else
- Q_EMIT tiltChanged(dxrot, dyrot);
}
return false;
}
diff --git a/src/imports/sensors2/qsensor2tilt.h b/src/imports/sensors2/qsensor2tilt.h
index 0def8b38..359db0d5 100644
--- a/src/imports/sensors2/qsensor2tilt.h
+++ b/src/imports/sensors2/qsensor2tilt.h
@@ -55,9 +55,7 @@ class QSensor2Tilt : public qsensor2common, public QAccelerometerFilter
Q_ENUMS(Unit Speed)
Q_PROPERTY(qreal yRotation READ yRotation NOTIFY yRotationChanged)
Q_PROPERTY(qreal xRotation READ xRotation NOTIFY xRotationChanged)
- Q_PROPERTY(Unit unit READ unit WRITE setUnit NOTIFY unitChanged)
Q_PROPERTY(Speed speed READ speed WRITE setSpeed NOTIFY speedChanged)
- Q_PROPERTY(qreal accuracy READ accuracy WRITE setAccuracy NOTIFY accuracyChanged)
Q_PROPERTY(QByteArray settings READ settings WRITE setSettings)
public:
@@ -65,11 +63,6 @@ public:
virtual ~QSensor2Tilt();
Q_INVOKABLE void calibrate();
- enum Unit{
- Radians = 0
- , Degrees
- };
-
enum Speed{
Slow = 0
, Medium
@@ -78,24 +71,18 @@ public:
Q_SIGNALS:
- void unitChanged();
void yRotationChanged();
void xRotationChanged();
void speedChanged();
void tiltChanged(qreal deltaX, qreal deltaY);
- void accuracyChanged();
public:
// Override of QAcclerometerFilter::filter(QAccelerometerReading*)
qreal yRotation();
qreal xRotation();
- Unit unit();
- void setUnit(const Unit val);
Speed speed();
void setSpeed(const Speed val);
void setEnabled(bool val);
- qreal accuracy();
- void setAccuracy(const qreal val);
QByteArray settings() const;
void setSettings(const QByteArray val);
void createRunModeDataRateMap();
@@ -109,7 +96,6 @@ private:
qreal _yRotation;
qreal _xRotation;
qreal _radAccuracy;
- Unit _unit;
qreal _pitch;
qreal _roll;
qreal _calibratedPitch;
diff --git a/src/plugins/sensors/generic/generic.pro b/src/plugins/sensors/generic/generic.pro
index d5c9e531..22d7c133 100644
--- a/src/plugins/sensors/generic/generic.pro
+++ b/src/plugins/sensors/generic/generic.pro
@@ -7,12 +7,14 @@ DESTDIR = $$QT.sensors.plugins/sensors
HEADERS += genericorientationsensor.h\
genericrotationsensor.h\
- genericalssensor.h
+ genericalssensor.h\
+ generictiltsensor.h
SOURCES += genericorientationsensor.cpp\
main.cpp\
genericrotationsensor.cpp\
- genericalssensor.cpp
+ genericalssensor.cpp\
+ generictiltsensor.cpp
OTHER_FILES = plugin.json
diff --git a/src/plugins/sensors/generic/generictiltsensor.cpp b/src/plugins/sensors/generic/generictiltsensor.cpp
new file mode 100644
index 00000000..df07355d
--- /dev/null
+++ b/src/plugins/sensors/generic/generictiltsensor.cpp
@@ -0,0 +1,181 @@
+/****************************************************************************
+**
+** 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 "generictiltsensor.h"
+#include <QDebug>
+#define _USE_MATH_DEFINES
+#include <qmath.h>
+
+char const * const GenericTiltSensor::id("generic.tilt");
+
+GenericTiltSensor::GenericTiltSensor(QSensor *sensor)
+ : QSensorBackend(sensor)
+ , radAccuracy(M_PI / 180)
+ , pitch(0)
+ , roll(0)
+ , calibratedPitch(0)
+ , calibratedRoll(0)
+{
+ accelerometer = new QAccelerometer(this);
+ accelerometer->addFilter(this);
+ accelerometer->connectToBackend();
+
+ setReading<QTiltReading>(&m_reading);
+ setDataRates(accelerometer);
+}
+
+void GenericTiltSensor::start()
+{
+ accelerometer->setDataRate(sensor()->dataRate());
+ accelerometer->setAlwaysOn(sensor()->isAlwaysOn());
+ accelerometer->start();
+ if (!accelerometer->isActive())
+ sensorStopped();
+ if (accelerometer->isBusy())
+ sensorBusy();
+}
+
+void GenericTiltSensor::stop()
+{
+ accelerometer->stop();
+}
+
+/*
+ Angle between Ground and X
+ | Ax |
+ pitch = arctan| ----------------------- |
+ | sqrt(Ay * Ay + Az * Az)|
+*/
+static inline qreal calcPitch(double Ax, double Ay, double Az)
+{
+ return -qAtan2(Ax, sqrt(Ay * Ay + Az * Az));
+}
+
+/*
+ Angle between Ground and Y
+ | Ay |
+ roll = arctan| ----------------------- |
+ | sqrt(Ax * Ax + Az * Az)|
+*/
+static inline qreal calcRoll(double Ax, double Ay, double Az)
+{
+ return qAtan2(Ay, (sqrt(Ax * Ax + Az * Az)));
+}
+
+void GenericTiltSensor::calibrate()
+{
+ calibratedPitch = pitch;
+ calibratedRoll = roll;
+}
+
+bool GenericTiltSensor::filter(QAccelerometerReading *reading)
+{
+ /*
+ z y
+ | /
+ |/___ x
+ */
+
+ qreal ax = reading->x();
+ qreal ay = reading->y();
+ qreal az = reading->z();
+#ifdef LOGCALIBRATION
+ qDebug() << "------------ new value -----------";
+ qDebug() << "old _pitch: " << _pitch;
+ qDebug() << "old _roll: " << _roll;
+ qDebug() << "_calibratedPitch: " << _calibratedPitch;
+ qDebug() << "_calibratedRoll: " << _calibratedRoll;
+#endif
+ pitch = calcPitch(ax, ay, az);
+ roll = calcRoll (ax, ay, az);
+#ifdef LOGCALIBRATION
+ qDebug() << "_pitch: " << _pitch;
+ qDebug() << "_roll: " << _roll;
+#endif
+ qreal xrot = roll - calibratedRoll;
+ qreal yrot = pitch - calibratedPitch;
+ //get angle beteen 0 and 180 or 0 -180
+ qreal aG = 1 * sin(xrot);
+ qreal aK = 1 * cos(xrot);
+ xrot = qAtan2(aG, aK);
+ if (xrot > M_PI_2)
+ xrot = M_PI - xrot;
+ else if (xrot < -M_PI_2)
+ xrot = -(M_PI + xrot);
+ aG = 1 * sin(yrot);
+ aK = 1 * cos(yrot);
+ yrot = qAtan2(aG, aK);
+ if (yrot > M_PI_2)
+ yrot = M_PI - yrot;
+ else if (yrot < -M_PI_2)
+ yrot = -(M_PI + yrot);
+
+
+#ifdef LOGCALIBRATION
+ qDebug() << "new xrot: " << xrot;
+ qDebug() << "new yrot: " << yrot;
+ qDebug() << "----------------------------------";
+#endif
+ qreal dxrot = xrot - xRotation;
+ qreal dyrot = yrot - yRotation;
+ if (dxrot < 0) dxrot = -dxrot;
+ if (dyrot < 0) dyrot = -dyrot;
+
+ bool change = false;
+ if (dxrot >= radAccuracy){
+ xRotation = xrot;
+ change = true;
+ }
+ if (dyrot >= radAccuracy){
+ yRotation = yrot;
+ change = true;
+ }
+ if (xRotation != m_reading.xRotation()
+ || yRotation != m_reading.yRotation()
+ || m_reading.timestamp() == 0) {
+ m_reading.setTimestamp(reading->timestamp());
+ m_reading.setXRotation(xRotation);
+ m_reading.setYRotation(yRotation);
+ newReadingAvailable();
+ }
+
+ return false;
+}
diff --git a/src/plugins/sensors/generic/generictiltsensor.h b/src/plugins/sensors/generic/generictiltsensor.h
new file mode 100644
index 00000000..0633662c
--- /dev/null
+++ b/src/plugins/sensors/generic/generictiltsensor.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** 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 GENERICTILTSENSOR_H
+#define GENERICTILTSENSOR_H
+
+#include <qsensorbackend.h>
+#include <qtiltsensor.h>
+#include <qaccelerometer.h>
+
+QT_BEGIN_HEADER
+QT_BEGIN_NAMESPACE
+
+class GenericTiltSensor : public QSensorBackend, public QAccelerometerFilter
+{
+public:
+
+ static char const * const id;
+
+ GenericTiltSensor(QSensor *sensor);
+
+ void start();
+ void stop();
+
+ void calibrate();
+
+ bool filter(QAccelerometerReading *reading);
+
+private:
+ QTiltReading m_reading;
+ QAccelerometer *accelerometer;
+ qreal radAccuracy;
+ qreal pitch;
+ qreal roll;
+ qreal calibratedPitch;
+ qreal calibratedRoll;
+ qreal xRotation;
+ qreal yRotation;
+};
+
+QT_END_NAMESPACE
+QT_END_HEADER
+
+#endif
+
diff --git a/src/plugins/sensors/generic/main.cpp b/src/plugins/sensors/generic/main.cpp
index eb54158d..c4554890 100644
--- a/src/plugins/sensors/generic/main.cpp
+++ b/src/plugins/sensors/generic/main.cpp
@@ -70,6 +70,8 @@ public:
QSensorManager::registerBackend(QRotationSensor::type, genericrotationsensor::id, this);
if (!QSensorManager::isBackendRegistered(QAmbientLightSensor::type, genericalssensor::id))
QSensorManager::registerBackend(QAmbientLightSensor::type, genericalssensor::id, this);
+ if (!QSensorManager::isBackendRegistered(QAmbientLightSensor::type, genericalssensor::id))
+ QSensorManager::registerBackend(QAmbientLightSensor::type, genericalssensor::id, this);
} else {
if (QSensorManager::isBackendRegistered(QOrientationSensor::type, genericorientationsensor::id))
QSensorManager::unregisterBackend(QOrientationSensor::type, genericorientationsensor::id);
diff --git a/src/sensors/qsensor.cpp b/src/sensors/qsensor.cpp
index 4a5cb304..0e9fcea3 100644
--- a/src/sensors/qsensor.cpp
+++ b/src/sensors/qsensor.cpp
@@ -224,6 +224,14 @@ QSensor::QSensor(const QByteArray &type, QSensorPrivate &dd, QObject* parent)
d->init(type);
}
+/*! \internal
+ */
+QSensorBackend *QSensor::backend() const
+{
+ Q_D(const QSensor);
+ return d->backend;
+}
+
/*!
Destroy the sensor. Stops the sensor if it has not already been stopped.
*/
diff --git a/src/sensors/qsensor.h b/src/sensors/qsensor.h
index 8b2a96b9..46d011d3 100644
--- a/src/sensors/qsensor.h
+++ b/src/sensors/qsensor.h
@@ -171,6 +171,7 @@ Q_SIGNALS:
protected:
explicit QSensor(const QByteArray &type, QSensorPrivate &dd, QObject* parent = 0);
+ QSensorBackend *backend() const;
private:
void registerInstance();
diff --git a/src/sensors/qtiltsensor.cpp b/src/sensors/qtiltsensor.cpp
new file mode 100644
index 00000000..b78746bc
--- /dev/null
+++ b/src/sensors/qtiltsensor.cpp
@@ -0,0 +1,175 @@
+/****************************************************************************
+**
+** 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 "qtiltsensor.h"
+#include "qtiltsensor_p.h"
+
+#include "qsensorbackend.h"
+
+#include <QtCore/QMetaObject>
+
+QT_BEGIN_NAMESPACE
+
+IMPLEMENT_READING(QTiltReading)
+
+/*!
+ \class QTiltReading
+ \ingroup sensors_reading
+ \inmodule QtSensors
+
+ \brief The QTiltReading class holds readings from the tilt sensor.
+
+ The tilt sensor reports the angle of tilt in degrees of the device along the X and Y plane.
+
+*/
+
+
+/*!
+ \property QTiltReading::yRotation
+ \brief This property holds the amount of tilt on the Y axis.
+*/
+qreal QTiltReading::yRotation() const
+{
+ return d->yRotation;
+}
+
+/*!
+ Sets yRotation to \a y.
+*/
+void QTiltReading::setYRotation(qreal y)
+{
+ d->yRotation = y;
+}
+
+/*!
+ \property QTiltReading::xRotation
+ \brief This property holds the amount of tilt on the X axis.
+
+*/
+qreal QTiltReading::xRotation() const
+{
+ return d->xRotation;
+}
+
+/*!
+ Sets xRotation to \a x.
+*/
+void QTiltReading::setXRotation(qreal x)
+{
+ d->xRotation = x;
+}
+
+// =====================================================================
+
+/*!
+ \class QTiltFilter
+ \ingroup sensors_filter
+ \inmodule QtSensors
+
+ \brief The QTiltFilter class is a convenience wrapper around QSensorFilter.
+
+ The only difference is that the filter() method features a pointer to QTiltReading
+ instead of QSensorReading.
+*/
+
+/*!
+ \fn QTiltFilter::filter(QTiltReading *reading)
+
+ Called when \a reading changes. Returns false to prevent the reading from propagating.
+
+ \sa QSensorFilter::filter()
+*/
+
+char const * const QTiltSensor::type("QTiltSensor");
+
+/*!
+ \class QTiltSensor
+ \ingroup sensors_type
+ \inmodule QtSensors
+
+ \brief The QTiltSensor class is a convenience wrapper around QSensor.
+
+ The only behavioural difference is that this class sets the type properly.QMetaObject::invokeMethod(backend(), "calibrate");
+
+ This class also features a reading() function that returns a QTiltReading instead of a QSensorReading.
+
+ For details about how the sensor works, see \l QTiltReading.
+
+ \sa QTiltReading
+*/
+
+/*!
+ \fn QTiltSensor::QTiltSensor(QObject *parent)
+
+ Construct the sensor as a child of \a parent.
+*/
+QTiltSensor::QTiltSensor(QObject *parent)
+ : QSensor(QTiltSensor::type, parent)
+{
+}
+
+/*!
+ \fn QTiltSensor::~QTiltSensor()
+
+ Destroy the sensor. Stops the sensor if it has not already been stopped.
+*/
+QTiltSensor::~QTiltSensor()
+{
+}
+/*!
+ \fn QTiltSensor::reading() const
+
+ Returns the reading class for this sensor.
+
+ \sa QSensor::reading()
+*/
+
+
+/*!
+ Calibrates the tilt sensor. Uses the current tilt angles as 0.
+ */
+void QTiltSensor::calibrate()
+{
+ QMetaObject::invokeMethod(backend(), "calibrate", Qt::DirectConnection);
+}
+
+#include "moc_qtiltsensor.cpp"
+QT_END_NAMESPACE
diff --git a/src/sensors/qtiltsensor.h b/src/sensors/qtiltsensor.h
new file mode 100644
index 00000000..8742280b
--- /dev/null
+++ b/src/sensors/qtiltsensor.h
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** 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 QTILTSENSOR_H
+#define QTILTSENSOR_H
+
+#include "qsensor.h"
+
+QT_BEGIN_HEADER
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(QtSensors)
+
+class QTiltReadingPrivate;
+
+class Q_SENSORS_EXPORT QTiltReading : public QSensorReading
+{
+ Q_OBJECT
+ Q_PROPERTY(qreal yRotation READ yRotation)
+ Q_PROPERTY(qreal xRotation READ xRotation)
+ DECLARE_READING(QTiltReading)
+
+public:
+ qreal yRotation() const;
+ void setYRotation(qreal y);
+
+ qreal xRotation() const;
+ void setXRotation(qreal x);
+
+};
+
+class Q_SENSORS_EXPORT QTiltFilter : public QSensorFilter
+{
+public:
+ virtual bool filter(QTiltReading *reading) = 0;
+private:
+ bool filter(QSensorReading *reading) { return filter(static_cast<QTiltReading*>(reading)); }
+};
+
+class Q_SENSORS_EXPORT QTiltSensor : public QSensor
+{
+ Q_OBJECT
+public:
+ explicit QTiltSensor(QObject *parent = 0);
+ ~QTiltSensor();
+ QTiltReading *reading() const { return static_cast<QTiltReading*>(QSensor::reading()); }
+ static char const * const type;
+
+ Q_INVOKABLE void calibrate();
+
+private:
+ Q_DISABLE_COPY(QTiltSensor)
+};
+
+QT_END_NAMESPACE
+QT_END_HEADER
+#endif
diff --git a/src/sensors/qtiltsensor_p.h b/src/sensors/qtiltsensor_p.h
new file mode 100644
index 00000000..14946243
--- /dev/null
+++ b/src/sensors/qtiltsensor_p.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 QTILTSENSOR_P_H
+#define QTILTSENSOR_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+QT_BEGIN_HEADER
+QT_BEGIN_NAMESPACE
+
+class QTiltReadingPrivate
+{
+public:
+ QTiltReadingPrivate()
+ : yRotation(0)
+ , xRotation(0)
+ {
+ }
+
+ qreal yRotation;
+ qreal xRotation;
+};
+
+QT_END_NAMESPACE
+QT_END_HEADER
+#endif
diff --git a/src/sensors/sensors.pro b/src/sensors/sensors.pro
index d72e9c3a..8f11f10e 100644
--- a/src/sensors/sensors.pro
+++ b/src/sensors/sensors.pro
@@ -60,6 +60,7 @@ SENSORS=\
qirproximitysensor\
qrotationsensor\
qtapsensor\
+ qtiltsensor\
qgyroscope\
for(s,SENSORS) {
diff --git a/tests/auto/legacy_sensors/tst_legacy_sensors.cpp b/tests/auto/legacy_sensors/tst_legacy_sensors.cpp
index 6745b9ce..ec2de81a 100644
--- a/tests/auto/legacy_sensors/tst_legacy_sensors.cpp
+++ b/tests/auto/legacy_sensors/tst_legacy_sensors.cpp
@@ -173,6 +173,8 @@ private slots:
QTest::newRow("1.3 GyroscopeReading") << "1.3" << "GyroscopeReading" << false;
QTest::newRow("1.3 IRProximitySensor") << "1.3" << "IRProximitySensor" << true;
QTest::newRow("1.3 IRProximityReading") << "1.3" << "IRProximityReading" << false;
+ QTest::newRow("1.3 TiltSensor") << "1.3" << "TiltSensor" << true;
+ QTest::newRow("1.3 TiltReading") << "1.3" << "TiltReading" << false;
}
void elements()
@@ -238,6 +240,7 @@ private slots:
QTest::newRow("1.3 LightSensor") << "1.3" << "LightSensor" << true;
QTest::newRow("1.3 Gyroscope") << "1.3" << "Gyroscope" << true;
QTest::newRow("1.3 IRProximitySensor") << "1.3" << "IRProximitySensor" << true;
+ QTest::newRow("1.3 TiltSensor") << "1.3" << "TiltSensor" << true;
}
void alwaysOn()
diff --git a/tests/auto/qsensor/test_backends.h b/tests/auto/qsensor/test_backends.h
index 0d8e2bab..a36a8586 100644
--- a/tests/auto/qsensor/test_backends.h
+++ b/tests/auto/qsensor/test_backends.h
@@ -58,6 +58,7 @@ void unregister_test_backends();
#include <qrotationsensor.h>
#include <qtapsensor.h>
#include <qirproximitysensor.h>
+#include <qtiltsensor.h>
#define PREPARE_SENSORINTERFACE_DECLS(SensorClass, ReadingClass, FilterClass, readingcode)\
class SensorClass ## _impl : public QSensorBackend\
@@ -132,6 +133,10 @@ PREPARE_SENSORINTERFACE(QTapSensor, QTapReading, QTapFilter, {
PREPARE_SENSORINTERFACE(QIRProximitySensor, QIRProximityReading, QIRProximityFilter, {
reading->setReflectance(0.5);
})
+PREPARE_SENSORINTERFACE(QTiltSensor, QTiltReading, QTiltFilter, {
+ reading->setYRotation(1.0);
+ reading->setXRotation(1.0);
+})
#define TEST_SENSORINTERFACE(SensorClass, ReadingClass, readingcode)\
do {\
diff --git a/tests/auto/qsensor/tst_qsensor.cpp b/tests/auto/qsensor/tst_qsensor.cpp
index abb0a6d8..5b4c40b8 100644
--- a/tests/auto/qsensor/tst_qsensor.cpp
+++ b/tests/auto/qsensor/tst_qsensor.cpp
@@ -892,6 +892,11 @@ private slots:
QCOMPARE(reading->isDoubleTap(), true);
})
+ TEST_SENSORINTERFACE(QTiltSensor, QTiltReading, {
+ QCOMPARE(reading->yRotation(), 1.0);
+ QCOMPARE(reading->xRotation(), 1.0);
+ })
+
TEST_SENSORINTERFACE(QIRProximitySensor, QIRProximityReading, {
QCOMPARE(reading->reflectance(), 0.5);
})
diff --git a/tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp b/tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp
index 8828d19b..42ef629b 100644
--- a/tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp
+++ b/tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp
@@ -69,10 +69,8 @@ private slots:
void testTilt();
void testTilt_receivedSignalsCount();
void testTiltSettings();
- void testTiltAccuracy();
void testTiltCalibration();
void testTiltRunningMode();
- void testTiltUnit();
void testProximity();
void testAmbientLight();
void testGesture();
@@ -239,11 +237,6 @@ void tst_Sensors2QMLAPI::testTilt()
_tilt->setProperty("enabled", true);
QCOMPARE(spy.count() , 0);
- _tilt->setProperty("unit", QSensor2Tilt::Radians);
- QSignalSpy spyunitch(_tilt, SIGNAL(unitChanged()));
- _tilt->setProperty("unit", QSensor2Tilt::Degrees);
- QCOMPARE(spyunitch.count() , 1);
-
QByteArray settings;
settings.append(QString::number(-5.0));
settings.append(";");
@@ -310,44 +303,6 @@ void tst_Sensors2QMLAPI::testTiltSettings()
QCOMPARE(settings, val);
}
-void tst_Sensors2QMLAPI::testTiltAccuracy()
-{
- if (!_tilt)
- _tilt = new QSensor2Tilt(this);
-
- QByteArray settings;
- settings.append(QString::number(0.0));
- settings.append(";");
- settings.append(QString::number(0.0));
- _tilt->setProperty("settings", settings);
- _tilt->setProperty("enabled", true);
-
- QDeclAccelerometer* accel = _plugin.stAccel;
-
- //be sure we set rotation to 0
- _tilt->setProperty("accuracy", 0.0);
- QVERIFY(0.01 > _tilt->property("accuracy").toFloat());
-
- accel->test(0,0,1);
-
- //now set accuracy a little bigger then Pi / 4 in deg
- _tilt->setProperty("accuracy", 180 / 4.0 + 0.1);
- QSignalSpy spyxrot(_tilt, SIGNAL(xRotationChanged()));
- QSignalSpy spyyrot(_tilt, SIGNAL(yRotationChanged()));
-
- accel->test(1, 1, 0);
- QCOMPARE(spyxrot.count() , 0);
- QCOMPARE(spyyrot.count() , 0);
-
- spyxrot.clear();
- spyyrot.clear();
- _tilt->setProperty("accuracy", 180 / 4.0 + 0.1 - 0.1);
- accel->test(1, 1, 0);
- QCOMPARE(spyxrot.count() , 1);
- QCOMPARE(spyyrot.count() , 1);
-
-}
-
void tst_Sensors2QMLAPI::testTilt_receivedSignalsCount()
{
QCOMPARE(xrotch , 23);
@@ -365,12 +320,10 @@ void tst_Sensors2QMLAPI::testTiltCalibration()
settings.append(QString::number(0.0));
_tilt->setProperty("settings", settings);
_tilt->setProperty("enabled", true);
- _tilt->setProperty("unit", QSensor2Tilt::Degrees);
QDeclAccelerometer* accel = _plugin.stAccel;
//be sure we set rotation to 0
- _tilt->setProperty("accuracy", 0.0);
accel->test(-3.59904, 5.52114, 7.07059);
_tilt->calibrate();
accel->test(-3.59904, 5.52114, 7.07059);
@@ -393,34 +346,6 @@ void tst_Sensors2QMLAPI::testTiltCalibration()
_tilt->setProperty("enabled", false);
}
-void tst_Sensors2QMLAPI::testTiltUnit()
-{
- if (!_tilt)
- _tilt = new QSensor2Tilt(this);
- QDeclAccelerometer* accel = _plugin.stAccel;
- _tilt->setProperty("enabled", false);
- _tilt->setProperty("accuracy", 0.0);
- _tilt->setProperty("unit", QVariant(QSensor2Tilt::Radians));
- accel->test(-3.59904, 5.52114, 7.07059);
- qreal xRotation = _tilt->property("xRotation").toReal();
- qreal yRotation = _tilt->property("yRotation").toReal();
- xRotation += 0.159136;
- yRotation -= 0.43440;
- QVERIFY(xRotation < 0.0001);
- QVERIFY(yRotation < 0.0001);
- QCOMPARE(_tilt->property("unit").toInt(), (int)QSensor2Tilt::Radians);
-
- _tilt->setProperty("unit", QVariant(QSensor2Tilt::Degrees));
- accel->test(-3.59904, 5.52114, 7.07059);
- xRotation = _tilt->property("xRotation").toReal();
- yRotation = _tilt->property("yRotation").toReal();
- xRotation += 9.11778;
- yRotation -= 24.8898;
- QVERIFY(xRotation < 0.0001);
- QVERIFY(yRotation < 0.0001);
- QCOMPARE(_tilt->property("unit").toInt(), (int)QSensor2Tilt::Degrees);
-}
-
void tst_Sensors2QMLAPI::testTiltRunningMode()
{
if (!_tilt)