summaryrefslogtreecommitdiffstats
path: root/src/plugins/sensorgestures
diff options
context:
space:
mode:
authorLorn Potter <lorn.potter@nokia.com>2012-03-22 15:54:02 +1000
committerQt by Nokia <qt-info@nokia.com>2012-03-22 07:02:31 +0100
commitd03033a2a4ba45f4b47fbf36ec84b13d4718ef24 (patch)
treeaf036698b6738e818a6de50412eef757810a51dd /src/plugins/sensorgestures
parent06eaf5882495f2fad5d180e9b994e958c44eef28 (diff)
whip is now too much like slam. so make whip be the old slam.
Change-Id: Ib4be08e5fc828c24b00b0c90e0e9448603eef6bf Reviewed-by: Lincoln Ramsay <lincoln.ramsay@nokia.com>
Diffstat (limited to 'src/plugins/sensorgestures')
-rw-r--r--src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp156
-rw-r--r--src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.h21
2 files changed, 115 insertions, 62 deletions
diff --git a/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp
index e36fd268..8300f8ea 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 019793a2..3405cce7 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