summaryrefslogtreecommitdiffstats
path: root/src/plugins/sensors
diff options
context:
space:
mode:
authorLorn Potter <lorn.potter@canonical.com>2016-11-09 05:27:16 +1000
committerLorn Potter <lorn.potter@canonical.com>2016-11-21 04:27:28 +0000
commit26446d7dc33c44e2f84fe95381f02aca87c1a537 (patch)
tree1e60542cc39f27f61d44369a2fd7c174de1e4ee5 /src/plugins/sensors
parent53a414e33ce45f28b89217678597416b681128d4 (diff)
[ChangeLog][QtSensors][QSensor] Add new sensor: lidsensor
Change-Id: I57123eed34ee4618f1cba643c2ce49c8c621a6cd Reviewed-by: Lorn Potter <lorn.potter@canonical.com>
Diffstat (limited to 'src/plugins/sensors')
-rw-r--r--src/plugins/sensors/sensorfw/Sensors.conf1
-rw-r--r--src/plugins/sensors/sensorfw/main.cpp3
-rw-r--r--src/plugins/sensors/sensorfw/sensorfw.pri4
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwlidsensor.cpp91
-rw-r--r--src/plugins/sensors/sensorfw/sensorfwlidsensor.h70
5 files changed, 168 insertions, 1 deletions
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 <QtSensors/qsensorplugin.h>
#include <QtSensors/qsensorbackend.h>
@@ -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<QLidReading>(&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<LidSensorChannelInterface>(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 <QtSensors/qlidsensor.h>
+
+#include <lidsensor_i.h>
+#include <liddata.h>
+
+
+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