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 --- .../qtsensors/qslamgesturerecognizer.cpp | 26 ++++++++++++---------- .../qtsensors/qslamgesturerecognizer.h | 2 ++ 2 files changed, 16 insertions(+), 12 deletions(-) (limited to 'src/plugins') 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