| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #include <qirproximitysensor.h> |
| 5 | #include "qirproximitysensor_p.h" |
| 6 | |
| 7 | QT_BEGIN_NAMESPACE |
| 8 | |
| 9 | IMPLEMENT_READING(QIRProximityReading) |
| 10 | |
| 11 | /*! |
| 12 | \class QIRProximityReading |
| 13 | \ingroup sensors_reading |
| 14 | \inmodule QtSensors |
| 15 | \since 5.1 |
| 16 | \internal |
| 17 | |
| 18 | \brief The QIRProximityReading class holds readings from the IR proximity sensor. |
| 19 | |
| 20 | The IR (infra-red) proximity sensor detects proximity by beaming out infra-red light |
| 21 | and detecting how much of the light returns. |
| 22 | |
| 23 | The biggest limitation of this technology is that there is no reliable way to turn the |
| 24 | reflectance values into distances unless both the item being detected and the ambient |
| 25 | conditions are known. |
| 26 | |
| 27 | \section2 QIRProximityReading Units |
| 28 | |
| 29 | The sensor reports reflectance as a decimal fraction in the range of 0 - 1. That is, 0 indicates |
| 30 | nothing was detected within the range of the sensor and 1 indicates the infra-red signal |
| 31 | returned at the full power level that it was sent at. |
| 32 | |
| 33 | With some IR sensors, it is quite uncommon to reach the top and the bottom of the |
| 34 | value range, and some parts of the range ends might not be obtainable at all. This is due to the |
| 35 | behavior of the sensor hardware. With these sensors, the absolute value of reflectance should never |
| 36 | be used directly. Instead, applications should react to the relative change of the reading values. Use |
| 37 | QProximitySensor if it is only necessary to check if something is close to the device or not. |
| 38 | */ |
| 39 | |
| 40 | /*! |
| 41 | \property QIRProximityReading::reflectance |
| 42 | \brief Holds the reflectance value. |
| 43 | |
| 44 | The reflectance is a decimal fraction (from 0 to 1) indicating how much of the transmitted |
| 45 | infra-red light was returned. |
| 46 | |
| 47 | \sa {QIRProximityReading Units} |
| 48 | */ |
| 49 | qreal QIRProximityReading::reflectance() const |
| 50 | { |
| 51 | return d->reflectance; |
| 52 | } |
| 53 | |
| 54 | /*! |
| 55 | Sets the reflectance value to \a reflectance. |
| 56 | */ |
| 57 | void QIRProximityReading::setReflectance(qreal reflectance) |
| 58 | { |
| 59 | d->reflectance = reflectance; |
| 60 | } |
| 61 | |
| 62 | // ===================================================================== |
| 63 | |
| 64 | /*! |
| 65 | \class QIRProximityFilter |
| 66 | \ingroup sensors_filter |
| 67 | \inmodule QtSensors |
| 68 | \since 5.1 |
| 69 | \internal |
| 70 | |
| 71 | \brief The QIRProximityFilter class is a convenience wrapper around QSensorFilter. |
| 72 | |
| 73 | The only difference is that the filter() method features a pointer to QIRProximityReading |
| 74 | instead of QSensorReading. |
| 75 | */ |
| 76 | |
| 77 | /*! |
| 78 | \fn QIRProximityFilter::filter(QIRProximityReading *reading) |
| 79 | |
| 80 | Called when \a reading changes. Returns false to prevent the reading from propagating. |
| 81 | |
| 82 | \sa QSensorFilter::filter() |
| 83 | */ |
| 84 | |
| 85 | bool QIRProximityFilter::filter(QSensorReading *reading) |
| 86 | { |
| 87 | return filter(reading: static_cast<QIRProximityReading*>(reading)); |
| 88 | } |
| 89 | |
| 90 | char const * const QIRProximitySensor::sensorType("QIRProximitySensor" ); |
| 91 | |
| 92 | /*! |
| 93 | \class QIRProximitySensor |
| 94 | \ingroup sensors_type |
| 95 | \inmodule QtSensors |
| 96 | \since 5.1 |
| 97 | \internal |
| 98 | |
| 99 | \brief The QIRProximitySensor class is a convenience wrapper around QSensor. |
| 100 | |
| 101 | The only behavioural difference is that this class sets the type properly. |
| 102 | |
| 103 | This class also features a reading() function that returns a QIRProximityReading instead of a QSensorReading. |
| 104 | |
| 105 | For details about how the sensor works, see \l QIRProximityReading. |
| 106 | |
| 107 | \sa QIRProximityReading |
| 108 | */ |
| 109 | |
| 110 | /*! |
| 111 | Construct the sensor as a child of \a parent. |
| 112 | */ |
| 113 | QIRProximitySensor::QIRProximitySensor(QObject *parent) |
| 114 | : QSensor(QIRProximitySensor::sensorType, parent) |
| 115 | { |
| 116 | } |
| 117 | |
| 118 | /*! |
| 119 | Destroy the sensor. Stops the sensor if it has not already been stopped. |
| 120 | */ |
| 121 | QIRProximitySensor::~QIRProximitySensor() |
| 122 | { |
| 123 | } |
| 124 | |
| 125 | /*! |
| 126 | \fn QIRProximitySensor::reading() const |
| 127 | |
| 128 | Returns the reading class for this sensor. |
| 129 | |
| 130 | \sa QSensor::reading() |
| 131 | */ |
| 132 | |
| 133 | QIRProximityReading *QIRProximitySensor::reading() const |
| 134 | { |
| 135 | return static_cast<QIRProximityReading*>(QSensor::reading()); |
| 136 | } |
| 137 | |
| 138 | QT_END_NAMESPACE |
| 139 | #include "moc_qirproximitysensor.cpp" |
| 140 | |