diff options
Diffstat (limited to 'src/plugins/sensors/generic')
-rw-r--r-- | src/plugins/sensors/generic/generic.pro | 30 | ||||
-rw-r--r-- | src/plugins/sensors/generic/genericrotationsensor.cpp | 4 | ||||
-rw-r--r-- | src/plugins/sensors/generic/genericrotationsensor.h | 1 | ||||
-rw-r--r-- | src/plugins/sensors/generic/generictiltsensor.cpp | 47 | ||||
-rw-r--r-- | src/plugins/sensors/generic/generictiltsensor.h | 4 | ||||
-rw-r--r-- | src/plugins/sensors/generic/main.cpp | 44 |
6 files changed, 94 insertions, 36 deletions
diff --git a/src/plugins/sensors/generic/generic.pro b/src/plugins/sensors/generic/generic.pro index 2d4f9f9..fcc1bfc 100644 --- a/src/plugins/sensors/generic/generic.pro +++ b/src/plugins/sensors/generic/generic.pro @@ -4,15 +4,27 @@ QT = core sensors PLUGIN_TYPE = sensors load(qt_plugin) -HEADERS += genericorientationsensor.h\ - genericrotationsensor.h\ - genericalssensor.h\ - generictiltsensor.h - -SOURCES += genericorientationsensor.cpp\ - main.cpp\ - genericrotationsensor.cpp\ - genericalssensor.cpp\ +HEADERS += generictiltsensor.h + +SOURCES += main.cpp\ generictiltsensor.cpp +DEFINES += QTSENSORS_GENERICTILTSENSOR + +!blackberry { + HEADERS += genericorientationsensor.h\ + genericalssensor.h + + SOURCES += genericorientationsensor.cpp\ + genericalssensor.cpp + DEFINES += QTSENSORS_GENERICORIENTATIONSENSOR QTSENSORS_GENERICALSSENSOR +} + +!blackberry:!android { + HEADERS += genericrotationsensor.h + + SOURCES += genericrotationsensor.cpp + + DEFINES += QTSENSORS_GENERICROTATIONSENSOR +} OTHER_FILES = plugin.json diff --git a/src/plugins/sensors/generic/genericrotationsensor.cpp b/src/plugins/sensors/generic/genericrotationsensor.cpp index b5f80cb..0548adc 100644 --- a/src/plugins/sensors/generic/genericrotationsensor.cpp +++ b/src/plugins/sensors/generic/genericrotationsensor.cpp @@ -57,7 +57,9 @@ genericrotationsensor::genericrotationsensor(QSensor *sensor) setReading<QRotationReading>(&m_reading); setDataRates(accelerometer); - sensor->setProperty("hasZ", false); + QRotationSensor * const rotationSensor = qobject_cast<QRotationSensor *>(sensor); + if (rotationSensor) + rotationSensor->setHasZ(false); } void genericrotationsensor::start() diff --git a/src/plugins/sensors/generic/genericrotationsensor.h b/src/plugins/sensors/generic/genericrotationsensor.h index 3475caf..ffa48ea 100644 --- a/src/plugins/sensors/generic/genericrotationsensor.h +++ b/src/plugins/sensors/generic/genericrotationsensor.h @@ -62,7 +62,6 @@ public: private: QRotationReading m_reading; QAccelerometer *accelerometer; - QMagnetometer *magnetometer; }; #endif diff --git a/src/plugins/sensors/generic/generictiltsensor.cpp b/src/plugins/sensors/generic/generictiltsensor.cpp index 6aefb57..95c8525 100644 --- a/src/plugins/sensors/generic/generictiltsensor.cpp +++ b/src/plugins/sensors/generic/generictiltsensor.cpp @@ -53,6 +53,8 @@ GenericTiltSensor::GenericTiltSensor(QSensor *sensor) , roll(0) , calibratedPitch(0) , calibratedRoll(0) + , xRotation(0) + , yRotation(0) { accelerometer = new QAccelerometer(this); accelerometer->addFilter(this); @@ -106,6 +108,11 @@ void GenericTiltSensor::calibrate() calibratedRoll = roll; } +static qreal rad2deg(qreal rad) +{ + return rad / (2 * M_PI) * 360; +} + bool GenericTiltSensor::filter(QAccelerometerReading *reading) { /* @@ -119,16 +126,16 @@ bool GenericTiltSensor::filter(QAccelerometerReading *reading) qreal az = reading->z(); #ifdef LOGCALIBRATION qDebug() << "------------ new value -----------"; - qDebug() << "old _pitch: " << _pitch; - qDebug() << "old _roll: " << _roll; - qDebug() << "_calibratedPitch: " << _calibratedPitch; - qDebug() << "_calibratedRoll: " << _calibratedRoll; + qDebug() << "old _pitch: " << pitch; + qDebug() << "old _roll: " << roll; + qDebug() << "_calibratedPitch: " << calibratedPitch; + qDebug() << "_calibratedRoll: " << calibratedRoll; #endif pitch = calcPitch(ax, ay, az); roll = calcRoll (ax, ay, az); #ifdef LOGCALIBRATION - qDebug() << "_pitch: " << _pitch; - qDebug() << "_roll: " << _roll; + qDebug() << "_pitch: " << pitch; + qDebug() << "_roll: " << roll; #endif qreal xrot = roll - calibratedRoll; qreal yrot = pitch - calibratedPitch; @@ -154,23 +161,22 @@ bool GenericTiltSensor::filter(QAccelerometerReading *reading) qDebug() << "new yrot: " << yrot; qDebug() << "----------------------------------"; #endif - qreal dxrot = xrot - xRotation; - qreal dyrot = yrot - yRotation; + qreal dxrot = rad2deg(xrot) - xRotation; + qreal dyrot = rad2deg(yrot) - yRotation; if (dxrot < 0) dxrot = -dxrot; if (dyrot < 0) dyrot = -dyrot; - bool change = false; - if (dxrot >= radAccuracy) { - xRotation = xrot; - change = true; + bool setNewReading = false; + if (dxrot >= rad2deg(radAccuracy) || !sensor()->skipDuplicates()) { + xRotation = rad2deg(xrot); + setNewReading = true; } - if (dyrot >= radAccuracy) { - yRotation = yrot; - change = true; + if (dyrot >= rad2deg(radAccuracy) || !sensor()->skipDuplicates()) { + yRotation = rad2deg(yrot); + setNewReading = true; } - if (xRotation != m_reading.xRotation() - || yRotation != m_reading.yRotation() - || m_reading.timestamp() == 0) { + + if (setNewReading || m_reading.timestamp() == 0) { m_reading.setTimestamp(reading->timestamp()); m_reading.setXRotation(xRotation); m_reading.setYRotation(yRotation); @@ -179,3 +185,8 @@ bool GenericTiltSensor::filter(QAccelerometerReading *reading) return false; } + +bool GenericTiltSensor::isFeatureSupported(QSensor::Feature feature) const +{ + return (feature == QSensor::SkipDuplicates); +} diff --git a/src/plugins/sensors/generic/generictiltsensor.h b/src/plugins/sensors/generic/generictiltsensor.h index 0633662..0f84ca6 100644 --- a/src/plugins/sensors/generic/generictiltsensor.h +++ b/src/plugins/sensors/generic/generictiltsensor.h @@ -46,7 +46,6 @@ #include <qtiltsensor.h> #include <qaccelerometer.h> -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class GenericTiltSensor : public QSensorBackend, public QAccelerometerFilter @@ -64,6 +63,8 @@ public: bool filter(QAccelerometerReading *reading); + bool isFeatureSupported(QSensor::Feature feature) const Q_DECL_OVERRIDE; + private: QTiltReading m_reading; QAccelerometer *accelerometer; @@ -77,7 +78,6 @@ private: }; QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/plugins/sensors/generic/main.cpp b/src/plugins/sensors/generic/main.cpp index 15507b6..aa9f58c 100644 --- a/src/plugins/sensors/generic/main.cpp +++ b/src/plugins/sensors/generic/main.cpp @@ -39,9 +39,18 @@ ** ****************************************************************************/ +#ifdef QTSENSORS_GENERICORIENTATIONSENSOR #include "genericorientationsensor.h" +#endif +#ifdef QTSENSORS_GENERICROTATIONSENSOR #include "genericrotationsensor.h" +#endif +#ifdef QTSENSORS_GENERICALSSENSOR #include "genericalssensor.h" +#endif +#ifdef QTSENSORS_GENERICTILTSENSOR +#include "generictiltsensor.h" +#endif #include <qsensorplugin.h> #include <qsensorbackend.h> #include <qsensormanager.h> @@ -56,7 +65,6 @@ class genericSensorPlugin : public QObject, public QSensorPluginInterface, publi public: void registerSensors() { - qDebug() << "loaded the Generic plugin"; // Nothing to register here } @@ -64,34 +72,60 @@ public: { if (!QSensor::defaultSensorForType(QAccelerometer::type).isEmpty()) { // There is an accelerometer available. Register the backends +#ifdef QTSENSORS_GENERICORIENTATIONSENSOR if (!QSensorManager::isBackendRegistered(QOrientationSensor::type, genericorientationsensor::id)) QSensorManager::registerBackend(QOrientationSensor::type, genericorientationsensor::id, this); +#endif +#ifdef QTSENSORS_GENERICROTATIONSENSOR if (!QSensorManager::isBackendRegistered(QRotationSensor::type, genericrotationsensor::id)) QSensorManager::registerBackend(QRotationSensor::type, genericrotationsensor::id, this); +#endif +#ifdef QTSENSORS_GENERICALSSENSOR if (!QSensorManager::isBackendRegistered(QAmbientLightSensor::type, genericalssensor::id)) QSensorManager::registerBackend(QAmbientLightSensor::type, genericalssensor::id, this); - if (!QSensorManager::isBackendRegistered(QAmbientLightSensor::type, genericalssensor::id)) - QSensorManager::registerBackend(QAmbientLightSensor::type, genericalssensor::id, this); +#endif +#ifdef QTSENSORS_GENERICTILTSENSOR + if (!QSensorManager::isBackendRegistered(QTiltSensor::type, GenericTiltSensor::id)) + QSensorManager::registerBackend(QTiltSensor::type, GenericTiltSensor::id, this); +#endif } else { +#ifdef QTSENSORS_GENERICORIENTATIONSENSOR if (QSensorManager::isBackendRegistered(QOrientationSensor::type, genericorientationsensor::id)) QSensorManager::unregisterBackend(QOrientationSensor::type, genericorientationsensor::id); +#endif +#ifdef QTSENSORS_GENERICROTATIONSENSOR if (QSensorManager::isBackendRegistered(QRotationSensor::type, genericrotationsensor::id)) QSensorManager::unregisterBackend(QRotationSensor::type, genericrotationsensor::id); +#endif +#ifdef QTSENSORS_GENERICALSSENSOR if (QSensorManager::isBackendRegistered(QAmbientLightSensor::type, genericalssensor::id)) QSensorManager::unregisterBackend(QAmbientLightSensor::type, genericalssensor::id); +#endif +#ifdef QTSENSORS_GENERICTILTSENSOR + if (QSensorManager::isBackendRegistered(QTiltSensor::type, GenericTiltSensor::id)) + QSensorManager::unregisterBackend(QTiltSensor::type, GenericTiltSensor::id); +#endif } } QSensorBackend *createBackend(QSensor *sensor) { +#ifdef QTSENSORS_GENERICORIENTATIONSENSOR if (sensor->identifier() == genericorientationsensor::id) return new genericorientationsensor(sensor); - +#endif +#ifdef QTSENSORS_GENERICROTATIONSENSOR if (sensor->identifier() == genericrotationsensor::id) return new genericrotationsensor(sensor); - +#endif +#ifdef QTSENSORS_GENERICALSSENSOR if (sensor->identifier() == genericalssensor::id) return new genericalssensor(sensor); +#endif +#ifdef QTSENSORS_GENERICTILTSENSOR + if (sensor->identifier() == GenericTiltSensor::id) + return new GenericTiltSensor(sensor); +#endif return 0; } |