From 9c69ffa9a60b8d573491b71ed4187140e827724b Mon Sep 17 00:00:00 2001 From: Tomasz Olszak Date: Fri, 9 Aug 2013 21:12:33 +0000 Subject: Added tizen sensors plugin Change-Id: Ib455e5c53be47ae4910f56b5b714a4a44e6a8fb3 Reviewed-by: Witold Wysota Reviewed-by: Tomasz Olszak --- src/plugins/sensors/sensors.pro | 5 + src/plugins/sensors/tizen/main.cpp | 116 +++++++++++ src/plugins/sensors/tizen/plugin.json | 1 + src/plugins/sensors/tizen/tizen.pro | 31 +++ src/plugins/sensors/tizen/tizenaccelerometer.cpp | 104 ++++++++++ src/plugins/sensors/tizen/tizenaccelerometer.h | 65 ++++++ src/plugins/sensors/tizen/tizencompass.cpp | 123 +++++++++++ src/plugins/sensors/tizen/tizencompass.h | 64 ++++++ .../sensors/tizen/tizendeviceorientation.cpp | 103 ++++++++++ src/plugins/sensors/tizen/tizendeviceorientation.h | 66 ++++++ src/plugins/sensors/tizen/tizengravity.cpp | 104 ++++++++++ src/plugins/sensors/tizen/tizengravity.h | 63 ++++++ src/plugins/sensors/tizen/tizengyroscope.cpp | 104 ++++++++++ src/plugins/sensors/tizen/tizengyroscope.h | 63 ++++++ src/plugins/sensors/tizen/tizenlight.cpp | 103 ++++++++++ src/plugins/sensors/tizen/tizenlight.h | 62 ++++++ src/plugins/sensors/tizen/tizenmagnetometer.cpp | 124 ++++++++++++ src/plugins/sensors/tizen/tizenmagnetometer.h | 64 ++++++ src/plugins/sensors/tizen/tizenproximity.cpp | 106 ++++++++++ src/plugins/sensors/tizen/tizenproximity.h | 65 ++++++ src/plugins/sensors/tizen/tizensensorbase.cpp | 225 +++++++++++++++++++++ src/plugins/sensors/tizen/tizensensorbase.h | 78 +++++++ 22 files changed, 1839 insertions(+) create mode 100644 src/plugins/sensors/tizen/main.cpp create mode 100644 src/plugins/sensors/tizen/plugin.json create mode 100644 src/plugins/sensors/tizen/tizen.pro create mode 100644 src/plugins/sensors/tizen/tizenaccelerometer.cpp create mode 100644 src/plugins/sensors/tizen/tizenaccelerometer.h create mode 100644 src/plugins/sensors/tizen/tizencompass.cpp create mode 100644 src/plugins/sensors/tizen/tizencompass.h create mode 100644 src/plugins/sensors/tizen/tizendeviceorientation.cpp create mode 100644 src/plugins/sensors/tizen/tizendeviceorientation.h create mode 100644 src/plugins/sensors/tizen/tizengravity.cpp create mode 100644 src/plugins/sensors/tizen/tizengravity.h create mode 100644 src/plugins/sensors/tizen/tizengyroscope.cpp create mode 100644 src/plugins/sensors/tizen/tizengyroscope.h create mode 100644 src/plugins/sensors/tizen/tizenlight.cpp create mode 100644 src/plugins/sensors/tizen/tizenlight.h create mode 100644 src/plugins/sensors/tizen/tizenmagnetometer.cpp create mode 100644 src/plugins/sensors/tizen/tizenmagnetometer.h create mode 100644 src/plugins/sensors/tizen/tizenproximity.cpp create mode 100644 src/plugins/sensors/tizen/tizenproximity.h create mode 100644 src/plugins/sensors/tizen/tizensensorbase.cpp create mode 100644 src/plugins/sensors/tizen/tizensensorbase.h diff --git a/src/plugins/sensors/sensors.pro b/src/plugins/sensors/sensors.pro index a66ed4a..39d2332 100644 --- a/src/plugins/sensors/sensors.pro +++ b/src/plugins/sensors/sensors.pro @@ -20,6 +20,10 @@ winrt { isEmpty(SENSORS_PLUGINS): SENSORS_PLUGINS = winrt generic } +tizen { + isEmpty(SENSORS_PLUGINS): SENSORS_PLUGINS = tizen generic +} + qtHaveModule(simulator) { isEmpty(SENSORS_PLUGINS): SENSORS_PLUGINS = simulator generic } @@ -37,3 +41,4 @@ isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, android):android:SUBDIRS += a 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 +isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, tizen):tizen:SUBDIRS += tizen diff --git a/src/plugins/sensors/tizen/main.cpp b/src/plugins/sensors/tizen/main.cpp new file mode 100644 index 0000000..a09104c --- /dev/null +++ b/src/plugins/sensors/tizen/main.cpp @@ -0,0 +1,116 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Tomasz Olszak. +** 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 +#include +#include +#include "tizenaccelerometer.h" +#include "tizendeviceorientation.h" +#include "tizencompass.h" +#include "tizenlight.h" +#include "tizengravity.h" +#include "tizenmagnetometer.h" +#include "tizengyroscope.h" +#include "tizenproximity.h" + +class TizenSensorPlugin : 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() + { + if (TizenSensorBase::isTizenSensorSupported(SENSOR_ACCELEROMETER)) { + QSensorManager::registerBackend(QAccelerometer::type, TizenAccelerometer::id, this); + QSensorManager::setDefaultBackend(QAccelerometer::type, TizenAccelerometer::id); + } + if (TizenSensorBase::isTizenSensorSupported(SENSOR_DEVICE_ORIENTATION)) { + QSensorManager::registerBackend(QRotationSensor::type, TizenDeviceOrientation::id, this); + QSensorManager::setDefaultBackend(QRotationSensor::type, TizenDeviceOrientation::id); + QSensorManager::registerBackend(QCompass::type, TizenCompass::id, this); + QSensorManager::setDefaultBackend(QCompass::type, TizenCompass::id); + } + if (TizenSensorBase::isTizenSensorSupported(SENSOR_LIGHT)) { + QSensorManager::registerBackend(QLightSensor::type, TizenLight::id, this); + QSensorManager::setDefaultBackend(QLightSensor::type, TizenLight::id); + } + if (TizenSensorBase::isTizenSensorSupported(SENSOR_GRAVITY)) { + QSensorManager::registerBackend(QAccelerometer::type, TizenGravity::id, this); + } + if (TizenSensorBase::isTizenSensorSupported(SENSOR_MAGNETIC)) { + QSensorManager::registerBackend(QMagnetometer::type, TizenMagnetometer::id, this); + QSensorManager::setDefaultBackend(QMagnetometer::type, TizenMagnetometer::id); + } + if (TizenSensorBase::isTizenSensorSupported(SENSOR_GYROSCOPE)) { + QSensorManager::registerBackend(QGyroscope::type, TizenGyroscope::id, this); + QSensorManager::setDefaultBackend(QGyroscope::type, TizenGyroscope::id); + } + if (TizenSensorBase::isTizenSensorSupported(SENSOR_PROXIMITY)) { + QSensorManager::registerBackend(QProximitySensor::type, TizenProximity::id, this); + QSensorManager::setDefaultBackend(QProximitySensor::type, TizenProximity::id); + } + } + + QSensorBackend *createBackend(QSensor *sensor) + { + if (sensor->identifier() == TizenAccelerometer::id) { + return new TizenAccelerometer(sensor); + } else if (sensor->identifier() == TizenDeviceOrientation::id) { + return new TizenDeviceOrientation(sensor); + } else if (sensor->identifier() == TizenCompass::id) { + return new TizenCompass(sensor); + } else if (sensor->identifier() == TizenLight::id) { + return new TizenLight(sensor); + } else if (sensor->identifier() == TizenGravity::id) { + return new TizenGravity(sensor); + } else if (sensor->identifier() == TizenMagnetometer::id) { + return new TizenMagnetometer(sensor); + } else if (sensor->identifier() == TizenGyroscope::id) { + return new TizenGyroscope(sensor); + } else if (sensor->identifier() == TizenProximity::id) { + return new TizenProximity(sensor); + } + return 0; + } +}; + +#include "main.moc" diff --git a/src/plugins/sensors/tizen/plugin.json b/src/plugins/sensors/tizen/plugin.json new file mode 100644 index 0000000..669c163 --- /dev/null +++ b/src/plugins/sensors/tizen/plugin.json @@ -0,0 +1 @@ +{ "Keys": [ "tizen" ] } diff --git a/src/plugins/sensors/tizen/tizen.pro b/src/plugins/sensors/tizen/tizen.pro new file mode 100644 index 0000000..0ac40f6 --- /dev/null +++ b/src/plugins/sensors/tizen/tizen.pro @@ -0,0 +1,31 @@ +TARGET = qtsensors_tizen +QT = core sensors + +PLUGIN_TYPE = sensors +PLUGIN_CLASS_NAME = TizenSensorPlugin +load(qt_plugin) + +OTHER_FILES = plugin.json + +HEADERS += tizenaccelerometer.h \ + tizensensorbase.h \ + tizendeviceorientation.h \ + tizencompass.h \ + tizenlight.h \ + tizengyroscope.h \ + tizenproximity.h \ + tizenmagnetometer.h \ + tizengravity.h + +SOURCES += main.cpp \ + tizenaccelerometer.cpp \ + tizensensorbase.cpp \ + tizendeviceorientation.cpp \ + tizencompass.cpp \ + tizenlight.cpp \ + tizengyroscope.cpp \ + tizenproximity.cpp \ + tizenmagnetometer.cpp \ + tizengravity.cpp + +LIBS += -lcapi-system-sensor diff --git a/src/plugins/sensors/tizen/tizenaccelerometer.cpp b/src/plugins/sensors/tizen/tizenaccelerometer.cpp new file mode 100644 index 0000000..e31a215 --- /dev/null +++ b/src/plugins/sensors/tizen/tizenaccelerometer.cpp @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Tomasz Olszak +** 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 "tizenaccelerometer.h" + +char const *const TizenAccelerometer::id("tizen.accelerometer"); + +static void tizen_accelerometer_cb(unsigned long long timestamp, sensor_data_accuracy_e /*accuracy*/, float x, float y, float z, void *user_data) { + TizenAccelerometer *tizenAccelerometer = static_cast(user_data); + Q_CHECK_PTR(tizenAccelerometer); + tizenAccelerometer->update(timestamp, x, y, z); +} + +TizenAccelerometer::TizenAccelerometer(QSensor *sensor, QObject *parent): + TizenSensorBase(sensor, SENSOR_ACCELEROMETER, parent) +{ + int intervalInMs = 1000; + + if (sensor->dataRate() > 0) + intervalInMs = 1000 / sensor->dataRate(); + + setReading(&m_reading); + + sensor_error_e result = sensor_error_e(sensor_accelerometer_set_cb(m_sensor, intervalInMs, tizen_accelerometer_cb, this)); + printErrorMessage(QStringLiteral("Error while setting %1 sensor callback").arg(m_sensorDescription), result); +} + +TizenAccelerometer::~TizenAccelerometer() +{ + sensor_error_e result = sensor_error_e(sensor_accelerometer_unset_cb(m_sensor)); + printErrorMessage(QStringLiteral("Error while unsetting %1 sensor callback").arg(m_sensorDescription), result); +} + +void TizenAccelerometer::start() +{ + TizenSensorBase::start(); + if (m_sensor) { + float x, y, z; + sensor_data_accuracy_e accuracy; + sensor_error_e result = sensor_error_e(sensor_accelerometer_read_data(m_sensor, &accuracy, &x, &y, &z)); + if (wasError(result)) { + printErrorMessage(QStringLiteral("Error while getting %1 sensor data").arg(m_sensorDescription), result); + } else { + update(0, x, y, z); + } + } +} + +void TizenAccelerometer::update(quint64 timestamp, float x, float y, float z) +{ + TIZENSENSORLOG() << " x:" << x << ", y:" << y << ", z:" << z; + m_reading.setTimestamp(timestamp); + m_reading.setX(x); + m_reading.setY(y); + m_reading.setZ(z); + newReadingAvailable(); +} + +void TizenAccelerometer::onDataRateChanged() +{ + TIZENSENSORLOG() << "Changing data rate to:" << sensor()->dataRate(); + if (m_sensor) { + sensor_error_e result = sensor_error_e(sensor_accelerometer_set_interval(m_sensor, sensor()->dataRate())); + printErrorMessage(QStringLiteral("Error while changing interval for %1 sensor").arg(m_sensorDescription), result); + } +} diff --git a/src/plugins/sensors/tizen/tizenaccelerometer.h b/src/plugins/sensors/tizen/tizenaccelerometer.h new file mode 100644 index 0000000..f48296c --- /dev/null +++ b/src/plugins/sensors/tizen/tizenaccelerometer.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Tomasz Olszak +** 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 TIZENACCELEROMETER_H +#define TIZENACCELEROMETER_H + +#include +#include "tizensensorbase.h" + +class TizenAccelerometer : public TizenSensorBase +{ +public: + + static char const *const id; + + explicit TizenAccelerometer(QSensor *sensor, QObject *parent = 0); + ~TizenAccelerometer(); + + void start() Q_DECL_OVERRIDE; + + void onDataRateChanged() Q_DECL_OVERRIDE; + void update(quint64 timestamp, float x,float y, float z); +private: + QAccelerometerReading m_reading; +}; +#endif // TIZENACCELEROMETER_H diff --git a/src/plugins/sensors/tizen/tizencompass.cpp b/src/plugins/sensors/tizen/tizencompass.cpp new file mode 100644 index 0000000..05e95df --- /dev/null +++ b/src/plugins/sensors/tizen/tizencompass.cpp @@ -0,0 +1,123 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Tomasz Olszak +** 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 "tizencompass.h" + +char const *const TizenCompass::id("tizen.compass"); + +static void tizen_compass_cb(unsigned long long timestamp, sensor_data_accuracy_e accuracy, float yaw, float /*pitch*/, float /*roll*/, void* user_data) { + TizenCompass *tizenCompass = static_cast(user_data); + Q_CHECK_PTR(tizenCompass); + tizenCompass->update(timestamp, yaw, accuracy); +} + +static qreal sensor_data_accuracy_e_toCalibrationLevel(sensor_data_accuracy_e accuracy) +{ + switch (accuracy) { + case SENSOR_DATA_ACCURACY_UNDEFINED: + return 0; + case SENSOR_DATA_ACCURACY_BAD: + return 0.25; + case SENSOR_DATA_ACCURACY_NORMAL: + return 0.5; + case SENSOR_DATA_ACCURACY_GOOD: + return 0.75; + case SENSOR_DATA_ACCURACY_VERYGOOD: + return 1; + } + return 0; +} + +TizenCompass::TizenCompass(QSensor *sensor, QObject *parent) : + TizenSensorBase(sensor, SENSOR_DEVICE_ORIENTATION, parent) +{ + m_sensorDescription += "[Compass]"; + + int intervalInMs = 1000; + + if (sensor->dataRate() > 0) + intervalInMs = 1000 / sensor->dataRate(); + + setReading(&m_reading); + + sensor_error_e result = sensor_error_e(sensor_device_orientation_set_cb(m_sensor, intervalInMs, tizen_compass_cb, this)); + printErrorMessage(QStringLiteral("Error while setting %1 sensor callback").arg(m_sensorDescription), result); +} + +TizenCompass::~TizenCompass() +{ + sensor_error_e result = sensor_error_e(sensor_device_orientation_unset_cb(m_sensor)); + printErrorMessage(QStringLiteral("Error while unsetting %1 sensor callback").arg(m_sensorDescription), result); +} + +void TizenCompass::start() +{ + TizenSensorBase::start(); + if (m_sensor) { + float yaw, pitch, roll; + sensor_data_accuracy_e accuracy; + sensor_error_e result = sensor_error_e(sensor_device_orientation_read_data(m_sensor, &accuracy, &yaw, &pitch, &roll)); + if (wasError(result)) { + printErrorMessage(QStringLiteral("Error while getting %1 sensor data").arg(m_sensorDescription), result); + } else { + update(0, yaw, accuracy); + } + } +} + +void TizenCompass::update(quint64 timestamp, float azimuth, sensor_data_accuracy_e accuracy) +{ + m_reading.setTimestamp(timestamp); + m_reading.setAzimuth(azimuth); + m_reading.setCalibrationLevel(sensor_data_accuracy_e_toCalibrationLevel(accuracy)); + TIZENSENSORLOG() << "azimuth:" << azimuth << ", calibrationLevel:" << m_reading.calibrationLevel(); + newReadingAvailable(); +} + +void TizenCompass::onDataRateChanged() +{ + TIZENSENSORLOG() << "Changing data rate to:" << sensor()->dataRate(); + if (m_sensor) { + sensor_error_e result = sensor_error_e(sensor_device_orientation_set_interval(m_sensor, sensor()->dataRate())); + printErrorMessage(QStringLiteral("Error while changing interval for %1 sensor").arg(m_sensorDescription), result); + } +} + diff --git a/src/plugins/sensors/tizen/tizencompass.h b/src/plugins/sensors/tizen/tizencompass.h new file mode 100644 index 0000000..adfcbe0 --- /dev/null +++ b/src/plugins/sensors/tizen/tizencompass.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Tomasz Olszak +** 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 TIZENCOMPASS_H +#define TIZENCOMPASS_H +#include +#include "tizensensorbase.h" + +class TizenCompass : public TizenSensorBase +{ + Q_OBJECT +public: + static char const *const id; + + explicit TizenCompass(QSensor * sensor, QObject *parent = 0); + ~TizenCompass(); + + void start() Q_DECL_OVERRIDE; + + void onDataRateChanged() Q_DECL_OVERRIDE; + void update(quint64 timestamp, float azimuth, sensor_data_accuracy_e accuracy); +private: + QCompassReading m_reading; +}; + +#endif // TIZENCOMPASS_H diff --git a/src/plugins/sensors/tizen/tizendeviceorientation.cpp b/src/plugins/sensors/tizen/tizendeviceorientation.cpp new file mode 100644 index 0000000..f5182f2 --- /dev/null +++ b/src/plugins/sensors/tizen/tizendeviceorientation.cpp @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Tomasz Olszak +** 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 "tizendeviceorientation.h" + +char const *const TizenDeviceOrientation::id("tizen.rotation"); + +static void tizen_device_orientation_cb(unsigned long long timestamp, sensor_data_accuracy_e /*accuracy*/, float yaw, float pitch, float roll, void* user_data) { + TizenDeviceOrientation *tizenDeviceOrientation = static_cast(user_data); + Q_CHECK_PTR(tizenDeviceOrientation); + tizenDeviceOrientation->update(timestamp, yaw, pitch, roll); +} + +TizenDeviceOrientation::TizenDeviceOrientation(QSensor *sensor, QObject *parent) : + TizenSensorBase(sensor, SENSOR_DEVICE_ORIENTATION, parent) +{ + int intervalInMs = 1000; + + if (sensor->dataRate() > 0) + intervalInMs = 1000 / sensor->dataRate(); + + setReading(&m_reading); + + sensor_error_e result = sensor_error_e(sensor_device_orientation_set_cb(m_sensor, intervalInMs, tizen_device_orientation_cb, this)); + printErrorMessage(QStringLiteral("Error while setting %1 sensor callback").arg(m_sensorDescription), result); +} + +TizenDeviceOrientation::~TizenDeviceOrientation() +{ + sensor_error_e result = sensor_error_e(sensor_device_orientation_unset_cb(m_sensor)); + printErrorMessage(QStringLiteral("Error while unsetting %1 sensor callback").arg(m_sensorDescription), result); +} + +void TizenDeviceOrientation::start() +{ + TizenSensorBase::start(); + if (m_sensor) { + float yaw, pitch, roll; + sensor_data_accuracy_e accuracy; + sensor_error_e result = sensor_error_e(sensor_device_orientation_read_data(m_sensor, &accuracy, &yaw, &pitch, &roll)); + if (wasError(result)) { + printErrorMessage(QStringLiteral("Error while getting %1 sensor data").arg(m_sensorDescription), result); + } else { + update(0, yaw, pitch, roll); + } + } +} + +void TizenDeviceOrientation::update(quint64 timestamp, float yaw, float pitch, float roll) +{ + TIZENSENSORLOG() << "yaw:" << yaw << ", pitch:" << pitch << ", roll:" << roll; + m_reading.setTimestamp(timestamp); + m_reading.setFromEuler(yaw, pitch, roll); + newReadingAvailable(); +} + +void TizenDeviceOrientation::onDataRateChanged() +{ + TIZENSENSORLOG() << "Changing data rate to:" << sensor()->dataRate(); + if (m_sensor) { + sensor_error_e result = sensor_error_e(sensor_device_orientation_set_interval(m_sensor, sensor()->dataRate())); + printErrorMessage(QStringLiteral("Error while changing interval for %1 sensor").arg(m_sensorDescription), result); + } +} + diff --git a/src/plugins/sensors/tizen/tizendeviceorientation.h b/src/plugins/sensors/tizen/tizendeviceorientation.h new file mode 100644 index 0000000..428715d --- /dev/null +++ b/src/plugins/sensors/tizen/tizendeviceorientation.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Tomasz Olszak +** 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 TIZENDEVICEORIENTATION_H +#define TIZENDEVICEORIENTATION_H + +#include +#include "tizensensorbase.h" + +class TizenDeviceOrientation : public TizenSensorBase +{ + Q_OBJECT +public: + + static char const *const id; + + explicit TizenDeviceOrientation(QSensor * sensor, QObject *parent = 0); + ~TizenDeviceOrientation(); + + void start() Q_DECL_OVERRIDE; + + void onDataRateChanged() Q_DECL_OVERRIDE; + void update(quint64 timestamp, float yaw, float pitch, float roll); +private: + QRotationReading m_reading; +}; + +#endif // TIZENDEVICEORIENTATION_H diff --git a/src/plugins/sensors/tizen/tizengravity.cpp b/src/plugins/sensors/tizen/tizengravity.cpp new file mode 100644 index 0000000..4e99e03 --- /dev/null +++ b/src/plugins/sensors/tizen/tizengravity.cpp @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Tomasz Olszak +** 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 "tizengravity.h" + +char const *const TizenGravity::id("tizen.gravity"); + +static void tizen_gravity_cb(unsigned long long timestamp, sensor_data_accuracy_e /*accuracy*/, float x, float y, float z, void *user_data) { + TizenGravity *tizenGravity = static_cast(user_data); + Q_CHECK_PTR(tizenGravity); + tizenGravity->update(timestamp, x, y, z); +} + +TizenGravity::TizenGravity(QSensor *sensor, QObject *parent): + TizenSensorBase(sensor, SENSOR_GRAVITY, parent) +{ + int intervalInMs = 1000; + + if (sensor->dataRate() > 0) + intervalInMs = 1000 / sensor->dataRate(); + + setReading(&m_reading); + + sensor_error_e result = sensor_error_e(sensor_gravity_set_cb(m_sensor, intervalInMs, tizen_gravity_cb, this)); + printErrorMessage(QStringLiteral("Error while setting %1 sensor callback").arg(m_sensorDescription), result); +} + +TizenGravity::~TizenGravity() +{ + sensor_error_e result = sensor_error_e(sensor_gravity_unset_cb(m_sensor)); + printErrorMessage(QStringLiteral("Error while unsetting %1 sensor callback").arg(m_sensorDescription), result); +} + +void TizenGravity::start() +{ + TizenSensorBase::start(); + if (m_sensor) { + float x, y, z; + sensor_data_accuracy_e accuracy; + sensor_error_e result = sensor_error_e(sensor_gravity_read_data(m_sensor, &accuracy, &x, &y, &z)); + if (wasError(result)) { + printErrorMessage(QStringLiteral("Error while getting %1 sensor data").arg(m_sensorDescription), result); + } else { + update(0, x, y, z); + } + } +} + +void TizenGravity::update(quint64 timestamp, float x, float y, float z) +{ + TIZENSENSORLOG() << " x:" << x << ", y:" << y << ", z:" << z; + m_reading.setTimestamp(timestamp); + m_reading.setX(x); + m_reading.setY(y); + m_reading.setZ(z); + newReadingAvailable(); +} + +void TizenGravity::onDataRateChanged() +{ + TIZENSENSORLOG() << "Changing data rate to:" << sensor()->dataRate(); + if (m_sensor) { + sensor_error_e result = sensor_error_e(sensor_gravity_set_interval(m_sensor, sensor()->dataRate())); + printErrorMessage(QStringLiteral("Error while changing interval for %1 sensor").arg(m_sensorDescription), result); + } +} diff --git a/src/plugins/sensors/tizen/tizengravity.h b/src/plugins/sensors/tizen/tizengravity.h new file mode 100644 index 0000000..9bb5d7e --- /dev/null +++ b/src/plugins/sensors/tizen/tizengravity.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Tomasz Olszak +** 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 TIZENGRAVITY_H +#define TIZENGRAVITY_H +#include +#include "tizensensorbase.h" + +class TizenGravity : public TizenSensorBase +{ +public: + static char const *const id; + + explicit TizenGravity(QSensor *sensor, QObject *parent = 0); + ~TizenGravity(); + + void start() Q_DECL_OVERRIDE; + + void onDataRateChanged() Q_DECL_OVERRIDE; + void update(quint64 timestamp, float x,float y, float z); +private: + QAccelerometerReading m_reading; +}; + +#endif // TIZENGRAVITY_H diff --git a/src/plugins/sensors/tizen/tizengyroscope.cpp b/src/plugins/sensors/tizen/tizengyroscope.cpp new file mode 100644 index 0000000..739eb6c --- /dev/null +++ b/src/plugins/sensors/tizen/tizengyroscope.cpp @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Tomasz Olszak +** 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 "tizengyroscope.h" + +char const *const TizenGyroscope::id("tizen.gyroscope"); + +static void tizen_gyroscope_cb(unsigned long long timestamp, sensor_data_accuracy_e /*accuracy*/, float x, float y, float z, void* user_data) { + TizenGyroscope *tizenGyroscope = static_cast(user_data); + Q_CHECK_PTR(tizenGyroscope); + tizenGyroscope->update(timestamp, x, y, z); +} + +TizenGyroscope::TizenGyroscope(QSensor *sensor, QObject *parent) : + TizenSensorBase(sensor, SENSOR_GYROSCOPE, parent) +{ + int intervalInMs = 1000; + + if (sensor->dataRate() > 0) + intervalInMs = 1000 / sensor->dataRate(); + + setReading(&m_reading); + + sensor_error_e result = sensor_error_e(sensor_gyroscope_set_cb(m_sensor, intervalInMs, tizen_gyroscope_cb, this)); + printErrorMessage(QStringLiteral("Error while setting %1 sensor callback").arg(m_sensorDescription), result); +} + +TizenGyroscope::~TizenGyroscope() +{ + sensor_error_e result = sensor_error_e(sensor_gyroscope_unset_cb(m_sensor)); + printErrorMessage(QStringLiteral("Error while unsetting %1 sensor callback").arg(m_sensorDescription), result); +} + +void TizenGyroscope::start() +{ + TizenSensorBase::start(); + if (m_sensor) { + float x, y, z; + sensor_data_accuracy_e accuracy; + sensor_error_e result = sensor_error_e(sensor_gyroscope_read_data(m_sensor, &accuracy, &x, &y, &z)); + if (wasError(result)) { + printErrorMessage(QStringLiteral("Error while getting %1 sensor data").arg(m_sensorDescription), result); + } else { + update(0, x, y, z); + } + } +} + +void TizenGyroscope::update(quint64 timestamp, float x, float y, float z) +{ + m_reading.setTimestamp(timestamp); + m_reading.setX(x); + m_reading.setY(y); + m_reading.setZ(z); + TIZENSENSORLOG() << " x:" << x << ", y:" << y << ", z:" << z; + newReadingAvailable(); +} + +void TizenGyroscope::onDataRateChanged() +{ + TIZENSENSORLOG() << "Changing data rate to:" << sensor()->dataRate(); + if (m_sensor) { + sensor_error_e result = sensor_error_e(sensor_gyroscope_set_interval(m_sensor, sensor()->dataRate())); + printErrorMessage(QStringLiteral("Error while changing interval for %1 sensor").arg(m_sensorDescription), result); + } +} diff --git a/src/plugins/sensors/tizen/tizengyroscope.h b/src/plugins/sensors/tizen/tizengyroscope.h new file mode 100644 index 0000000..8cc5342 --- /dev/null +++ b/src/plugins/sensors/tizen/tizengyroscope.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Tomasz Olszak +** 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 TIZENGYROSCOPE_H +#define TIZENGYROSCOPE_H +#include +#include "tizensensorbase.h" + +class TizenGyroscope : public TizenSensorBase +{ +public: + static char const *const id; + + explicit TizenGyroscope(QSensor *sensor, QObject *parent = 0); + ~TizenGyroscope(); + + void start() Q_DECL_OVERRIDE; + + void onDataRateChanged() Q_DECL_OVERRIDE; + void update(quint64 timestamp, float x, float y, float z); +private: + QGyroscopeReading m_reading; +}; + +#endif // TIZENGYROSCOPE_H diff --git a/src/plugins/sensors/tizen/tizenlight.cpp b/src/plugins/sensors/tizen/tizenlight.cpp new file mode 100644 index 0000000..605c7c4 --- /dev/null +++ b/src/plugins/sensors/tizen/tizenlight.cpp @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Tomasz Olszak +** 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 "tizenlight.h" + +char const *const TizenLight::id("tizen.light"); + +static void tizen_light_cb(unsigned long long timestamp, float lux, void* user_data) { + TizenLight *tizenLight = static_cast(user_data); + Q_CHECK_PTR(tizenLight); + tizenLight->update(timestamp, lux); +} + +TizenLight::TizenLight(QSensor *sensor, QObject *parent) : + TizenSensorBase(sensor, SENSOR_LIGHT, parent) +{ + int intervalInMs = 1000; + + if (sensor->dataRate() > 0) + intervalInMs = 1000 / sensor->dataRate(); + + setReading(&m_reading); + + sensor_error_e result = sensor_error_e(sensor_light_set_cb(m_sensor, intervalInMs, tizen_light_cb, this)); + printErrorMessage(QStringLiteral("Error while setting %1 sensor callback").arg(m_sensorDescription), result); +} + +TizenLight::~TizenLight() +{ + sensor_error_e result = sensor_error_e(sensor_light_unset_cb(m_sensor)); + printErrorMessage(QStringLiteral("Error while unsetting %1 sensor callback").arg(m_sensorDescription), result); +} + +void TizenLight::start() +{ + TizenSensorBase::start(); + if (m_sensor) { + float lux; + sensor_error_e result = sensor_error_e(sensor_light_read_data(m_sensor, &lux)); + if (wasError(result)) { + printErrorMessage(QStringLiteral("Error while getting %1 sensor data").arg(m_sensorDescription), result); + } else { + update(0, lux); + } + } +} + +void TizenLight::update(quint64 timestamp, float lux) +{ + m_reading.setTimestamp(timestamp); + m_reading.setLux(lux); + TIZENSENSORLOG() << "lux:" << lux; + newReadingAvailable(); +} + +void TizenLight::onDataRateChanged() +{ + TIZENSENSORLOG() << "Changing data rate to:" << sensor()->dataRate(); + if (m_sensor) { + sensor_error_e result = sensor_error_e(sensor_light_set_interval(m_sensor, sensor()->dataRate())); + printErrorMessage(QStringLiteral("Error while changing interval for %1 sensor").arg(m_sensorDescription), result); + } +} + + diff --git a/src/plugins/sensors/tizen/tizenlight.h b/src/plugins/sensors/tizen/tizenlight.h new file mode 100644 index 0000000..3ac1101 --- /dev/null +++ b/src/plugins/sensors/tizen/tizenlight.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Tomasz Olszak +** 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 TIZENLIGHT_H +#define TIZENLIGHT_H +#include +#include "tizensensorbase.h" + +class TizenLight : public TizenSensorBase +{ +public: + static char const *const id; + + explicit TizenLight(QSensor *sensor, QObject *parent = 0); + ~TizenLight(); + + void start() Q_DECL_OVERRIDE; + + void onDataRateChanged() Q_DECL_OVERRIDE; + void update(quint64 timestamp, float lux); +private: + QLightReading m_reading; +}; +#endif // TIZENLIGHT_H diff --git a/src/plugins/sensors/tizen/tizenmagnetometer.cpp b/src/plugins/sensors/tizen/tizenmagnetometer.cpp new file mode 100644 index 0000000..c7b7b8a --- /dev/null +++ b/src/plugins/sensors/tizen/tizenmagnetometer.cpp @@ -0,0 +1,124 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Tomasz Olszak +** 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 "tizenmagnetometer.h" + +char const *const TizenMagnetometer::id("tizen.magnetometer"); + +static void tizen_magnetic_cb(unsigned long long timestamp, sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data) { + TizenMagnetometer *tizenMagnetometer = static_cast(user_data); + Q_CHECK_PTR(tizenMagnetometer); + tizenMagnetometer->update(timestamp, x, y, z, accuracy); +} + +static qreal sensor_data_accuracy_e_toCalibrationLevel(sensor_data_accuracy_e accuracy) +{ + switch (accuracy) { + case SENSOR_DATA_ACCURACY_UNDEFINED: + return 0; + case SENSOR_DATA_ACCURACY_BAD: + return 0.25; + case SENSOR_DATA_ACCURACY_NORMAL: + return 0.5; + case SENSOR_DATA_ACCURACY_GOOD: + return 0.75; + case SENSOR_DATA_ACCURACY_VERYGOOD: + return 1; + } + return 0; +} + +TizenMagnetometer::TizenMagnetometer(QSensor *sensor, QObject *parent): + TizenSensorBase(sensor, SENSOR_MAGNETIC, parent) +{ + int intervalInMs = 1000; + + if (sensor->dataRate() > 0) + intervalInMs = 1000 / sensor->dataRate(); + + setReading(&m_reading); + + sensor_error_e result = sensor_error_e(sensor_magnetic_set_cb(m_sensor, intervalInMs, tizen_magnetic_cb, this)); + printErrorMessage(QStringLiteral("Error while setting %1 sensor callback").arg(m_sensorDescription), result); +} + +TizenMagnetometer::~TizenMagnetometer() +{ + sensor_error_e result = sensor_error_e(sensor_magnetic_unset_cb(m_sensor)); + + printErrorMessage(QStringLiteral("Error while unsetting %1 sensor callback").arg(m_sensorDescription), result); +} + +void TizenMagnetometer::start() +{ + TizenSensorBase::start(); + if (m_sensor) { + float x, y, z; + sensor_data_accuracy_e accuracy; + sensor_error_e result = sensor_error_e(sensor_magnetic_read_data(m_sensor, &accuracy, &x, &y, &z)); + if (wasError(result)) { + printErrorMessage(QStringLiteral("Error while getting %1 sensor data").arg(m_sensorDescription), result); + } else { + update(0, x, y, z, accuracy); + } + } +} + + +void TizenMagnetometer::update(quint64 timestamp, float x, float y, float z, sensor_data_accuracy_e accuracy) +{ + TIZENSENSORLOG() << " x:" << x << ", y:" << y << ", z:" << z; + m_reading.setTimestamp(timestamp); + m_reading.setX(x); + m_reading.setY(y); + m_reading.setZ(z); + m_reading.setCalibrationLevel(sensor_data_accuracy_e_toCalibrationLevel(accuracy)); + newReadingAvailable(); +} + +void TizenMagnetometer::onDataRateChanged() +{ + TIZENSENSORLOG() << "Changing data rate to:" << sensor()->dataRate(); + if (m_sensor) { + sensor_error_e result = sensor_error_e(sensor_magnetic_set_interval(m_sensor, sensor()->dataRate())); + printErrorMessage(QStringLiteral("Error while changing interval for %1 sensor").arg(m_sensorDescription), result); + } +} diff --git a/src/plugins/sensors/tizen/tizenmagnetometer.h b/src/plugins/sensors/tizen/tizenmagnetometer.h new file mode 100644 index 0000000..bc277ec --- /dev/null +++ b/src/plugins/sensors/tizen/tizenmagnetometer.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Tomasz Olszak +** 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 TIZENMAGNETOMETER_H +#define TIZENMAGNETOMETER_H + +#include +#include "tizensensorbase.h" + +class TizenMagnetometer : public TizenSensorBase +{ +public: + static char const *const id; + + explicit TizenMagnetometer(QSensor *sensor, QObject *parent = 0); + ~TizenMagnetometer(); + + void start() Q_DECL_OVERRIDE; + + void onDataRateChanged() Q_DECL_OVERRIDE; + void update(quint64 timestamp, float x, float y, float z, sensor_data_accuracy_e accuracy); +private: + QMagnetometerReading m_reading; +}; + +#endif // TIZENMAGNETOMETER_H diff --git a/src/plugins/sensors/tizen/tizenproximity.cpp b/src/plugins/sensors/tizen/tizenproximity.cpp new file mode 100644 index 0000000..570e3a3 --- /dev/null +++ b/src/plugins/sensors/tizen/tizenproximity.cpp @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Tomasz Olszak +** 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 "tizenproximity.h" + +char const *const TizenProximity::id("tizen.proximity"); + +static void tizen_proximity_cb(unsigned long long timestamp, float distance, void* user_data) { + TizenProximity *tizenProximity = static_cast(user_data); + Q_CHECK_PTR(tizenProximity); + tizenProximity->update(timestamp, distance); +} + +TizenProximity::TizenProximity(QSensor *sensor, QObject *parent) : + TizenSensorBase(sensor, SENSOR_PROXIMITY, parent) +{ + int intervalInMs = 1000; + + if (sensor->dataRate() > 0) + intervalInMs = 1000 / sensor->dataRate(); + + setReading(&m_reading); + + sensor_error_e result = sensor_error_e(sensor_proximity_set_cb(m_sensor, intervalInMs, tizen_proximity_cb, this)); + printErrorMessage(QStringLiteral("Error while setting %1 sensor callback").arg(m_sensorDescription), result); +} + +TizenProximity::~TizenProximity() +{ + sensor_error_e result = sensor_error_e(sensor_proximity_unset_cb(m_sensor)); + printErrorMessage(QStringLiteral("Error while unsetting %1 sensor callback").arg(m_sensorDescription), result); +} + +void TizenProximity::start() +{ + TizenSensorBase::start(); + if (m_sensor) { + float distance; + sensor_error_e result = sensor_error_e(sensor_proximity_read_data(m_sensor, &distance)); + if (wasError(result)) { + printErrorMessage(QStringLiteral("Error while getting %1 sensor data").arg(m_sensorDescription), result); + } else { + update(0, distance); + } + } +} + + +void TizenProximity::update(quint64 timestamp, float distance) +{ + m_reading.setTimestamp(timestamp); + //determined empirically + m_reading.setClose(distance < 3); + m_reading.setProperty("distance",distance); + TIZENSENSORLOG() << "distance:" << m_reading.property("distance") << ", close:" << m_reading.close(); + newReadingAvailable(); +} + +void TizenProximity::onDataRateChanged() +{ + TIZENSENSORLOG() << "Changing data rate to:" << sensor()->dataRate(); + if (m_sensor) { + sensor_error_e result = sensor_error_e(sensor_proximity_set_interval(m_sensor, sensor()->dataRate())); + printErrorMessage(QStringLiteral("Error while changing interval for %1 sensor").arg(m_sensorDescription), result); + } +} + + diff --git a/src/plugins/sensors/tizen/tizenproximity.h b/src/plugins/sensors/tizen/tizenproximity.h new file mode 100644 index 0000000..aabf7f9 --- /dev/null +++ b/src/plugins/sensors/tizen/tizenproximity.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Tomasz Olszak +** 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 TIZENPROXIMITY_H +#define TIZENPROXIMITY_H +#include +#include "tizensensorbase.h" + +class TizenProximity : public TizenSensorBase +{ + Q_OBJECT +public: + + static char const *const id; + + explicit TizenProximity(QSensor * sensor, QObject *parent = 0); + ~TizenProximity(); + + void start() Q_DECL_OVERRIDE; + + void onDataRateChanged() Q_DECL_OVERRIDE; + void update(quint64 timestamp, float distance); +private: + QProximityReading m_reading; +}; + +#endif // TIZENPROXIMITY_H diff --git a/src/plugins/sensors/tizen/tizensensorbase.cpp b/src/plugins/sensors/tizen/tizensensorbase.cpp new file mode 100644 index 0000000..384ab20 --- /dev/null +++ b/src/plugins/sensors/tizen/tizensensorbase.cpp @@ -0,0 +1,225 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Tomasz Olszak +** 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 "tizensensorbase.h" + + +TizenSensorBase::TizenSensorBase(QSensor *sensor, sensor_type_e sensorType, QObject *parent): + QSensorBackend(sensor, parent), m_sensor(0), m_sensorType(sensorType), m_supported(-1), m_sensorDescription(sensorDescription(sensorType)) +{ + + createSensor(); + int sensorMinRate, sensorMaxRate; + sensor_error_e result = sensor_error_e(sensor_get_delay_boundary(m_sensorType, &sensorMinRate, &sensorMaxRate)); + if (wasError(result)) { + TIZENSENSORLOG() << QStringLiteral("Error while getting delay boundary for %1 sensor").arg(m_sensorDescription); + addDataRate(0, 1000); + } else { + addDataRate(sensorMinRate, sensorMaxRate); + } + + float maxRange; + float minRange; + float resolution; + char *vendor = 0; + char *model = 0; + result = sensor_error_e(sensor_get_spec(m_sensorType, &vendor, &model, &maxRange, &minRange, &resolution)); + if (!wasError(result)) { + addOutputRange(minRange, maxRange, resolution); + setDescription(QString("%1 - %2").arg(vendor).arg(model)); + delete vendor; + delete model; + } else { + TIZENSENSORLOG() << QStringLiteral("Error while getting %1 sensor specs").arg(m_sensorDescription); + } + + connect(sensor, &QSensor::dataRateChanged, this, &TizenSensorBase::onDataRateChanged); +} + +TizenSensorBase::~TizenSensorBase() +{ + destroySensor(); +} + +void TizenSensorBase::onDataRateChanged() +{ + +} + +sensor_h TizenSensorBase::createSensor() +{ + if (m_sensor) + return m_sensor; + + TIZENSENSORLOG() << QStringLiteral("Creating %1 sensor").arg(m_sensorDescription); + if (isSupported()) { + sensor_error_e result = sensor_error_e(sensor_create(&m_sensor)); + if (wasError(result)) { + m_sensor = 0; + printErrorMessage(QStringLiteral("Error while creating %1 sensor").arg(m_sensorDescription), result); + } + } else { + qWarning() << "Device orientation sensor is not supported - can't create sensor"; + } + return m_sensor; +} + +void TizenSensorBase::destroySensor() +{ + TIZENSENSORLOG() << QStringLiteral("Destroying %1 sensor").arg(m_sensorDescription); + if (m_sensor) { + sensor_error_e result = sensor_error_e(sensor_destroy(m_sensor)); + printErrorMessage(QStringLiteral("Error while destroying %1 sensor").arg(m_sensorDescription), result); + } +} + +bool TizenSensorBase::isSupported() +{ + if (m_supported > -1) + return m_supported == 1; + m_supported = TizenSensorBase::isTizenSensorSupported(m_sensorType) ? 1 : 0; + return m_supported; +} + +bool TizenSensorBase::isTizenSensorSupported(sensor_type_e type) +{ + bool result = false; + sensor_error_e operationResult = sensor_error_e(sensor_is_supported(type, &result)); + if (wasError(operationResult)) { + printErrorMessage(QStringLiteral("Checking if %1 sensor is supported failed").arg(sensorDescription(type)), operationResult); + result = false; + } + return result; +} + + +void TizenSensorBase::start() +{ + if (!createSensor()) + return; + + TIZENSENSORLOG() << QStringLiteral("Starting %1 sensor.").arg(m_sensorDescription); + sensor_error_e result = sensor_error_e(sensor_start(m_sensor, m_sensorType)); + printErrorMessage(QStringLiteral("Error while starting %1 sensor").arg(m_sensorDescription), result); +} + + +void TizenSensorBase::stop() +{ + TIZENSENSORLOG() << QStringLiteral("Stopping %1 sensor").arg(m_sensorDescription); + if (m_sensor) { + sensor_error_e result = sensor_error_e(sensor_stop(m_sensor, m_sensorType)); + printErrorMessage(QStringLiteral("Error while stopping %1 sensor").arg(m_sensorDescription), result); + } +} + +void TizenSensorBase::printErrorMessage(QString prefix, sensor_error_e error) +{ + if (error == SENSOR_ERROR_NONE) + return; + + switch (error) { + case SENSOR_ERROR_INVALID_PARAMETER: + qWarning() << prefix <<": Invalid parameter."; + break; + case SENSOR_ERROR_NOT_SUPPORTED: + qWarning() << prefix <<": The sensor type is not supported in current device."; + break; + case SENSOR_ERROR_IO_ERROR: + qWarning() << prefix <<": I/O error."; + break; + case SENSOR_ERROR_OPERATION_FAILED: + qWarning() << prefix <<": Operation failed."; + break; + case SENSOR_ERROR_OUT_OF_MEMORY: + qWarning() << prefix <<": Out of memory."; + break; + default: + qWarning() << prefix <<": Undefined Error."; + break; + } +} + +QString TizenSensorBase::sensorDescription(sensor_type_e type) +{ + switch (type) { + case SENSOR_ACCELEROMETER: + return QStringLiteral("Accelerometer"); + case SENSOR_GRAVITY: + return QStringLiteral("Gravity"); + case SENSOR_LINEAR_ACCELERATION: + return QStringLiteral("Linear acceleration"); + case SENSOR_DEVICE_ORIENTATION: + return QStringLiteral("Device orientation"); + case SENSOR_MAGNETIC: + return QStringLiteral("Magnetic"); + case SENSOR_ORIENTATION: + return QStringLiteral("Orientation"); + case SENSOR_GYROSCOPE: + return QStringLiteral("Gyroscope"); + case SENSOR_LIGHT: + return QStringLiteral("Light"); + case SENSOR_PROXIMITY: + return QStringLiteral("Proximity"); + case SENSOR_MOTION_SNAP: + return QStringLiteral("Snap motion"); + case SENSOR_MOTION_SHAKE: + return QStringLiteral("Shake motion"); + case SENSOR_MOTION_DOUBLETAP: + return QStringLiteral("Double tap motion"); + case SENSOR_MOTION_PANNING: + return QStringLiteral("Panning motion"); + case SENSOR_MOTION_PANNING_BROWSE: + return QStringLiteral("Panning browse motion"); + case SENSOR_MOTION_TILT: + return QStringLiteral("Tilt motion"); + case SENSOR_MOTION_FACEDOWN: + return QStringLiteral("Face down motion"); + case SENSOR_MOTION_DIRECTCALL: + return QStringLiteral("Direct call motion"); + case SENSOR_MOTION_SMART_ALERT: + return QStringLiteral("Smart alert motion"); + case SENSOR_MOTION_NO_MOVE: + return QStringLiteral("No motion"); + default: + return QStringLiteral("Unknown"); + } +} diff --git a/src/plugins/sensors/tizen/tizensensorbase.h b/src/plugins/sensors/tizen/tizensensorbase.h new file mode 100644 index 0000000..fdf6449 --- /dev/null +++ b/src/plugins/sensors/tizen/tizensensorbase.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Tomasz Olszak +** 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 TIZENSENSORBASE_H +#define TIZENSENSORBASE_H +#include +#include +#include + +#ifdef TIZEN_SENSORS_DEBUG +#define TIZENSENSORLOG() if (0); else qDebug() +#else +#define TIZENSENSORLOG() while (0) qDebug() +#endif + +class TizenSensorBase : public QSensorBackend +{ + Q_OBJECT +public: + explicit TizenSensorBase(QSensor * sensor, sensor_type_e sensorType, QObject *parent = 0); + virtual ~TizenSensorBase(); + virtual void start() Q_DECL_OVERRIDE; + virtual void stop() Q_DECL_OVERRIDE; + static bool isTizenSensorSupported(sensor_type_e type); + bool isSupported(); +protected slots: + virtual void onDataRateChanged(); +protected: + virtual sensor_h createSensor(); + virtual void destroySensor(); + static bool wasError(sensor_error_e result){ return result != SENSOR_ERROR_NONE;} + static void printErrorMessage(QString prefix, sensor_error_e error); + static QString sensorDescription(sensor_type_e type); + sensor_h m_sensor; + sensor_type_e m_sensorType; + qint8 m_supported; + QString m_sensorDescription; +}; + +#endif // TIZENSENSORBASE_H -- cgit v1.2.1