summaryrefslogtreecommitdiffstats
path: root/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp
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/qtsensors/qwhipsensorgesturerecognizer.cpp
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/qtsensors/qwhipsensorgesturerecognizer.cpp')
-rw-r--r--src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp31
1 files changed, 25 insertions, 6 deletions
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;
}