summaryrefslogtreecommitdiffstats
path: root/src/plugins/sensorgestures
diff options
context:
space:
mode:
authorLorn Potter <lorn.potter@nokia.com>2012-03-20 15:11:51 +1000
committerQt by Nokia <qt-info@nokia.com>2012-03-20 06:19:46 +0100
commit929fbe06c860f2da0d695ec2346b046b16b0472c (patch)
tree2913f1901833ae67423747f5ddef5646d7fd2ec9 /src/plugins/sensorgestures
parent683d15f9e5a0688db4e1f64cad1a54c757d8517c (diff)
make slam easier and re-add orientation stuff
Change-Id: I7703a6abc537f317aa1186c919494faa866137fd Reviewed-by: Lorn Potter <lorn.potter@nokia.com>
Diffstat (limited to 'src/plugins/sensorgestures')
-rw-r--r--src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.cpp16
-rw-r--r--src/plugins/sensorgestures/qtsensors/qtwistsensorgesturerecognizer.cpp3
-rw-r--r--src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp31
-rw-r--r--src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.h2
4 files changed, 38 insertions, 14 deletions
diff --git a/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.cpp
index b63c833f..5fc4f493 100644
--- a/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.cpp
+++ b/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.cpp
@@ -68,7 +68,7 @@ void QSlamSensorGestureRecognizer::create()
timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(timeout()));
timer->setSingleShot(true);
- timer->setInterval(1250);
+ timer->setInterval(850);
}
@@ -122,8 +122,8 @@ void QSlamSensorGestureRecognizer::orientationReadingChanged(QOrientationReading
orientationReading = reading;
}
-#define SLAM_FACTOR -16.0
-#define SLAM_WIGGLE_FACTOR 0.95
+#define SLAM_FACTOR -11.0
+#define SLAM_WIGGLE_FACTOR 0.35
void QSlamSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading)
{
@@ -143,9 +143,9 @@ void QSlamSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading)
zList.insert(0,qAbs(averageZ));
- //// very hacky
if (orientationReading == 0)
return;
+ //// very hacky
if (orientationReading->orientation() == QOrientationReading::FaceUp) {
z = z - 9.8;
}
@@ -159,9 +159,11 @@ void QSlamSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading)
if (slamMap.count() > 5)
slamMap.removeLast();
+
if (z < SLAM_FACTOR
- && qAbs(diffX) < (accelRange * SLAM_WIGGLE_FACTOR)
- && qAbs(diffY) < (accelRange * SLAM_WIGGLE_FACTOR)) {
+ && qAbs(diffX) > -(accelRange * .1285)//-5.0115
+ && qAbs(lastX) < 7
+ && qAbs(x) < 7) {
slamMap.insert(0,true);
if (!detecting && !timer->isActive()) {
timer->start();
@@ -176,7 +178,7 @@ void QSlamSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading)
negativeList.removeLast();
if ((((x < 0 && lastX > 0) || (x > 0 && lastX < 0))
- && qAbs(diffX) > (accelRange * 0.7))
+ && qAbs(diffX) > (accelRange * 0.7)) //27.3
|| (((y < 0 && lastY > 0) || (y > 0 && lastY < 0))
&& qAbs(diffY) > (accelRange * 0.7))) {
negativeList.insert(0,true);
diff --git a/src/plugins/sensorgestures/qtsensors/qtwistsensorgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qtwistsensorgesturerecognizer.cpp
index 040068f3..80eb3783 100644
--- a/src/plugins/sensorgestures/qtsensors/qtwistsensorgesturerecognizer.cpp
+++ b/src/plugins/sensorgestures/qtsensors/qtwistsensorgesturerecognizer.cpp
@@ -168,7 +168,8 @@ void QTwistSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading)
lastRoll = degrees;
}
- if (!detecting && qAbs(degrees) > THRESHOLD_DEGREES
+ if (orientationReading->orientation() == QOrientationReading::FaceUp
+ && !detecting && qAbs(degrees) > THRESHOLD_DEGREES
&& pitch < RESTING_VARIANCE) {
detecting = true;
diff --git a/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp
index e7a31985..27aff5b4 100644
--- a/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp
+++ b/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp
@@ -77,10 +77,18 @@ QString QWhipSensorGestureRecognizer::id() const
bool QWhipSensorGestureRecognizer::start()
{
if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Accel)) {
- accelRange = QtSensorGestureSensorHandler::instance()->accelRange;
- active = true;
- connect(QtSensorGestureSensorHandler::instance(),SIGNAL(accelReadingChanged(QAccelerometerReading *)),
- this,SLOT(accelChanged(QAccelerometerReading *)));
+ if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Orientation)) {
+ accelRange = QtSensorGestureSensorHandler::instance()->accelRange;
+ active = true;
+ connect(QtSensorGestureSensorHandler::instance(),SIGNAL(orientationReadingChanged(QOrientationReading *)),
+ this,SLOT(orientationReadingChanged(QOrientationReading *)));
+
+ connect(QtSensorGestureSensorHandler::instance(),SIGNAL(accelReadingChanged(QAccelerometerReading *)),
+ this,SLOT(accelChanged(QAccelerometerReading *)));
+ } else {
+ QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Accel);
+ active = false;
+ }
} else {
active = false;
}
@@ -90,6 +98,10 @@ bool QWhipSensorGestureRecognizer::start()
bool QWhipSensorGestureRecognizer::stop()
{
QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Accel);
+ QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Orientation);
+ disconnect(QtSensorGestureSensorHandler::instance(),SIGNAL(orientationReadingChanged(QOrientationReading *)),
+ this,SLOT(orientationReadingChanged(QOrientationReading *)));
+
disconnect(QtSensorGestureSensorHandler::instance(),SIGNAL(accelReadingChanged(QAccelerometerReading *)),
this,SLOT(accelChanged(QAccelerometerReading *)));
active = false;
@@ -101,6 +113,11 @@ bool QWhipSensorGestureRecognizer::isActive()
return active;
}
+void QWhipSensorGestureRecognizer::orientationReadingChanged(QOrientationReading *reading)
+{
+ orientationReading = reading;
+}
+
#define WHIP_THRESHOLD_FACTOR 0.4//29.25 //33.15
#define WHIP_DETECTION_FACTOR 0.15 // 5.85
@@ -131,13 +148,15 @@ void QWhipSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading)
if (qAbs(difference) < 1) {
return;
}
+ if (orientationReading == 0)
+ return;
qreal y = reading->y();
qreal roll = qAtan(x / qSqrt(y*y + z*z)) * RADIANS_TO_DEGREES;
if (detecting) {
if (roll > WHIP_Y_DEGREES
- && qAbs(averageZ) < 4.0
+ && orientationReading->orientation() == QOrientationReading::TopUp
&& ((!wasNegative && qAbs(detectedX - x) >= accelRange * WHIP_THRESHOLD_FACTOR)
|| (wasNegative && detectedX - x >= (accelRange * WHIP_THRESHOLD_FACTOR))) ) {
Q_EMIT whip();
@@ -146,6 +165,7 @@ void QWhipSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading)
timer->stop();
}
} else if (!timer->isActive()
+ && orientationReading->orientation() == QOrientationReading::TopUp
&& roll < WHIP_Y_DEGREES
&& ((difference > accelRange * WHIP_DETECTION_FACTOR)
|| (difference < -accelRange * WHIP_DETECTION_FACTOR))) {
@@ -164,7 +184,6 @@ void QWhipSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading)
void QWhipSensorGestureRecognizer::timeout()
{
- qDebug() << __FUNCTION__;
detecting = false;
}
diff --git a/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.h b/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.h
index 0b27efcf..019793a2 100644
--- a/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.h
+++ b/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.h
@@ -68,9 +68,11 @@ Q_SIGNALS:
private slots:
void accelChanged(QAccelerometerReading *reading);
+ void orientationReadingChanged(QOrientationReading *reading);
void timeout();
private:
+ QOrientationReading *orientationReading;
QTimer *timer;
int accelRange;
bool wasNegative;