diff options
author | Alexander Volkov <a.volkov@rusbitech.ru> | 2015-07-02 16:59:13 +0300 |
---|---|---|
committer | Alexander Volkov <a.volkov@rusbitech.ru> | 2015-10-05 07:01:22 +0000 |
commit | a58b60600aa3f280c01f2f741fd7b43d8adc0994 (patch) | |
tree | 3bd3c7d3f88a7c335101dd3bc06c314658627482 /src/plugins | |
parent | 2184fc69bcfd62bb441b733a12ac577bc8411dae (diff) | |
download | qtsensors-a58b60600aa3f280c01f2f741fd7b43d8adc0994.tar.gz |
Add iio-sensor-proxy backend
iio-sensor-proxy is a daemon that listens to sensors on IIO
subsystem on Linux and provides access to the sensor readings
over D-Bus. Currently it provides only orientation and ambient-
light level.
https://github.com/hadess/iio-sensor-proxy
Change-Id: I035bda0b43a16552a9f2bd88a064e53d5f105451
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Diffstat (limited to 'src/plugins')
12 files changed, 657 insertions, 1 deletions
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..355097a --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/iio-sensor-proxy.pro @@ -0,0 +1,26 @@ +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 + +SOURCES += iiosensorproxysensorbase.cpp \ + iiosensorproxylightsensor.cpp \ + iiosensorproxyorientationsensor.cpp \ + main.cpp + +DBUS_INTERFACES += sensor_proxy dbus_properties + +sensor_proxy.files = net.hadess.SensorProxy.xml +sensor_proxy.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/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..85737b3 --- /dev/null +++ b/src/plugins/sensors/iio-sensor-proxy/main.cpp @@ -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$ +** +****************************************************************************/ + +#include "iiosensorproxyorientationsensor.h" +#include "iiosensorproxylightsensor.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); + } + + QSensorBackend *createBackend(QSensor *sensor) + { + if (sensor->identifier() == IIOSensorProxyOrientationSensor::id) + return new IIOSensorProxyOrientationSensor(sensor); + else if (sensor->identifier() == IIOSensorProxyLightSensor::id) + return new IIOSensorProxyLightSensor(sensor); + + return 0; + } +}; + +#include "main.moc" 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 |