diff options
Diffstat (limited to 'src')
11 files changed, 114 insertions, 109 deletions
diff --git a/src/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.cpp index bfc1f82..1af52f0 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 475ad51..9362744 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 bb392d9..8a12ee7 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 738d720..a2d0eb4 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 e676122..bdf38d3 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 ede338f..7d770e6 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 3ed052c..2d7374c 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 3956f17..002f838 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,15 +142,28 @@ 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 && (qAbs(lastRoll + degrees) > (degrees / 2)) @@ -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 f087dce..c702010 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 { diff --git a/src/plugins/sensorgestures/shake/qshakerecognizer.cpp b/src/plugins/sensorgestures/shake/qshakerecognizer.cpp index df64402..a296eb0 100644 --- a/src/plugins/sensorgestures/shake/qshakerecognizer.cpp +++ b/src/plugins/sensorgestures/shake/qshakerecognizer.cpp @@ -46,7 +46,10 @@ QShakeSensorGestureRecognizer::QShakeSensorGestureRecognizer(QObject *parent) : QSensorGestureRecognizer(parent) + , timerTimeout(450) , active(0) + , shaking(0) + , shakeCount(0) { } @@ -58,6 +61,7 @@ void QShakeSensorGestureRecognizer::create() { accel = new QAccelerometer(this); accel->connectToBackend(); + accel->setDataRate(50); qoutputrangelist outputranges = accel->outputRanges(); @@ -67,7 +71,10 @@ void QShakeSensorGestureRecognizer::create() accelRange = 4; //this should never happen connect(accel,SIGNAL(readingChanged()),this,SLOT(accelChanged())); - + timer = new QTimer(this); + connect(timer,SIGNAL(timeout()),this,SLOT(timeout())); + timer->setSingleShot(true); + timer->setInterval(timerTimeout); } bool QShakeSensorGestureRecognizer::start() @@ -109,27 +116,26 @@ void QShakeSensorGestureRecognizer::accelChanged() if (qAbs(prevData.x - currentData.x) < 1 && qAbs(prevData.y - currentData.y) < 1 && qAbs(prevData.z - currentData.z) < 1) { - prevData.x = currentData.x; prevData.y = currentData.y; prevData.z = currentData.z; return; } - - if (!shaking && checkForShake(prevData, currentData, THRESHOLD) && + bool wasShake = checkForShake(prevData, currentData, THRESHOLD); + if (!shaking && wasShake && shakeCount >= NUMBER_SHAKES) { shaking = true; shakeCount = 0; - Q_EMIT shake(); Q_EMIT detected("shake"); - } else if (checkForShake(prevData, currentData, THRESHOLD)) { + } else if (wasShake) { + shakeCount++; - } else if (!checkForShake(prevData, currentData, 200)) { - shakeCount = 0; - shaking = false; + if (shakeCount > NUMBER_SHAKES) { + timer->start(); + } } prevData.x = currentData.x; @@ -137,6 +143,11 @@ void QShakeSensorGestureRecognizer::accelChanged() prevData.z = currentData.z; } +void QShakeSensorGestureRecognizer::timeout() +{ + shakeCount = 0; + shaking = false; +} bool QShakeSensorGestureRecognizer::checkForShake(AccelData prevSensorData, AccelData currentSensorData, qreal threshold) { @@ -144,8 +155,9 @@ bool QShakeSensorGestureRecognizer::checkForShake(AccelData prevSensorData, Acce double deltaY = qAbs(prevSensorData.y - currentSensorData.y); double deltaZ = qAbs(prevSensorData.z - currentSensorData.z); - return (deltaX > threshold && deltaY > threshold) || - (deltaX > threshold && deltaZ > threshold) || - (deltaY > threshold && deltaZ > threshold); + return (deltaX > threshold + || deltaY > threshold + || deltaZ > threshold); + (deltaY > threshold && deltaZ > threshold); } diff --git a/src/plugins/sensorgestures/shake/qshakerecognizer.h b/src/plugins/sensorgestures/shake/qshakerecognizer.h index dfba26b..96a6e2f 100644 --- a/src/plugins/sensorgestures/shake/qshakerecognizer.h +++ b/src/plugins/sensorgestures/shake/qshakerecognizer.h @@ -73,11 +73,15 @@ public: bool stop(); bool isActive(); + QTimer *timer; + int timerTimeout; + Q_SIGNALS: void shake(); private slots: void accelChanged(); + void timeout(); private: QAccelerometer *accel; bool active; |