summaryrefslogtreecommitdiffstats
path: root/src/plugins/sensorgestures
diff options
context:
space:
mode:
authorLorn Potter <lorn.potter@nokia.com>2011-12-05 15:28:37 +1000
committerQt by Nokia <qt-info@nokia.com>2011-12-06 07:33:57 +0100
commit82644f8405291a55d52f9e874a3e0bcf313ac98f (patch)
tree835ad5ddf723a3d18ff3d822898e7432dc62e8d1 /src/plugins/sensorgestures
parent44255a0b3042633aec46cae0a6fc192d19389fb3 (diff)
add z and y axis accumulation for shake as well.
Change-Id: If20750a1772da7fc7dc3665f68950c5c0aa6d30c Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Lincoln Ramsay <lincoln.ramsay@nokia.com>
Diffstat (limited to 'src/plugins/sensorgestures')
-rw-r--r--src/plugins/sensorgestures/shake/qshakerecognizer.cpp58
-rw-r--r--src/plugins/sensorgestures/shake/qshakerecognizer.h1
2 files changed, 33 insertions, 26 deletions
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