1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtSensors module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include <qirproximitysensor.h>
41#include "qirproximitysensor_p.h"
42
43QT_BEGIN_NAMESPACE
44
45IMPLEMENT_READING(QIRProximityReading)
46
47/*!
48 \class QIRProximityReading
49 \ingroup sensors_reading
50 \inmodule QtSensors
51 \since 5.1
52
53 \brief The QIRProximityReading class holds readings from the IR proximity sensor.
54
55 The IR (infra-red) proximity sensor detects proximity by beaming out infra-red light
56 and detecting how much of the light returns.
57
58 The biggest limitation of this technology is that there is no reliable way to turn the
59 reflectance values into distances unless both the item being detected and the ambient
60 conditions are known.
61
62 \section2 QIRProximityReading Units
63
64 The sensor reports reflectance as a decimal fraction in the range of 0 - 1. That is, 0 indicates
65 nothing was detected within the range of the sensor and 1 indicates the infra-red signal
66 returned at the full power level that it was sent at.
67
68 With some IR sensors, it is quite uncommon to reach the top and the bottom of the
69 value range, and some parts of the range ends might not be obtainable at all. This is due to the
70 behavior of the sensor hardware. With these sensors, the absolute value of reflectance should never
71 be used directly. Instead, applications should react to the relative change of the reading values. Use
72 QProximitySensor if it is only necessary to check if something is close to the device or not.
73*/
74
75/*!
76 \property QIRProximityReading::reflectance
77 \brief Holds the reflectance value.
78
79 The reflectance is a decimal fraction (from 0 to 1) indicating how much of the transmitted
80 infra-red light was returned.
81
82 \sa {QIRProximityReading Units}
83*/
84qreal QIRProximityReading::reflectance() const
85{
86 return d->reflectance;
87}
88
89/*!
90 Sets the reflectance value to \a reflectance.
91*/
92void QIRProximityReading::setReflectance(qreal reflectance)
93{
94 d->reflectance = reflectance;
95}
96
97// =====================================================================
98
99/*!
100 \class QIRProximityFilter
101 \ingroup sensors_filter
102 \inmodule QtSensors
103 \since 5.1
104
105 \brief The QIRProximityFilter class is a convenience wrapper around QSensorFilter.
106
107 The only difference is that the filter() method features a pointer to QIRProximityReading
108 instead of QSensorReading.
109*/
110
111/*!
112 \fn QIRProximityFilter::filter(QIRProximityReading *reading)
113
114 Called when \a reading changes. Returns false to prevent the reading from propagating.
115
116 \sa QSensorFilter::filter()
117*/
118
119bool QIRProximityFilter::filter(QSensorReading *reading)
120{
121 return filter(reading: static_cast<QIRProximityReading*>(reading));
122}
123
124char const * const QIRProximitySensor::type("QIRProximitySensor");
125
126/*!
127 \class QIRProximitySensor
128 \ingroup sensors_type
129 \inmodule QtSensors
130 \since 5.1
131
132 \brief The QIRProximitySensor class is a convenience wrapper around QSensor.
133
134 The only behavioural difference is that this class sets the type properly.
135
136 This class also features a reading() function that returns a QIRProximityReading instead of a QSensorReading.
137
138 For details about how the sensor works, see \l QIRProximityReading.
139
140 \sa QIRProximityReading
141*/
142
143/*!
144 Construct the sensor as a child of \a parent.
145*/
146QIRProximitySensor::QIRProximitySensor(QObject *parent)
147 : QSensor(QIRProximitySensor::type, parent)
148{
149}
150
151/*!
152 Destroy the sensor. Stops the sensor if it has not already been stopped.
153*/
154QIRProximitySensor::~QIRProximitySensor()
155{
156}
157
158/*!
159 \fn QIRProximitySensor::reading() const
160
161 Returns the reading class for this sensor.
162
163 \sa QSensor::reading()
164*/
165
166QIRProximityReading *QIRProximitySensor::reading() const
167{
168 return static_cast<QIRProximityReading*>(QSensor::reading());
169}
170
171QT_END_NAMESPACE
172#include "moc_qirproximitysensor.cpp"
173

source code of qtsensors/src/sensors/qirproximitysensor.cpp