summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Knight <andrew.knight@digia.com>2014-02-15 09:44:41 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-16 18:35:48 +0100
commit2b67b50af18bb2a17ff10d5a37abfd85fc7e9d01 (patch)
treec4c388ce1be1d24a4354440f3a5145400c84aa51 /src
parent06b5371b87528e92cff015ee0465677840e65120 (diff)
downloadqtsensors-2b67b50af18bb2a17ff10d5a37abfd85fc7e9d01.tar.gz
Initial sensors backend for WinRT/Windows Phonev5.3.0-alpha1
This provides the sensor plugin with support for accelerometer, gyroscope, rotation sensor, orientation sensor, compass, and ambient light sensor. Change-Id: Ic91a6cef98e4011858552c5cd6407b494579fe17 Reviewed-by: Thomas McGuire <thomas.mcguire@kdab.com> Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/sensors/sensors.pro5
-rw-r--r--src/plugins/sensors/winrt/main.cpp105
-rw-r--r--src/plugins/sensors/winrt/plugin.json1
-rw-r--r--src/plugins/sensors/winrt/winrt.pro31
-rw-r--r--src/plugins/sensors/winrt/winrtaccelerometer.cpp204
-rw-r--r--src/plugins/sensors/winrt/winrtaccelerometer.h66
-rw-r--r--src/plugins/sensors/winrt/winrtambientlightsensor.cpp203
-rw-r--r--src/plugins/sensors/winrt/winrtambientlightsensor.h66
-rw-r--r--src/plugins/sensors/winrt/winrtcommon.cpp54
-rw-r--r--src/plugins/sensors/winrt/winrtcommon.h62
-rw-r--r--src/plugins/sensors/winrt/winrtcompass.cpp224
-rw-r--r--src/plugins/sensors/winrt/winrtcompass.h66
-rw-r--r--src/plugins/sensors/winrt/winrtgyroscope.cpp201
-rw-r--r--src/plugins/sensors/winrt/winrtgyroscope.h73
-rw-r--r--src/plugins/sensors/winrt/winrtorientationsensor.cpp188
-rw-r--r--src/plugins/sensors/winrt/winrtorientationsensor.h66
-rw-r--r--src/plugins/sensors/winrt/winrtrotationsensor.cpp199
-rw-r--r--src/plugins/sensors/winrt/winrtrotationsensor.h73
-rw-r--r--src/sensors/doc/src/compatmap.qdoc36
19 files changed, 1923 insertions, 0 deletions
diff --git a/src/plugins/sensors/sensors.pro b/src/plugins/sensors/sensors.pro
index 66f9f5a..a566716 100644
--- a/src/plugins/sensors/sensors.pro
+++ b/src/plugins/sensors/sensors.pro
@@ -18,6 +18,10 @@ ios {
isEmpty(SENSORS_PLUGINS): SENSORS_PLUGINS = ios generic
}
+winrt {
+ isEmpty(SENSORS_PLUGINS): SENSORS_PLUGINS = winrt generic
+}
+
isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, dummy):SUBDIRS += dummy
isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, generic):SUBDIRS += generic
isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, simulator):simulator:SUBDIRS += simulator
@@ -26,3 +30,4 @@ isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, linux):linux:SUBDIRS += linux
isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, android):android:SUBDIRS += android
isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, sensorfw):sensorfw:SUBDIRS += sensorfw
isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, ios):ios:SUBDIRS += ios
+isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, winrt):winrt:SUBDIRS += winrt
diff --git a/src/plugins/sensors/winrt/main.cpp b/src/plugins/sensors/winrt/main.cpp
new file mode 100644
index 0000000..13b8712
--- /dev/null
+++ b/src/plugins/sensors/winrt/main.cpp
@@ -0,0 +1,105 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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 "winrtaccelerometer.h"
+#include "winrtcompass.h"
+#include "winrtgyroscope.h"
+#include "winrtrotationsensor.h"
+#ifndef Q_OS_WINPHONE
+# include "winrtambientlightsensor.h"
+# include "winrtorientationsensor.h"
+#endif
+#include <QtSensors/QAccelerometer>
+#include <QtSensors/QAmbientLightSensor>
+#include <QtSensors/QCompass>
+#include <QtSensors/QGyroscope>
+#include <QtSensors/QOrientationSensor>
+#include <QtSensors/QRotationSensor>
+#include <QtSensors/QSensorBackendFactory>
+#include <QtSensors/QSensorManager>
+#include <QtSensors/QSensorPluginInterface>
+
+class WinRtSensorPlugin : public QObject, public QSensorPluginInterface, public QSensorBackendFactory
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID "com.qt-project.Qt.QSensorPluginInterface/1.0" FILE "plugin.json")
+ Q_INTERFACES(QSensorPluginInterface)
+public:
+ void registerSensors()
+ {
+ QSensorManager::registerBackend(QAccelerometer::type, QByteArrayLiteral("WinRtAccelerometer"), this);
+ QSensorManager::registerBackend(QCompass::type, QByteArrayLiteral("WinRtCompass"), this);
+ QSensorManager::registerBackend(QGyroscope::type, QByteArrayLiteral("WinRtGyroscope"), this);
+ QSensorManager::registerBackend(QRotationSensor::type, QByteArrayLiteral("WinRtRotationSensor"), this);
+#ifndef Q_OS_WINPHONE
+ QSensorManager::registerBackend(QAmbientLightSensor::type, QByteArrayLiteral("WinRtAmbientLightSensor"), this);
+ QSensorManager::registerBackend(QOrientationSensor::type, QByteArrayLiteral("WinRtOrientationSensor"), this);
+#endif
+ }
+
+ QSensorBackend *createBackend(QSensor *sensor)
+ {
+ if (sensor->identifier() == QByteArrayLiteral("WinRtAccelerometer"))
+ return new WinRtAccelerometer(sensor);
+
+ if (sensor->identifier() == QByteArrayLiteral("WinRtCompass"))
+ return new WinRtCompass(sensor);
+
+ if (sensor->identifier() == QByteArrayLiteral("WinRtGyroscope"))
+ return new WinRtGyroscope(sensor);
+
+ if (sensor->identifier() == QByteArrayLiteral("WinRtRotationSensor"))
+ return new WinRtRotationSensor(sensor);
+
+#ifndef Q_OS_WINPHONE
+ if (sensor->identifier() == QByteArrayLiteral("WinRtAmbientLightSensor"))
+ return new WinRtAmbientLightSensor(sensor);
+
+ if (sensor->identifier() == QByteArrayLiteral("WinRtOrientationSensor"))
+ return new WinRtOrientationSensor(sensor);
+#endif // !Q_OS_WINPHONE
+
+ return 0;
+ }
+};
+
+#include "main.moc"
+
diff --git a/src/plugins/sensors/winrt/plugin.json b/src/plugins/sensors/winrt/plugin.json
new file mode 100644
index 0000000..8a55b3a
--- /dev/null
+++ b/src/plugins/sensors/winrt/plugin.json
@@ -0,0 +1 @@
+{ "Keys": [ "notused" ] }
diff --git a/src/plugins/sensors/winrt/winrt.pro b/src/plugins/sensors/winrt/winrt.pro
new file mode 100644
index 0000000..494e1bf
--- /dev/null
+++ b/src/plugins/sensors/winrt/winrt.pro
@@ -0,0 +1,31 @@
+TARGET = qtsensors_winrt
+QT = sensors core
+
+PLUGIN_TYPE = sensors
+load(qt_plugin)
+
+HEADERS += \
+ winrtaccelerometer.h \
+ winrtcommon.h \
+ winrtcompass.h \
+ winrtrotationsensor.h \
+ winrtgyroscope.h
+
+SOURCES += \
+ main.cpp \
+ winrtaccelerometer.cpp \
+ winrtcommon.cpp \
+ winrtcompass.cpp \
+ winrtrotationsensor.cpp \
+ winrtgyroscope.cpp
+
+!winphone {
+ HEADERS += \
+ winrtambientlightsensor.h \
+ winrtorientationsensor.h
+ SOURCES += \
+ winrtambientlightsensor.cpp \
+ winrtorientationsensor.cpp
+}
+
+OTHER_FILES = plugin.json
diff --git a/src/plugins/sensors/winrt/winrtaccelerometer.cpp b/src/plugins/sensors/winrt/winrtaccelerometer.cpp
new file mode 100644
index 0000000..c8e8b26
--- /dev/null
+++ b/src/plugins/sensors/winrt/winrtaccelerometer.cpp
@@ -0,0 +1,204 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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 "winrtaccelerometer.h"
+#include "winrtcommon.h"
+
+#include <QtSensors/QAccelerometerReading>
+
+#include <wrl.h>
+#include <windows.devices.sensors.h>
+using namespace Microsoft::WRL;
+using namespace Microsoft::WRL::Wrappers;
+using namespace ABI::Windows::Foundation;
+using namespace ABI::Windows::Devices::Sensors;
+
+typedef ITypedEventHandler<Accelerometer *, AccelerometerReadingChangedEventArgs *> AccelerometerReadingHandler;
+
+QT_USE_NAMESPACE
+
+#define GRAVITY_EARTH_MS2 9.80665
+
+class WinRtAccelerometerPrivate
+{
+public:
+ WinRtAccelerometerPrivate(WinRtAccelerometer *p)
+ : minimumReportInterval(0), q(p)
+ {
+ token.value = 0;
+ }
+
+ QAccelerometerReading reading;
+
+ ComPtr<IAccelerometer> sensor;
+ EventRegistrationToken token;
+ quint32 minimumReportInterval;
+
+ HRESULT readingChanged(IAccelerometer *, IAccelerometerReadingChangedEventArgs *args)
+ {
+ ComPtr<IAccelerometerReading> value;
+ HRESULT hr = args->get_Reading(&value);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Failed to get accelerometer reading" << qt_error_string(hr);
+ return hr;
+ }
+
+ DOUBLE x;
+ hr = value->get_AccelerationX(&x);
+ if (FAILED(hr))
+ qCWarning(lcWinRtSensors) << "Failed to get acceleration X" << qt_error_string(hr);
+
+ DOUBLE y;
+ hr = value->get_AccelerationY(&y);
+ if (FAILED(hr))
+ qCWarning(lcWinRtSensors) << "Failed to get acceleration Y" << qt_error_string(hr);
+
+ DOUBLE z;
+ hr = value->get_AccelerationZ(&z);
+ if (FAILED(hr))
+ qCWarning(lcWinRtSensors) << "Failed to get acceleration Z" << qt_error_string(hr);
+
+ DateTime dateTime;
+ hr = value->get_Timestamp(&dateTime);
+ if (FAILED(hr))
+ qCWarning(lcWinRtSensors) << "Failed to get acceleration timestamp" << qt_error_string(hr);
+
+ // The reading is in G force, so convert to m/s/s
+ reading.setX(x * GRAVITY_EARTH_MS2);
+ reading.setY(y * GRAVITY_EARTH_MS2);
+ reading.setZ(z * GRAVITY_EARTH_MS2);
+ reading.setTimestamp(dateTimeToMsSinceEpoch(dateTime));
+ q->newReadingAvailable();
+
+ return S_OK;
+ }
+
+private:
+ WinRtAccelerometer *q;
+};
+
+WinRtAccelerometer::WinRtAccelerometer(QSensor *sensor)
+ : QSensorBackend(sensor), d_ptr(new WinRtAccelerometerPrivate(this))
+{
+ Q_D(WinRtAccelerometer);
+ HStringReference classId(RuntimeClass_Windows_Devices_Sensors_Accelerometer);
+ ComPtr<IAccelerometerStatics> factory;
+ HRESULT hr = RoGetActivationFactory(classId.Get(), IID_PPV_ARGS(&factory));
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to initialize accelerometer factory."
+ << qt_error_string(hr);
+ sensorError(hr);
+ return;
+ }
+
+ hr = factory->GetDefault(&d->sensor);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to get default accelerometer."
+ << qt_error_string(hr);
+ sensorError(hr);
+ return;
+ }
+
+ hr = d->sensor->get_MinimumReportInterval(&d->minimumReportInterval);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to get the minimum report interval."
+ << qt_error_string(hr);
+ sensorError(hr);
+ return;
+ }
+
+ setReading<QAccelerometerReading>(&d->reading);
+}
+
+WinRtAccelerometer::~WinRtAccelerometer()
+{
+}
+
+void WinRtAccelerometer::start()
+{
+ Q_D(WinRtAccelerometer);
+ if (!d->sensor)
+ return;
+ if (d->token.value)
+ return;
+
+ ComPtr<AccelerometerReadingHandler> callback =
+ Callback<AccelerometerReadingHandler>(d, &WinRtAccelerometerPrivate::readingChanged);
+ HRESULT hr = d->sensor->add_ReadingChanged(callback.Get(), &d->token);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to attach to reading changed event."
+ << qt_error_string(hr);
+ sensorError(hr);
+ return;
+ }
+ quint32 reportInterval = qMax(d->minimumReportInterval, quint32(1000/sensor()->dataRate()));
+ hr = d->sensor->put_ReportInterval(reportInterval);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to attach to set report interval."
+ << qt_error_string(hr);
+ sensorError(hr);
+ }
+}
+
+void WinRtAccelerometer::stop()
+{
+ Q_D(WinRtAccelerometer);
+ if (!d->sensor)
+ return;
+ if (!d->token.value)
+ return;
+
+ HRESULT hr = d->sensor->remove_ReadingChanged(d->token);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to detach from reading changed event."
+ << qt_error_string(hr);
+ sensorError(hr);
+ return;
+ }
+ d->sensor->put_ReportInterval(0);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to reset report interval."
+ << qt_error_string(hr);
+ sensorError(hr);
+ return;
+ }
+ d->token.value = 0;
+}
diff --git a/src/plugins/sensors/winrt/winrtaccelerometer.h b/src/plugins/sensors/winrt/winrtaccelerometer.h
new file mode 100644
index 0000000..a71d73b
--- /dev/null
+++ b/src/plugins/sensors/winrt/winrtaccelerometer.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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 WINRTACCELEROMETER_H
+#define WINRTACCELEROMETER_H
+
+#include <QtSensors/QSensorBackend>
+#include <QtCore/QScopedPointer>
+
+QT_USE_NAMESPACE
+
+class WinRtAccelerometerPrivate;
+class WinRtAccelerometer : public QSensorBackend
+{
+ Q_OBJECT
+public:
+ WinRtAccelerometer(QSensor *sensor);
+ ~WinRtAccelerometer();
+
+ void start() Q_DECL_OVERRIDE;
+ void stop() Q_DECL_OVERRIDE;
+
+private:
+ QScopedPointer<WinRtAccelerometerPrivate> d_ptr;
+ Q_DECLARE_PRIVATE(WinRtAccelerometer)
+};
+
+#endif // WINRTACCELEROMETER_H
diff --git a/src/plugins/sensors/winrt/winrtambientlightsensor.cpp b/src/plugins/sensors/winrt/winrtambientlightsensor.cpp
new file mode 100644
index 0000000..18ee641
--- /dev/null
+++ b/src/plugins/sensors/winrt/winrtambientlightsensor.cpp
@@ -0,0 +1,203 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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 "winrtambientlightsensor.h"
+#include "winrtcommon.h"
+
+#include <QtSensors/QAmbientLightSensor>
+
+#include <wrl.h>
+#include <windows.devices.sensors.h>
+using namespace Microsoft::WRL;
+using namespace Microsoft::WRL::Wrappers;
+using namespace ABI::Windows::Foundation;
+using namespace ABI::Windows::Devices::Sensors;
+
+typedef ITypedEventHandler<LightSensor *, LightSensorReadingChangedEventArgs *> LightSensorReadingHandler;
+
+QT_USE_NAMESPACE
+
+class WinRtAmbientLightSensorPrivate
+{
+public:
+ WinRtAmbientLightSensorPrivate(WinRtAmbientLightSensor *p)
+ : minimumReportInterval(0), q(p)
+ {
+ token.value = 0;
+ }
+
+ QAmbientLightReading reading;
+
+ ComPtr<ILightSensor> sensor;
+ EventRegistrationToken token;
+ quint32 minimumReportInterval;
+
+ HRESULT readingChanged(ILightSensor *, ILightSensorReadingChangedEventArgs *args)
+ {
+ ComPtr<ILightSensorReading> value;
+ HRESULT hr = args->get_Reading(&value);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Failed to get light sensor reading" << qt_error_string(hr);
+ return hr;
+ }
+
+ FLOAT lux;
+ hr = value->get_IlluminanceInLux(&lux);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Failed to get illuminance value" << qt_error_string(hr);
+ return hr;
+ }
+
+ DateTime dateTime;
+ hr = value->get_Timestamp(&dateTime);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Failed to get light sensor reading timestamp" << qt_error_string(hr);
+ return hr;
+ }
+
+ // Using same values as BB light sensor
+ if (lux < 10)
+ reading.setLightLevel(QAmbientLightReading::Dark);
+ else if (lux < 80)
+ reading.setLightLevel(QAmbientLightReading::Twilight);
+ else if (lux < 400)
+ reading.setLightLevel(QAmbientLightReading::Light);
+ else if (lux < 2500)
+ reading.setLightLevel(QAmbientLightReading::Bright);
+ else
+ reading.setLightLevel(QAmbientLightReading::Sunny);
+
+ reading.setTimestamp(dateTimeToMsSinceEpoch(dateTime));
+ q->newReadingAvailable();
+ return S_OK;
+ }
+
+private:
+ WinRtAmbientLightSensor *q;
+};
+
+WinRtAmbientLightSensor::WinRtAmbientLightSensor(QSensor *sensor)
+ : QSensorBackend(sensor), d_ptr(new WinRtAmbientLightSensorPrivate(this))
+{
+ Q_D(WinRtAmbientLightSensor);
+ HStringReference classId(RuntimeClass_Windows_Devices_Sensors_LightSensor);
+ ComPtr<ILightSensorStatics> factory;
+ HRESULT hr = RoGetActivationFactory(classId.Get(), IID_PPV_ARGS(&factory));
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to initialize light sensor factory."
+ << qt_error_string(hr);
+ sensorError(hr);
+ return;
+ }
+
+ hr = factory->GetDefault(&d->sensor);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to get default light sensor."
+ << qt_error_string(hr);
+ sensorError(hr);
+ return;
+ }
+
+ hr = d->sensor->get_MinimumReportInterval(&d->minimumReportInterval);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to get the minimum report interval."
+ << qt_error_string(hr);
+ sensorError(hr);
+ return;
+ }
+
+ setReading<QAmbientLightReading>(&d->reading);
+}
+
+WinRtAmbientLightSensor::~WinRtAmbientLightSensor()
+{
+}
+
+void WinRtAmbientLightSensor::start()
+{
+ Q_D(WinRtAmbientLightSensor);
+ if (!d->sensor)
+ return;
+ if (d->token.value)
+ return;
+
+ ComPtr<LightSensorReadingHandler> callback =
+ Callback<LightSensorReadingHandler>(d, &WinRtAmbientLightSensorPrivate::readingChanged);
+ HRESULT hr = d->sensor->add_ReadingChanged(callback.Get(), &d->token);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to attach to reading changed event."
+ << qt_error_string(hr);
+ sensorError(hr);
+ return;
+ }
+ quint32 reportInterval = qMax(d->minimumReportInterval, quint32(1000/sensor()->dataRate()));
+ hr = d->sensor->put_ReportInterval(reportInterval);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to attach to set report interval."
+ << qt_error_string(hr);
+ sensorError(hr);
+ }
+}
+
+void WinRtAmbientLightSensor::stop()
+{
+ Q_D(WinRtAmbientLightSensor);
+ if (!d->sensor)
+ return;
+ if (!d->token.value)
+ return;
+
+ HRESULT hr = d->sensor->remove_ReadingChanged(d->token);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to detach from reading changed event."
+ << qt_error_string(hr);
+ sensorError(hr);
+ return;
+ }
+ d->sensor->put_ReportInterval(0);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to reset report interval."
+ << qt_error_string(hr);
+ sensorError(hr);
+ return;
+ }
+ d->token.value = 0;
+}
diff --git a/src/plugins/sensors/winrt/winrtambientlightsensor.h b/src/plugins/sensors/winrt/winrtambientlightsensor.h
new file mode 100644
index 0000000..c65ae96
--- /dev/null
+++ b/src/plugins/sensors/winrt/winrtambientlightsensor.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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 WINRTAMBIENTLIGHTSENSOR_H
+#define WINRTAMBIENTLIGHTSENSOR_H
+
+#include <QtSensors/QSensorBackend>
+#include <QtCore/QScopedPointer>
+
+QT_USE_NAMESPACE
+
+class WinRtAmbientLightSensorPrivate;
+class WinRtAmbientLightSensor : public QSensorBackend
+{
+ Q_OBJECT
+public:
+ WinRtAmbientLightSensor(QSensor *sensor);
+ ~WinRtAmbientLightSensor();
+
+ void start() Q_DECL_OVERRIDE;
+ void stop() Q_DECL_OVERRIDE;
+
+private:
+ QScopedPointer<WinRtAmbientLightSensorPrivate> d_ptr;
+ Q_DECLARE_PRIVATE(WinRtAmbientLightSensor)
+};
+
+#endif // WINRTAMBIENTLIGHTSENSOR_H
diff --git a/src/plugins/sensors/winrt/winrtcommon.cpp b/src/plugins/sensors/winrt/winrtcommon.cpp
new file mode 100644
index 0000000..29b057f
--- /dev/null
+++ b/src/plugins/sensors/winrt/winrtcommon.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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 "winrtcommon.h"
+
+#include <windows.foundation.h>
+
+QT_USE_NAMESPACE
+
+Q_LOGGING_CATEGORY(lcWinRtSensors, "qt.sensors.winrt")
+
+quint64 dateTimeToMsSinceEpoch(const ABI::Windows::Foundation::DateTime &dateTime)
+{
+ // Convert 100-ns units since 01-01-1601 to ms since 01-01-1970
+ return dateTime.UniversalTime / 10000 - 11644473600000LL;
+}
diff --git a/src/plugins/sensors/winrt/winrtcommon.h b/src/plugins/sensors/winrt/winrtcommon.h
new file mode 100644
index 0000000..a4a0cc6
--- /dev/null
+++ b/src/plugins/sensors/winrt/winrtcommon.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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 WINRTCOMMON_H
+#define WINRTCOMMON_H
+
+#include <QtCore/QLoggingCategory>
+
+namespace ABI {
+ namespace Windows {
+ namespace Foundation {
+ struct DateTime;
+ }
+ }
+}
+
+QT_USE_NAMESPACE
+
+Q_DECLARE_LOGGING_CATEGORY(lcWinRtSensors)
+
+quint64 dateTimeToMsSinceEpoch(const ABI::Windows::Foundation::DateTime &dateTime);
+
+#endif // WINRTCOMMON_H
+
diff --git a/src/plugins/sensors/winrt/winrtcompass.cpp b/src/plugins/sensors/winrt/winrtcompass.cpp
new file mode 100644
index 0000000..bc2430f
--- /dev/null
+++ b/src/plugins/sensors/winrt/winrtcompass.cpp
@@ -0,0 +1,224 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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 "winrtcompass.h"
+#include "winrtcommon.h"
+
+#include <QtSensors/QCompass>
+
+QT_USE_NAMESPACE
+
+#include <wrl.h>
+#include <windows.devices.sensors.h>
+using namespace Microsoft::WRL;
+using namespace Microsoft::WRL::Wrappers;
+using namespace ABI::Windows::Foundation;
+using namespace ABI::Windows::Devices::Sensors;
+
+typedef ITypedEventHandler<Compass *, CompassReadingChangedEventArgs *> CompassReadingHandler;
+
+QT_USE_NAMESPACE
+
+class WinRtCompassPrivate
+{
+public:
+ WinRtCompassPrivate(WinRtCompass *p)
+ : minimumReportInterval(0), q(p)
+ {
+ token.value = 0;
+ }
+
+ QCompassReading reading;
+
+ ComPtr<ICompass> sensor;
+ EventRegistrationToken token;
+ quint32 minimumReportInterval;
+
+ HRESULT readingChanged(ICompass *, ICompassReadingChangedEventArgs *args)
+ {
+ ComPtr<ICompassReading> value;
+ HRESULT hr = args->get_Reading(&value);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Failed to get light sensor reading." << qt_error_string(hr);
+ return hr;
+ }
+
+ DOUBLE heading;
+ hr = value->get_HeadingMagneticNorth(&heading);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Failed to get compass heading." << qt_error_string(hr);
+ return hr;
+ }
+
+ DateTime dateTime;
+ hr = value->get_Timestamp(&dateTime);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Failed to get compass reading timestamp." << qt_error_string(hr);
+ return hr;
+ }
+#ifndef Q_OS_WINPHONE // Windows Phone doesn't implement the accuracy interface
+ ComPtr<ICompassReadingHeadingAccuracy> accuracyReading;
+ hr = value.As(&accuracyReading);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Failed to cast compass reading to obtain accuracy." << qt_error_string(hr);
+ return hr;
+ }
+
+ MagnetometerAccuracy accuracy;
+ hr = accuracyReading->get_HeadingAccuracy(&accuracy);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Failed to get compass reading accuracy." << qt_error_string(hr);
+ return hr;
+ }
+
+ switch (accuracy) {
+ default:
+ case MagnetometerAccuracy_Unknown:
+ reading.setCalibrationLevel(0.00);
+ break;
+ case MagnetometerAccuracy_Unreliable:
+ reading.setCalibrationLevel(0.33);
+ break;
+ case MagnetometerAccuracy_Approximate:
+ reading.setCalibrationLevel(0.67);
+ break;
+ case MagnetometerAccuracy_High:
+ reading.setCalibrationLevel(1.00);
+ break;
+ }
+#endif
+ reading.setAzimuth(heading);
+ reading.setTimestamp(dateTimeToMsSinceEpoch(dateTime));
+ q->newReadingAvailable();
+ return S_OK;
+ }
+
+private:
+ WinRtCompass *q;
+};
+
+WinRtCompass::WinRtCompass(QSensor *sensor)
+ : QSensorBackend(sensor), d_ptr(new WinRtCompassPrivate(this))
+{
+ Q_D(WinRtCompass);
+ HStringReference classId(RuntimeClass_Windows_Devices_Sensors_Compass);
+ ComPtr<ICompassStatics> factory;
+ HRESULT hr = RoGetActivationFactory(classId.Get(), IID_PPV_ARGS(&factory));
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to initialize light sensor factory."
+ << qt_error_string(hr);
+ sensorError(hr);
+ return;
+ }
+
+ hr = factory->GetDefault(&d->sensor);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to get default light sensor."
+ << qt_error_string(hr);
+ sensorError(hr);
+ return;
+ }
+
+ hr = d->sensor->get_MinimumReportInterval(&d->minimumReportInterval);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to get the minimum report interval."
+ << qt_error_string(hr);
+ sensorError(hr);
+ return;
+ }
+
+ setReading<QCompassReading>(&d->reading);
+}
+
+WinRtCompass::~WinRtCompass()
+{
+}
+
+void WinRtCompass::start()
+{
+ Q_D(WinRtCompass);
+ if (!d->sensor)
+ return;
+ if (d->token.value)
+ return;
+
+ ComPtr<CompassReadingHandler> callback =
+ Callback<CompassReadingHandler>(d, &WinRtCompassPrivate::readingChanged);
+ HRESULT hr = d->sensor->add_ReadingChanged(callback.Get(), &d->token);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to attach to reading changed event."
+ << qt_error_string(hr);
+ sensorError(hr);
+ return;
+ }
+ quint32 reportInterval = qMax(d->minimumReportInterval, quint32(1000/sensor()->dataRate()));
+ hr = d->sensor->put_ReportInterval(reportInterval);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to attach to set report interval."
+ << qt_error_string(hr);
+ sensorError(hr);
+ }
+}
+
+void WinRtCompass::stop()
+{
+ Q_D(WinRtCompass);
+ if (!d->sensor)
+ return;
+ if (!d->token.value)
+ return;
+
+ HRESULT hr = d->sensor->remove_ReadingChanged(d->token);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to detach from reading changed event."
+ << qt_error_string(hr);
+ sensorError(hr);
+ return;
+ }
+ d->sensor->put_ReportInterval(0);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to reset report interval."
+ << qt_error_string(hr);
+ sensorError(hr);
+ return;
+ }
+ d->token.value = 0;
+}
diff --git a/src/plugins/sensors/winrt/winrtcompass.h b/src/plugins/sensors/winrt/winrtcompass.h
new file mode 100644
index 0000000..479ab75
--- /dev/null
+++ b/src/plugins/sensors/winrt/winrtcompass.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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 WINRTCOMPASS_H
+#define WINRTCOMPASS_H
+
+#include <QtSensors/QSensorBackend>
+#include <QtCore/QScopedPointer>
+
+QT_USE_NAMESPACE
+
+class WinRtCompassPrivate;
+class WinRtCompass : public QSensorBackend
+{
+ Q_OBJECT
+public:
+ WinRtCompass(QSensor *sensor);
+ ~WinRtCompass();
+
+ void start() Q_DECL_OVERRIDE;
+ void stop() Q_DECL_OVERRIDE;
+
+private:
+ QScopedPointer<WinRtCompassPrivate> d_ptr;
+ Q_DECLARE_PRIVATE(WinRtCompass)
+};
+
+#endif // WINRTCOMPASS_H
diff --git a/src/plugins/sensors/winrt/winrtgyroscope.cpp b/src/plugins/sensors/winrt/winrtgyroscope.cpp
new file mode 100644
index 0000000..dec6512
--- /dev/null
+++ b/src/plugins/sensors/winrt/winrtgyroscope.cpp
@@ -0,0 +1,201 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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 "winrtgyroscope.h"
+#include "winrtcommon.h"
+
+#include <QtSensors/QGyroscope>
+
+#include <wrl.h>
+#include <windows.devices.sensors.h>
+using namespace Microsoft::WRL;
+using namespace Microsoft::WRL::Wrappers;
+using namespace ABI::Windows::Foundation;
+using namespace ABI::Windows::Devices::Sensors;
+
+typedef ITypedEventHandler<Gyrometer *, GyrometerReadingChangedEventArgs *> InclinometerReadingHandler;
+
+QT_USE_NAMESPACE
+
+class WinRtGyroscopePrivate
+{
+public:
+ WinRtGyroscopePrivate(WinRtGyroscope *p)
+ : minimumReportInterval(0), q(p)
+ {
+ token.value = 0;
+ }
+
+ QGyroscopeReading reading;
+
+ ComPtr<IGyrometer> sensor;
+ EventRegistrationToken token;
+ quint32 minimumReportInterval;
+
+ HRESULT readingChanged(IGyrometer *, IGyrometerReadingChangedEventArgs *args)
+ {
+ ComPtr<IGyrometerReading> value;
+ HRESULT hr = args->get_Reading(&value);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Failed to get gyroscope reading" << qt_error_string(hr);
+ return hr;
+ }
+
+ DOUBLE x;
+ hr = value->get_AngularVelocityX(&x);
+ if (FAILED(hr))
+ qCWarning(lcWinRtSensors) << "Failed to get gyroscope X" << qt_error_string(hr);
+
+ DOUBLE y;
+ hr = value->get_AngularVelocityY(&y);
+ if (FAILED(hr))
+ qCWarning(lcWinRtSensors) << "Failed to get gyroscope Y" << qt_error_string(hr);
+
+ DOUBLE z;
+ hr = value->get_AngularVelocityZ(&z);
+ if (FAILED(hr))
+ qCWarning(lcWinRtSensors) << "Failed to get gyroscope Z" << qt_error_string(hr);
+
+ DateTime dateTime;
+ hr = value->get_Timestamp(&dateTime);
+ if (FAILED(hr))
+ qCWarning(lcWinRtSensors) << "Failed to get gyroscope timestamp" << qt_error_string(hr);
+
+ reading.setX(x);
+ reading.setY(y);
+ reading.setZ(z);
+ reading.setTimestamp(dateTimeToMsSinceEpoch(dateTime));
+ q->newReadingAvailable();
+
+ return S_OK;
+ }
+
+private:
+ WinRtGyroscope *q;
+};
+
+WinRtGyroscope::WinRtGyroscope(QSensor *sensor)
+ : QSensorBackend(sensor), d_ptr(new WinRtGyroscopePrivate(this))
+{
+ Q_D(WinRtGyroscope);
+ HStringReference classId(RuntimeClass_Windows_Devices_Sensors_Gyrometer);
+ ComPtr<IGyrometerStatics> factory;
+ HRESULT hr = RoGetActivationFactory(classId.Get(), IID_PPV_ARGS(&factory));
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to initialize gyroscope sensor factory."
+ << qt_error_string(hr);
+ sensorError(hr);
+ return;
+ }
+
+ hr = factory->GetDefault(&d->sensor);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to get default gyroscope sensor."
+ << qt_error_string(hr);
+ sensorError(hr);
+ return;
+ }
+
+ hr = d->sensor->get_MinimumReportInterval(&d->minimumReportInterval);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to get the minimum report interval."
+ << qt_error_string(hr);
+ sensorError(hr);
+ return;
+ }
+
+ setReading<QGyroscopeReading>(&d->reading);
+}
+
+WinRtGyroscope::~WinRtGyroscope()
+{
+}
+
+void WinRtGyroscope::start()
+{
+ Q_D(WinRtGyroscope);
+ if (!d->sensor)
+ return;
+ if (d->token.value)
+ return;
+
+ ComPtr<InclinometerReadingHandler> callback =
+ Callback<InclinometerReadingHandler>(d, &WinRtGyroscopePrivate::readingChanged);
+ HRESULT hr = d->sensor->add_ReadingChanged(callback.Get(), &d->token);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to attach to reading changed event."
+ << qt_error_string(hr);
+ sensorError(hr);
+ return;
+ }
+ quint32 reportInterval = qMax(d->minimumReportInterval, quint32(1000/sensor()->dataRate()));
+ hr = d->sensor->put_ReportInterval(reportInterval);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to attach to set report interval."
+ << qt_error_string(hr);
+ sensorError(hr);
+ }
+}
+
+void WinRtGyroscope::stop()
+{
+ Q_D(WinRtGyroscope);
+ if (!d->sensor)
+ return;
+ if (!d->token.value)
+ return;
+
+ HRESULT hr = d->sensor->remove_ReadingChanged(d->token);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to detach from reading changed event."
+ << qt_error_string(hr);
+ sensorError(hr);
+ return;
+ }
+ d->sensor->put_ReportInterval(0);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to reset report interval."
+ << qt_error_string(hr);
+ sensorError(hr);
+ return;
+ }
+ d->token.value = 0;
+}
diff --git a/src/plugins/sensors/winrt/winrtgyroscope.h b/src/plugins/sensors/winrt/winrtgyroscope.h
new file mode 100644
index 0000000..6275ec8
--- /dev/null
+++ b/src/plugins/sensors/winrt/winrtgyroscope.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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 WINRTGYROSCOPE_H
+#define WINRTGYROSCOPE_H
+
+#include <QtSensors/QSensorBackend>
+#include <QtCore/QScopedPointer>
+
+QT_USE_NAMESPACE
+
+class WinRtGyroscopePrivate;
+class WinRtGyroscope : public QSensorBackend
+{
+ Q_OBJECT
+public:
+ WinRtGyroscope(QSensor *sensor);
+ ~WinRtGyroscope();
+
+ bool isFeatureSupported(QSensor::Feature feature) const Q_DECL_OVERRIDE
+ {
+ if (feature == QSensor::AxesOrientation || feature == QSensor::AccelerationMode)
+ return true;
+ return false;
+ }
+
+ void start() Q_DECL_OVERRIDE;
+ void stop() Q_DECL_OVERRIDE;
+
+private:
+ QScopedPointer<WinRtGyroscopePrivate> d_ptr;
+ Q_DECLARE_PRIVATE(WinRtGyroscope)
+};
+
+#endif // WINRTGYROSCOPE_H
diff --git a/src/plugins/sensors/winrt/winrtorientationsensor.cpp b/src/plugins/sensors/winrt/winrtorientationsensor.cpp
new file mode 100644
index 0000000..6d85e51
--- /dev/null
+++ b/src/plugins/sensors/winrt/winrtorientationsensor.cpp
@@ -0,0 +1,188 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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 "winrtorientationsensor.h"
+#include "winrtcommon.h"
+
+#include <QtSensors/QOrientationSensor>
+
+QT_USE_NAMESPACE
+
+#include <wrl.h>
+#include <windows.devices.sensors.h>
+using namespace Microsoft::WRL;
+using namespace Microsoft::WRL::Wrappers;
+using namespace ABI::Windows::Foundation;
+using namespace ABI::Windows::Devices::Sensors;
+
+typedef ITypedEventHandler<SimpleOrientationSensor *, SimpleOrientationSensorOrientationChangedEventArgs *> SimpleOrientationReadingHandler;
+
+QT_USE_NAMESPACE
+
+class WinRtOrientationSensorPrivate
+{
+public:
+ WinRtOrientationSensorPrivate(WinRtOrientationSensor *p) : q(p)
+ {
+ token.value = 0;
+ }
+
+ QOrientationReading reading;
+
+ ComPtr<ISimpleOrientationSensor> sensor;
+ EventRegistrationToken token;
+
+ HRESULT readingChanged(ISimpleOrientationSensor *,
+ ISimpleOrientationSensorOrientationChangedEventArgs *args)
+ {
+ SimpleOrientation value;
+ HRESULT hr = args->get_Orientation(&value);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Failed to get orientation value." << qt_error_string(hr);
+ return hr;
+ }
+
+ DateTime dateTime;
+ hr = args->get_Timestamp(&dateTime);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Failed to get compass reading timestamp." << qt_error_string(hr);
+ return hr;
+ }
+
+ switch (value) {
+ default:
+ reading.setOrientation(QOrientationReading::Undefined);
+ break;
+ case SimpleOrientation_NotRotated:
+ reading.setOrientation(QOrientationReading::TopUp);
+ break;
+ case SimpleOrientation_Rotated90DegreesCounterclockwise:
+ reading.setOrientation(QOrientationReading::RightUp);
+ break;
+ case SimpleOrientation_Rotated180DegreesCounterclockwise:
+ reading.setOrientation(QOrientationReading::TopDown);
+ break;
+ case SimpleOrientation_Rotated270DegreesCounterclockwise:
+ reading.setOrientation(QOrientationReading::LeftUp);
+ break;
+ case SimpleOrientation_Faceup:
+ reading.setOrientation(QOrientationReading::FaceUp);
+ break;
+ case SimpleOrientation_Facedown:
+ reading.setOrientation(QOrientationReading::FaceDown);
+ break;
+ }
+
+ reading.setTimestamp(dateTimeToMsSinceEpoch(dateTime));
+ q->newReadingAvailable();
+ return S_OK;
+ }
+
+private:
+ WinRtOrientationSensor *q;
+};
+
+WinRtOrientationSensor::WinRtOrientationSensor(QSensor *sensor)
+ : QSensorBackend(sensor), d_ptr(new WinRtOrientationSensorPrivate(this))
+{
+ Q_D(WinRtOrientationSensor);
+ HStringReference classId(RuntimeClass_Windows_Devices_Sensors_SimpleOrientationSensor);
+ ComPtr<ISimpleOrientationSensorStatics> factory;
+ HRESULT hr = RoGetActivationFactory(classId.Get(), IID_PPV_ARGS(&factory));
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to initialize orientation sensor factory."
+ << qt_error_string(hr);
+ sensorError(hr);
+ return;
+ }
+
+ hr = factory->GetDefault(&d->sensor);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to get default orientation sensor."
+ << qt_error_string(hr);
+ sensorError(hr);
+ return;
+ }
+
+ setReading<QOrientationReading>(&d->reading);
+}
+
+WinRtOrientationSensor::~WinRtOrientationSensor()
+{
+}
+
+void WinRtOrientationSensor::start()
+{
+ Q_D(WinRtOrientationSensor);
+ if (!d->sensor)
+ return;
+ if (d->token.value)
+ return;
+
+ ComPtr<SimpleOrientationReadingHandler> callback =
+ Callback<SimpleOrientationReadingHandler>(d, &WinRtOrientationSensorPrivate::readingChanged);
+ HRESULT hr = d->sensor->add_OrientationChanged(callback.Get(), &d->token);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to attach to reading changed event."
+ << qt_error_string(hr);
+ sensorError(hr);
+ return;
+ }
+}
+
+void WinRtOrientationSensor::stop()
+{
+ Q_D(WinRtOrientationSensor);
+ if (!d->sensor)
+ return;
+ if (!d->token.value)
+ return;
+
+ HRESULT hr = d->sensor->remove_OrientationChanged(d->token);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to detach from reading changed event."
+ << qt_error_string(hr);
+ sensorError(hr);
+ return;
+ }
+
+ d->token.value = 0;
+}
diff --git a/src/plugins/sensors/winrt/winrtorientationsensor.h b/src/plugins/sensors/winrt/winrtorientationsensor.h
new file mode 100644
index 0000000..31ecf0a
--- /dev/null
+++ b/src/plugins/sensors/winrt/winrtorientationsensor.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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 WINRTORIENTATIONSENSOR_H
+#define WINRTORIENTATIONSENSOR_H
+
+#include <QtSensors/QSensorBackend>
+#include <QtCore/QScopedPointer>
+
+QT_USE_NAMESPACE
+
+class WinRtOrientationSensorPrivate;
+class WinRtOrientationSensor : public QSensorBackend
+{
+ Q_OBJECT
+public:
+ WinRtOrientationSensor(QSensor *sensor);
+ ~WinRtOrientationSensor();
+
+ void start() Q_DECL_OVERRIDE;
+ void stop() Q_DECL_OVERRIDE;
+
+private:
+ QScopedPointer<WinRtOrientationSensorPrivate> d_ptr;
+ Q_DECLARE_PRIVATE(WinRtOrientationSensor)
+};
+
+#endif // WINRTORIENTATIONSENSOR_H
diff --git a/src/plugins/sensors/winrt/winrtrotationsensor.cpp b/src/plugins/sensors/winrt/winrtrotationsensor.cpp
new file mode 100644
index 0000000..e4e3edc
--- /dev/null
+++ b/src/plugins/sensors/winrt/winrtrotationsensor.cpp
@@ -0,0 +1,199 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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 "winrtrotationsensor.h"
+#include "winrtcommon.h"
+
+#include <QtSensors/QRotationSensor>
+
+#include <wrl.h>
+#include <windows.devices.sensors.h>
+using namespace Microsoft::WRL;
+using namespace Microsoft::WRL::Wrappers;
+using namespace ABI::Windows::Foundation;
+using namespace ABI::Windows::Devices::Sensors;
+
+typedef ITypedEventHandler<Inclinometer *, InclinometerReadingChangedEventArgs *> InclinometerReadingHandler;
+
+QT_USE_NAMESPACE
+
+class WinRtRotationSensorPrivate
+{
+public:
+ WinRtRotationSensorPrivate(WinRtRotationSensor *p)
+ : minimumReportInterval(0), q(p)
+ {
+ token.value = 0;
+ }
+
+ QRotationReading reading;
+
+ ComPtr<IInclinometer> sensor;
+ EventRegistrationToken token;
+ quint32 minimumReportInterval;
+
+ HRESULT readingChanged(IInclinometer *, IInclinometerReadingChangedEventArgs *args)
+ {
+ ComPtr<IInclinometerReading> value;
+ HRESULT hr = args->get_Reading(&value);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Failed to get rotation reading" << qt_error_string(hr);
+ return hr;
+ }
+
+ FLOAT x;
+ hr = value->get_PitchDegrees(&x);
+ if (FAILED(hr))
+ qCWarning(lcWinRtSensors) << "Failed to get rotation X" << qt_error_string(hr);
+
+ FLOAT y;
+ hr = value->get_RollDegrees(&y);
+ if (FAILED(hr))
+ qCWarning(lcWinRtSensors) << "Failed to get rotation Y" << qt_error_string(hr);
+
+ FLOAT z;
+ hr = value->get_YawDegrees(&z);
+ if (FAILED(hr))
+ qCWarning(lcWinRtSensors) << "Failed to get rotation Z" << qt_error_string(hr);
+
+ DateTime dateTime;
+ hr = value->get_Timestamp(&dateTime);
+ if (FAILED(hr))
+ qCWarning(lcWinRtSensors) << "Failed to get rotation timestamp" << qt_error_string(hr);
+
+ reading.setFromEuler(x, y, z);
+ reading.setTimestamp(dateTimeToMsSinceEpoch(dateTime));
+ q->newReadingAvailable();
+
+ return S_OK;
+ }
+
+private:
+ WinRtRotationSensor *q;
+};
+
+WinRtRotationSensor::WinRtRotationSensor(QSensor *sensor)
+ : QSensorBackend(sensor), d_ptr(new WinRtRotationSensorPrivate(this))
+{
+ Q_D(WinRtRotationSensor);
+ HStringReference classId(RuntimeClass_Windows_Devices_Sensors_Inclinometer);
+ ComPtr<IInclinometerStatics> factory;
+ HRESULT hr = RoGetActivationFactory(classId.Get(), IID_PPV_ARGS(&factory));
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to initialize rotation sensor factory."
+ << qt_error_string(hr);
+ sensorError(hr);
+ return;
+ }
+
+ hr = factory->GetDefault(&d->sensor);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to get default rotation sensor."
+ << qt_error_string(hr);
+ sensorError(hr);
+ return;
+ }
+
+ hr = d->sensor->get_MinimumReportInterval(&d->minimumReportInterval);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to get the minimum report interval."
+ << qt_error_string(hr);
+ sensorError(hr);
+ return;
+ }
+
+ setReading<QRotationReading>(&d->reading);
+}
+
+WinRtRotationSensor::~WinRtRotationSensor()
+{
+}
+
+void WinRtRotationSensor::start()
+{
+ Q_D(WinRtRotationSensor);
+ if (!d->sensor)
+ return;
+ if (d->token.value)
+ return;
+
+ ComPtr<InclinometerReadingHandler> callback =
+ Callback<InclinometerReadingHandler>(d, &WinRtRotationSensorPrivate::readingChanged);
+ HRESULT hr = d->sensor->add_ReadingChanged(callback.Get(), &d->token);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to attach to reading changed event."
+ << qt_error_string(hr);
+ sensorError(hr);
+ return;
+ }
+ quint32 reportInterval = qMax(d->minimumReportInterval, quint32(1000/sensor()->dataRate()));
+ hr = d->sensor->put_ReportInterval(reportInterval);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to attach to set report interval."
+ << qt_error_string(hr);
+ sensorError(hr);
+ }
+}
+
+void WinRtRotationSensor::stop()
+{
+ Q_D(WinRtRotationSensor);
+ if (!d->sensor)
+ return;
+ if (!d->token.value)
+ return;
+
+ HRESULT hr = d->sensor->remove_ReadingChanged(d->token);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to detach from reading changed event."
+ << qt_error_string(hr);
+ sensorError(hr);
+ return;
+ }
+ d->sensor->put_ReportInterval(0);
+ if (FAILED(hr)) {
+ qCWarning(lcWinRtSensors) << "Unable to reset report interval."
+ << qt_error_string(hr);
+ sensorError(hr);
+ return;
+ }
+ d->token.value = 0;
+}
diff --git a/src/plugins/sensors/winrt/winrtrotationsensor.h b/src/plugins/sensors/winrt/winrtrotationsensor.h
new file mode 100644
index 0000000..21d823c
--- /dev/null
+++ b/src/plugins/sensors/winrt/winrtrotationsensor.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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 WINRTROTATIONSENSOR_H
+#define WINRTROTATIONSENSOR_H
+
+#include <QtSensors/QSensorBackend>
+#include <QtCore/QScopedPointer>
+
+QT_USE_NAMESPACE
+
+class WinRtRotationSensorPrivate;
+class WinRtRotationSensor : public QSensorBackend
+{
+ Q_OBJECT
+public:
+ WinRtRotationSensor(QSensor *sensor);
+ ~WinRtRotationSensor();
+
+ bool isFeatureSupported(QSensor::Feature feature) const Q_DECL_OVERRIDE
+ {
+ if (feature == QSensor::AxesOrientation || feature == QSensor::AccelerationMode)
+ return true;
+ return false;
+ }
+
+ void start() Q_DECL_OVERRIDE;
+ void stop() Q_DECL_OVERRIDE;
+
+private:
+ QScopedPointer<WinRtRotationSensorPrivate> d_ptr;
+ Q_DECLARE_PRIVATE(WinRtRotationSensor)
+};
+
+#endif // WINRTROTATIONSENSOR_H
diff --git a/src/sensors/doc/src/compatmap.qdoc b/src/sensors/doc/src/compatmap.qdoc
index a287a82..622069b 100644
--- a/src/sensors/doc/src/compatmap.qdoc
+++ b/src/sensors/doc/src/compatmap.qdoc
@@ -57,6 +57,8 @@
<td><b>Android</b></td>
<td><b>Linux</b></td>
<td><b>iOS</b></td>
+ <td><b>Windows 8/RT</b></td>
+ <td><b>Windows Phone</b></td>
<td><b>Generic</b></td>
<td><b>Sensorfw</b></td>
</tr>
@@ -66,6 +68,8 @@
<td bgcolor="green"></td>
<td bgcolor="green"></td>
<td bgcolor="green"></td>
+ <td bgcolor="green"></td>
+ <td bgcolor="green"></td>
<td bgcolor="gray"></td>
<td bgcolor="green"></td>
</tr>
@@ -77,6 +81,8 @@
<td bgcolor="gray"></td>
<td bgcolor="gray"></td>
<td bgcolor="gray"></td>
+ <td bgcolor="gray"></td>
+ <td bgcolor="gray"></td>
</tr>
<tr>
<td nowrap="nowrap">Ambient Light Sensor</td>
@@ -84,6 +90,8 @@
<td bgcolor="gray"></td>
<td bgcolor="gray"></td>
<td bgcolor="gray"></td>
+ <td bgcolor="green"></td>
+ <td bgcolor="gray"></td>
<td bgcolor="gray"></td>
<td bgcolor="green"></td>
</tr>
@@ -95,6 +103,8 @@
<td bgcolor="gray"></td>
<td bgcolor="gray"></td>
<td bgcolor="gray"></td>
+ <td bgcolor="gray"></td>
+ <td bgcolor="gray"></td>
</tr>
<tr>
<td nowrap="nowrap">Compass</td>
@@ -102,6 +112,8 @@
<td bgcolor="gray"></td>
<td bgcolor="gray"></td>
<td bgcolor="green"></td>
+ <td bgcolor="green"></td>
+ <td bgcolor="green"></td>
<td bgcolor="gray"></td>
<td bgcolor="green"></td>
</tr>
@@ -111,6 +123,8 @@
<td bgcolor="green"></td>
<td bgcolor="gray"></td>
<td bgcolor="green"></td>
+ <td bgcolor="green"></td>
+ <td bgcolor="green"></td>
<td bgcolor="gray"></td>
<td bgcolor="green"></td>
</tr>
@@ -122,6 +136,8 @@
<td bgcolor="gray"></td>
<td bgcolor="gray"></td>
<td bgcolor="gray"></td>
+ <td bgcolor="gray"></td>
+ <td bgcolor="gray"></td>
</tr>
<tr>
<td nowrap="nowrap">IR Proximity Sensor</td>
@@ -130,6 +146,8 @@
<td bgcolor="gray"></td>
<td bgcolor="gray"></td>
<td bgcolor="gray"></td>
+ <td bgcolor="gray"></td>
+ <td bgcolor="gray"></td>
<td bgcolor="green"></td>
</tr>
<tr>
@@ -139,6 +157,8 @@
<td bgcolor="gray"></td>
<td bgcolor="gray"></td>
<td bgcolor="gray"></td>
+ <td bgcolor="gray"></td>
+ <td bgcolor="gray"></td>
<td bgcolor="green"></td>
</tr>
<tr>
@@ -148,6 +168,8 @@
<td bgcolor="gray"></td>
<td bgcolor="green"></td>
<td bgcolor="gray"></td>
+ <td bgcolor="gray"></td>
+ <td bgcolor="gray"></td>
<td bgcolor="green"></td>
</tr>
<tr>
@@ -157,6 +179,8 @@
<td bgcolor="gray"></td>
<td bgcolor="gray"></td>
<td bgcolor="green"></td>
+ <td bgcolor="gray"></td>
+ <td bgcolor="green"></td>
<td bgcolor="green"></td>
</tr>
<tr>
@@ -167,6 +191,8 @@
<td bgcolor="gray"></td>
<td bgcolor="gray"></td>
<td bgcolor="gray"></td>
+ <td bgcolor="gray"></td>
+ <td bgcolor="gray"></td>
</tr>
<tr>
<td nowrap="nowrap">Proximity Sensor</td>
@@ -175,6 +201,8 @@
<td bgcolor="gray"></td>
<td bgcolor="green"></td>
<td bgcolor="gray"></td>
+ <td bgcolor="gray"></td>
+ <td bgcolor="gray"></td>
<td bgcolor="green"></td>
</tr>
<tr>
@@ -185,6 +213,8 @@
<td bgcolor="gray"></td>
<td bgcolor="green"></td>
<td bgcolor="green"></td>
+ <td bgcolor="green"></td>
+ <td bgcolor="green"></td>
</tr>
<tr>
<td nowrap="nowrap">Tap Sensor</td>
@@ -194,6 +224,8 @@
<td bgcolor="gray"></td>
<td bgcolor="gray"></td>
<td bgcolor="gray"></td>
+ <td bgcolor="gray"></td>
+ <td bgcolor="gray"></td>
</tr>
<tr>
<td nowrap="nowrap">Tilt Sensor</td>
@@ -201,6 +233,8 @@
<td bgcolor="gray"></td>
<td bgcolor="gray"></td>
<td bgcolor="gray"></td>
+ <td bgcolor="gray"></td>
+ <td bgcolor="gray"></td>
<td bgcolor="green"></td>
<td bgcolor="gray"></td>
</tr>
@@ -211,6 +245,8 @@
<td bgcolor="gray"></td>
<td bgcolor="gray"></td>
<td bgcolor="gray"></td>
+ <td bgcolor="gray"></td>
+ <td bgcolor="gray"></td>
<td bgcolor="green"></td>
</tr>
</table>