diff options
Diffstat (limited to 'src/plugins/sensorgestures/qtsensors')
25 files changed, 0 insertions, 3331 deletions
diff --git a/src/plugins/sensorgestures/qtsensors/CMakeLists.txt b/src/plugins/sensorgestures/qtsensors/CMakeLists.txt deleted file mode 100644 index dc9730eb..00000000 --- a/src/plugins/sensorgestures/qtsensors/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -##################################################################### -## QtSensorGesturePlugin Plugin: -##################################################################### - -qt_internal_add_plugin(QtSensorGesturePlugin - OUTPUT_NAME qtsensorgestures_plugin - PLUGIN_TYPE sensorgestures - DEFAULT_IF FALSE - SOURCES - qcoversensorgesturerecognizer.cpp qcoversensorgesturerecognizer.h - qdoubletapsensorgesturerecognizer.cpp qdoubletapsensorgesturerecognizer.h - qfreefallsensorgesturerecognizer.cpp qfreefallsensorgesturerecognizer.h - qhoversensorgesturerecognizer.cpp qhoversensorgesturerecognizer.h - qpickupsensorgesturerecognizer.cpp qpickupsensorgesturerecognizer.h - qshake2recognizer.cpp qshake2recognizer.h - qslamgesturerecognizer.cpp qslamgesturerecognizer.h - qtsensorgestureplugin.cpp qtsensorgestureplugin.h - qtsensorgesturesensorhandler.cpp qtsensorgesturesensorhandler.h - qturnoversensorgesturerecognizer.cpp qturnoversensorgesturerecognizer.h - qtwistsensorgesturerecognizer.cpp qtwistsensorgesturerecognizer.h - qwhipsensorgesturerecognizer.cpp qwhipsensorgesturerecognizer.h - LIBRARIES - Qt::Core - Qt::Sensors -) - -#### Keys ignored in scope 1:.:.:qtsensors.pro:<TRUE>: -# OTHER_FILES = "plugin.json" -# PLUGIN_EXTENDS = "-" diff --git a/src/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.cpp deleted file mode 100644 index 6bb65e9f..00000000 --- a/src/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qcoversensorgesturerecognizer.h" -#include "qtsensorgesturesensorhandler.h" - -QT_BEGIN_NAMESPACE - -QCoverSensorGestureRecognizer::QCoverSensorGestureRecognizer(QObject *parent) - : QSensorGestureRecognizer(parent), - orientationReading(0), - proximityReading(0), - timer(0), - active(0), - detecting(0) -{ -} - -QCoverSensorGestureRecognizer::~QCoverSensorGestureRecognizer() -{ -} - -void QCoverSensorGestureRecognizer::create() -{ - timer = new QTimer(this); - connect(timer,SIGNAL(timeout()),this,SLOT(timeout())); - timer->setSingleShot(true); - timer->setInterval(750); -} - -QString QCoverSensorGestureRecognizer::id() const -{ - return QString("QtSensors.cover"); -} - -bool QCoverSensorGestureRecognizer::start() -{ - if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Proximity)) { - if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Orientation)) { - active = true; - 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::Proximity); - active = false; - } - } else { - active = false; - } - return active; -} - -bool QCoverSensorGestureRecognizer::stop() -{ - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Proximity); - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Orientation); - - disconnect(QtSensorGestureSensorHandler::instance(),SIGNAL(proximityReadingChanged(QProximityReading*)), - this,SLOT(proximityChanged(QProximityReading*))); - disconnect(QtSensorGestureSensorHandler::instance(),SIGNAL(orientationReadingChanged(QOrientationReading*)), - this,SLOT(orientationReadingChanged(QOrientationReading*))); - - active = false; - timer->stop(); - return active; -} - -bool QCoverSensorGestureRecognizer::isActive() -{ - return active; -} - -void QCoverSensorGestureRecognizer::proximityChanged(QProximityReading *reading) -{ - if (orientationReading == 0) - return; - - proximityReading = reading->close(); - - // look at case of face up->face down->face up. - if (orientationReading->orientation() == QOrientationReading::FaceUp - && proximityReading) { - if (!timer->isActive()) { - timer->start(); - detecting = true; - } - } -} - -void QCoverSensorGestureRecognizer::orientationReadingChanged(QOrientationReading *reading) -{ - orientationReading = reading; -} - -void QCoverSensorGestureRecognizer::timeout() -{ - if ((orientationReading->orientation() == QOrientationReading::FaceUp) - && proximityReading) { - Q_EMIT cover(); - Q_EMIT detected("cover"); - detecting = false; - } -} - -QT_END_NAMESPACE diff --git a/src/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.h b/src/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.h deleted file mode 100644 index d9c57e80..00000000 --- a/src/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.h +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef QCOVERSENSORGESTURERECOGNIZER_H -#define QCOVERSENSORGESTURERECOGNIZER_H - -#include <QtSensors/qsensorgesturerecognizer.h> -#include <QTimer> - -#include "qtsensorgesturesensorhandler.h" - -QT_BEGIN_NAMESPACE - -class QCoverSensorGestureRecognizer : public QSensorGestureRecognizer -{ - Q_OBJECT -public: - explicit QCoverSensorGestureRecognizer(QObject *parent = 0); - ~QCoverSensorGestureRecognizer(); - - void create() override; - - QString id() const override; - bool start() override; - bool stop() override; - bool isActive() override; - -Q_SIGNALS: - void cover(); - -private slots: - void proximityChanged(QProximityReading *reading); - void orientationReadingChanged(QOrientationReading *reading); - void timeout(); - -private: - - QOrientationReading *orientationReading; - bool proximityReading; - - QTimer *timer; - bool active; - bool detecting; -}; - -QT_END_NAMESPACE -#endif // QCOVERSENSORGESTURERECOGNIZER_H diff --git a/src/plugins/sensorgestures/qtsensors/qdoubletapsensorgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qdoubletapsensorgesturerecognizer.cpp deleted file mode 100644 index 6d765a1a..00000000 --- a/src/plugins/sensorgestures/qtsensors/qdoubletapsensorgesturerecognizer.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtSensors/QTapSensor> -#include "qdoubletapsensorgesturerecognizer.h" -QT_BEGIN_NAMESPACE - -QDoubleTapSensorGestureRecognizer::QDoubleTapSensorGestureRecognizer(QObject *parent) : - QSensorGestureRecognizer(parent) - , active(0) -{ -} - -QDoubleTapSensorGestureRecognizer::~QDoubleTapSensorGestureRecognizer() -{ -} - -void QDoubleTapSensorGestureRecognizer::create() -{ -} - - -QString QDoubleTapSensorGestureRecognizer::id() const -{ - return QString("QtSensors.doubletap"); -} - -bool QDoubleTapSensorGestureRecognizer::start() -{ - if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Tap)) { - active = true; - connect(QtSensorGestureSensorHandler::instance(),SIGNAL(dTabReadingChanged(QTapReading*)), - this,SLOT(tapChanged(QTapReading*))); - } else { - active = false; - } - return active; -} - -bool QDoubleTapSensorGestureRecognizer::stop() -{ - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Tap); - disconnect(QtSensorGestureSensorHandler::instance(),SIGNAL(dTabReadingChanged(QTapReading*)), - this,SLOT(tapChanged(QTapReading*))); - active = false; - return active; -} - -bool QDoubleTapSensorGestureRecognizer::isActive() -{ - return active; -} - -void QDoubleTapSensorGestureRecognizer::tapChanged(QTapReading *reading) -{ - if (reading->isDoubleTap()) { - Q_EMIT doubletap(); - Q_EMIT detected("doubletap"); - } -} - - -QT_END_NAMESPACE diff --git a/src/plugins/sensorgestures/qtsensors/qdoubletapsensorgesturerecognizer.h b/src/plugins/sensorgestures/qtsensors/qdoubletapsensorgesturerecognizer.h deleted file mode 100644 index 73d7db56..00000000 --- a/src/plugins/sensorgestures/qtsensors/qdoubletapsensorgesturerecognizer.h +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QDOUBLETAPSENSORGESTURERECOGNIZER_H -#define QDOUBLETAPSENSORGESTURERECOGNIZER_H - -#include <QtSensors/QSensor> - -#include <QtSensors/qsensorgesturerecognizer.h> -#include <QtSensors/QTapSensor> - -#include "qtsensorgesturesensorhandler.h" - -QT_BEGIN_NAMESPACE - -class QDoubleTapSensorGestureRecognizer : public QSensorGestureRecognizer -{ - Q_OBJECT -public: - explicit QDoubleTapSensorGestureRecognizer(QObject *parent = 0); - ~QDoubleTapSensorGestureRecognizer(); - - void create() override; - - QString id() const override; - bool start() override; - bool stop() override; - bool isActive() override; - -Q_SIGNALS: - void doubletap(); - -private slots: - void tapChanged(QTapReading *reading); - -private: - QTapSensor *tapSensor; - bool active; - -}; -QT_END_NAMESPACE -#endif // QDOUBLETAPSENSORGESTURERECOGNIZER_H diff --git a/src/plugins/sensorgestures/qtsensors/qfreefallsensorgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qfreefallsensorgesturerecognizer.cpp deleted file mode 100644 index d158e1f0..00000000 --- a/src/plugins/sensorgestures/qtsensors/qfreefallsensorgesturerecognizer.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 Lorn Potter -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include <qmath.h> - -#include "qfreefallsensorgesturerecognizer.h" - -QT_BEGIN_NAMESPACE - -QFreefallSensorGestureRecognizer::QFreefallSensorGestureRecognizer(QObject *parent) - : QSensorGestureRecognizer(parent) - , active(0) - , detecting(0) -{ -} - -QFreefallSensorGestureRecognizer::~QFreefallSensorGestureRecognizer() -{ -} - -void QFreefallSensorGestureRecognizer::create() -{ -} - -QString QFreefallSensorGestureRecognizer::id() const -{ - return QString("QtSensors.freefall"); -} - -bool QFreefallSensorGestureRecognizer::start() -{ - if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Accel)) { - active = true; - connect(QtSensorGestureSensorHandler::instance(),SIGNAL(accelReadingChanged(QAccelerometerReading*)), - this,SLOT(accelChanged(QAccelerometerReading*))); - } else { - active = false; - } - return active; - -} - -bool QFreefallSensorGestureRecognizer::stop() -{ - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Accel); - disconnect(QtSensorGestureSensorHandler::instance(),SIGNAL(accelReadingChanged(QAccelerometerReading*)), - this,SLOT(accelChanged(QAccelerometerReading*))); - active = false; - - return active; -} - -bool QFreefallSensorGestureRecognizer::isActive() -{ - return active; -} - -#define FREEFALL_THRESHOLD 1.0 -#define LANDED_THRESHOLD 20.0 -#define FREEFALL_MAX 4 - -void QFreefallSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) -{ - const qreal x = reading->x(); - const qreal y = reading->y(); - const qreal z = reading->z(); - qreal sum = qSqrt(x * x + y * y + z * z); - - if (qAbs(sum) < FREEFALL_THRESHOLD) { - detecting = true; - freefallList.append(sum); - } else { - if (detecting && qAbs(sum) > LANDED_THRESHOLD) { - Q_EMIT landed(); - Q_EMIT detected("landed"); - freefallList.clear(); - } - } - - if (freefallList.count() > FREEFALL_MAX) { - Q_EMIT freefall(); - Q_EMIT detected("freefall"); - } -} - - -QT_END_NAMESPACE - diff --git a/src/plugins/sensorgestures/qtsensors/qfreefallsensorgesturerecognizer.h b/src/plugins/sensorgestures/qtsensors/qfreefallsensorgesturerecognizer.h deleted file mode 100644 index 124475ad..00000000 --- a/src/plugins/sensorgestures/qtsensors/qfreefallsensorgesturerecognizer.h +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 Lorn Potter -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - - -#ifndef QFREEFALLSENSORGESTURERECOGNIZER_H -#define QFREEFALLSENSORGESTURERECOGNIZER_H - -#include <QtSensors/qsensorgesturerecognizer.h> - -#include "qtsensorgesturesensorhandler.h" - -QT_BEGIN_NAMESPACE - -class QFreefallSensorGestureRecognizer : public QSensorGestureRecognizer -{ - Q_OBJECT -public: - explicit QFreefallSensorGestureRecognizer(QObject *parent = 0); - ~QFreefallSensorGestureRecognizer(); - - void create() override; - - QString id() const override; - bool start() override; - bool stop() override; - bool isActive() override; - -Q_SIGNALS: - void freefall(); - void landed(); - -private slots: - void accelChanged(QAccelerometerReading *reading); - -private: - - bool active; - bool detecting; - QList <qreal> freefallList; - -}; -QT_END_NAMESPACE -#endif // QPICKUPSENSORGESTURERECOGNIZER_H diff --git a/src/plugins/sensorgestures/qtsensors/qhoversensorgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qhoversensorgesturerecognizer.cpp deleted file mode 100644 index 9a1fa1c5..00000000 --- a/src/plugins/sensorgestures/qtsensors/qhoversensorgesturerecognizer.cpp +++ /dev/null @@ -1,222 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include "qhoversensorgesturerecognizer.h" -#include <math.h> - -#define TIMER2_TIMEOUT 5000 - -QT_BEGIN_NAMESPACE - -QHoverSensorGestureRecognizer::QHoverSensorGestureRecognizer(QObject *parent) : - QSensorGestureRecognizer(parent), - orientationReading(0),reflectance(0), - hoverOk(0), detecting(0), active(0), initialReflectance(0), useHack(0), - lastTimestamp(0), timer2Active(0), lapsedTime2(0) -{ -} - -QHoverSensorGestureRecognizer::~QHoverSensorGestureRecognizer() -{ -} - -void QHoverSensorGestureRecognizer::create() -{ - -} - -QString QHoverSensorGestureRecognizer::id() const -{ - return QString("QtSensors.hover"); -} - -bool QHoverSensorGestureRecognizer::start() -{ - if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::IrProximity)) { - if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Orientation)) { - active = true; - connect(QtSensorGestureSensorHandler::instance(),SIGNAL(irProximityReadingChanged(QIRProximityReading*)), - this,SLOT(irProximityReadingChanged(QIRProximityReading*))); - connect(QtSensorGestureSensorHandler::instance(),SIGNAL(orientationReadingChanged(QOrientationReading*)), - this,SLOT(orientationReadingChanged(QOrientationReading*))); - } else { - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::IrProximity); - active = false; - } - } else { - active = false; - } - - detecting = false; - detectedHigh = 0; - initialReflectance = 0; - useHack = false; - timer2Active = false; - lapsedTime2 = 0; - return active; -} - -bool QHoverSensorGestureRecognizer::stop() -{ - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::IrProximity); - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Orientation); - disconnect(QtSensorGestureSensorHandler::instance(),SIGNAL(irProximityReadingChanged(QIRProximityReading*)), - this,SLOT(irProximityReadingChanged(QIRProximityReading*))); - disconnect(QtSensorGestureSensorHandler::instance(),SIGNAL(orientationReadingChanged(QOrientationReading*)), - this,SLOT(orientationReadingChanged(QOrientationReading*))); - active = false; - timer2Active = false; - initialReflectance = 0; - return active; -} - -bool QHoverSensorGestureRecognizer::isActive() -{ - return active; -} - - -void QHoverSensorGestureRecognizer::orientationReadingChanged(QOrientationReading *reading) -{ - orientationReading = reading; -} - -void QHoverSensorGestureRecognizer::irProximityReadingChanged(QIRProximityReading *reading) -{ - reflectance = reading->reflectance(); - if (reflectance == 0) - return; - - if (initialReflectance == 0) { - initialReflectance = reflectance; - } - - if (initialReflectance > .2) { - useHack = true; - initialReflectance -= .1; - } - if (useHack) - reflectance -= .1; - - if (detecting && !hoverOk) { - detectedHigh = qMax(detectedHigh, reflectance); - } - - if (reflectance > 0.4) { - // if close stop detecting - hoverOk = false; - detecting = false; - detectedHigh = 0; - } - - qreal detectedPercent = 100 - (detectedHigh / reflectance * 100); - - qint16 percentCheck; - if (useHack) - percentCheck = -60; - else - percentCheck = -101; - - quint64 timestamp = reading->timestamp(); - - if (!detecting - && checkForHovering()) { - detecting = true; - detecting = true; - timer2Active = true; - detectedHigh = reflectance; - } else if (detecting - && detectedPercent < percentCheck - && !checkForHovering()) { - // went light again after 1 seconds - Q_EMIT hover(); - Q_EMIT detected("hover"); - hoverOk = false; - detecting = false; - detectedHigh = 0; - timer2Active = false;; - } - if (detecting && reflectance < 0.2) { - timeout(); - } - if (timer2Active && lastTimestamp > 0) - lapsedTime2 += (timestamp - lastTimestamp )/1000; - - if (timer2Active && lapsedTime2 >= TIMER2_TIMEOUT) { - timeout2(); - } - - lastTimestamp = reading->timestamp(); -} - -bool QHoverSensorGestureRecognizer::checkForHovering() -{ - if (orientationReading == 0) { - return false; - } - if (orientationReading->orientation() != QOrientationReading::FaceUp) - return false; - if ( (reflectance > 0.2 && reflectance < 0.4) - && (initialReflectance - reflectance) < -0.1) - return true; - - return false; -} - - -void QHoverSensorGestureRecognizer::timeout() -{ - if (checkForHovering()) { - hoverOk = true; - timer2Active = true; - } else { - detecting = false; - detectedHigh = 0; - } -} - -void QHoverSensorGestureRecognizer::timeout2() -{ - detecting = false; - hoverOk = false; - detectedHigh = 0; -} - -QT_END_NAMESPACE diff --git a/src/plugins/sensorgestures/qtsensors/qhoversensorgesturerecognizer.h b/src/plugins/sensorgestures/qtsensors/qhoversensorgesturerecognizer.h deleted file mode 100644 index d0c8f706..00000000 --- a/src/plugins/sensorgestures/qtsensors/qhoversensorgesturerecognizer.h +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef QHOVERSENSORGESTURERECOGNIZER_H -#define QHOVERSENSORGESTURERECOGNIZER_H - -#include <QtSensors/QSensorGestureRecognizer> - -#include "qtsensorgesturesensorhandler.h" - - -QT_BEGIN_NAMESPACE - -class QHoverSensorGestureRecognizer : public QSensorGestureRecognizer -{ - Q_OBJECT -public: - explicit QHoverSensorGestureRecognizer(QObject *parent = 0); - ~QHoverSensorGestureRecognizer(); - - void create() override; - - QString id() const override; - bool start() override; - bool stop() override; - bool isActive() override; - -Q_SIGNALS: - void hover(); - -private slots: - void orientationReadingChanged(QOrientationReading *reading); - void irProximityReadingChanged(QIRProximityReading *reading); - void timeout(); - void timeout2(); -private: - QOrientationReading *orientationReading; - qreal reflectance; - bool hoverOk; - bool detecting; - - qreal detectedHigh; - bool active; - qreal initialReflectance; - bool checkForHovering(); - bool useHack; - - quint64 lastTimestamp; - - bool timer2Active; - quint64 lapsedTime2; - -}; -QT_END_NAMESPACE -#endif // QHOVERSENSORGESTURERECOGNIZER_H diff --git a/src/plugins/sensorgestures/qtsensors/qpickupsensorgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qpickupsensorgesturerecognizer.cpp deleted file mode 100644 index 33688706..00000000 --- a/src/plugins/sensorgestures/qtsensors/qpickupsensorgesturerecognizer.cpp +++ /dev/null @@ -1,213 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qpickupsensorgesturerecognizer.h" - -#include <QtCore/qmath.h> - -#define TIMER_TIMEOUT 250 - -QT_BEGIN_NAMESPACE - -QPickupSensorGestureRecognizer::QPickupSensorGestureRecognizer(QObject *parent) - : QSensorGestureRecognizer(parent) - , accelReading(0) - , active(0) - , pXaxis(0) - , pYaxis(0) - , pZaxis(0) - , lastpitch(0) - , detecting(0) -{ -} - -QPickupSensorGestureRecognizer::~QPickupSensorGestureRecognizer() -{ -} - -void QPickupSensorGestureRecognizer::create() -{ -} - -QString QPickupSensorGestureRecognizer::id() const -{ - return QString("QtSensors.pickup"); -} - -bool QPickupSensorGestureRecognizer::start() -{ - if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Accel)) { - active = true; - connect(QtSensorGestureSensorHandler::instance(),SIGNAL(accelReadingChanged(QAccelerometerReading*)), - this,SLOT(accelChanged(QAccelerometerReading*))); - } else { - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Accel); - active = false; - } - clear(); - - return active; - -} - -bool QPickupSensorGestureRecognizer::stop() -{ - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Accel); - disconnect(QtSensorGestureSensorHandler::instance(),SIGNAL(accelReadingChanged(QAccelerometerReading*)), - this,SLOT(accelChanged(QAccelerometerReading*))); - active = false; - - return active; -} - -bool QPickupSensorGestureRecognizer::isActive() -{ - return active; -} - -#define PICKUP_BOTTOM_THRESHOLD 25 -#define PICKUP_TOP_THRESHOLD 80 -#define PICKUP_ANGLE_THRESHOLD 25 -#define PICKUP_ROLL_THRESHOLD 13 - -void QPickupSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) -{ - accelReading = reading; - const qreal x = reading->x(); - const qreal y = reading->y(); - const qreal z = reading->z(); - const qreal xdiff = pXaxis - x; - const qreal ydiff = pYaxis - y; - const qreal zdiff = pZaxis - z; - - qreal pitch = qRadiansToDegrees(qAtan(y / qSqrt(x * x + z * z))); - qreal roll = qRadiansToDegrees(qAtan(x / qSqrt(y * y + z * z))); - - if ((qAbs(xdiff) < 0.7 && qAbs(ydiff) < .7 && qAbs(zdiff) < .7) - || z < 0) { - detecting = false; - } else if (pitch > PICKUP_BOTTOM_THRESHOLD && pitch < PICKUP_TOP_THRESHOLD) { - detecting = true; - } - - if ( pitchList.count() > 21) { - pitchList.removeFirst(); - } - if ( rollList.count() > 21) { - rollList.removeFirst(); - } - - if (pitch > 1) { - pitchList.append(pitch); - } - if (roll > 1) { - rollList.append(roll); - } - - if (detecting && pitchList.count() > 5 ) { - timeout(); - } - - lastpitch = pitch; - pXaxis = x; - pYaxis = y; - pZaxis = z; -} - -void QPickupSensorGestureRecognizer::timeout() -{ - qreal averageRoll = 0; - for (int r = 0; r < rollList.count(); r++) { - averageRoll += rollList.at(r); - } - averageRoll /= rollList.count(); - - if (averageRoll > PICKUP_ROLL_THRESHOLD) { - clear(); - return; - } - if (pitchList.isEmpty() - || pitchList.at(0) > PICKUP_BOTTOM_THRESHOLD) { - clear(); - return; - } - - qreal previousPitch = 0; - qreal startPitch = -1.0; - int goodCount = 0; - - qreal averagePitch = 0; - for (int i = 0; i < pitchList.count(); i++) { - averagePitch += pitchList.at(i); - if (previousPitch < pitchList.at(i) - && qAbs(pitchList.at(i)) - qAbs(previousPitch) < 20) { - if (goodCount == 1 && previousPitch != 0) { - startPitch = previousPitch; - } - goodCount++; - } - - previousPitch = pitchList.at(i); - } - averagePitch /= pitchList.count(); - - if (averagePitch < 5) { - clear(); - return; - } - - if (goodCount >= 3 && - (pitchList.last() < PICKUP_TOP_THRESHOLD - && pitchList.last() > PICKUP_BOTTOM_THRESHOLD) - && startPitch > 0 - && (pitchList.last() - startPitch) > PICKUP_ANGLE_THRESHOLD) { - Q_EMIT pickup(); - Q_EMIT detected("pickup"); - } - clear(); -} - -void QPickupSensorGestureRecognizer::clear() -{ - pitchList.clear(); - detecting = false; -} - -QT_END_NAMESPACE - diff --git a/src/plugins/sensorgestures/qtsensors/qpickupsensorgesturerecognizer.h b/src/plugins/sensorgestures/qtsensors/qpickupsensorgesturerecognizer.h deleted file mode 100644 index fdc0a6fe..00000000 --- a/src/plugins/sensorgestures/qtsensors/qpickupsensorgesturerecognizer.h +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef QPICKUPSENSORGESTURERECOGNIZER_H -#define QPICKUPSENSORGESTURERECOGNIZER_H - -#include <QtSensors/qsensorgesturerecognizer.h> -#include "qtsensorgesturesensorhandler.h" - -QT_BEGIN_NAMESPACE - -class QPickupSensorGestureRecognizer : public QSensorGestureRecognizer -{ - Q_OBJECT -public: - explicit QPickupSensorGestureRecognizer(QObject *parent = 0); - ~QPickupSensorGestureRecognizer(); - - void create() override; - - QString id() const override; - bool start() override; - bool stop() override; - bool isActive() override; - -Q_SIGNALS: - void pickup(); - -private slots: - void accelChanged(QAccelerometerReading *reading); - - void timeout(); -private: - QAccelerometerReading *accelReading; - - bool active; - qreal pXaxis; - qreal pYaxis; - qreal pZaxis; - - qreal lastpitch; - bool detecting; - - QList <qreal> pitchList; - QList <qreal> rollList; - - void clear(); -}; -QT_END_NAMESPACE -#endif // QPICKUPSENSORGESTURERECOGNIZER_H diff --git a/src/plugins/sensorgestures/qtsensors/qshake2recognizer.cpp b/src/plugins/sensorgestures/qtsensors/qshake2recognizer.cpp deleted file mode 100644 index 16313b41..00000000 --- a/src/plugins/sensorgestures/qtsensors/qshake2recognizer.cpp +++ /dev/null @@ -1,231 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QDebug> - -#include "qshake2recognizer.h" -#include <math.h> - - -QT_BEGIN_NAMESPACE - -QShake2SensorGestureRecognizer::QShake2SensorGestureRecognizer(QObject *parent) - : QSensorGestureRecognizer(parent) - , active(0) - , shakeDirection(QShake2SensorGestureRecognizer::ShakeUndefined) - , shaking(0) - , shakeCount(0) - , lapsedTime(0) - , lastTimestamp(0), - timerActive(0) -{ - timerTimeout = 250; -} - -QShake2SensorGestureRecognizer::~QShake2SensorGestureRecognizer() -{ -} - -void QShake2SensorGestureRecognizer::create() -{ -} - -bool QShake2SensorGestureRecognizer::start() -{ - if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Accel)) { - active = true; - connect(QtSensorGestureSensorHandler::instance(),SIGNAL(accelReadingChanged(QAccelerometerReading*)), - this,SLOT(accelChanged(QAccelerometerReading*))); - } else { - active = false; - } - prevData.x = 0; - prevData.y = 0; - prevData.z = 0; - shakeCount = 0; - shaking = false; - shakeDirection = QShake2SensorGestureRecognizer::ShakeUndefined; - - return active; -} - -bool QShake2SensorGestureRecognizer::stop() -{ - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Accel); - disconnect(QtSensorGestureSensorHandler::instance(),SIGNAL(accelReadingChanged(QAccelerometerReading*)), - this,SLOT(accelChanged(QAccelerometerReading*))); - active = false; - return active; -} - -bool QShake2SensorGestureRecognizer::isActive() -{ - return active; -} - -QString QShake2SensorGestureRecognizer::id() const -{ - return QString("QtSensors.shake2"); -} - -#define NUMBER_SHAKES 3 -#define THRESHOLD 25 - -void QShake2SensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) -{ - const qreal x = reading->x(); - const qreal y = reading->y(); - const qreal z = reading->z(); - - const quint64 timestamp = reading->timestamp(); - - currentData.x = x; - currentData.y = y; - currentData.z = z; - - 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; - } - - bool wasShake; - wasShake = checkForShake(prevData, currentData, THRESHOLD); - - if (!shaking && wasShake && - shakeCount == NUMBER_SHAKES) { - shaking = true; - shakeCount = 0; - lapsedTime = 0; - timerActive = false; - switch (shakeDirection) { - case QShake2SensorGestureRecognizer::ShakeLeft: - Q_EMIT shakeLeft(); - Q_EMIT detected("shakeLeft"); - break; - case QShake2SensorGestureRecognizer::ShakeRight: - Q_EMIT shakeRight(); - Q_EMIT detected("shakeRight"); - break; - case QShake2SensorGestureRecognizer::ShakeUp: - Q_EMIT shakeUp(); - Q_EMIT detected("shakeUp"); - break; - case QShake2SensorGestureRecognizer::ShakeDown: - Q_EMIT shakeDown(); - Q_EMIT detected("shakeDown"); - break; - default: - break; - }; - - } else if (wasShake) { - - if (shakeCount == 0 && shakeDirection == QShake2SensorGestureRecognizer::ShakeUndefined) { - - const int xdiff = prevData.x - currentData.x; - const int ydiff = prevData.x - currentData.y; - - const int max = qMax(qAbs(ydiff), qAbs(xdiff)); - if (max == qAbs(xdiff)) { - if (isNegative(xdiff)) - shakeDirection = QShake2SensorGestureRecognizer::ShakeLeft; - else - shakeDirection = QShake2SensorGestureRecognizer::ShakeRight; - - } else if (max == qAbs(ydiff)) { - if (isNegative(ydiff)) - shakeDirection = QShake2SensorGestureRecognizer::ShakeDown; - else - shakeDirection = QShake2SensorGestureRecognizer::ShakeUp; - } - } - shakeCount++; - if (shakeCount == NUMBER_SHAKES) { - timerActive = true; - } - } - - if (timerActive && lastTimestamp > 0) - lapsedTime += (timestamp - lastTimestamp )/1000; - - if (timerActive && lapsedTime >= timerTimeout) { - timeout(); - } - prevData.x = currentData.x; - prevData.y = currentData.y; - prevData.z = currentData.z; - lastTimestamp = timestamp; -} - -void QShake2SensorGestureRecognizer::timeout() -{ - shakeCount = 0; - shaking = false; - shakeDirection = QShake2SensorGestureRecognizer::ShakeUndefined; - timerActive = false; - lapsedTime = 0; - lastTimestamp = 0; -} - -bool QShake2SensorGestureRecognizer::checkForShake(ShakeData prevSensorData, ShakeData currentSensorData, qreal threshold) -{ - const double deltaX = qAbs(prevSensorData.x - currentSensorData.x); - const double deltaY = qAbs(prevSensorData.y - currentSensorData.y); - const double deltaZ = qAbs(prevSensorData.z - currentSensorData.z); - - return (deltaX > threshold - || deltaY > threshold - || deltaZ > threshold); -} - -bool QShake2SensorGestureRecognizer::isNegative(qreal num) -{ - if (num < 0) - return true; - return false; -} - - - -QT_END_NAMESPACE diff --git a/src/plugins/sensorgestures/qtsensors/qshake2recognizer.h b/src/plugins/sensorgestures/qtsensors/qshake2recognizer.h deleted file mode 100644 index 9e402cf6..00000000 --- a/src/plugins/sensorgestures/qtsensors/qshake2recognizer.h +++ /dev/null @@ -1,116 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSHAKERECOGNIZER_H -#define QSHAKERECOGNIZER_H - -#include <QDebug> - -#include <QtSensors/qsensorgesturerecognizer.h> - -#include "qtsensorgesturesensorhandler.h" - -QT_BEGIN_NAMESPACE - -struct ShakeData { - qreal x; - qreal y; - qreal z; -}; - -class QShake2SensorGestureRecognizer : public QSensorGestureRecognizer -{ - Q_OBJECT - -public: - - enum ShakeDirection { - ShakeUndefined = 0, - ShakeLeft, - ShakeRight, - ShakeUp, - ShakeDown - }; - - QShake2SensorGestureRecognizer(QObject *parent = 0); - ~QShake2SensorGestureRecognizer(); - - void create() override; - - QString id() const override; - bool start() override; - bool stop() override; - bool isActive() override; - - int timerTimeout; - - -Q_SIGNALS: - void shakeLeft(); - void shakeRight(); - void shakeUp(); - void shakeDown(); - -private slots: - void accelChanged(QAccelerometerReading *reading); - void timeout(); - - -private: - QAccelerometerReading *accelReading; - - bool active; - - ShakeDirection shakeDirection; - - ShakeData prevData; - ShakeData currentData; - - bool checkForShake(ShakeData prevSensorData, ShakeData currentSensorData, qreal threshold); - bool shaking; - int shakeCount; - int threshold; - - bool isNegative(qreal num); - qreal lapsedTime; - quint64 lastTimestamp; - bool timerActive; -}; -QT_END_NAMESPACE -#endif // QSHAKERECOGNIZER_H diff --git a/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.cpp deleted file mode 100644 index 658f81eb..00000000 --- a/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.cpp +++ /dev/null @@ -1,215 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qslamgesturerecognizer.h" -#include "qtsensorgesturesensorhandler.h" - - -#include <QtCore/qmath.h> - -QT_BEGIN_NAMESPACE - -QSlamSensorGestureRecognizer::QSlamSensorGestureRecognizer(QObject *parent) : - QSensorGestureRecognizer(parent), - orientationReading(0), - accelRange(0), - active(0), - lastX(0), - lastY(0), - lastZ(0), - detectedX(0), - detecting(0), - accelX(0), - roll(0), - resting(0), - lastTimestamp(0), - lapsedTime(0), - timerActive(0) -{ -} - -QSlamSensorGestureRecognizer::~QSlamSensorGestureRecognizer() -{ -} - -void QSlamSensorGestureRecognizer::create() -{ -} - - -QString QSlamSensorGestureRecognizer::id() const -{ - return QString("QtSensors.slam"); -} - -bool QSlamSensorGestureRecognizer::start() -{ - if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Accel)) { - if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Orientation)) { - active = true; - accelRange = QtSensorGestureSensorHandler::instance()->accelRange; - 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; - } - } else { - active = false; - } - return active; -} - -bool QSlamSensorGestureRecognizer::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*))); - detecting = false; - restingList.clear(); - active = false; - return active; -} - -bool QSlamSensorGestureRecognizer::isActive() -{ - return active; -} - -void QSlamSensorGestureRecognizer::orientationReadingChanged(QOrientationReading *reading) -{ - orientationReading = reading; -} - -#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) -{ - const qreal x = reading->x(); - const qreal y = reading->y(); - const qreal z = reading->z(); - quint64 timestamp = reading->timestamp(); - - 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() > SLAM_RESTING_COUNT) - restingList.removeLast(); - restingList.insert(0, resting); - - - if (timerActive && lastTimestamp > 0) - lapsedTime += (timestamp - lastTimestamp )/1000; - - if (timerActive && lapsedTime >= 250) { - doSlam(); - } - lastTimestamp = timestamp; - - if (orientationReading == 0) { - return; - } - - const qreal difference = lastX - x; - - if (!detecting - && orientationReading->orientation() == QOrientationReading::TopUp - && resting - && hasBeenResting()) { - detectedX = x; - // start of gesture - detecting = true; - if (difference > 0) - wasNegative = false; - else - wasNegative = true; - restingList.clear(); - } - if (detecting - && qAbs(difference) > (accelRange * SLAM_DETECTION_FACTOR)) { - timerActive = true; - } - 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++) { - if (!restingList.at(i)) { - return false; - } - } - return true; -} - -void QSlamSensorGestureRecognizer::doSlam() -{ - if (detecting && (orientationReading->orientation() == QOrientationReading::RightUp - || orientationReading->orientation() == QOrientationReading::LeftUp)) { - Q_EMIT slam(); - Q_EMIT detected("slam"); - restingList.clear(); - detecting = false; - } - timerActive = false; - lapsedTime = 0; -} - -QT_END_NAMESPACE diff --git a/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.h b/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.h deleted file mode 100644 index 4217eec3..00000000 --- a/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.h +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef QSLAMSENSORGESTURERECOGNIZER_H -#define QSLAMSENSORGESTURERECOGNIZER_H - -#include <QtSensors/qsensorgesturerecognizer.h> -#include <QtSensors/QOrientationSensor> -#include <QtSensors/QAccelerometer> -#include <QtSensors/QAccelerometerReading> -#include <QtSensors/QOrientationReading> -QT_BEGIN_NAMESPACE - -class QSlamSensorGestureRecognizer : public QSensorGestureRecognizer -{ - Q_OBJECT -public: - explicit QSlamSensorGestureRecognizer(QObject *parent = 0); - ~QSlamSensorGestureRecognizer(); - - void create() override; - - QString id() const override; - bool start() override; - bool stop() override; - bool isActive() override; - -Q_SIGNALS: - void slam(); - -private slots: - void accelChanged(QAccelerometerReading *reading); - void orientationReadingChanged(QOrientationReading *reading); - void doSlam(); - -private: - - QAccelerometer *accel; - QOrientationReading *orientationReading; - int accelRange; - bool active; - - bool wasNegative; - qreal lastX; - qreal lastY; - qreal lastZ; - qreal detectedX; - - bool detecting; - - qreal accelX; - qreal roll; - QList<qreal> restingList; - bool resting; - - bool hasBeenResting(); - quint64 lastTimestamp; - quint64 lapsedTime; - bool timerActive; -}; - -QT_END_NAMESPACE -#endif // QSLAMSENSORGESTURERECOGNIZER_H diff --git a/src/plugins/sensorgestures/qtsensors/qtsensorgestureplugin.cpp b/src/plugins/sensorgestures/qtsensors/qtsensorgestureplugin.cpp deleted file mode 100644 index 7e091479..00000000 --- a/src/plugins/sensorgestures/qtsensors/qtsensorgestureplugin.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtPlugin> -#include <QStringList> -#include <QObject> - -#include "qtsensorgestureplugin.h" - -#include <QtSensors/qsensorgestureplugininterface.h> - -#include "qcoversensorgesturerecognizer.h" -#include "qtwistsensorgesturerecognizer.h" -#include "qdoubletapsensorgesturerecognizer.h" -#include "qhoversensorgesturerecognizer.h" -#include "qpickupsensorgesturerecognizer.h" -#include "qshake2recognizer.h" -#include "qslamgesturerecognizer.h" -#include "qturnoversensorgesturerecognizer.h" -#include "qwhipsensorgesturerecognizer.h" -#include "qfreefallsensorgesturerecognizer.h" - - -QT_BEGIN_NAMESPACE - - -QtSensorGesturePlugin::QtSensorGesturePlugin() -{ -} - -QtSensorGesturePlugin::~QtSensorGesturePlugin() -{ -} - -QStringList QtSensorGesturePlugin::supportedIds() const -{ - QStringList list; - list << "QtSensors.cover"; - list << "QtSensors.doubletap"; - list << "QtSensors.hover"; - list << "QtSensors.freefall"; - list << "QtSensors.pickup"; - list << "QtSensors.shake2"; - list << "QtSensors.slam"; - list << "QtSensors.turnover"; - list << "QtSensors.twist"; - list << "QtSensors.whip"; - return list; -} - -QList <QSensorGestureRecognizer *> QtSensorGesturePlugin::createRecognizers() -{ - QList <QSensorGestureRecognizer *> recognizers; - - recognizers.append(new QCoverSensorGestureRecognizer(this)); - - recognizers.append(new QDoubleTapSensorGestureRecognizer(this)); - - recognizers.append(new QHoverSensorGestureRecognizer(this)); - - recognizers.append(new QPickupSensorGestureRecognizer(this)); - - recognizers.append(new QShake2SensorGestureRecognizer(this)); - - recognizers.append(new QSlamSensorGestureRecognizer(this)); - - recognizers.append(new QTurnoverSensorGestureRecognizer(this)); - - recognizers.append(new QWhipSensorGestureRecognizer(this)); - - recognizers.append(new QTwistSensorGestureRecognizer(this)); - - recognizers.append(new QFreefallSensorGestureRecognizer(this)); - return recognizers; -} - -QT_END_NAMESPACE diff --git a/src/plugins/sensorgestures/qtsensors/qtsensorgestureplugin.h b/src/plugins/sensorgestures/qtsensors/qtsensorgestureplugin.h deleted file mode 100644 index 87a93f16..00000000 --- a/src/plugins/sensorgestures/qtsensors/qtsensorgestureplugin.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTSENSORGESTURESPLUGIN_H -#define QTSENSORGESTURESPLUGIN_H - -#include <QObject> -#include <QStringList> - -#include <QtSensors/qsensorgestureplugininterface.h> - -QT_BEGIN_NAMESPACE - -class QtSensorGesturePlugin : public QObject, public QSensorGesturePluginInterface -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID "org.qt-project.QSensorGesturePluginInterface") - Q_INTERFACES(QSensorGesturePluginInterface) - -public: - explicit QtSensorGesturePlugin(); - ~QtSensorGesturePlugin(); - QList <QSensorGestureRecognizer *> createRecognizers() override; - - QStringList gestureSignals() const; - QStringList supportedIds() const override; - QString name() const override { return "QtSensorGestures"; } - -}; - -QT_END_NAMESPACE -#endif // QTSENSORGESTURESPLUGIN_H diff --git a/src/plugins/sensorgestures/qtsensors/qtsensorgesturesensorhandler.cpp b/src/plugins/sensorgestures/qtsensors/qtsensorgesturesensorhandler.cpp deleted file mode 100644 index 84d9203f..00000000 --- a/src/plugins/sensorgestures/qtsensors/qtsensorgesturesensorhandler.cpp +++ /dev/null @@ -1,193 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QDebug> - -#include "qtsensorgesturesensorhandler.h" - -QtSensorGestureSensorHandler::QtSensorGestureSensorHandler(QObject *parent) : - QObject(parent), - accel(0), orientation(0), proximity(0), irProx(0),tapSensor(0) -{ -} - -QtSensorGestureSensorHandler* QtSensorGestureSensorHandler::instance() -{ - static QtSensorGestureSensorHandler *instance = 0; - if (!instance) { - instance = new QtSensorGestureSensorHandler; - } - return instance; -} - -void QtSensorGestureSensorHandler::accelChanged() -{ - Q_EMIT accelReadingChanged(accel->reading()); -} - -void QtSensorGestureSensorHandler::orientationChanged() -{ - Q_EMIT orientationReadingChanged(orientation->reading()); -} - -void QtSensorGestureSensorHandler::proximityChanged() -{ - Q_EMIT proximityReadingChanged(proximity->reading()); -} - -void QtSensorGestureSensorHandler::irProximityChanged() -{ - Q_EMIT irProximityReadingChanged(irProx->reading()); -} - -void QtSensorGestureSensorHandler::doubletap() -{ - Q_EMIT dTabReadingChanged(tapSensor->reading()); -} - -bool QtSensorGestureSensorHandler::startSensor(SensorGestureSensors sensor) -{ - bool ok = true; - switch (sensor) { - case Accel: - //accel - if (accel == 0x0) { - accel = new QAccelerometer(this); - ok = accel->connectToBackend(); - accel->setDataRate(100); - qoutputrangelist outputranges = accel->outputRanges(); - - if (outputranges.count() > 0) - accelRange = (int)(outputranges.at(0).maximum);//39 - else - accelRange = 39; //this should never happen - connect(accel,SIGNAL(readingChanged()),this,SLOT(accelChanged())); - } - if (ok && !accel->isActive()) - accel->start(); - break; - case Orientation: - //orientation - if (orientation == 0x0) { - orientation = new QOrientationSensor(this); - ok = orientation->connectToBackend(); - orientation->setDataRate(50); - connect(orientation,SIGNAL(readingChanged()),this,SLOT(orientationChanged())); - } - if (ok && !orientation->isActive()) - orientation->start(); - break; - case Proximity: - //proximity - if (proximity == 0x0) { - proximity = new QProximitySensor(this); - ok = proximity->connectToBackend(); - connect(proximity,SIGNAL(readingChanged()),this,SLOT(proximityChanged())); - } - if (ok && !proximity->isActive()) - proximity->start(); - break; - case IrProximity: - //irproximity - if (irProx == 0x0) { - irProx = new QIRProximitySensor(this); - irProx->setDataRate(50); - ok = irProx->connectToBackend(); - connect(irProx,SIGNAL(readingChanged()),this,SLOT(irProximityChanged())); - } - if (ok && !irProx->isActive()) - irProx->start(); - break; - case Tap: - //dtap - if (tapSensor == 0x0) { - tapSensor = new QTapSensor(this); - ok = tapSensor->connectToBackend(); - connect(tapSensor,SIGNAL(readingChanged()),this,SLOT(doubletap())); - } - if (ok && !tapSensor->isActive()) - tapSensor->start(); - break; - }; - int val = usedSensorsMap.value(sensor); - usedSensorsMap.insert(sensor,++val); - - return ok; -} - -void QtSensorGestureSensorHandler::stopSensor(SensorGestureSensors sensor) -{ - // qDebug() << __FUNCTION__ << sensor; - if (usedSensorsMap.value(sensor) == 0) - return; - int val = usedSensorsMap.value(sensor); - usedSensorsMap.insert(sensor,--val); - switch (sensor) { - case Accel: - //accel - if (usedSensorsMap.value(sensor) == 0) { - accel->stop(); - } - break; - case Orientation: - if (usedSensorsMap.value(sensor) == 0) { - orientation->stop(); - } - //orientation - break; - case Proximity: - if (usedSensorsMap.value(sensor) == 0) { - proximity->stop(); - } - //proximity - break; - case IrProximity: - if (usedSensorsMap.value(sensor) == 0) { - irProx->stop(); - } - //irproximity - break; - case Tap: - if (usedSensorsMap.value(sensor) == 0) { - tapSensor->stop(); - } - //dtap - break; - }; -} diff --git a/src/plugins/sensorgestures/qtsensors/qtsensorgesturesensorhandler.h b/src/plugins/sensorgestures/qtsensors/qtsensorgesturesensorhandler.h deleted file mode 100644 index 2c63092c..00000000 --- a/src/plugins/sensorgestures/qtsensors/qtsensorgesturesensorhandler.h +++ /dev/null @@ -1,98 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTSENSORGESTURESENSORHANDLER_H -#define QTSENSORGESTURESENSORHANDLER_H - -#include <QObject> - -#include <QtSensors/QAccelerometer> -#include <QtSensors/QAccelerometerFilter> -#include <QtSensors/QSensor> -#include <QtSensors/QOrientationSensor> -#include <QtSensors/QProximitySensor> -#include <QtSensors/QIRProximitySensor> -#include <QtSensors/QTapSensor> - -class QtSensorGestureSensorHandler : public QObject -{ - Q_OBJECT -public: - explicit QtSensorGestureSensorHandler(QObject *parent = 0); - - enum SensorGestureSensors { - Accel = 0, - Orientation, - Proximity, - IrProximity, - Tap - }; - Q_ENUM(SensorGestureSensors) - static QtSensorGestureSensorHandler *instance(); - qreal accelRange; - -public slots: - void accelChanged(); - void orientationChanged(); - void proximityChanged(); - void irProximityChanged(); - void doubletap(); - - bool startSensor(SensorGestureSensors sensor); - void stopSensor(SensorGestureSensors sensor); - -Q_SIGNALS: - void accelReadingChanged(QAccelerometerReading *reading); - void orientationReadingChanged(QOrientationReading *reading); - void proximityReadingChanged(QProximityReading *reading); - void irProximityReadingChanged(QIRProximityReading *reading); - void dTabReadingChanged(QTapReading *reading); - -private: - QAccelerometer *accel; - QOrientationSensor *orientation; - QProximitySensor *proximity; - QIRProximitySensor *irProx; - QTapSensor *tapSensor; - - QMap<SensorGestureSensors, int> usedSensorsMap; - -}; - -#endif // QTSENSORGESTURESENSORHANDLER_H diff --git a/src/plugins/sensorgestures/qtsensors/qturnoversensorgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qturnoversensorgesturerecognizer.cpp deleted file mode 100644 index e2d9bea8..00000000 --- a/src/plugins/sensorgestures/qtsensors/qturnoversensorgesturerecognizer.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtSensors/QSensor> - -#include "qturnoversensorgesturerecognizer.h" -#include "qtsensorgesturesensorhandler.h" - -QT_BEGIN_NAMESPACE - -// turnover and put down i.e. facedown - -QTurnoverSensorGestureRecognizer::QTurnoverSensorGestureRecognizer(QObject *parent) : - QSensorGestureRecognizer(parent), - isClose(0) - , isFaceDown(0), active(0) -{ -} - -QTurnoverSensorGestureRecognizer::~QTurnoverSensorGestureRecognizer() -{ -} - -void QTurnoverSensorGestureRecognizer::create() -{ -} - -bool QTurnoverSensorGestureRecognizer::start() -{ - if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Proximity)) { - if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Orientation)) { - active = true; - 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::Proximity); - active = false; - } - } else { - active = false; - } - return active; -} - -bool QTurnoverSensorGestureRecognizer::stop() -{ - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Proximity); - QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Orientation); - - disconnect(QtSensorGestureSensorHandler::instance(),SIGNAL(proximityReadingChanged(QProximityReading*)), - this,SLOT(proximityChanged(QProximityReading*))); - disconnect(QtSensorGestureSensorHandler::instance(),SIGNAL(orientationReadingChanged(QOrientationReading*)), - this,SLOT(orientationReadingChanged(QOrientationReading*))); - - active = false; - - return active; -} - -bool QTurnoverSensorGestureRecognizer::isActive() -{ - return active; -} - -QString QTurnoverSensorGestureRecognizer::id() const -{ - return QString("QtSensors.turnover"); -} - -void QTurnoverSensorGestureRecognizer::proximityChanged(QProximityReading *reading) -{ - isClose = reading->close(); - if (isClose) - isRecognized(); -} - -void QTurnoverSensorGestureRecognizer::orientationReadingChanged(QOrientationReading *reading) -{ - switch (reading->orientation()) { - case QOrientationReading::FaceDown: - { - isFaceDown = true; - isRecognized(); - } - break; - default: - isFaceDown = false; - break; - }; -} - -void QTurnoverSensorGestureRecognizer::isRecognized() -{ - if (isClose && isFaceDown) { - Q_EMIT turnover(); - Q_EMIT detected("turnover"); - } -} -QT_END_NAMESPACE - diff --git a/src/plugins/sensorgestures/qtsensors/qturnoversensorgesturerecognizer.h b/src/plugins/sensorgestures/qtsensors/qturnoversensorgesturerecognizer.h deleted file mode 100644 index 295cb5f7..00000000 --- a/src/plugins/sensorgestures/qtsensors/qturnoversensorgesturerecognizer.h +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTURNOVERSENSORGESTURERECOGNIZER_H -#define QTURNOVERSENSORGESTURERECOGNIZER_H - -#include <QtSensors/qsensorgesturerecognizer.h> -#include "qtsensorgesturesensorhandler.h" - -QT_BEGIN_NAMESPACE - -class QTurnoverSensorGestureRecognizer : public QSensorGestureRecognizer -{ - Q_OBJECT -public: - explicit QTurnoverSensorGestureRecognizer(QObject *parent = 0); - ~QTurnoverSensorGestureRecognizer(); - - void create() override; - - QString id() const override; - bool start() override; - bool stop() override; - bool isActive() override; - -Q_SIGNALS: - void turnover(); - -private slots: - void orientationReadingChanged(QOrientationReading *reading); - void proximityChanged(QProximityReading *reading); - void isRecognized(); - -private: - - bool isClose; - bool isFaceDown; - bool active; - - QList<qreal> zList; - -}; -QT_END_NAMESPACE -#endif // QTURNOVERSENSORGESTURERECOGNIZER_H diff --git a/src/plugins/sensorgestures/qtsensors/qtwistsensorgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qtwistsensorgesturerecognizer.cpp deleted file mode 100644 index 6a1f1706..00000000 --- a/src/plugins/sensorgestures/qtsensors/qtwistsensorgesturerecognizer.cpp +++ /dev/null @@ -1,291 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include "qtwistsensorgesturerecognizer.h" - -#include <QtCore/qmath.h> - -QT_BEGIN_NAMESPACE - -#define TIMER_TIMEOUT 750 -QTwistSensorGestureRecognizer::QTwistSensorGestureRecognizer(QObject *parent) - : QSensorGestureRecognizer(parent) - , orientationReading(0) - , active(0) - , detecting(0) - , checking(0) - , increaseCount(0) - , decreaseCount(0) - , lastAngle(0) - , detectedAngle(0) -{ -} - -QTwistSensorGestureRecognizer::~QTwistSensorGestureRecognizer() -{ -} - -void QTwistSensorGestureRecognizer::create() -{ -} - -QString QTwistSensorGestureRecognizer::id() const -{ - return QString("QtSensors.twist"); -} - -bool QTwistSensorGestureRecognizer::start() -{ - if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Accel)) { - if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Orientation)) { - 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; - } - } else { - - active = false; - } - - return active; -} - -bool QTwistSensorGestureRecognizer::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*))); - - reset(); - orientationList.clear(); - active = false; - return active; -} - -bool QTwistSensorGestureRecognizer::isActive() -{ - return active; -} - -void QTwistSensorGestureRecognizer::orientationReadingChanged(QOrientationReading *reading) -{ - orientationReading = reading; - if (orientationList.count() == 3) - orientationList.removeFirst(); - - orientationList.append(reading->orientation()); - - if (orientationList.count() == 3 - && orientationList.at(2) == QOrientationReading::FaceUp - && (orientationList.at(1) == QOrientationReading::RightUp - || orientationList.at(1) == QOrientationReading::LeftUp)) { - checkTwist(); - } - - checkOrientation(); -} - -bool QTwistSensorGestureRecognizer::checkOrientation() -{ - if (orientationReading->orientation() == QOrientationReading::TopDown - || orientationReading->orientation() == QOrientationReading::FaceDown) { - reset(); - return false; - } - return true; -} - -void QTwistSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) -{ - if (orientationReading == 0) - return; - - const qreal x = reading->x(); - const qreal y = reading->y(); - const qreal z = reading->z(); - - if (!detecting && !checking&& dataList.count() > 21) - dataList.removeFirst(); - - qreal angle = qRadiansToDegrees(qAtan(x / qSqrt(y * y + z * z))); - - if (qAbs(angle) > 2) { - if (detecting) { - if ((angle > 0 && angle < lastAngle) - || (angle < 0 && angle > lastAngle)) { - decreaseCount++; - } else { - if (decreaseCount > 0) - decreaseCount--; - } - } - - if (!detecting && ((angle > 0 && angle > lastAngle) - || (angle < 0 && angle < lastAngle)) - && ((angle > 0 && lastAngle > 0) - || (angle < 0 && lastAngle < 0))) { - increaseCount++; - } else - if (!detecting && increaseCount > 3 && qAbs(angle) > 30) { - decreaseCount = 0; - detecting = true; - detectedAngle = qRadiansToDegrees(qAtan(y / qSqrt(x * x + z * z))); - } - } else { - increaseCount = 0; - increaseCount = 0; - } - - lastAngle = angle; - if (detecting && decreaseCount >= 4 && qAbs(angle) < 25) { - checkTwist(); - } - - twistAccelData data; - data.x = x; - data.y = y; - data.z = z; - - if (qAbs(x) > 1) - dataList.append(data); - - if (qAbs(z) > 15.0) { - reset(); - } - -} - -void QTwistSensorGestureRecognizer::checkTwist() -{ - checking = true; - int lastx = 0; - bool ok = false; - bool spinpoint = false; - - if (detectedAngle < 0) { - reset(); - return; - } - - //// check for orientation changes first - if (orientationList.count() < 2) - return; - - if (orientationList.count() > 2) - if (orientationList.at(0) == orientationList.at(2) - && (orientationList.at(1) == QOrientationReading::LeftUp - || orientationList.at(1) == QOrientationReading::RightUp)) { - ok = true; - if (orientationList.at(1) == QOrientationReading::RightUp) - detectedAngle = 1; - else - detectedAngle = -1; - } - - // now the manual increase/decrease count - if (!ok) { - if (increaseCount < 1 || decreaseCount < 3) - return; - - if (increaseCount > 6 && decreaseCount > 4) { - ok = true; - if (orientationList.at(1) == QOrientationReading::RightUp) - detectedAngle = 1; - else - detectedAngle = -1; - } - } - // now we're really grasping for anything - if (!ok) - for (int i = 0; i < dataList.count(); i++) { - twistAccelData curData = dataList.at(i); - if (!spinpoint && qAbs(curData.x) < 1) - continue; - if (curData.z >= 0 ) { - if (!spinpoint && (curData.x > lastx || curData.x < lastx) && curData.x - lastx > 1) { - ok = true; - } else if (spinpoint && (curData.x < lastx || curData.x > lastx)&& lastx - curData.x > 1) { - ok = true; - } else { - ok = false; - } - } else if (!spinpoint && curData.z < 0) { - spinpoint = true; - } else if (spinpoint && curData.z > 9) { - break; - } - - lastx = curData.x; - } - if (ok) { - if (detectedAngle > 0) { - Q_EMIT twistLeft(); - Q_EMIT detected("twistLeft"); - } else { - Q_EMIT twistRight(); - Q_EMIT detected("twistRight"); - } - } - reset(); -} - -void QTwistSensorGestureRecognizer::reset() -{ - detecting = false; - checking = false; - dataList.clear(); - increaseCount = 0; - decreaseCount = 0; - lastAngle = 0; -} - - - -QT_END_NAMESPACE diff --git a/src/plugins/sensorgestures/qtsensors/qtwistsensorgesturerecognizer.h b/src/plugins/sensorgestures/qtsensors/qtwistsensorgesturerecognizer.h deleted file mode 100644 index 3080e2a6..00000000 --- a/src/plugins/sensorgestures/qtsensors/qtwistsensorgesturerecognizer.h +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef QWFLICKSENSORGESTURERECOGNIZER_H -#define QWFLICKSENSORGESTURERECOGNIZER_H - -#include <QtSensors/qsensorgesturerecognizer.h> -#include <QtSensors/QAccelerometer> -#include <QtSensors/QOrientationSensor> -#include "qtsensorgesturesensorhandler.h" - -QT_BEGIN_NAMESPACE - -struct twistAccelData { - qreal x; - qreal y; - qreal z; -}; - -class QTwistSensorGestureRecognizer : public QSensorGestureRecognizer -{ - Q_OBJECT -public: - explicit QTwistSensorGestureRecognizer(QObject *parent = 0); - ~QTwistSensorGestureRecognizer(); - - void create() override; - - QString id() const override; - bool start() override; - bool stop() override; - bool isActive() override; - -Q_SIGNALS: - void twistLeft(); - void twistRight(); - -private slots: - void accelChanged(QAccelerometerReading *reading); - void orientationReadingChanged(QOrientationReading *reading); - void checkTwist(); - -private: - - QOrientationReading *orientationReading; - bool active; - bool detecting; - QList <twistAccelData> dataList; - bool checking; - void reset(); - bool checkOrientation(); - int increaseCount; - int decreaseCount; - qreal lastAngle; - QList <QOrientationReading::Orientation> orientationList; - qreal detectedAngle; -}; -QT_END_NAMESPACE -#endif // QWFLICKSENSORGESTURERECOGNIZER_H diff --git a/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp deleted file mode 100644 index b0298485..00000000 --- a/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp +++ /dev/null @@ -1,240 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include "qwhipsensorgesturerecognizer.h" -#include "qtsensorgesturesensorhandler.h" - -#include <QtCore/qmath.h> - -#define TIMER_TIMEOUT 850 - -QT_BEGIN_NAMESPACE - -QWhipSensorGestureRecognizer::QWhipSensorGestureRecognizer(QObject *parent) - : QSensorGestureRecognizer(parent), - orientationReading(0), - accelRange(0), - active(0), - lastX(0), - lastY(0), - lastZ(0), - detecting(0), - whipOk(0) - , lastTimestamp(0) - , timerActive(0) - , lapsedTime(0) -{ -} - -QWhipSensorGestureRecognizer::~QWhipSensorGestureRecognizer() -{ -} - -void QWhipSensorGestureRecognizer::create() -{ -} - -QString QWhipSensorGestureRecognizer::id() const -{ - return QString("QtSensors.whip"); -} - -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; - } - } else { - active = false; - } - lastTimestamp = 0; - timerActive = false; - lapsedTime = 0; - return active; -} - -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; - return active; -} - -bool QWhipSensorGestureRecognizer::isActive() -{ - return active; -} - -void QWhipSensorGestureRecognizer::orientationReadingChanged(QOrientationReading *reading) -{ - orientationReading = reading; -} - -#define WHIP_FACTOR -11.0 -#define WHIP_WIGGLE_FACTOR 0.35 - -void QWhipSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) -{ - const qreal x = reading->x(); - const qreal y = reading->y(); - qreal z = reading->z(); - - quint64 timestamp = reading->timestamp(); - - if (zList.count() > 4) - zList.removeLast(); - - qreal averageZ = 0; - for (const qreal& az : qAsConst<QList<qreal>>(zList)) - averageZ += az; - - averageZ /= zList.count(); - - zList.insert(0,z); - - if (orientationReading == 0) - return; - //// very hacky - if (orientationReading->orientation() == QOrientationReading::FaceUp) { - z = z - 9.8; - } - - const qreal diffX = lastX - x; - const qreal diffY = lastY - y; - - if (detecting && whipMap.count() > 5 && whipMap.at(5) == true) { - checkForWhip(); - } - - if (whipMap.count() > 5) - whipMap.removeLast(); - - if (negativeList.count() > 5) - negativeList.removeLast(); - - if (z < WHIP_FACTOR - && qAbs(diffX) > -(accelRange * .1285)//-5.0115 - && qAbs(lastX) < 7 - && qAbs(x) < 7) { - whipMap.insert(0,true); - if (!detecting && !timerActive) { - timerActive = true; - detecting = true; - } - } else { - whipMap.insert(0,false); - } - - // check if shaking - if ((((x < 0 && lastX > 0) || (x > 0 && lastX < 0)) - && qAbs(diffX) > (accelRange * 0.7)) //27.3 - || (((y < 0 && lastY > 0) || (y > 0 && lastY < 0)) - && qAbs(diffY) > (accelRange * 0.7))) { - negativeList.insert(0,true); - } else { - negativeList.insert(0,false); - } - - lastX = x; - lastY = y; - lastZ = z; - - if (timerActive && lastTimestamp > 0) - lapsedTime += (timestamp - lastTimestamp )/1000; - - if (timerActive && lapsedTime >= TIMER_TIMEOUT) { - timeout(); - } -} - -void QWhipSensorGestureRecognizer::timeout() -{ - detecting = false; -} - - -void QWhipSensorGestureRecognizer::checkForWhip() -{ - whipOk = false; - - int check = 0; - for (const qreal& az : qAsConst<QList<qreal>>(zList)) { - if (az < -10) - check++; - } - if (check >= 4) - whipOk = true; - else - return; - - if (whipOk) { - bool ok = true; - for (int i = 0; i < negativeList.count() - 1; i++) { - if (negativeList.at(i)) { - ok = false; - } - } - if (ok) { - Q_EMIT whip(); - Q_EMIT detected("whip"); - } - detecting = false; - whipMap.clear(); - timerActive = false; - } -} - -QT_END_NAMESPACE diff --git a/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.h b/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.h deleted file mode 100644 index 6d674ab5..00000000 --- a/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.h +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSensors module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef QWHIPSENSORGESTURERECOGNIZER_H -#define QWHIPSENSORGESTURERECOGNIZER_H - -#include <QtSensors/qsensorgesturerecognizer.h> - -#include "qtsensorgesturesensorhandler.h" - -QT_BEGIN_NAMESPACE - -class QWhipSensorGestureRecognizer : public QSensorGestureRecognizer -{ - Q_OBJECT -public: - explicit QWhipSensorGestureRecognizer(QObject *parent = 0); - ~QWhipSensorGestureRecognizer(); - - void create() override; - - QString id() const override; - bool start() override; - bool stop() override; - bool isActive() override; - -Q_SIGNALS: - void whip(); - -private slots: - void accelChanged(QAccelerometerReading *reading); - void orientationReadingChanged(QOrientationReading *reading); - void timeout(); - -private: - QOrientationReading *orientationReading; - qreal accelRange; - bool active; - - qreal lastX; - qreal lastY; - qreal lastZ; - - bool detecting; - bool whipOk; - - QList<bool> whipMap; - - void checkForWhip(); - - QList <bool> negativeList; - - QList<qreal> zList; - - quint64 lastTimestamp; - - bool timerActive; - quint64 lapsedTime; - -}; - -QT_END_NAMESPACE -#endif // QWHIPSENSORGESTURERECOGNIZER_H |