diff options
-rw-r--r-- | doc/src/images/sensorgesture-whip.png | bin | 0 -> 32058 bytes | |||
-rw-r--r-- | doc/src/images/sensorgesture-whip_1.png | bin | 32073 -> 0 bytes | |||
-rw-r--r-- | doc/src/images/sensorgesture-whip_2.png | bin | 31187 -> 0 bytes | |||
-rw-r--r-- | doc/src/qtsensorgestures-plugins.qdoc | 5 | ||||
-rw-r--r-- | src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp | 156 | ||||
-rw-r--r-- | src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.h | 21 |
6 files changed, 117 insertions, 65 deletions
diff --git a/doc/src/images/sensorgesture-whip.png b/doc/src/images/sensorgesture-whip.png Binary files differnew file mode 100644 index 0000000..aa998bb --- /dev/null +++ b/doc/src/images/sensorgesture-whip.png diff --git a/doc/src/images/sensorgesture-whip_1.png b/doc/src/images/sensorgesture-whip_1.png Binary files differdeleted file mode 100644 index 4ac08cd..0000000 --- a/doc/src/images/sensorgesture-whip_1.png +++ /dev/null diff --git a/doc/src/images/sensorgesture-whip_2.png b/doc/src/images/sensorgesture-whip_2.png Binary files differdeleted file mode 100644 index bcfd661..0000000 --- a/doc/src/images/sensorgesture-whip_2.png +++ /dev/null diff --git a/doc/src/qtsensorgestures-plugins.qdoc b/doc/src/qtsensorgestures-plugins.qdoc index 0301748..d78f401 100644 --- a/doc/src/qtsensorgestures-plugins.qdoc +++ b/doc/src/qtsensorgestures-plugins.qdoc @@ -160,9 +160,8 @@ For QtSensorGestures plugin: \row \li QtSensors.whip \li whip - \li Phone held top up, is moved like a whip gesture, back towards one side of the phone, then forward towards the other side, using the Accelerometer and Orientation sensors. - \li \image sensorgesture-whip_1.png - \image sensorgesture-whip_2.png + \li Move phone quickly down and then back up. using the Accelerometer and Orientation sensors. + \li \image sensorgesture-whip.png \endtable */ diff --git a/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp index e36fd26..8300f8e 100644 --- a/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp +++ b/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp @@ -48,13 +48,15 @@ QT_BEGIN_NAMESPACE QWhipSensorGestureRecognizer::QWhipSensorGestureRecognizer(QObject *parent) - : QSensorGestureRecognizer(parent) - , wasNegative(0) - , lastX(0) - , detectedX(0) - , active(0) - , detecting(0) -{ + : QSensorGestureRecognizer(parent), + orientationReading(0), + accelRange(0), + active(0), + lastX(0), + lastY(0), + lastZ(0), + detecting(0), + whipOk(0){ } QWhipSensorGestureRecognizer::~QWhipSensorGestureRecognizer() @@ -66,7 +68,7 @@ void QWhipSensorGestureRecognizer::create() timer = new QTimer(this); connect(timer,SIGNAL(timeout()),this,SLOT(timeout())); timer->setSingleShot(true); - timer->setInterval(750); + timer->setInterval(850); } QString QWhipSensorGestureRecognizer::id() const @@ -118,68 +120,72 @@ void QWhipSensorGestureRecognizer::orientationReadingChanged(QOrientationReading orientationReading = reading; } -#define WHIP_THRESHOLD_FACTOR 0.4//29.25 //33.15 -#define WHIP_DETECTION_FACTOR 0.15 // 5.85 - -#define WHIP_DEGREES 25 - -#define WHIP_Y_DEGREES 15 -#define WHIP_DEGREES_BELOW - -#define RADIANS_TO_DEGREES 57.2957795 +#define WHIP_FACTOR -11.0 +#define WHIP_WIGGLE_FACTOR 0.35 void QWhipSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) { const qreal x = reading->x(); - const qreal difference = lastX - x; - const qreal z = reading->z(); + const qreal y = reading->y(); + qreal z = reading->z(); + + if (zList.count() > 4) + zList.removeLast(); qreal averageZ = 0; - Q_FOREACH (const qreal az, zList) { + Q_FOREACH (qreal az, zList) { averageZ += az; } - if (zList.count() > 0) - averageZ /= zList.count(); + averageZ += z; + averageZ /= zList.count() + 1; - if (zList.count() > 5) - zList.removeLast(); - zList.insert(0,qAbs(z)); + zList.insert(0,qAbs(averageZ)); - if (qAbs(difference) < 1) { - return; - } if (orientationReading == 0) return; + //// very hacky + if (orientationReading->orientation() == QOrientationReading::FaceUp) { + z = z - 9.8; + } - const qreal y = reading->y(); - const qreal roll = qAtan(x / qSqrt(y*y + z*z)) * RADIANS_TO_DEGREES; + const qreal diffX = lastX - x; + const qreal diffY = lastY - y; - if (detecting) { - if (roll > WHIP_Y_DEGREES - && orientationReading->orientation() == QOrientationReading::TopUp - && ((!wasNegative && qAbs(detectedX - x) >= accelRange * WHIP_THRESHOLD_FACTOR) - || (wasNegative && detectedX - x >= (accelRange * WHIP_THRESHOLD_FACTOR))) ) { - Q_EMIT whip(); - Q_EMIT detected("whip"); - detecting = false; - timer->stop(); + if (detecting && whipMap.count() > 5 && whipMap.at(5) == true) { + checkForWhip(); + } + + if (whipMap.count() > 5) + whipMap.removeLast(); + + if (z < WHIP_FACTOR + && qAbs(diffX) > -(accelRange * .1285)//-5.0115 + && qAbs(lastX) < 7 + && qAbs(x) < 7) { + whipMap.insert(0,true); + if (!detecting && !timer->isActive()) { + timer->start(); + detecting = true; } - } else if (!timer->isActive() - && orientationReading->orientation() == QOrientationReading::TopUp - && roll < WHIP_Y_DEGREES - && ((difference > accelRange * WHIP_DETECTION_FACTOR) - || (difference < -accelRange * WHIP_DETECTION_FACTOR))) { - detectedX = x; -// start of gesture - timer->start(); - detecting = true; - if (difference > 0) - wasNegative = false; - else - wasNegative = true; - zList.clear(); + } else { + whipMap.insert(0,false); + } + lastZ = z; + + if (negativeList.count() > 5) + negativeList.removeLast(); + + if ((((x < 0 && lastX > 0) || (x > 0 && lastX < 0)) + && qAbs(diffX) > (accelRange * 0.7)) //27.3 + || (((y < 0 && lastY > 0) || (y > 0 && lastY < 0)) + && qAbs(diffY) > (accelRange * 0.7))) { + negativeList.insert(0,true); + } else { + negativeList.insert(0,false); } - lastX = x; + + lastX = x; lastY = y; + } void QWhipSensorGestureRecognizer::timeout() @@ -187,4 +193,46 @@ void QWhipSensorGestureRecognizer::timeout() detecting = false; } + +void QWhipSensorGestureRecognizer::checkForWhip() +{ + whipOk = false; + + qreal averageZ = 0; + Q_FOREACH (qreal az, zList) { + averageZ += az; + } + averageZ /= zList.count(); + + if (qAbs(averageZ) < 6.0) + return; + for (int i = 0; i < whipMap.count() - 1; 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++) { + if (negativeList.at(i)) { + ok = false; + } + } + + if (ok) { + Q_EMIT whip(); + Q_EMIT detected("whip"); + } + detecting = false; + whipMap.clear(); + timer->stop(); + } +} QT_END_NAMESPACE diff --git a/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.h b/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.h index 019793a..3405cce 100644 --- a/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.h +++ b/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.h @@ -74,18 +74,23 @@ private slots: private: QOrientationReading *orientationReading; QTimer *timer; - int accelRange; - bool wasNegative; - qreal lastX; - qreal detectedX; - + qreal accelRange; bool active; - qreal accelX; - qreal roll; + qreal lastX; + qreal lastY; + qreal lastZ; + bool detecting; - QList<qreal> zList; + bool whipOk; + QList<bool> whipMap; + + void checkForWhip(); + + QList <bool> negativeList; + + QList<qreal> zList; }; QT_END_NAMESPACE |