diff options
author | Lorn Potter <lorn.potter@nokia.com> | 2012-03-08 08:09:32 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-08 02:02:32 +0100 |
commit | 22b8a1ca8ebb2d862fb99d061342a1190b747fec (patch) | |
tree | ed05754b4e2bfbb4b1f4c6689fe8ad19cea8a2c4 /src/plugins/sensorgestures | |
parent | fb9638d88f55107e5e8d7eb3bbc30bc99890feb9 (diff) | |
download | qtsensors-22b8a1ca8ebb2d862fb99d061342a1190b747fec.tar.gz |
fix some issues and make whip easier
Change-Id: I14f84219e07bcede9badc4f02566f38533084009
Reviewed-by: Lincoln Ramsay <lincoln.ramsay@nokia.com>
Diffstat (limited to 'src/plugins/sensorgestures')
6 files changed, 64 insertions, 52 deletions
diff --git a/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.cpp index dd7bcd9..b63c833 100644 --- a/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.cpp +++ b/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.cpp @@ -131,7 +131,19 @@ void QSlamSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) qreal y = reading->y(); qreal z = reading->z(); -//// very hacky + if (zList.count() > 4) + zList.removeLast(); + + qreal averageZ = 0; + Q_FOREACH (qreal az, zList) { + averageZ += az; + } + averageZ += z; + averageZ /= zList.count() + 1; + + zList.insert(0,qAbs(averageZ)); + + //// very hacky if (orientationReading == 0) return; if (orientationReading->orientation() == QOrientationReading::FaceUp) { @@ -148,8 +160,8 @@ 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 * SLAM_WIGGLE_FACTOR) + && qAbs(diffY) < (accelRange * SLAM_WIGGLE_FACTOR)) { slamMap.insert(0,true); if (!detecting && !timer->isActive()) { timer->start(); @@ -164,9 +176,9 @@ void QSlamSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) negativeList.removeLast(); if ((((x < 0 && lastX > 0) || (x > 0 && lastX < 0)) - && qAbs(diffX) > (accelRange * 0.5)) - || ((y < 0 && lastY > 0) || (y > 0 && lastY < 0)) - && qAbs(diffY) > (accelRange * 0.5)) { + && qAbs(diffX) > (accelRange * 0.7)) + || (((y < 0 && lastY > 0) || (y > 0 && lastY < 0)) + && qAbs(diffY) > (accelRange * 0.7))) { negativeList.insert(0,true); } else { negativeList.insert(0,false); @@ -186,6 +198,15 @@ void QSlamSensorGestureRecognizer:: checkForSlam() { slamOk = 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 < slamMap.count() - 1; i++) { if (!slamMap.at(i)) { slamOk = true; @@ -204,6 +225,7 @@ void QSlamSensorGestureRecognizer:: checkForSlam() ok = false; } } + if (ok) { Q_EMIT slam(); Q_EMIT detected("slam"); diff --git a/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.h b/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.h index e5f71d6..7c366cf 100644 --- a/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.h +++ b/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.h @@ -93,8 +93,7 @@ private: QList <bool> negativeList; - //QList<qreal> yList; - + QList<qreal> zList; }; QT_END_NAMESPACE diff --git a/src/plugins/sensorgestures/qtsensors/qtsensorgesturesensorhandler.cpp b/src/plugins/sensorgestures/qtsensors/qtsensorgesturesensorhandler.cpp index 028ab04..ea2a378 100644 --- a/src/plugins/sensorgestures/qtsensors/qtsensorgesturesensorhandler.cpp +++ b/src/plugins/sensorgestures/qtsensors/qtsensorgesturesensorhandler.cpp @@ -95,7 +95,7 @@ bool QtSensorGestureSensorHandler::startSensor(SensorGestureSensors sensor) qoutputrangelist outputranges = accel->outputRanges(); if (outputranges.count() > 0) - accelRange = (int)(outputranges.at(0).maximum *2);//39 + accelRange = (int)(outputranges.at(0).maximum);//39 else accelRange = 39; //this should never happen connect(accel,SIGNAL(readingChanged()),this,SLOT(accelChanged())); diff --git a/src/plugins/sensorgestures/qtsensors/qturnoversensorgesturerecognizer.h b/src/plugins/sensorgestures/qtsensors/qturnoversensorgesturerecognizer.h index d32611e..592e0cd 100644 --- a/src/plugins/sensorgestures/qtsensors/qturnoversensorgesturerecognizer.h +++ b/src/plugins/sensorgestures/qtsensors/qturnoversensorgesturerecognizer.h @@ -73,6 +73,7 @@ private: bool active; void isRecognized(); + QList<qreal> zList; }; QT_END_NAMESPACE diff --git a/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp index a8b9092..a638789 100644 --- a/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp +++ b/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp @@ -48,8 +48,8 @@ QT_BEGIN_NAMESPACE QWhipSensorGestureRecognizer::QWhipSensorGestureRecognizer(QObject *parent) : - QSensorGestureRecognizer(parent), orientationReading(0), whipIt(0), lastX(0), - detectedX(0), active(0) + QSensorGestureRecognizer(parent), lastX(0), + detectedX(0), active(0),wasNegative(0), detecting(0) { } @@ -73,18 +73,10 @@ QString QWhipSensorGestureRecognizer::id() const bool QWhipSensorGestureRecognizer::start() { if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Accel)) { - 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; - } + accelRange = QtSensorGestureSensorHandler::instance()->accelRange; + active = true; + connect(QtSensorGestureSensorHandler::instance(),SIGNAL(accelReadingChanged(QAccelerometerReading *)), + this,SLOT(accelChanged(QAccelerometerReading *))); } else { active = false; } @@ -94,10 +86,6 @@ 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; @@ -109,7 +97,7 @@ bool QWhipSensorGestureRecognizer::isActive() return active; } -#define WHIP_THRESHOLD_FACTOR 0.85 //37 +#define WHIP_THRESHOLD_FACTOR 0.4//29.25 //33.15 #define WHIP_DETECTION_FACTOR 0.15 // 5.85 #define WHIP_DEGREES 25 @@ -119,58 +107,61 @@ bool QWhipSensorGestureRecognizer::isActive() #define RADIANS_TO_DEGREES 57.2957795 - -void QWhipSensorGestureRecognizer::orientationReadingChanged(QOrientationReading *reading) -{ - orientationReading = reading; -} - void QWhipSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) { qreal x = reading->x(); qreal difference = lastX - x; + qreal z = reading->z(); - if (qAbs(difference) < 1) - return; - if (orientationReading == 0) + qreal averageZ = 0; + Q_FOREACH (qreal az, zList) { + averageZ += az; + } + if (zList.count() > 0) + averageZ /= zList.count(); + + if (zList.count() > 5) + zList.removeLast(); + zList.insert(0,qAbs(z)); + + if (qAbs(difference) < 1) { return; + } qreal y = reading->y(); - qreal z = reading->z(); - qreal roll = qAtan(x / qSqrt(y*y + z*z)) * RADIANS_TO_DEGREES; - if (whipIt) { - - if (/*orientationReading->orientation() == QOrientationReading::TopUp - && */ roll > WHIP_Y_DEGREES - && ((!wasNegative && qAbs(detectedX - x) > accelRange * WHIP_THRESHOLD_FACTOR) - || (wasNegative && detectedX - x > (accelRange * WHIP_THRESHOLD_FACTOR))) ) { + if (detecting) { + if (roll > WHIP_Y_DEGREES + && qAbs(averageZ) < 4.0 + && ((!wasNegative && qAbs(detectedX - x) >= accelRange * WHIP_THRESHOLD_FACTOR) + || (wasNegative && detectedX - x >= (accelRange * WHIP_THRESHOLD_FACTOR))) ) { Q_EMIT whip(); Q_EMIT detected("whip"); - whipIt = false; + detecting = false; timer->stop(); } } 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(); - whipIt = true; + detecting = true; if (difference > 0) wasNegative = false; else wasNegative = true; + zList.clear(); } lastX = x; } void QWhipSensorGestureRecognizer::timeout() { - whipIt = false; + qDebug() << __FUNCTION__; + detecting = false; } QT_END_NAMESPACE diff --git a/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.h b/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.h index 234a69a..0b27efc 100644 --- a/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.h +++ b/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.h @@ -68,14 +68,11 @@ Q_SIGNALS: private slots: void accelChanged(QAccelerometerReading *reading); - void orientationReadingChanged(QOrientationReading *reading); void timeout(); private: - QOrientationReading *orientationReading; QTimer *timer; int accelRange; - bool whipIt; bool wasNegative; qreal lastX; qreal detectedX; @@ -84,6 +81,8 @@ private: qreal accelX; qreal roll; + bool detecting; + QList<qreal> zList; }; |