diff options
25 files changed, 845 insertions, 13 deletions
diff --git a/.qmake.conf b/.qmake.conf index 66a0241..4ef7016 100644 --- a/.qmake.conf +++ b/.qmake.conf @@ -1,3 +1,3 @@ load(qt_build_config) -MODULE_VERSION = 5.6.0 +MODULE_VERSION = 5.7.0 diff --git a/src/plugins/sensors/iio-sensor-proxy/iio-sensor-proxy.pro b/src/plugins/sensors/iio-sensor-proxy/iio-sensor-proxy.pro new file mode 100644 index 0000000..b68d9fb --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/iio-sensor-proxy.pro @@ -0,0 +1,31 @@ +TARGET = qtsensors_iio-sensor-proxy +QT = core dbus sensors + +PLUGIN_TYPE = sensors +PLUGIN_CLASS_NAME = IIOSensorProxySensorPlugin +load(qt_plugin) + +!android:LIBS += -lrt +HEADERS += iiosensorproxysensorbase.h \ + iiosensorproxylightsensor.h \ + iiosensorproxyorientationsensor.h \ + iiosensorproxycompass.h + +SOURCES += iiosensorproxysensorbase.cpp \ + iiosensorproxylightsensor.cpp \ + iiosensorproxyorientationsensor.cpp \ + iiosensorproxycompass.cpp \ + main.cpp + +DBUS_INTERFACES += sensor_proxy sensor_proxy_compass dbus_properties + +sensor_proxy.files = net.hadess.SensorProxy.xml +sensor_proxy.header_flags = -N + +sensor_proxy_compass.files = net.hadess.SensorProxy.Compass.xml +sensor_proxy_compass.header_flags = -N + +dbus_properties.files = org.freedesktop.DBus.Properties.xml +dbus_properties.header_flags = -N + +OTHER_FILES = plugin.json $$DBUS_INTERFACES diff --git a/src/plugins/sensors/iio-sensor-proxy/iiosensorproxycompass.cpp b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxycompass.cpp new file mode 100644 index 0000000..e530e0d --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxycompass.cpp @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Alexander Volkov <a.volkov@rusbitech.ru> +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "iiosensorproxycompass.h" +#include "compass_interface.h" + +#include <QtDBus/QDBusPendingReply> + +char const * const IIOSensorProxyCompass::id("iio-sensor-proxy.compass"); + +static inline QString dbusPath() { return QStringLiteral("/net/hadess/SensorProxy/Compass"); } + +IIOSensorProxyCompass::IIOSensorProxyCompass(QSensor *sensor) + : IIOSensorProxySensorBase(dbusPath(), NetHadessSensorProxyCompassInterface::staticInterfaceName(), sensor) +{ + setReading<QCompassReading>(&m_reading); + m_sensorProxyInterface = new NetHadessSensorProxyCompassInterface(serviceName(), dbusPath(), + QDBusConnection::systemBus(), this); +} + +IIOSensorProxyCompass::~IIOSensorProxyCompass() +{ +} + +void IIOSensorProxyCompass::start() +{ + if (isServiceRunning()) { + if (m_sensorProxyInterface->hasCompass()) { + QDBusPendingReply<> reply = m_sensorProxyInterface->ClaimCompass(); + reply.waitForFinished(); + if (!reply.isError()) { + double azimuth = m_sensorProxyInterface->compassHeading(); + updateAzimuth(azimuth); + return; + } + } + } + sensorStopped(); +} + +void IIOSensorProxyCompass::stop() +{ + if (isServiceRunning()) { + QDBusPendingReply<> reply = m_sensorProxyInterface->ReleaseCompass(); + reply.waitForFinished(); + } + sensorStopped(); +} + +void IIOSensorProxyCompass::updateProperties(const QVariantMap &changedProperties) +{ + if (changedProperties.contains("CompassHeading")) { + double azimuth = changedProperties.value("CompassHeading").toDouble(); + updateAzimuth(azimuth); + } +} + +void IIOSensorProxyCompass::updateAzimuth(double azimuth) +{ + m_reading.setAzimuth(azimuth); + m_reading.setTimestamp(produceTimestamp()); + newReadingAvailable(); +} diff --git a/src/plugins/sensors/iio-sensor-proxy/iiosensorproxycompass.h b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxycompass.h new file mode 100644 index 0000000..3adf77b --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxycompass.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Alexander Volkov <a.volkov@rusbitech.ru> +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef IIOSENSORPROXY_COMPASS_H +#define IIOSENSORPROXY_COMPASS_H + +#include "iiosensorproxysensorbase.h" + +#include <qcompass.h> + +class NetHadessSensorProxyCompassInterface; + +class IIOSensorProxyCompass : public IIOSensorProxySensorBase +{ + Q_OBJECT +public: + static char const * const id; + + IIOSensorProxyCompass(QSensor *sensor); + ~IIOSensorProxyCompass(); + + void start() Q_DECL_OVERRIDE; + void stop() Q_DECL_OVERRIDE; + +protected: + void updateProperties(const QVariantMap &changedProperties) Q_DECL_OVERRIDE; + +private: + void updateAzimuth(double azimuth); + + QCompassReading m_reading; + NetHadessSensorProxyCompassInterface *m_sensorProxyInterface; +}; + +#endif // IIOSENSORPROXY_COMPASS_H diff --git a/src/plugins/sensors/iio-sensor-proxy/iiosensorproxylightsensor.cpp b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxylightsensor.cpp new file mode 100644 index 0000000..38bce63 --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxylightsensor.cpp @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Alexander Volkov <a.volkov@rusbitech.ru> +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "iiosensorproxylightsensor.h" +#include "sensorproxy_interface.h" + +#include <QtDBus/QDBusPendingReply> + +char const * const IIOSensorProxyLightSensor::id("iio-sensor-proxy.lightsensor"); + +static inline QString dbusPath() { return QStringLiteral("/net/hadess/SensorProxy"); } + +IIOSensorProxyLightSensor::IIOSensorProxyLightSensor(QSensor *sensor) + : IIOSensorProxySensorBase(dbusPath(), NetHadessSensorProxyInterface::staticInterfaceName(), sensor) +{ + setReading<QLightReading>(&m_reading); + m_sensorProxyInterface = new NetHadessSensorProxyInterface(serviceName(), dbusPath(), + QDBusConnection::systemBus(), this); +} + +IIOSensorProxyLightSensor::~IIOSensorProxyLightSensor() +{ +} + +void IIOSensorProxyLightSensor::start() +{ + if (isServiceRunning()) { + if (m_sensorProxyInterface->hasAmbientLight() + && m_sensorProxyInterface->lightLevelUnit() == QLatin1String("lux")) { + QDBusPendingReply<> reply = m_sensorProxyInterface->ClaimLight(); + reply.waitForFinished(); + if (!reply.isError()) { + updateLightLevel(m_sensorProxyInterface->lightLevel()); + return; + } + } + } + sensorStopped(); +} + +void IIOSensorProxyLightSensor::stop() +{ + if (isServiceRunning()) { + QDBusPendingReply<> reply = m_sensorProxyInterface->ReleaseLight(); + reply.waitForFinished(); + } + sensorStopped(); +} + +void IIOSensorProxyLightSensor::updateProperties(const QVariantMap &changedProperties) +{ + if (changedProperties.contains("LightLevel")) { + double lux = changedProperties.value("LightLevel").toDouble(); + updateLightLevel(lux); + } +} + +void IIOSensorProxyLightSensor::updateLightLevel(double lux) +{ + m_reading.setLux(lux); + m_reading.setTimestamp(produceTimestamp()); + newReadingAvailable(); +} diff --git a/src/plugins/sensors/iio-sensor-proxy/iiosensorproxylightsensor.h b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxylightsensor.h new file mode 100644 index 0000000..96cedc7 --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxylightsensor.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Alexander Volkov <a.volkov@rusbitech.ru> +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef IIOSENSORPROXY_LIGHTSENSOR_H +#define IIOSENSORPROXY_LIGHTSENSOR_H + +#include "iiosensorproxysensorbase.h" + +#include <qlightsensor.h> + +class NetHadessSensorProxyInterface; + +class IIOSensorProxyLightSensor : public IIOSensorProxySensorBase +{ + Q_OBJECT +public: + static char const * const id; + + IIOSensorProxyLightSensor(QSensor *sensor); + ~IIOSensorProxyLightSensor(); + + void start() Q_DECL_OVERRIDE; + void stop() Q_DECL_OVERRIDE; + +protected: + void updateProperties(const QVariantMap &changedProperties) Q_DECL_OVERRIDE; + +private: + void updateLightLevel(double lux); + + QLightReading m_reading; + NetHadessSensorProxyInterface *m_sensorProxyInterface; +}; + +#endif // IIOSENSORPROXY_LIGHTSENSOR_H diff --git a/src/plugins/sensors/iio-sensor-proxy/iiosensorproxyorientationsensor.cpp b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxyorientationsensor.cpp new file mode 100644 index 0000000..b904217 --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxyorientationsensor.cpp @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Alexander Volkov <a.volkov@rusbitech.ru> +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "iiosensorproxyorientationsensor.h" +#include "sensorproxy_interface.h" + +#include <QtDBus/QDBusPendingReply> + +char const * const IIOSensorProxyOrientationSensor::id("iio-sensor-proxy.orientationsensor"); + +static inline QString dbusPath() { return QStringLiteral("/net/hadess/SensorProxy"); } + +IIOSensorProxyOrientationSensor::IIOSensorProxyOrientationSensor(QSensor *sensor) + : IIOSensorProxySensorBase(dbusPath(), NetHadessSensorProxyInterface::staticInterfaceName(), sensor) +{ + setReading<QOrientationReading>(&m_reading); + m_sensorProxyInterface = new NetHadessSensorProxyInterface(serviceName(), dbusPath(), + QDBusConnection::systemBus(), this); +} + +IIOSensorProxyOrientationSensor::~IIOSensorProxyOrientationSensor() +{ +} + +void IIOSensorProxyOrientationSensor::start() +{ + if (isServiceRunning()) { + if (m_sensorProxyInterface->hasAccelerometer()) { + QDBusPendingReply<> reply = m_sensorProxyInterface->ClaimAccelerometer(); + reply.waitForFinished(); + if (!reply.isError()) { + QString orientation = m_sensorProxyInterface->accelerometerOrientation(); + updateOrientation(orientation); + return; + } + } + } + sensorStopped(); +} + +void IIOSensorProxyOrientationSensor::stop() +{ + if (isServiceRunning()) { + QDBusPendingReply<> reply = m_sensorProxyInterface->ReleaseAccelerometer(); + reply.waitForFinished(); + } + sensorStopped(); +} + +void IIOSensorProxyOrientationSensor::updateProperties(const QVariantMap &changedProperties) +{ + if (changedProperties.contains("AccelerometerOrientation")) { + QString orientation = changedProperties.value("AccelerometerOrientation").toString(); + updateOrientation(orientation); + } +} + +void IIOSensorProxyOrientationSensor::updateOrientation(const QString &orientation) +{ + QOrientationReading::Orientation o = QOrientationReading::Undefined; + if (orientation == QLatin1String("normal")) + o = QOrientationReading::TopUp; + else if (orientation == QLatin1String("bottom-up")) + o = QOrientationReading::TopDown; + else if (orientation == QLatin1String("left-up")) + o = QOrientationReading::LeftUp; + else if (orientation == QLatin1String("right-up")) + o = QOrientationReading::RightUp; + + m_reading.setOrientation(o); + m_reading.setTimestamp(produceTimestamp()); + newReadingAvailable(); +} diff --git a/src/plugins/sensors/iio-sensor-proxy/iiosensorproxyorientationsensor.h b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxyorientationsensor.h new file mode 100644 index 0000000..39bc4ee --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxyorientationsensor.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Alexander Volkov <a.volkov@rusbitech.ru> +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef IIOSENSORPROXY_ORIENTATIONSENSOR_H +#define IIOSENSORPROXY_ORIENTATIONSENSOR_H + +#include "iiosensorproxysensorbase.h" + +#include <qorientationsensor.h> + +class NetHadessSensorProxyInterface; + +class IIOSensorProxyOrientationSensor : public IIOSensorProxySensorBase +{ + Q_OBJECT +public: + static char const * const id; + + IIOSensorProxyOrientationSensor(QSensor *sensor); + ~IIOSensorProxyOrientationSensor(); + + void start() Q_DECL_OVERRIDE; + void stop() Q_DECL_OVERRIDE; + +protected: + void updateProperties(const QVariantMap &changedProperties) Q_DECL_OVERRIDE; + +private: + void updateOrientation(const QString &orientation); + + QOrientationReading m_reading; + NetHadessSensorProxyInterface *m_sensorProxyInterface; +}; + +#endif // IIOSENSORPROXY_ORIENTATIONSENSOR_H diff --git a/src/plugins/sensors/iio-sensor-proxy/iiosensorproxysensorbase.cpp b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxysensorbase.cpp new file mode 100644 index 0000000..09cb2a3 --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxysensorbase.cpp @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Alexander Volkov <a.volkov@rusbitech.ru> +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "iiosensorproxysensorbase.h" +#include "sensorproxy_interface.h" +#include "properties_interface.h" + +#include <QtDBus/QDBusConnection> +#include <QtDBus/QDBusServiceWatcher> +#include <QtDBus/QDBusConnectionInterface> + +#include <time.h> + +quint64 IIOSensorProxySensorBase::produceTimestamp() +{ + struct timespec tv; + int ok; + +#ifdef CLOCK_MONOTONIC_RAW + ok = clock_gettime(CLOCK_MONOTONIC_RAW, &tv); + if (ok != 0) +#endif + ok = clock_gettime(CLOCK_MONOTONIC, &tv); + Q_ASSERT(ok == 0); + + quint64 result = (tv.tv_sec * 1000000ULL) + (tv.tv_nsec * 0.001); // scale to microseconds + return result; +} + +IIOSensorProxySensorBase::IIOSensorProxySensorBase(const QString& dbusPath, const QString dbusIface, QSensor *sensor) + : QSensorBackend(sensor) + , m_dbusInterface(dbusIface) +{ + QDBusServiceWatcher *watcher = new QDBusServiceWatcher(serviceName(), QDBusConnection::systemBus(), + QDBusServiceWatcher::WatchForRegistration | + QDBusServiceWatcher::WatchForUnregistration, this); + connect(watcher, SIGNAL(serviceRegistered(QString)), + this, SLOT(serviceRegistered())); + connect(watcher, SIGNAL(serviceUnregistered(QString)), + this, SLOT(serviceUnregistered())); + + m_serviceRunning = QDBusConnection::systemBus().interface()->isServiceRegistered(serviceName()); + + m_propertiesInterface = new OrgFreedesktopDBusPropertiesInterface(serviceName(), dbusPath, + QDBusConnection::systemBus(), this); + connect(m_propertiesInterface, SIGNAL(PropertiesChanged(QString,QVariantMap,QStringList)), + this, SLOT(propertiesChanged(QString,QVariantMap,QStringList))); +} + +IIOSensorProxySensorBase::~IIOSensorProxySensorBase() +{ +} + +QString IIOSensorProxySensorBase::serviceName() const +{ + return QLatin1String("net.hadess.SensorProxy"); +} + +void IIOSensorProxySensorBase::serviceRegistered() +{ + m_serviceRunning = true; +} + +void IIOSensorProxySensorBase::serviceUnregistered() +{ + m_serviceRunning = false; + sensorStopped(); +} + +void IIOSensorProxySensorBase::propertiesChanged(const QString &interface, + const QVariantMap &changedProperties, + const QStringList &/*invalidatedProperties*/) +{ + if (interface == m_dbusInterface) + updateProperties(changedProperties); +} diff --git a/src/plugins/sensors/iio-sensor-proxy/iiosensorproxysensorbase.h b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxysensorbase.h new file mode 100644 index 0000000..f114c3e --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/iiosensorproxysensorbase.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Alexander Volkov <a.volkov@rusbitech.ru> +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef IIOSENSORPROXY_SENSORBASE_H +#define IIOSENSORPROXY_SENSORBASE_H + +#include <qsensorbackend.h> + +class OrgFreedesktopDBusPropertiesInterface; + +class IIOSensorProxySensorBase : public QSensorBackend +{ + Q_OBJECT +public: + static char const * const id; + + IIOSensorProxySensorBase(const QString &dbusPath, const QString dbusIface, QSensor *sensor); + ~IIOSensorProxySensorBase(); + + bool isServiceRunning() const { return m_serviceRunning; } + QString serviceName() const; + +protected: + static quint64 produceTimestamp(); + virtual void updateProperties(const QVariantMap &changedProperties) = 0; + +private slots: + void serviceRegistered(); + void serviceUnregistered(); + void propertiesChanged(const QString &interface, const QVariantMap &changedProperties, + const QStringList &invalidatedProperties); + +private: + bool m_serviceRunning; + OrgFreedesktopDBusPropertiesInterface *m_propertiesInterface; + QString m_dbusInterface; +}; + +#endif // IIOSENSORPROXY_SENSORBASE_H diff --git a/src/plugins/sensors/iio-sensor-proxy/main.cpp b/src/plugins/sensors/iio-sensor-proxy/main.cpp new file mode 100644 index 0000000..5776052 --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/main.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Alexander Volkov <a.volkov@rusbitech.ru> +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "iiosensorproxyorientationsensor.h" +#include "iiosensorproxylightsensor.h" +#include "iiosensorproxycompass.h" + +#include <qsensorplugin.h> +#include <qsensorbackend.h> +#include <qsensormanager.h> + +#include <QtCore/QFile> +#include <QtCore/QDebug> + +class IIOSensorProxySensorPlugin : 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 (!QSensorManager::isBackendRegistered(QOrientationSensor::type, IIOSensorProxyOrientationSensor::id)) + QSensorManager::registerBackend(QOrientationSensor::type, IIOSensorProxyOrientationSensor::id, this); + if (!QSensorManager::isBackendRegistered(QLightSensor::type, IIOSensorProxyLightSensor::id)) + QSensorManager::registerBackend(QLightSensor::type, IIOSensorProxyLightSensor::id, this); + if (!QSensorManager::isBackendRegistered(QCompass::type, IIOSensorProxyCompass::id)) + QSensorManager::registerBackend(QCompass::type, IIOSensorProxyCompass::id, this); + } + + QSensorBackend *createBackend(QSensor *sensor) + { + if (sensor->identifier() == IIOSensorProxyOrientationSensor::id) + return new IIOSensorProxyOrientationSensor(sensor); + else if (sensor->identifier() == IIOSensorProxyLightSensor::id) + return new IIOSensorProxyLightSensor(sensor); + else if (sensor->identifier() == IIOSensorProxyCompass::id) + return new IIOSensorProxyCompass(sensor); + + return 0; + } +}; + +#include "main.moc" diff --git a/src/plugins/sensors/iio-sensor-proxy/net.hadess.SensorProxy.Compass.xml b/src/plugins/sensors/iio-sensor-proxy/net.hadess.SensorProxy.Compass.xml new file mode 100644 index 0000000..bcadffd --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/net.hadess.SensorProxy.Compass.xml @@ -0,0 +1,14 @@ +<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" + "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> +<node> + <interface name="net.hadess.SensorProxy.Compass"> + <method name="ClaimCompass"> + </method> + <method name="ReleaseCompass"> + </method> + <property type="b" name="HasCompass" access="read"> + </property> + <property type="d" name="CompassHeading" access="read"> + </property> + </interface> +</node> diff --git a/src/plugins/sensors/iio-sensor-proxy/net.hadess.SensorProxy.xml b/src/plugins/sensors/iio-sensor-proxy/net.hadess.SensorProxy.xml new file mode 100644 index 0000000..94d9869 --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/net.hadess.SensorProxy.xml @@ -0,0 +1,24 @@ +<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" + "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> +<node> + <interface name="net.hadess.SensorProxy"> + <method name="ClaimAccelerometer"> + </method> + <method name="ReleaseAccelerometer"> + </method> + <method name="ClaimLight"> + </method> + <method name="ReleaseLight"> + </method> + <property type="b" name="HasAccelerometer" access="read"> + </property> + <property type="s" name="AccelerometerOrientation" access="read"> + </property> + <property type="b" name="HasAmbientLight" access="read"> + </property> + <property type="s" name="LightLevelUnit" access="read"> + </property> + <property type="d" name="LightLevel" access="read"> + </property> + </interface> +</node> diff --git a/src/plugins/sensors/iio-sensor-proxy/org.freedesktop.DBus.Properties.xml b/src/plugins/sensors/iio-sensor-proxy/org.freedesktop.DBus.Properties.xml new file mode 100644 index 0000000..5dc94f5 --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/org.freedesktop.DBus.Properties.xml @@ -0,0 +1,27 @@ +<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" + "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> +<node> + <interface name="org.freedesktop.DBus.Properties"> + <method name="Get"> + <arg name="interface" type="s" direction="in"/> + <arg name="name" type="s" direction="in"/> + <arg name="value" type="v" direction="out"/> + </method> + <method name="Set"> + <arg name="interface" type="s" direction="in"/> + <arg name="name" type="s" direction="in"/> + <arg name="value" type="v" direction="in"/> + </method> + <method name="GetAll"> + <arg name="interface" type="s" direction="in"/> + <arg name="properties" type="a{sv}" direction="out"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/> + </method> + <signal name="PropertiesChanged"> + <arg name="interface" type="s"/> + <arg name="changed_properties" type="a{sv}"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="QVariantMap"/> + <arg name="invalidated_properties" type="as"/> + </signal> + </interface> +</node> diff --git a/src/plugins/sensors/iio-sensor-proxy/plugin.json b/src/plugins/sensors/iio-sensor-proxy/plugin.json new file mode 100644 index 0000000..5397f76 --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/plugin.json @@ -0,0 +1 @@ +{ "Keys": [ "iio-sensor-proxy" ] } diff --git a/src/plugins/sensors/sensors.pro b/src/plugins/sensors/sensors.pro index e232a85..5a860fd 100644 --- a/src/plugins/sensors/sensors.pro +++ b/src/plugins/sensors/sensors.pro @@ -21,13 +21,14 @@ qtHaveModule(simulator) { } linux { - isEmpty(SENSORS_PLUGINS): SENSORS_PLUGINS = linux generic + isEmpty(SENSORS_PLUGINS): SENSORS_PLUGINS = linux iio-sensor-proxy generic } contains(SENSORS_PLUGINS, dummy):SUBDIRS += dummy isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, generic):SUBDIRS += generic isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, simulator):qtHaveModule(simulator):SUBDIRS += simulator isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, linux):linux:SUBDIRS += linux +isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, iio-sensor-proxy):linux:qtHaveModule(dbus):SUBDIRS += iio-sensor-proxy 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 diff --git a/src/sensors/doc/src/compatmap.qdoc b/src/sensors/doc/src/compatmap.qdoc index c976014..4f45fcb 100644 --- a/src/sensors/doc/src/compatmap.qdoc +++ b/src/sensors/doc/src/compatmap.qdoc @@ -104,7 +104,7 @@ <tr> <td nowrap="nowrap">Compass</td> <td bgcolor="gray"></td> - <td bgcolor="gray"></td> + <td bgcolor="green"></td> <td bgcolor="green"></td> <td bgcolor="green"></td> <td bgcolor="green"></td> @@ -154,7 +154,7 @@ <tr> <td nowrap="nowrap">Light Sensor</td> <td bgcolor="green"></td> - <td bgcolor="gray"></td> + <td bgcolor="green"></td> <td bgcolor="gray"></td> <td bgcolor="gray"></td> <td bgcolor="gray"></td> @@ -174,7 +174,7 @@ <tr> <td nowrap="nowrap">Orientation Sensor</td> <td bgcolor="gray"></td> - <td bgcolor="gray"></td> + <td bgcolor="green"></td> <td bgcolor="gray"></td> <td bgcolor="green"></td> <td bgcolor="gray"></td> diff --git a/tests/auto/legacy_sensors/legacy_sensors.pro b/tests/auto/legacy_sensors/legacy_sensors.pro index 06a0bab..daf0185 100644 --- a/tests/auto/legacy_sensors/legacy_sensors.pro +++ b/tests/auto/legacy_sensors/legacy_sensors.pro @@ -13,4 +13,3 @@ HEADERS += \ SOURCES += \ test_backends.cpp -DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/qsensor/qsensor.pro b/tests/auto/qsensor/qsensor.pro index 90de01a..1366a5d 100644 --- a/tests/auto/qsensor/qsensor.pro +++ b/tests/auto/qsensor/qsensor.pro @@ -25,4 +25,3 @@ SOURCES += \ test_sensorplugin.cpp\ test_backends.cpp -DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/qsensorgestureplugins/qsensorgestureplugins.pro b/tests/auto/qsensorgestureplugins/qsensorgestureplugins.pro index 2cc31a2..117afab 100644 --- a/tests/auto/qsensorgestureplugins/qsensorgestureplugins.pro +++ b/tests/auto/qsensorgestureplugins/qsensorgestureplugins.pro @@ -15,4 +15,3 @@ HEADERS += \ SOURCES += \ test_backends.cpp -DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/qsensorgestures/qsensorgestures.pro b/tests/auto/qsensorgestures/qsensorgestures.pro index b091d57..e3b152c 100644 --- a/tests/auto/qsensorgestures/qsensorgestures.pro +++ b/tests/auto/qsensorgestures/qsensorgestures.pro @@ -32,4 +32,3 @@ SOURCES += \ plugins/test/qtestrecognizer.cpp \ plugins/test/qtest2recognizer.cpp -DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/qsensorgestures_gestures/qsensorgestures_gestures.pro b/tests/auto/qsensorgestures_gestures/qsensorgestures_gestures.pro index f4051d0..f2259d4 100644 --- a/tests/auto/qsensorgestures_gestures/qsensorgestures_gestures.pro +++ b/tests/auto/qsensorgestures_gestures/qsensorgestures_gestures.pro @@ -19,4 +19,3 @@ HEADERS += \ mockbackends.h TESTDATA += mock_data dataset2_mock_data -DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/qtsensors5/qtsensors5.pro b/tests/auto/qtsensors5/qtsensors5.pro index 77bbd4c..45c2b68 100644 --- a/tests/auto/qtsensors5/qtsensors5.pro +++ b/tests/auto/qtsensors5/qtsensors5.pro @@ -4,4 +4,3 @@ TARGET=tst_qtsensors5 QT = core testlib gui qml SOURCES += tst_qtsensors5.cpp -DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/sensors2qmlapi/sensors2qmlapi.pro b/tests/auto/sensors2qmlapi/sensors2qmlapi.pro index faa0c33..3d5e237 100644 --- a/tests/auto/sensors2qmlapi/sensors2qmlapi.pro +++ b/tests/auto/sensors2qmlapi/sensors2qmlapi.pro @@ -14,4 +14,3 @@ HEADERS += \ qtemplategestureplugin.h \ qtemplaterecognizer.h -DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/manual/sensor_explorer/sensor_explorer.pro b/tests/manual/sensor_explorer/sensor_explorer.pro index f14709c..353c49e 100644 --- a/tests/manual/sensor_explorer/sensor_explorer.pro +++ b/tests/manual/sensor_explorer/sensor_explorer.pro @@ -14,4 +14,3 @@ SOURCES=\ main.cpp -DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 |