From 26446d7dc33c44e2f84fe95381f02aca87c1a537 Mon Sep 17 00:00:00 2001 From: Lorn Potter Date: Wed, 9 Nov 2016 05:27:16 +1000 Subject: [ChangeLog][QtSensors][QSensor] Add new sensor: lidsensor Change-Id: I57123eed34ee4618f1cba643c2ce49c8c621a6cd Reviewed-by: Lorn Potter --- src/plugins/sensors/sensorfw/Sensors.conf | 1 + src/plugins/sensors/sensorfw/main.cpp | 3 + src/plugins/sensors/sensorfw/sensorfw.pri | 4 +- src/plugins/sensors/sensorfw/sensorfwlidsensor.cpp | 91 ++++++++++++++++++++++ src/plugins/sensors/sensorfw/sensorfwlidsensor.h | 70 +++++++++++++++++ 5 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 src/plugins/sensors/sensorfw/sensorfwlidsensor.cpp create mode 100644 src/plugins/sensors/sensorfw/sensorfwlidsensor.h (limited to 'src/plugins') diff --git a/src/plugins/sensors/sensorfw/Sensors.conf b/src/plugins/sensors/sensorfw/Sensors.conf index 31d1aff0..b3db5ff3 100644 --- a/src/plugins/sensors/sensorfw/Sensors.conf +++ b/src/plugins/sensors/sensorfw/Sensors.conf @@ -10,3 +10,4 @@ QTapSensor=sensorfw.tapsensor QLightSensor=sensorfw.lightsensor QIRProximitySensor=sensorfw.irproximitysensor QGyroscope=sensorfw.gyroscope +QLidSensor=sensorfw.lidsensor diff --git a/src/plugins/sensors/sensorfw/main.cpp b/src/plugins/sensors/sensorfw/main.cpp index 7d4a8839..bc1246ab 100644 --- a/src/plugins/sensors/sensorfw/main.cpp +++ b/src/plugins/sensors/sensorfw/main.cpp @@ -48,6 +48,7 @@ #include "sensorfwtapsensor.h" #include "sensorfwgyroscope.h" #include "sensorfwlightsensor.h" +#include "sensorfwlidsensor.h" #include #include @@ -97,6 +98,8 @@ public: return new SensorfwTapSensor(sensor); if (sensor->identifier() == SensorfwGyroscope::id) return new SensorfwGyroscope(sensor); + if (sensor->identifier() == SensorfwLidSensor::id) + return new SensorfwLidSensor(sensor); if (sensor->identifier() == SensorfwLightSensor::id) return new SensorfwLightSensor(sensor); if (sensor->identifier() == SensorfwIrProximitySensor::id) diff --git a/src/plugins/sensors/sensorfw/sensorfw.pri b/src/plugins/sensors/sensorfw/sensorfw.pri index 31d7254c..ce8e3ab7 100644 --- a/src/plugins/sensors/sensorfw/sensorfw.pri +++ b/src/plugins/sensors/sensorfw/sensorfw.pri @@ -9,7 +9,8 @@ HEADERS += sensorfwsensorbase.h \ sensorfwrotationsensor.h \ sensorfwtapsensor.h \ sensorfwlightsensor.h \ - sensorfwirproximitysensor.h + sensorfwirproximitysensor.h \ + sensorfwlidsensor.h SOURCES += sensorfwsensorbase.cpp \ sensorfwaccelerometer.cpp \ @@ -23,4 +24,5 @@ SOURCES += sensorfwsensorbase.cpp \ sensorfwrotationsensor.cpp \ sensorfwtapsensor.cpp \ sensorfwlightsensor.cpp \ + sensorfwlidsensor.cpp \ main.cpp diff --git a/src/plugins/sensors/sensorfw/sensorfwlidsensor.cpp b/src/plugins/sensors/sensorfw/sensorfwlidsensor.cpp new file mode 100644 index 00000000..18661b95 --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwlidsensor.cpp @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Canonical, Ltd +** Contact: https://www.qt.io/licensing/ +** +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sensorfwlidsensor.h" + +char const * const SensorfwLidSensor::id("sensorfw.lidsensor"); + +SensorfwLidSensor::SensorfwLidSensor(QSensor *sensor) + : SensorfwSensorBase(sensor) + , m_initDone(false) +{ + init(); + setReading(&m_reading); + sensor->setDataRate(10);//set a default rate +} + +void SensorfwLidSensor::slotDataAvailable(const LidData& data) +{ + switch (data.type_) { + case data.BackLid: + m_reading.setBackLidClosed(data.value_); + break; + case data.FrontLid: + m_reading.setFrontLidClosed(data.value_); + break; + }; + + m_reading.setTimestamp(data.timestamp_); + newReadingAvailable(); +} + +bool SensorfwLidSensor::doConnect() +{ + Q_ASSERT(m_sensorInterface); + return QObject::connect(m_sensorInterface, SIGNAL(lidChanged(LidData)), + this, SLOT(slotDataAvailable(LidData))); +} + +QString SensorfwLidSensor::sensorName() const +{ + return "lidsensor"; +} + +void SensorfwLidSensor::init() +{ + m_initDone = false; + initSensor(m_initDone); +} + +void SensorfwLidSensor::start() +{ + if (reinitIsNeeded) + init(); + SensorfwSensorBase::start(); +} diff --git a/src/plugins/sensors/sensorfw/sensorfwlidsensor.h b/src/plugins/sensors/sensorfw/sensorfwlidsensor.h new file mode 100644 index 00000000..734fd0f3 --- /dev/null +++ b/src/plugins/sensors/sensorfw/sensorfwlidsensor.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Canonical, Ltd +** Contact: https://www.qt.io/licensing/ +** +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#ifndef SENSORFWLIDSENSOR_H +#define SENSORFWLIDSENSOR_H + +#include "sensorfwsensorbase.h" +#include + +#include +#include + + +class SensorfwLidSensor : public SensorfwSensorBase +{ + Q_OBJECT + +public: + static char const * const id; + SensorfwLidSensor(QSensor *sensor); +protected: + bool doConnect() Q_DECL_OVERRIDE; + QString sensorName() const Q_DECL_OVERRIDE; + void start() Q_DECL_OVERRIDE; + virtual void init(); +private: + QLidReading m_reading; + bool m_initDone; +private slots: + void slotDataAvailable(const LidData& data); +}; + +#endif -- cgit v1.2.3