diff options
Diffstat (limited to 'src/plugins/sensors')
21 files changed, 545 insertions, 168 deletions
diff --git a/src/plugins/sensors/android/jar/src/org/qtproject/qt5/android/sensors/QtSensors.java b/src/plugins/sensors/android/jar/src/org/qtproject/qt5/android/sensors/QtSensors.java index c7956d2d..5507b07b 100644 --- a/src/plugins/sensors/android/jar/src/org/qtproject/qt5/android/sensors/QtSensors.java +++ b/src/plugins/sensors/android/jar/src/org/qtproject/qt5/android/sensors/QtSensors.java @@ -98,6 +98,17 @@ public class QtSensors implements SensorEventListener return null; } + private static float getSensorMaximumRange(int sensorType) + { + try { + Sensor s = m_sensorManager.getDefaultSensor(sensorType); + return s.getMaximumRange(); + } catch(Exception e) { + e.printStackTrace(); + } + return 0; + } + private static boolean registerSensor(int sensorType, int rate) { synchronized (m_syncObject) { diff --git a/src/plugins/sensors/android/src/androidjnisensors.cpp b/src/plugins/sensors/android/src/androidjnisensors.cpp index 6365433c..af39e0b6 100644 --- a/src/plugins/sensors/android/src/androidjnisensors.cpp +++ b/src/plugins/sensors/android/src/androidjnisensors.cpp @@ -53,6 +53,7 @@ static jmethodID getSensorListMethodId; static jmethodID registerSensorMethodId; static jmethodID unregisterSensorMethodId; static jmethodID getSensorDescriptionMethodId; +static jmethodID getSensorMaximumRangeMethodId; static QHash<int, QList<AndroidSensors::AndroidSensorsListenerInterface *> > listenersHash; QReadWriteLock listenersLocker; @@ -119,6 +120,15 @@ namespace AndroidSensors return ret; } + qreal sensorMaximumRange(AndroidSensorType sensor) + { + AttachedJNIEnv aenv; + if (!aenv.jniEnv) + return 0; + jfloat range = aenv.jniEnv->CallStaticFloatMethod(sensorsClass, getSensorMaximumRangeMethodId, jint(sensor)); + return range; + } + bool registerListener(AndroidSensorType sensor, AndroidSensorsListenerInterface *listener, int dataRate) { listenersLocker.lockForWrite(); @@ -214,6 +224,7 @@ static bool registerNatives(JNIEnv *env) GET_AND_CHECK_STATIC_METHOD(registerSensorMethodId, sensorsClass, "registerSensor", "(II)Z"); GET_AND_CHECK_STATIC_METHOD(unregisterSensorMethodId, sensorsClass, "unregisterSensor", "(I)Z"); GET_AND_CHECK_STATIC_METHOD(getSensorDescriptionMethodId, sensorsClass, "getSensorDescription", "(I)Ljava/lang/String;"); + GET_AND_CHECK_STATIC_METHOD(getSensorMaximumRangeMethodId, sensorsClass, "getSensorMaximumRange", "(I)F"); return true; } diff --git a/src/plugins/sensors/android/src/androidjnisensors.h b/src/plugins/sensors/android/src/androidjnisensors.h index 53ca58d0..30aab6cc 100644 --- a/src/plugins/sensors/android/src/androidjnisensors.h +++ b/src/plugins/sensors/android/src/androidjnisensors.h @@ -53,17 +53,21 @@ namespace AndroidSensors enum AndroidSensorType { TYPE_ACCELEROMETER = 1, - TYPE_AMBIENT_TEMPERATURE = 13, + TYPE_AMBIENT_TEMPERATURE = 13, //Added in API level 14 + TYPE_GAME_ROTATION_VECTOR = 15, //Added in API level 18 TYPE_GRAVITY = 9, TYPE_GYROSCOPE = 4, + TYPE_GYROSCOPE_UNCALIBRATED = 16, //Added in API level 18 TYPE_LIGHT = 5, TYPE_LINEAR_ACCELERATION = 10, TYPE_MAGNETIC_FIELD = 2, + TYPE_MAGNETIC_FIELD_UNCALIBRATED = 14, //Added in API level 18 TYPE_ORIENTATION = 3, //This constant was deprecated in API level 8. use SensorManager.getOrientation() instead. TYPE_PRESSURE = 6, TYPE_PROXIMITY = 8, - TYPE_RELATIVE_HUMIDITY = 12, + TYPE_RELATIVE_HUMIDITY = 12, //Added in API level 14 TYPE_ROTATION_VECTOR = 11, + TYPE_SIGNIFICANT_MOTION = 17, //Added in API level 18 TYPE_TEMPERATURE = 7 //This constant was deprecated in API level 14. use Sensor.TYPE_AMBIENT_TEMPERATURE instead. }; @@ -76,6 +80,7 @@ namespace AndroidSensors QVector<AndroidSensorType> availableSensors(); QString sensorDescription(AndroidSensorType sensor); + qreal sensorMaximumRange(AndroidSensorType sensor); bool registerListener(AndroidSensorType sensor, AndroidSensorsListenerInterface *listener, int dataRate = 0); bool unregisterListener(AndroidSensorType sensor, AndroidSensorsListenerInterface *listener); } diff --git a/src/plugins/sensors/android/src/androidpressure.cpp b/src/plugins/sensors/android/src/androidpressure.cpp new file mode 100644 index 00000000..1cabecbb --- /dev/null +++ b/src/plugins/sensors/android/src/androidpressure.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2013 BogDan Vatra <bogdan@kde.org> +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "androidpressure.h" + +AndroidPressure::AndroidPressure(AndroidSensors::AndroidSensorType type, QSensor *sensor) + : AndroidCommonSensor<QPressureReading>(type, sensor) +{} + + +void AndroidPressure::onAccuracyChanged(jint accuracy) +{ + Q_UNUSED(accuracy) +} + +void AndroidPressure::onSensorChanged(jlong timestamp, const jfloat *values, uint size) +{ + if (size < 1) + return; + m_reader.setTimestamp(timestamp/1000); + // check https://developer.android.com/reference/android/hardware/SensorEvent.html#values + m_reader.setPressure(values[0]*100); //Android uses hPa, we use Pa + newReadingAvailable(); +} diff --git a/src/plugins/sensors/android/src/androidpressure.h b/src/plugins/sensors/android/src/androidpressure.h new file mode 100644 index 00000000..44f1d53f --- /dev/null +++ b/src/plugins/sensors/android/src/androidpressure.h @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2013 BogDan Vatra <bogdan@kde.org> +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ANDROIDPRESSURE_H +#define ANDROIDPRESSURE_H +#include <qpressuresensor.h> + +#include "androidcommonsensor.h" + +class AndroidPressure : public AndroidCommonSensor<QPressureReading> +{ +public: + AndroidPressure(AndroidSensors::AndroidSensorType type, QSensor *sensor); +private: + virtual void onAccuracyChanged(jint accuracy); + virtual void onSensorChanged(jlong timestamp, const jfloat *values, uint size); +}; + +#endif // ANDROIDPRESSURE_H diff --git a/src/plugins/sensors/android/src/androidproximity.cpp b/src/plugins/sensors/android/src/androidproximity.cpp new file mode 100644 index 00000000..9d10f77b --- /dev/null +++ b/src/plugins/sensors/android/src/androidproximity.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2013 BogDan Vatra <bogdan@kde.org> +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "androidproximity.h" +#include "androidjnisensors.h" + +AndroidProximity::AndroidProximity(AndroidSensors::AndroidSensorType type, QSensor *sensor) + : AndroidCommonSensor<QProximityReading>(type, sensor) +{ + m_maximumRange = AndroidSensors::sensorMaximumRange(type); + + // if we can't get the range, we arbitrarily define anything closer than 10 cm as "close" + if (m_maximumRange <= 0) + m_maximumRange = 10.0; +} + + +void AndroidProximity::onAccuracyChanged(jint accuracy) +{ + Q_UNUSED(accuracy) +} + +void AndroidProximity::onSensorChanged(jlong timestamp, const jfloat *values, uint size) +{ + if (size < 1) + return; + m_reader.setTimestamp(timestamp/1000); + + qreal reading = values[0]; + bool close = (reading < m_maximumRange); + m_reader.setClose(close); + newReadingAvailable(); +} diff --git a/src/plugins/sensors/android/src/androidproximity.h b/src/plugins/sensors/android/src/androidproximity.h new file mode 100644 index 00000000..1911798d --- /dev/null +++ b/src/plugins/sensors/android/src/androidproximity.h @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2013 BogDan Vatra <bogdan@kde.org> +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ANDROIDPROXIMITY_H +#define ANDROIDPROXIMITY_H +#include <qproximitysensor.h> + +#include "androidcommonsensor.h" + +class AndroidProximity : public AndroidCommonSensor<QProximityReading> +{ +public: + AndroidProximity(AndroidSensors::AndroidSensorType type, QSensor *sensor); +private: + virtual void onAccuracyChanged(jint accuracy); + virtual void onSensorChanged(jlong timestamp, const jfloat *values, uint size); + qreal m_maximumRange; +}; + +#endif // ANDROIDPROXIMITY_H diff --git a/src/plugins/sensors/android/src/androidtemperature.cpp b/src/plugins/sensors/android/src/androidtemperature.cpp new file mode 100644 index 00000000..b3f41daa --- /dev/null +++ b/src/plugins/sensors/android/src/androidtemperature.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2013 BogDan Vatra <bogdan@kde.org> +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "androidtemperature.h" + +AndroidTemperature::AndroidTemperature(AndroidSensors::AndroidSensorType type, QSensor *sensor) + : AndroidCommonSensor<QAmbientTemperatureReading>(type, sensor) +{} + + +void AndroidTemperature::onAccuracyChanged(jint accuracy) +{ + Q_UNUSED(accuracy) +} + +void AndroidTemperature::onSensorChanged(jlong timestamp, const jfloat *values, uint size) +{ + if (size < 1) + return; + m_reader.setTimestamp(timestamp/1000); + + // TODO: I was unable to test this since the devices I was testing this with did not have + // a temperature sensor. Verify that this works and check that the units are correct. + + m_reader.setTemperature(values[0]); + newReadingAvailable(); +} diff --git a/src/plugins/sensors/android/src/androidtemperature.h b/src/plugins/sensors/android/src/androidtemperature.h new file mode 100644 index 00000000..667169cd --- /dev/null +++ b/src/plugins/sensors/android/src/androidtemperature.h @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2013 BogDan Vatra <bogdan@kde.org> +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ANDROIDTEMPERATURE_H +#define ANDROIDTEMPERATURE_H +#include <qambienttemperaturesensor.h> + +#include "androidcommonsensor.h" + +class AndroidTemperature : public AndroidCommonSensor<QAmbientTemperatureReading> +{ +public: + AndroidTemperature(AndroidSensors::AndroidSensorType type, QSensor *sensor); +private: + virtual void onAccuracyChanged(jint accuracy); + virtual void onSensorChanged(jlong timestamp, const jfloat *values, uint size); +}; + +#endif // ANDROIDTEMPERATURE_H diff --git a/src/plugins/sensors/android/src/main.cpp b/src/plugins/sensors/android/src/main.cpp index 0cb4de49..17d499ef 100644 --- a/src/plugins/sensors/android/src/main.cpp +++ b/src/plugins/sensors/android/src/main.cpp @@ -47,7 +47,10 @@ #include "androidgyroscope.h" #include "androidlight.h" #include "androidmagnetometer.h" +#include "androidpressure.h" +#include "androidproximity.h" #include "androidrotation.h" +#include "androidtemperature.h" using namespace AndroidSensors; @@ -66,7 +69,8 @@ public: break; case TYPE_AMBIENT_TEMPERATURE: case TYPE_TEMPERATURE: - break; // add the temperature sensor backend + QSensorManager::registerBackend(QAmbientTemperatureSensor::type, QByteArray::number(sensor), this); + break; case TYPE_GRAVITY: break; // add the gravity sensor backend case TYPE_GYROSCOPE: @@ -83,14 +87,22 @@ public: case TYPE_ORIENTATION: break; // add the orientation sensor backend case TYPE_PRESSURE: - break; // add the pressure sensor backend + QSensorManager::registerBackend(QPressureSensor::type, QByteArray::number(sensor), this); + break; case TYPE_PROXIMITY: - break; // add the proximity sensor backend + QSensorManager::registerBackend(QProximitySensor::type, QByteArray::number(sensor), this); + break; case TYPE_RELATIVE_HUMIDITY: break; // add the relative humidity sensor backend case TYPE_ROTATION_VECTOR: QSensorManager::registerBackend(QRotationSensor::type, QByteArray::number(sensor), this); break; + + case TYPE_GAME_ROTATION_VECTOR: + case TYPE_GYROSCOPE_UNCALIBRATED: + case TYPE_MAGNETIC_FIELD_UNCALIBRATED: + case TYPE_SIGNIFICANT_MOTION: + break; // add backends for API level 18 sensors } } } @@ -103,7 +115,7 @@ public: return new AndroidAccelerometer(type, sensor); case TYPE_AMBIENT_TEMPERATURE: case TYPE_TEMPERATURE: - break; // add the temperature sensor backend + return new AndroidTemperature(type, sensor); case TYPE_GRAVITY: break; // add the gravity sensor backend case TYPE_GYROSCOPE: @@ -117,13 +129,19 @@ public: case TYPE_ORIENTATION: break; // add the orientation sensor backend case TYPE_PRESSURE: - break; // add the pressure sensor backend + return new AndroidPressure(type, sensor); case TYPE_PROXIMITY: - break; // add the proximity sensor backend + return new AndroidProximity(type, sensor); case TYPE_RELATIVE_HUMIDITY: break; // add the relative humidity sensor backend case TYPE_ROTATION_VECTOR: return new AndroidRotation(type, sensor); + + case TYPE_GAME_ROTATION_VECTOR: + case TYPE_GYROSCOPE_UNCALIBRATED: + case TYPE_MAGNETIC_FIELD_UNCALIBRATED: + case TYPE_SIGNIFICANT_MOTION: + break; // add backends for API level 18 sensors } return 0; } diff --git a/src/plugins/sensors/android/src/src.pro b/src/plugins/sensors/android/src/src.pro index 715a0111..a184aae7 100644 --- a/src/plugins/sensors/android/src/src.pro +++ b/src/plugins/sensors/android/src/src.pro @@ -14,7 +14,10 @@ HEADERS = \ androidcommonsensor.h \ androidgyroscope.h \ androidmagnetometer.h \ + androidpressure.h \ + androidproximity.h \ androidrotation.h \ + androidtemperature.h \ androidlight.h SOURCES = \ @@ -23,7 +26,10 @@ SOURCES = \ androidaccelerometer.cpp \ androidgyroscope.cpp \ androidmagnetometer.cpp \ + androidpressure.cpp \ + androidproximity.cpp \ androidrotation.cpp \ + androidtemperature.cpp \ androidlight.cpp OTHER_FILES = plugin.json diff --git a/src/plugins/sensors/blackberry/bbpressuresensor.cpp b/src/plugins/sensors/blackberry/bbpressuresensor.cpp index 8cb9b1ea..edbb3927 100644 --- a/src/plugins/sensors/blackberry/bbpressuresensor.cpp +++ b/src/plugins/sensors/blackberry/bbpressuresensor.cpp @@ -53,8 +53,7 @@ QString BbPressureSensor::devicePath() bool BbPressureSensor::updateReadingFromEvent(const sensor_event_t &event, QPressureReading *reading) { - // TODO: I was unable to test this since the device I was testing this with did not have - // a pressure sensor. Verify that this works and check that the units are correct. reading->setPressure(event.pressure_s.pressure); + reading->setTemperature(event.pressure_s.temperature); return true; } diff --git a/src/plugins/sensors/blackberry/bbsensorbackend.cpp b/src/plugins/sensors/blackberry/bbsensorbackend.cpp index 6b614a8a..7822dd86 100644 --- a/src/plugins/sensors/blackberry/bbsensorbackend.cpp +++ b/src/plugins/sensors/blackberry/bbsensorbackend.cpp @@ -303,6 +303,7 @@ bool BbSensorBackendBase::isFeatureSupported(QSensor::Feature feature) const case QSensor::Buffering: case QSensor::AccelerationMode: case QSensor::SkipDuplicates: + case QSensor::PressureSensorTemperature: return true; case QSensor::GeoValues: #ifndef Q_OS_BLACKBERRY_TABLET diff --git a/src/plugins/sensors/blackberry/bbsensorbackend.h b/src/plugins/sensors/blackberry/bbsensorbackend.h index 4e7b8101..953d7bcf 100644 --- a/src/plugins/sensors/blackberry/bbsensorbackend.h +++ b/src/plugins/sensors/blackberry/bbsensorbackend.h @@ -45,8 +45,8 @@ #include <QtCore/QFile> #include <QtCore/QSocketNotifier> -// Earlier NDK versions did not ship sensor.h, that is why we have our own copy in -// here. +// Earlier NDK versions did not ship sensor.h and the Playbook NDK still +// doesn't include it, that is why we have our own copy in here. // We prefer the NDK version if that exists, as that is more up-to-date. #ifdef HAVE_NDK_SENSOR_H #include <sensor/sensor.h> diff --git a/src/plugins/sensors/blackberry/sensor.h b/src/plugins/sensors/blackberry/sensor.h index fb5b935d..7317f076 100644 --- a/src/plugins/sensors/blackberry/sensor.h +++ b/src/plugins/sensors/blackberry/sensor.h @@ -40,8 +40,12 @@ ****************************************************************************/ // -// This file is a temporary copy until it becomes available in the Blackberry NDK. +// This file is a copy of the "sensor.h" header for the BlackBerry Playbook OS. +// It is only inclulded here, because it is not available in the the Playbook NDK. // +#if !defined(Q_OS_BLACKBERRY_TABLET) +#error "This file is supposed to be used only for BlackBerry Playbook OS." +#endif #ifndef SENSOR_H_ #define SENSOR_H_ diff --git a/src/plugins/sensors/ios/iosaccelerometer.h b/src/plugins/sensors/ios/iosaccelerometer.h index 5fcac19f..1a6560b1 100644 --- a/src/plugins/sensors/ios/iosaccelerometer.h +++ b/src/plugins/sensors/ios/iosaccelerometer.h @@ -42,29 +42,28 @@ #ifndef IOSACCELEROMETER_H #define IOSACCELEROMETER_H -#include <Foundation/Foundation.h> +#include <CoreMotion/CMMotionManager.h> #include <qsensorbackend.h> #include <qaccelerometer.h> QT_BEGIN_NAMESPACE -@class QtIoAccelListener; - class IOSAccelerometer : public QSensorBackend { public: static char const * const id; explicit IOSAccelerometer(QSensor *sensor); - ~IOSAccelerometer(); + void timerEvent(QTimerEvent *); void start(); void stop(); private: - NSOperationQueue *m_updateQueue; + CMMotionManager *m_motionManager; QAccelerometerReading m_reading; + int m_timer; }; QT_END_NAMESPACE diff --git a/src/plugins/sensors/ios/iosaccelerometer.mm b/src/plugins/sensors/ios/iosaccelerometer.mm index b657b507..5f9c0f16 100644 --- a/src/plugins/sensors/ios/iosaccelerometer.mm +++ b/src/plugins/sensors/ios/iosaccelerometer.mm @@ -40,8 +40,6 @@ ****************************************************************************/ #include <UIKit/UIAccelerometer.h> -#include <CoreMotion/CMMotionManager.h> -#include <QPointer> #include "iosaccelerometer.h" #include "iosmotionmanager.h" @@ -52,49 +50,39 @@ QT_BEGIN_NAMESPACE IOSAccelerometer::IOSAccelerometer(QSensor *sensor) : QSensorBackend(sensor) - , m_updateQueue([[NSOperationQueue alloc] init]) + , m_motionManager([QIOSMotionManager sharedManager]) + , m_timer(0) { setReading<QAccelerometerReading>(&m_reading); addDataRate(1, 100); // 100Hz addOutputRange(-22.418, 22.418, 0.17651); // 2G } -IOSAccelerometer::~IOSAccelerometer() -{ - [m_updateQueue release]; -} - void IOSAccelerometer::start() { - CMMotionManager *motionManager = [QIOSMotionManager sharedManager]; - // Convert from Hz to NSTimeInterval: int hz = sensor()->dataRate(); - motionManager.accelerometerUpdateInterval = (hz == 0) ? 0 : 1. / hz; - - QPointer<QObject> self = this; - [motionManager startAccelerometerUpdatesToQueue:m_updateQueue withHandler:^(CMAccelerometerData *data, NSError *error) { - // NSOperationQueue is multi-threaded, so we process the data by queuing a callback to - // the main application queue. By the time the callback executes, IOSAccelerometer might - // have been deleted, so we need an extra QPointer check for that: - dispatch_async(dispatch_get_main_queue(), ^{ - if (self) { - Q_UNUSED(error); - // Convert from NSTimeInterval to microseconds and G to m/s2, and flip axes: - CMAcceleration acc = data.acceleration; - const qreal G = 9.8066; - m_reading.setTimestamp(quint64(data.timestamp * 1000000)); - m_reading.setX(qreal(acc.x) * G * -1); - m_reading.setY(qreal(acc.y) * G * -1); - m_reading.setZ(qreal(acc.z) * G * -1); - newReadingAvailable(); - } - }); - }]; + m_timer = startTimer(1000 / (hz == 0 ? 60 : hz)); + [m_motionManager startAccelerometerUpdates]; } void IOSAccelerometer::stop() { - [[QIOSMotionManager sharedManager] stopAccelerometerUpdates]; + [m_motionManager stopAccelerometerUpdates]; + killTimer(m_timer); + m_timer = 0; +} + +void IOSAccelerometer::timerEvent(QTimerEvent *) +{ + // Convert from NSTimeInterval to microseconds and G to m/s2, and flip axes: + CMAccelerometerData *data = m_motionManager.accelerometerData; + CMAcceleration acc = data.acceleration; + static const qreal G = 9.8066; + m_reading.setTimestamp(quint64(data.timestamp * 1e6)); + m_reading.setX(qreal(acc.x) * G * -1); + m_reading.setY(qreal(acc.y) * G * -1); + m_reading.setZ(qreal(acc.z) * G * -1); + newReadingAvailable(); } QT_END_NAMESPACE diff --git a/src/plugins/sensors/ios/iosgyroscope.h b/src/plugins/sensors/ios/iosgyroscope.h index ed46241c..4f4c399a 100644 --- a/src/plugins/sensors/ios/iosgyroscope.h +++ b/src/plugins/sensors/ios/iosgyroscope.h @@ -42,7 +42,7 @@ #ifndef IOSGYROSCOPE_H #define IOSGYROSCOPE_H -#include <Foundation/Foundation.h> +#include <CoreMotion/CMMotionManager.h> #include <qsensorbackend.h> #include <qgyroscope.h> @@ -55,14 +55,15 @@ public: static char const * const id; explicit IOSGyroscope(QSensor *sensor); - ~IOSGyroscope(); + void timerEvent(QTimerEvent *); void start(); void stop(); private: - NSOperationQueue *m_updateQueue; + CMMotionManager *m_motionManager; QGyroscopeReading m_reading; + int m_timer; }; QT_END_NAMESPACE diff --git a/src/plugins/sensors/ios/iosgyroscope.mm b/src/plugins/sensors/ios/iosgyroscope.mm index 700755de..8dfa3a4a 100644 --- a/src/plugins/sensors/ios/iosgyroscope.mm +++ b/src/plugins/sensors/ios/iosgyroscope.mm @@ -39,9 +39,6 @@ ** ****************************************************************************/ -#include <CoreMotion/CMMotionManager.h> -#include <QPointer> - #include "iosmotionmanager.h" #include "iosgyroscope.h" @@ -51,48 +48,38 @@ QT_BEGIN_NAMESPACE IOSGyroscope::IOSGyroscope(QSensor *sensor) : QSensorBackend(sensor) - , m_updateQueue([[NSOperationQueue alloc] init]) + , m_motionManager([QIOSMotionManager sharedManager]) + , m_timer(0) { setReading<QGyroscopeReading>(&m_reading); addDataRate(1, 100); // 100Hz is max it seems addOutputRange(-360, 360, 0.01); } -IOSGyroscope::~IOSGyroscope() -{ - [m_updateQueue release]; -} - void IOSGyroscope::start() { - CMMotionManager *motionManager = [QIOSMotionManager sharedManager]; - // Convert Hz to NSTimeInterval: int hz = sensor()->dataRate(); - motionManager.gyroUpdateInterval = (hz == 0) ? 0 : 1. / hz; - - QPointer<QObject> self = this; - [motionManager startGyroUpdatesToQueue:m_updateQueue withHandler:^(CMGyroData *data, NSError *error) { - // NSOperationQueue is multi-threaded, so we process the data by queuing a callback to - // the main application queue. By the time the callback executes, IOSAccelerometer might - // have been deleted, so we need an extra QPointer check for that: - dispatch_async(dispatch_get_main_queue(), ^{ - if (self) { - Q_UNUSED(error); - // Convert NSTimeInterval to microseconds and radians to degrees: - CMRotationRate rate = data.rotationRate; - m_reading.setTimestamp(quint64(data.timestamp * 1000000)); - m_reading.setX((qreal(rate.x) / M_PI) * 180); - m_reading.setY((qreal(rate.y) / M_PI) * 180); - m_reading.setZ((qreal(rate.z) / M_PI) * 180); - newReadingAvailable(); - } - }); - }]; + m_timer = startTimer(1000 / (hz == 0 ? 60 : hz)); + [m_motionManager startGyroUpdates]; } void IOSGyroscope::stop() { - [[QIOSMotionManager sharedManager] stopGyroUpdates]; + [m_motionManager stopGyroUpdates]; + killTimer(m_timer); + m_timer = 0; +} + +void IOSGyroscope::timerEvent(QTimerEvent *) +{ + // Convert NSTimeInterval to microseconds and radians to degrees: + CMGyroData *data = m_motionManager.gyroData; + CMRotationRate rate = data.rotationRate; + m_reading.setTimestamp(quint64(data.timestamp * 1e6)); + m_reading.setX((qreal(rate.x) / M_PI) * 180); + m_reading.setY((qreal(rate.y) / M_PI) * 180); + m_reading.setZ((qreal(rate.z) / M_PI) * 180); + newReadingAvailable(); } QT_END_NAMESPACE diff --git a/src/plugins/sensors/ios/iosmagnetometer.h b/src/plugins/sensors/ios/iosmagnetometer.h index 72ceab6d..b0dc848a 100644 --- a/src/plugins/sensors/ios/iosmagnetometer.h +++ b/src/plugins/sensors/ios/iosmagnetometer.h @@ -42,7 +42,7 @@ #ifndef IOSMAGNETOMETER_H #define IOSMAGNETOMETER_H -#include <Foundation/Foundation.h> +#include <CoreMotion/CMMotionManager.h> #include <qsensorbackend.h> #include <qmagnetometer.h> @@ -55,7 +55,7 @@ public: static char const * const id; explicit IOSMagnetometer(QSensor *sensor); - ~IOSMagnetometer(); + void timerEvent(QTimerEvent *); void start(); void stop(); @@ -64,8 +64,10 @@ public: void startDeviceMotion(); private: - NSOperationQueue *m_updateQueue; + CMMotionManager *m_motionManager; QMagnetometerReading m_reading; + int m_timer; + bool m_returnGeoValues; }; QT_END_NAMESPACE diff --git a/src/plugins/sensors/ios/iosmagnetometer.mm b/src/plugins/sensors/ios/iosmagnetometer.mm index f46d7d5b..95f85ae1 100644 --- a/src/plugins/sensors/ios/iosmagnetometer.mm +++ b/src/plugins/sensors/ios/iosmagnetometer.mm @@ -39,9 +39,6 @@ ** ****************************************************************************/ -#include <CoreMotion/CMMotionManager.h> -#include <QPointer> - #include "iosmotionmanager.h" #include "iosmagnetometer.h" @@ -51,7 +48,9 @@ char const * const IOSMagnetometer::id("ios.magnetometer"); IOSMagnetometer::IOSMagnetometer(QSensor *sensor) : QSensorBackend(sensor) - , m_updateQueue([[NSOperationQueue alloc] init]) + , m_motionManager([QIOSMotionManager sharedManager]) + , m_timer(0) + , m_returnGeoValues(false) { setReading<QMagnetometerReading>(&m_reading); // Technical information about data rate is not found, but @@ -62,94 +61,64 @@ IOSMagnetometer::IOSMagnetometer(QSensor *sensor) addOutputRange(-0.0002, 0.0002, 1e-08); } -IOSMagnetometer::~IOSMagnetometer() -{ - [m_updateQueue release]; -} - void IOSMagnetometer::start() { - if (static_cast<QMagnetometer *>(sensor())->returnGeoValues()) - startDeviceMotion(); + int hz = sensor()->dataRate(); + m_timer = startTimer(1000 / (hz == 0 ? 60 : hz)); + m_returnGeoValues = static_cast<QMagnetometer *>(sensor())->returnGeoValues(); + + if (m_returnGeoValues) + [m_motionManager startDeviceMotionUpdates]; else - startMagnetometer(); + [m_motionManager startMagnetometerUpdates]; } -void IOSMagnetometer::startMagnetometer() +void IOSMagnetometer::stop() { - CMMotionManager *motionManager = [QIOSMotionManager sharedManager]; - // Convert Hz to NSTimeInterval: - int hz = sensor()->dataRate(); - motionManager.magnetometerUpdateInterval = (hz == 0) ? 0 : 1. / hz; - - QPointer<QObject> self = this; - [motionManager startMagnetometerUpdatesToQueue:m_updateQueue withHandler:^(CMMagnetometerData *data, NSError *error) { - // NSOperationQueue is multi-threaded, so we process the data by queuing a callback to - // the main application queue. By the time the callback executes, IOSMagnetometer might - // have been deleted, so we need an extra QPointer check for that: - dispatch_async(dispatch_get_main_queue(), ^{ - if (self) { - Q_UNUSED(error); - CMMagneticField field = data.magneticField; - // Convert NSTimeInterval to microseconds and microtesla to tesla: - m_reading.setTimestamp(quint64(data.timestamp * 1e6)); - m_reading.setX(qreal(field.x) / 1e6); - m_reading.setY(qreal(field.y) / 1e6); - m_reading.setZ(qreal(field.z) / 1e6); - m_reading.setCalibrationLevel(1.0); - newReadingAvailable(); - } - }); - }]; + if (m_returnGeoValues) + [m_motionManager stopDeviceMotionUpdates]; + else + [m_motionManager stopMagnetometerUpdates]; + killTimer(m_timer); + m_timer = 0; } -void IOSMagnetometer::startDeviceMotion() +void IOSMagnetometer::timerEvent(QTimerEvent *) { - CMMotionManager *motionManager = [QIOSMotionManager sharedManager]; - // Convert Hz to NSTimeInterval: - int hz = sensor()->dataRate(); - motionManager.deviceMotionUpdateInterval = (hz == 0) ? 0 : 1. / hz; - QPointer<QObject> self = this; + CMMagneticField field; - [motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXArbitraryCorrectedZVertical - toQueue:m_updateQueue withHandler:^(CMDeviceMotion *data, NSError *error) { - dispatch_async(dispatch_get_main_queue(), ^{ - if (self) { - Q_UNUSED(error); - CMCalibratedMagneticField calibratedField = data.magneticField; - CMMagneticField field = calibratedField.field; - field = motionManager.deviceMotion.magneticField.field; - // Convert NSTimeInterval to microseconds and microtesla to tesla: - m_reading.setTimestamp(quint64(data.timestamp * 1e6)); - m_reading.setX(qreal(field.x) / 1e6); - m_reading.setY(qreal(field.y) / 1e6); - m_reading.setZ(qreal(field.z) / 1e6); + if (m_returnGeoValues) { + CMDeviceMotion *deviceMotion = m_motionManager.deviceMotion; + CMCalibratedMagneticField calibratedField = deviceMotion.magneticField; + field = calibratedField.field; + m_reading.setTimestamp(quint64(deviceMotion.timestamp * 1e6)); - switch (calibratedField.accuracy) { - case CMMagneticFieldCalibrationAccuracyUncalibrated: - m_reading.setCalibrationLevel(0.0); - break; - case CMMagneticFieldCalibrationAccuracyLow: - m_reading.setCalibrationLevel(0.3); - break; - case CMMagneticFieldCalibrationAccuracyMedium: - m_reading.setCalibrationLevel(0.6); - break; - case CMMagneticFieldCalibrationAccuracyHigh: - m_reading.setCalibrationLevel(1.0); - break; - } + switch (calibratedField.accuracy) { + case CMMagneticFieldCalibrationAccuracyUncalibrated: + m_reading.setCalibrationLevel(0.0); + break; + case CMMagneticFieldCalibrationAccuracyLow: + m_reading.setCalibrationLevel(0.3); + break; + case CMMagneticFieldCalibrationAccuracyMedium: + m_reading.setCalibrationLevel(0.6); + break; + case CMMagneticFieldCalibrationAccuracyHigh: + m_reading.setCalibrationLevel(1.0); + break; + } + } else { + CMMagnetometerData *data = m_motionManager.magnetometerData; + field = data.magneticField; + m_reading.setTimestamp(quint64(data.timestamp * 1e6)); + m_reading.setCalibrationLevel(1.0); + } - newReadingAvailable(); - } - }); - }]; -} - -void IOSMagnetometer::stop() -{ - [[QIOSMotionManager sharedManager] stopMagnetometerUpdates]; - [[QIOSMotionManager sharedManager] stopDeviceMotionUpdates]; + // Convert NSTimeInterval to microseconds and microtesla to tesla: + m_reading.setX(qreal(field.x) / 1e6); + m_reading.setY(qreal(field.y) / 1e6); + m_reading.setZ(qreal(field.z) / 1e6); + newReadingAvailable(); } QT_END_NAMESPACE |