From dfc746b0bf8baaedc580e72f9897814ef9f4c560 Mon Sep 17 00:00:00 2001 From: Lorn Potter Date: Mon, 26 Mar 2012 13:07:28 +1000 Subject: fix slam gesture to be downward only motion. Change-Id: I3b115ca075610e7ca63828d1b3cc3e72e3820d75 Reviewed-by: Lincoln Ramsay --- doc/src/images/sensorgesture-slam_1.png | Bin 30696 -> 26212 bytes doc/src/qtsensorgestures-plugins.qdoc | 4 ++-- .../qtsensors/qslamgesturerecognizer.cpp | 26 +++++++++++---------- .../qtsensors/qslamgesturerecognizer.h | 2 ++ 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/doc/src/images/sensorgesture-slam_1.png b/doc/src/images/sensorgesture-slam_1.png index 89b5e7d4..d56f8892 100644 Binary files a/doc/src/images/sensorgesture-slam_1.png and b/doc/src/images/sensorgesture-slam_1.png differ diff --git a/doc/src/qtsensorgestures-plugins.qdoc b/doc/src/qtsensorgestures-plugins.qdoc index d78f401e..b6dc9c77 100644 --- a/doc/src/qtsensorgestures-plugins.qdoc +++ b/doc/src/qtsensorgestures-plugins.qdoc @@ -143,8 +143,8 @@ For QtSensorGestures plugin: \row \li QtSensors.slam \li slam - \li Phone is held in a top up position with a side facing forward. Move phone up, then swing it down and then held stationary briefly. - Like it is being used to point at something with the top corner. using the Accelerometer and Orientation sensors. + \li Phone is held in a top up position with a side facing forward. Swing it with a downward motion and then + hold stationary briefly, like it is being used to point at something with the top corner. using the Accelerometer and Orientation sensors. \li \image sensorgesture-slam_1.png \image sensorgesture-slam_2.png \row diff --git a/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.cpp index f8db7c29..ea3be725 100644 --- a/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.cpp +++ b/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.cpp @@ -128,8 +128,6 @@ void QSlamSensorGestureRecognizer::orientationReadingChanged(QOrientationReading #define SLAM_Y_DEGREES 15 -#define RADIANS_TO_DEGREES 57.2957795 - void QSlamSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) { const qreal x = reading->x(); @@ -155,8 +153,6 @@ void QSlamSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) const qreal difference = lastX - x; - roll = qAtan(x / qSqrt(y*y + z*z)) * RADIANS_TO_DEGREES; - if (!timer->isActive() && detecting && (orientationReading->orientation() == QOrientationReading::RightUp @@ -164,12 +160,9 @@ void QSlamSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) && resting) { timer->start(); } - if (!detecting && orientationReading->orientation() == QOrientationReading::TopUp - && roll < SLAM_Y_DEGREES - && (difference > accelRange * SLAM_DETECTION_FACTOR - || difference < -accelRange * SLAM_DETECTION_FACTOR)) { + && hasBeenResting()) { detectedX = x; // start of gesture detecting = true; @@ -185,15 +178,24 @@ void QSlamSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) lastZ = z; } -void QSlamSensorGestureRecognizer:: checkForSlam() -{ +bool QSlamSensorGestureRecognizer::hasBeenResting() +{ for (int i = 0; i < restingList.count() - 1; i++) { if (!restingList.at(i)) { - detecting = false; - return; + return false; } } + return true; +} + +void QSlamSensorGestureRecognizer::checkForSlam() +{ + + if (!hasBeenResting()) { + detecting = false; + return; + } if (detecting && (orientationReading->orientation() == QOrientationReading::RightUp // 3 or 4 || orientationReading->orientation() == QOrientationReading::LeftUp)) { diff --git a/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.h b/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.h index 4ea6530a..eb31c818 100644 --- a/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.h +++ b/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.h @@ -92,6 +92,8 @@ private: QList restingList; bool resting; QList xList; + + bool hasBeenResting(); }; QT_END_NAMESPACE -- cgit v1.2.3