From fb06538ffb57d82ae63b61dc7798f740fe27ba3e Mon Sep 17 00:00:00 2001 From: Lorn Potter Date: Thu, 10 May 2012 09:00:58 +1000 Subject: 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 --- .../qtsensors/qcoversensorgesturerecognizer.cpp | 41 ++++++---------- .../qtsensors/qcoversensorgesturerecognizer.h | 6 +-- .../qtsensors/qhoversensorgesturerecognizer.cpp | 9 +--- .../sensorgestures/qtsensors/qshake2recognizer.cpp | 13 +++-- .../qtsensors/qslamgesturerecognizer.cpp | 55 ++++++++++------------ .../qtsensors/qslamgesturerecognizer.h | 3 +- .../qtsensors/qtsensorgesturesensorhandler.cpp | 1 + .../qtsensors/qtwistsensorgesturerecognizer.cpp | 48 ++++++++++--------- .../qtsensors/qwhipsensorgesturerecognizer.cpp | 7 ++- 9 files changed, 86 insertions(+), 97 deletions(-) (limited to 'src/plugins/sensorgestures/qtsensors') diff --git a/src/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.cpp index bfc1f827..1af52f07 100644 --- a/src/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.cpp +++ b/src/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.cpp @@ -46,7 +46,7 @@ QT_BEGIN_NAMESPACE QCoverSensorGestureRecognizer::QCoverSensorGestureRecognizer(QObject *parent) : QSensorGestureRecognizer(parent), - orientationReading(0), proximityReading(0),lastProx(0), active(0), detecting(0) + orientationReading(0), proximityReading(0),active(0), detecting(0) { } @@ -59,7 +59,7 @@ void QCoverSensorGestureRecognizer::create() timer = new QTimer(this); connect(timer,SIGNAL(timeout()),this,SLOT(timeout())); timer->setSingleShot(true); - timer->setInterval(1000); + timer->setInterval(750); } QString QCoverSensorGestureRecognizer::id() const @@ -69,16 +69,16 @@ QString QCoverSensorGestureRecognizer::id() const bool QCoverSensorGestureRecognizer::start() { - if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::IrProximity)) { + if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Proximity)) { if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Orientation)) { active = true; - connect(QtSensorGestureSensorHandler::instance(),SIGNAL(irProximityReadingChanged(QIRProximityReading *)), - this,SLOT(proximityChanged(QIRProximityReading *))); + connect(QtSensorGestureSensorHandler::instance(),SIGNAL(proximityReadingChanged(QProximityReading *)), + this,SLOT(proximityChanged(QProximityReading *))); connect(QtSensorGestureSensorHandler::instance(),SIGNAL(orientationReadingChanged(QOrientationReading *)), this,SLOT(orientationReadingChanged(QOrientationReading *))); } else { - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::IrProximity); + QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Proximity); active = false; } } else { @@ -89,13 +89,13 @@ bool QCoverSensorGestureRecognizer::start() bool QCoverSensorGestureRecognizer::stop() { - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::IrProximity); + QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Proximity); QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Orientation); - disconnect(QtSensorGestureSensorHandler::instance(),SIGNAL(irProximityReadingChanged(QIRProximityReading *)), - this,SLOT(proximityChanged(QIRProximityReading *))); + disconnect(QtSensorGestureSensorHandler::instance(),SIGNAL(proximityReadingChanged(QProximityReading *)), + this,SLOT(proximityChanged(QProximityReading *))); disconnect(QtSensorGestureSensorHandler::instance(),SIGNAL(orientationReadingChanged(QOrientationReading *)), - this,SLOT(orientationReadingChanged(QOrientationReading *))); + this,SLOT(orientationReadingChanged(QOrientationReading *))); active = false; @@ -107,32 +107,22 @@ bool QCoverSensorGestureRecognizer::isActive() return active; } -void QCoverSensorGestureRecognizer::proximityChanged(QIRProximityReading *reading) +void QCoverSensorGestureRecognizer::proximityChanged(QProximityReading *reading) { if (orientationReading == 0) return; - proximityReading = reading->reflectance(); - const qreal difference = lastProx - proximityReading; + proximityReading = reading->close(); - if (qAbs(difference) < .15) { - return; - } // look at case of face up->face down->face up. if (orientationReading->orientation() == QOrientationReading::FaceUp - && proximityReading > .55) { + && proximityReading) { if (!timer->isActive()) { timer->start(); detecting = true; } } - if (proximityReading < .55) { - if (timer->isActive()) { - timer->stop(); - detecting = false; - } - } - lastProx = proximityReading; + lastTs = reading->timestamp(); } void QCoverSensorGestureRecognizer::orientationReadingChanged(QOrientationReading *reading) @@ -143,12 +133,11 @@ void QCoverSensorGestureRecognizer::orientationReadingChanged(QOrientationReadin void QCoverSensorGestureRecognizer::timeout() { if ((orientationReading->orientation() == QOrientationReading::FaceUp) - && proximityReading > 0.55) { + && proximityReading) { Q_EMIT cover(); Q_EMIT detected("cover"); detecting = false; } - lastProx = proximityReading; } QT_END_NAMESPACE diff --git a/src/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.h b/src/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.h index 475ad518..93627448 100644 --- a/src/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.h +++ b/src/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.h @@ -68,20 +68,20 @@ Q_SIGNALS: void cover(); private slots: - void proximityChanged(QIRProximityReading *reading); + void proximityChanged(QProximityReading *reading); void orientationReadingChanged(QOrientationReading *reading); void timeout(); private: QOrientationReading *orientationReading; - qreal proximityReading; + bool proximityReading; QTimer *timer; - bool lastProx; QtSensorGestureSensorHandler *handler; bool active; bool detecting; + qreal lastTs; }; QT_END_NAMESPACE diff --git a/src/plugins/sensorgestures/qtsensors/qhoversensorgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qhoversensorgesturerecognizer.cpp index bb392d9b..8a12ee7a 100644 --- a/src/plugins/sensorgestures/qtsensors/qhoversensorgesturerecognizer.cpp +++ b/src/plugins/sensorgestures/qtsensors/qhoversensorgesturerecognizer.cpp @@ -103,13 +103,7 @@ void QHoverSensorGestureRecognizer::irProximityReadingChanged(QIRProximityReadin { reflectance = reading->reflectance(); - if (reflectance > .51) { - hoverOk = false; - detecting = false; - return; - } - - if (!detecting && (reflectance > .35 && reflectance < .50)) { + if (!detecting && (reflectance > .25 && reflectance < .50)) { detecting = true; timer->start(); timer2->start(); @@ -117,7 +111,6 @@ void QHoverSensorGestureRecognizer::irProximityReadingChanged(QIRProximityReadin } else if (hoverOk && detecting && reflectance < .33 - // && detectedHigh ) { // went light again after 1 seconds Q_EMIT hover(); diff --git a/src/plugins/sensorgestures/qtsensors/qshake2recognizer.cpp b/src/plugins/sensorgestures/qtsensors/qshake2recognizer.cpp index 738d720b..a2d0eb48 100644 --- a/src/plugins/sensorgestures/qtsensors/qshake2recognizer.cpp +++ b/src/plugins/sensorgestures/qtsensors/qshake2recognizer.cpp @@ -55,7 +55,7 @@ QShake2SensorGestureRecognizer::QShake2SensorGestureRecognizer(QObject *parent) , shaking(0) , shakeCount(0) { - timerTimeout = 750; + timerTimeout = 250; } QShake2SensorGestureRecognizer::~QShake2SensorGestureRecognizer() @@ -125,7 +125,8 @@ void QShake2SensorGestureRecognizer::accelChanged(QAccelerometerReading *reading return; } - if (!shaking && checkForShake(prevData, currentData, THRESHOLD) && + bool wasShake = checkForShake(prevData, currentData, THRESHOLD); + if (!shaking && wasShake && shakeCount >= NUMBER_SHAKES) { shaking = true; shakeCount = 0; @@ -151,7 +152,7 @@ void QShake2SensorGestureRecognizer::accelChanged(QAccelerometerReading *reading break; }; - } else if (checkForShake(prevData, currentData, THRESHOLD)) { + } else if (wasShake) { if (shakeCount == 0 && shakeDirection == QShake2SensorGestureRecognizer::ShakeUndefined) { @@ -174,8 +175,9 @@ void QShake2SensorGestureRecognizer::accelChanged(QAccelerometerReading *reading } } shakeCount++; - timer->start(); - + if (shakeCount == 3) { + timer->start(); + } } prevData.x = currentData.x; @@ -191,6 +193,7 @@ void QShake2SensorGestureRecognizer::timeout() shakeDirection = QShake2SensorGestureRecognizer::ShakeUndefined; } + bool QShake2SensorGestureRecognizer::checkForShake(ShakeData prevSensorData, ShakeData currentSensorData, qreal threshold) { const double deltaX = qAbs(prevSensorData.x - currentSensorData.x); 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 diff --git a/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.h b/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.h index ede338fa..7d770e64 100644 --- a/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.h +++ b/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.h @@ -69,13 +69,12 @@ Q_SIGNALS: private slots: void accelChanged(QAccelerometerReading *reading); void orientationReadingChanged(QOrientationReading *reading); - void checkForSlam(); + void doSlam(); private: QAccelerometer *accel; QOrientationReading *orientationReading; - QTimer *timer; int accelRange; bool active; diff --git a/src/plugins/sensorgestures/qtsensors/qtsensorgesturesensorhandler.cpp b/src/plugins/sensorgestures/qtsensors/qtsensorgesturesensorhandler.cpp index 3ed052ce..2d7374c2 100644 --- a/src/plugins/sensorgestures/qtsensors/qtsensorgesturesensorhandler.cpp +++ b/src/plugins/sensorgestures/qtsensors/qtsensorgesturesensorhandler.cpp @@ -109,6 +109,7 @@ bool QtSensorGestureSensorHandler::startSensor(SensorGestureSensors sensor) if (orientation == 0x0) { orientation = new QOrientationSensor(this); ok = orientation->connectToBackend(); + orientation->setDataRate(50); connect(orientation,SIGNAL(readingChanged()),this,SLOT(orientationChanged())); } if (ok && !orientation->isActive()) diff --git a/src/plugins/sensorgestures/qtsensors/qtwistsensorgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qtwistsensorgesturerecognizer.cpp index 3956f17d..002f838e 100644 --- a/src/plugins/sensorgestures/qtsensors/qtwistsensorgesturerecognizer.cpp +++ b/src/plugins/sensorgestures/qtsensors/qtwistsensorgesturerecognizer.cpp @@ -72,7 +72,7 @@ void QTwistSensorGestureRecognizer::create() timer = new QTimer(this); connect(timer,SIGNAL(timeout()),this,SLOT(timeout())); timer->setSingleShot(true); - timer->setInterval(500); + timer->setInterval(750); } QString QTwistSensorGestureRecognizer::id() const @@ -142,14 +142,27 @@ void QTwistSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) if (orientationReading == 0) return; + if (negativeList.count() > 5) + negativeList.removeLast(); + + if ((((x < 0 && lastX > 0) || (x > 0 && lastX < 0)) && qAbs(diffX) > (accelRange * 0.35)) + || (x < 0 && lastX < 0 && qAbs(diffX > accelRange * 0.35)) + || (x > 0 && lastX > 0 && qAbs(diffX > accelRange * 0.35)) + || (((y < 0 && lastY > 0) || (y > 0 && lastY < 0)) && qAbs(diffY) > (accelRange * 0.35))) { + negativeList.insert(0,true); + } else { + negativeList.insert(0,false); + } + + if (detecting + && isShake()) { + // if shake-like: + detecting = false; + timer->stop(); + lastRoll = degrees; + } + if (rollList.count() > 4) { - if (detecting - && isShake()) { - // if shake-like: - detecting = false; - timer->stop(); - lastRoll = degrees; - } if (detecting && qAbs(degrees) < RESTING_VARIANCE && qAbs(pitch) < RESTING_VARIANCE @@ -175,7 +188,6 @@ void QTwistSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) detecting = true; timer->start(); lastRoll = degrees; - lastOrientation = orientationReading->orientation(); } if (detecting && (orientationReading->orientation() == QOrientationReading::TopUp @@ -187,16 +199,6 @@ void QTwistSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) } } - if (negativeList.count() > 5) - 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))) { - negativeList.insert(0,true); - } else { - negativeList.insert(0,false); - } - if (rollList.count() > 5) rollList.removeLast(); rollList.insert(0,degrees); @@ -208,17 +210,17 @@ void QTwistSensorGestureRecognizer::timeout() { detecting = false; lastRoll = 0; - lastOrientation = QOrientationReading::Undefined; } bool QTwistSensorGestureRecognizer::isShake() { - for (int i = 0; i < negativeList.count() - 1; i++) { + int count = 0; + for (int i = 1; i < negativeList.count() - 1; i++) { if (negativeList.at(i)) { - return true; + count++; } } - return false; + return (count > 1); } diff --git a/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp index f087dce6..c702010e 100644 --- a/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp +++ b/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp @@ -157,6 +157,7 @@ void QWhipSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) if (whipMap.count() > 5) whipMap.removeLast(); +//qDebug() << z << qAbs(diffX) << qAbs(lastX) << qAbs(x) ; if (z < WHIP_FACTOR && qAbs(diffX) > -(accelRange * .1285)//-5.0115 @@ -166,6 +167,7 @@ void QWhipSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) if (!detecting && !timer->isActive()) { timer->start(); detecting = true; +// qDebug() << "start detecting"; } } else { whipMap.insert(0,false); @@ -196,6 +198,8 @@ void QWhipSensorGestureRecognizer::timeout() void QWhipSensorGestureRecognizer::checkForWhip() { + // qDebug() << __FUNCTION__; + whipOk = false; qreal averageZ = 0; @@ -203,11 +207,12 @@ void QWhipSensorGestureRecognizer::checkForWhip() averageZ += az; } averageZ /= zList.count(); + // qDebug() << qAbs(averageZ) << zList << whipMap; if (qAbs(averageZ) < 5.0) return; - for (int i = 0; i < whipMap.count() - 2; i++) { + for (int i = 0; i < 3; i++) { if (!whipMap.at(i)) { whipOk = true; } else { -- cgit v1.2.3