diff options
author | Lorn Potter <lorn.potter@nokia.com> | 2012-03-01 11:05:52 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-01 11:09:23 +0100 |
commit | 1c99076a1f55a28ac6c745d1df05226401f11107 (patch) | |
tree | 9ab51a2b516dbf9b5a6861b7008320368dfc6c9f /src/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.cpp | |
parent | d75fefbcce3dae2eda571905ae0d3485f038956c (diff) |
share sensors among the recognizers in QtSensors recognizer.
Change-Id: Ie08046de2e293b8b6271851ce8b740832a6de315
Reviewed-by: Lorn Potter <lorn.potter@nokia.com>
Diffstat (limited to 'src/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.cpp')
-rw-r--r-- | src/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.cpp | 78 |
1 files changed, 47 insertions, 31 deletions
diff --git a/src/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.cpp index 9053be00..47a08f53 100644 --- a/src/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.cpp +++ b/src/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.cpp @@ -39,15 +39,14 @@ ** ****************************************************************************/ - #include "qcoversensorgesturerecognizer.h" -#include <math.h> +#include "qtsensorgesturesensorhandler.h" QT_BEGIN_NAMESPACE QCoverSensorGestureRecognizer::QCoverSensorGestureRecognizer(QObject *parent) : QSensorGestureRecognizer(parent), - detecting(0), lastProx(0) + detecting(0), lastProx(0), proximityReading(0), active(0) { } @@ -57,12 +56,6 @@ QCoverSensorGestureRecognizer::~QCoverSensorGestureRecognizer() void QCoverSensorGestureRecognizer::create() { - proximity = new QIRProximitySensor(this); - proximity->connectToBackend(); - - orientation = new QOrientationSensor(this); - orientation->connectToBackend(); - timer = new QTimer(this); connect(timer,SIGNAL(timeout()),this,SLOT(timeout())); timer->setSingleShot(true); @@ -76,60 +69,83 @@ QString QCoverSensorGestureRecognizer::id() const bool QCoverSensorGestureRecognizer::start() { - connect(proximity,SIGNAL(readingChanged()),this,SLOT(proximityChanged())); - proximity->start(); - orientation->start(); - lastProx = proximity->reading()->reflectance(); - return proximity->isActive(); + if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::IrProximity)) { + if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Orientation)) { + active = true; + connect(QtSensorGestureSensorHandler::instance(),SIGNAL(irProximityReadingChanged(QIRProximityReading *)), + this,SLOT(proximityChanged(QIRProximityReading *))); + + connect(QtSensorGestureSensorHandler::instance(),SIGNAL(orientationReadingChanged(QOrientationReading *)), + this,SLOT(orientationReadingChanged(QOrientationReading *))); + } else { + QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::IrProximity); + active = false; + } + } else { + active = false; + } + return active; } bool QCoverSensorGestureRecognizer::stop() { - proximity->stop(); - orientation->stop(); - disconnect(proximity,SIGNAL(readingChanged()),this,SLOT(proximityChanged())); - return proximity->isActive(); + QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::IrProximity); + QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Orientation); + + disconnect(QtSensorGestureSensorHandler::instance(),SIGNAL(irProximityReadingChanged(QIRProximityReading *)), + this,SLOT(proximityChanged(QIRProximityReading *))); + disconnect(QtSensorGestureSensorHandler::instance(),SIGNAL(orientationReadingChanged(QOrientationReading *)), + this,SLOT(orientationReadingChanged(QOrientationReading *))); + + active = false; + + return active; } bool QCoverSensorGestureRecognizer::isActive() { - return proximity->isActive(); + return active; } -void QCoverSensorGestureRecognizer::proximityChanged() -{// look at case of face up->face down->face up. - - qreal refl = proximity->reading()->reflectance(); - qreal difference = lastProx - refl; +void QCoverSensorGestureRecognizer::proximityChanged(QIRProximityReading *reading) +{ + proximityReading = reading->reflectance(); + qreal difference = lastProx - proximityReading; if (qAbs(difference) < .15) { return; } - - if (orientation->reading()->orientation() == QOrientationReading::FaceUp - && refl > .55) { + // look at case of face up->face down->face up. + if (orientationReading->orientation() == QOrientationReading::FaceUp + && proximityReading > .55) { if (!timer->isActive()) { timer->start(); detecting = true; } } - if (refl < .55) { + if (proximityReading < .55) { if (timer->isActive()) { timer->stop(); detecting = false; } } - lastProx = refl; + lastProx = proximityReading; +} + +void QCoverSensorGestureRecognizer::orientationReadingChanged(QOrientationReading *reading) +{ + orientationReading = reading; } void QCoverSensorGestureRecognizer::timeout() { - if (detecting && orientation->reading()->orientation() == QOrientationReading::FaceUp - && proximity->reading()->reflectance() > 0.55) { + if ((orientationReading->orientation() == QOrientationReading::FaceUp) + && proximityReading > 0.55) { Q_EMIT cover(); Q_EMIT detected("cover"); detecting = false; } + lastProx = proximityReading; } QT_END_NAMESPACE |