diff options
author | Lorn Potter <lorn.potter@nokia.com> | 2012-05-10 09:00:58 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-05-11 11:51:15 +0200 |
commit | fb06538ffb57d82ae63b61dc7798f740fe27ba3e (patch) | |
tree | 229bbde8fa8b856e5999ea3f340f68ab35254957 /src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.cpp | |
parent | d45a9503de3f94a9630a34efb0e9ea02f894856e (diff) |
fix up gestures for auto test data
slam and other gestures need to be performed the way the test data
shows.
slam is effected the most as now the gesture needs no hold at end to be
recognized, in accordance with data collected.
Change-Id: Iedfcf8e42def0b1dfe1c4d289a416ca64d8846e1
Reviewed-by: Lincoln Ramsay <lincoln.ramsay@nokia.com>
Diffstat (limited to 'src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.cpp')
-rw-r--r-- | src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.cpp | 55 |
1 files changed, 26 insertions, 29 deletions
diff --git a/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.cpp index e676122d..bdf38d31 100644 --- a/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.cpp +++ b/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.cpp @@ -68,10 +68,6 @@ QSlamSensorGestureRecognizer::~QSlamSensorGestureRecognizer() void QSlamSensorGestureRecognizer::create() { - timer = new QTimer(this); - connect(timer,SIGNAL(timeout()),this,SLOT(checkForSlam())); - timer->setSingleShot(true); - timer->setInterval(500); } @@ -110,6 +106,8 @@ bool QSlamSensorGestureRecognizer::stop() disconnect(QtSensorGestureSensorHandler::instance(),SIGNAL(accelReadingChanged(QAccelerometerReading *)), this,SLOT(accelChanged(QAccelerometerReading *))); + detecting = false; + restingList.clear(); active = false; return active; } @@ -124,9 +122,10 @@ void QSlamSensorGestureRecognizer::orientationReadingChanged(QOrientationReading orientationReading = reading; } -#define SLAM_DETECTION_FACTOR 0.15 // 5.85 - -#define SLAM_Y_DEGREES 15 +#define SLAM_DETECTION_FACTOR 0.3 // 11.7 +#define SLAM_RESTING_FACTOR 2.5 +#define SLAM_RESTING_COUNT 5 +#define SLAM_ZERO_FACTOR .02 void QSlamSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) { @@ -134,30 +133,28 @@ void QSlamSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) const qreal y = reading->y(); const qreal z = reading->z(); - if (qAbs(lastX - x) < 2 && qAbs(lastY - y) < 2 && qAbs(lastZ - z) < 2) { + + if (qAbs(lastX - x) < SLAM_RESTING_FACTOR + && qAbs(lastY - y) < SLAM_RESTING_FACTOR + && qAbs(lastZ - z) < SLAM_RESTING_FACTOR) { resting = true; } else { resting = false; } - if (restingList.count() > 5) + if (restingList.count() > SLAM_RESTING_COUNT) restingList.removeLast(); restingList.insert(0, resting); - if (orientationReading == 0) + if (orientationReading == 0) { return; + } const qreal difference = lastX - x; - if (!timer->isActive() - && detecting - && (orientationReading->orientation() == QOrientationReading::RightUp - || orientationReading->orientation() == QOrientationReading::LeftUp) - && resting) { - timer->start(); - } if (!detecting && orientationReading->orientation() == QOrientationReading::TopUp + && resting && hasBeenResting()) { detectedX = x; // start of gesture @@ -168,13 +165,19 @@ void QSlamSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) wasNegative = true; restingList.clear(); } - + if (detecting + && qAbs(difference) > (accelRange * SLAM_DETECTION_FACTOR)) { + QTimer::singleShot(225,this,SLOT(doSlam())); + } + if (detecting && + (qAbs(difference) < SLAM_ZERO_FACTOR && qAbs(difference) > 0)) { + detecting = false; + } lastX = x; lastY = y; lastZ = z; } - bool QSlamSensorGestureRecognizer::hasBeenResting() { for (int i = 0; i < restingList.count() - 1; i++) { @@ -185,21 +188,15 @@ bool QSlamSensorGestureRecognizer::hasBeenResting() return true; } -void QSlamSensorGestureRecognizer::checkForSlam() +void QSlamSensorGestureRecognizer::doSlam() { - if (!hasBeenResting()) { - detecting = false; - return; - } - - if (detecting && (orientationReading->orientation() == QOrientationReading::RightUp // 3 or 4 - || orientationReading->orientation() == QOrientationReading::LeftUp)) { + if (detecting && (orientationReading->orientation() == QOrientationReading::RightUp + || orientationReading->orientation() == QOrientationReading::LeftUp)) { Q_EMIT slam(); Q_EMIT detected("slam"); restingList.clear(); + detecting = false; } - - detecting = false; } QT_END_NAMESPACE |