summaryrefslogtreecommitdiffstats
path: root/src/imports
diff options
context:
space:
mode:
authorLincoln Ramsay <lincoln.ramsay@nokia.com>2012-03-02 14:13:39 +1000
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-10-03 09:22:38 +0200
commit4c61854d60fb5d2c68c6dcb1fb5bdf5c0dead3e2 (patch)
treeb41d70a37b8a1ff76c32025d8562a94581a3bd22 /src/imports
parentfb68fb8c052ae08fabed8f49256e79b0d0915fb0 (diff)
Add TiltSensor to QtMobility.sensors 1.3
This has been adapted from the TiltSensor type in QtSensors 5.0 import but the code there has been split into multiple pieces. There's a C++ class, a generic backend and a QML interface. Change-Id: Ic09465a5f76250a02a13938abe4789958137376f Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Diffstat (limited to 'src/imports')
-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
9 files changed, 321 insertions, 93 deletions
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;