summaryrefslogtreecommitdiffstats
path: root/src/imports/sensors2
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/sensors2
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/sensors2')
-rw-r--r--src/imports/sensors2/plugins.qmltypes10
-rw-r--r--src/imports/sensors2/qsensor2tilt.cpp64
-rw-r--r--src/imports/sensors2/qsensor2tilt.h14
3 files changed, 11 insertions, 77 deletions
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;