diff options
author | Lorn Potter <lorn.potter@nokia.com> | 2012-05-24 08:14:44 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-05-24 06:27:32 +0200 |
commit | b3c30d5a489e92d28c63820d4a77357108471635 (patch) | |
tree | 4b2b20de8006cd82eb5a647a9dddc115c0303dbf /src/plugins/sensorgestures/qtsensors | |
parent | c8c03ee6b2a4d7de1ca13cb5848589c8a6134d4d (diff) |
fix false positive whip gesture.
false positive was tapping fingers on screen would produce a whip
:
Change-Id: Ibff1323f27e899cd63bdbaddcf0e77915a993b21
Reviewed-by: Lorn Potter <lorn.potter@nokia.com>
Diffstat (limited to 'src/plugins/sensorgestures/qtsensors')
-rw-r--r-- | src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp | 51 |
1 files changed, 18 insertions, 33 deletions
diff --git a/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp index ee0d02a6..74be37f4 100644 --- a/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp +++ b/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp @@ -138,10 +138,10 @@ void QWhipSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) Q_FOREACH (qreal az, zList) { averageZ += az; } - averageZ += z; - averageZ /= zList.count() + 1; +// averageZ += z; + averageZ /= zList.count(); - zList.insert(0,qAbs(averageZ)); + zList.insert(0,z); if (orientationReading == 0) return; @@ -159,7 +159,10 @@ void QWhipSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) if (whipMap.count() > 5) whipMap.removeLast(); -//qDebug() << z << qAbs(diffX) << qAbs(lastX) << qAbs(x) ; + + if (negativeList.count() > 5) + negativeList.removeLast(); + if (z < WHIP_FACTOR && qAbs(diffX) > -(accelRange * .1285)//-5.0115 @@ -169,16 +172,12 @@ void QWhipSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) if (!detecting && !timer->isActive()) { timer->start(); detecting = true; -// qDebug() << "start detecting"; } } else { whipMap.insert(0,false); } - lastZ = z; - - if (negativeList.count() > 5) - negativeList.removeLast(); + // check if shaking if ((((x < 0 && lastX > 0) || (x > 0 && lastX < 0)) && qAbs(diffX) > (accelRange * 0.7)) //27.3 || (((y < 0 && lastY > 0) || (y > 0 && lastY < 0)) @@ -188,8 +187,9 @@ void QWhipSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) negativeList.insert(0,false); } - lastX = x; lastY = y; - + lastX = x; + lastY = y; + lastZ = z; } void QWhipSensorGestureRecognizer::timeout() @@ -200,32 +200,17 @@ void QWhipSensorGestureRecognizer::timeout() void QWhipSensorGestureRecognizer::checkForWhip() { - // qDebug() << __FUNCTION__; - whipOk = false; - qreal averageZ = 0; + int check = 0; Q_FOREACH (qreal az, zList) { - averageZ += az; + if (az < -10) + check++; } - averageZ /= zList.count(); - // qDebug() << qAbs(averageZ) << zList << whipMap; - - if (qAbs(averageZ) < 5.0) + if (check >= 4) + whipOk = true; + else return; - - for (int i = 0; i < 3; i++) { - if (!whipMap.at(i)) { - whipOk = true; - } else { - detecting = false; - whipOk = false; - timer->stop(); - - return; - } - } - if (whipOk) { bool ok = true; for (int i = 0; i < negativeList.count() - 1; i++) { @@ -233,7 +218,6 @@ void QWhipSensorGestureRecognizer::checkForWhip() ok = false; } } - if (ok) { Q_EMIT whip(); Q_EMIT detected("whip"); @@ -243,4 +227,5 @@ void QWhipSensorGestureRecognizer::checkForWhip() timer->stop(); } } + QT_END_NAMESPACE |