From 82644f8405291a55d52f9e874a3e0bcf313ac98f Mon Sep 17 00:00:00 2001 From: Lorn Potter Date: Mon, 5 Dec 2011 15:28:37 +1000 Subject: add z and y axis accumulation for shake as well. Change-Id: If20750a1772da7fc7dc3665f68950c5c0aa6d30c Sanity-Review: Qt Sanity Bot Reviewed-by: Lincoln Ramsay --- .../sensorgestures/shake/qshakerecognizer.cpp | 58 ++++++++++++---------- .../sensorgestures/shake/qshakerecognizer.h | 1 + 2 files changed, 33 insertions(+), 26 deletions(-) (limited to 'src/plugins/sensorgestures') diff --git a/src/plugins/sensorgestures/shake/qshakerecognizer.cpp b/src/plugins/sensorgestures/shake/qshakerecognizer.cpp index e544b5aa..d9fa26be 100644 --- a/src/plugins/sensorgestures/shake/qshakerecognizer.cpp +++ b/src/plugins/sensorgestures/shake/qshakerecognizer.cpp @@ -52,6 +52,7 @@ QShakeSensorGestureRecognizer::QShakeSensorGestureRecognizer(QObject *parent) pYaxis = 0;nYaxis = 0; pZaxis = 0;nZaxis = 0; timerTimeout = 1500; + } QShakeSensorGestureRecognizer::~QShakeSensorGestureRecognizer() @@ -64,6 +65,13 @@ void QShakeSensorGestureRecognizer::create() accel->connectToBackend(); timer = new QTimer(this); + qoutputrangelist outputranges = accel->outputRanges(); + + if (outputranges.count() > 0) + accelRange = (int)(outputranges.at(0).maximum *2) / 9.8; //approx range in g's + else + accelRange = 4; //this should never happen + connect(timer,SIGNAL(timeout()),this,SLOT(timeout())); timer->setSingleShot(true); timer->setInterval(timerTimeout); @@ -86,7 +94,6 @@ bool QShakeSensorGestureRecognizer::stop() return !active; } - bool QShakeSensorGestureRecognizer::isActive() { return active; @@ -97,49 +104,48 @@ QString QShakeSensorGestureRecognizer::id() const return QString("QtSensors.shake"); } - #define NUMBER_SHAKES 3 void QShakeSensorGestureRecognizer::accelChanged() { qreal x = accel->reading()->x(); - qreal z = accel->reading()->z(); qreal xdiff = pXaxis - x; + qreal y = accel->reading()->y(); + qreal ydiff = pYaxis - y; + qreal z = accel->reading()->z(); + qreal zdiff = pZaxis - z; - if (abs(xdiff) > 10) { + if (abs(xdiff) > (5 * accelRange)) { nXaxis++; if (timer->isActive()) { timer->stop(); } timer->start(); } - if (nXaxis >= NUMBER_SHAKES) { - - Q_EMIT shake(); - Q_EMIT detected("shake"); - + if (abs(ydiff) > (5 * accelRange)) { + nYaxis++; if (timer->isActive()) { timer->stop(); } - timeout(); + timer->start(); } + if (abs(zdiff) > (5 * accelRange)) { + nZaxis++; + if (timer->isActive()) { + timer->stop(); + } + timer->start(); + } - // if (abs(zdiff) > 10) { - // nZaxis++; - // if (timer->isActive()) { - // timer->stop(); - // } - // timer->start(); - // } - - // if (nZaxis >= NUMBER_SHAKES) { - // Q_EMIT detected("ShakeZ"); - // Q_EMITshake(); - // if (timer->isActive()) { - // timer->stop(); - // } - // timeout(); - // } + if (nYaxis + nZaxis + nXaxis >= NUMBER_SHAKES) { + Q_EMIT shake(); + Q_EMIT detected("shake"); + if (timer->isActive()) { + timer->stop(); + } + timeout(); + } pXaxis = x; + pYaxis = y; pZaxis = z; } diff --git a/src/plugins/sensorgestures/shake/qshakerecognizer.h b/src/plugins/sensorgestures/shake/qshakerecognizer.h index 07c12c1e..4f3f1551 100644 --- a/src/plugins/sensorgestures/shake/qshakerecognizer.h +++ b/src/plugins/sensorgestures/shake/qshakerecognizer.h @@ -92,6 +92,7 @@ private: QTimer *timer; int timerTimeout; bool active; + int accelRange; }; #endif // QSHAKERECOGNIZER_H -- cgit v1.2.3