| 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 "qtiltsensor.h" |
| 41 | #include "qtiltsensor_p.h" |
| 42 | |
| 43 | #include "qsensorbackend.h" |
| 44 | |
| 45 | #include <QtCore/QMetaObject> |
| 46 | |
| 47 | QT_BEGIN_NAMESPACE |
| 48 | |
| 49 | IMPLEMENT_READING(QTiltReading) |
| 50 | |
| 51 | /*! |
| 52 | \class QTiltReading |
| 53 | \ingroup sensors_reading |
| 54 | \inmodule QtSensors |
| 55 | \since 5.1 |
| 56 | |
| 57 | \brief The QTiltReading class holds readings from the tilt sensor. |
| 58 | |
| 59 | The tilt sensor reports the angle of tilt in degrees of the device along the X and Y plane. |
| 60 | |
| 61 | */ |
| 62 | |
| 63 | |
| 64 | /*! |
| 65 | \property QTiltReading::yRotation |
| 66 | \brief This property holds the amount of tilt on the Y axis. |
| 67 | */ |
| 68 | qreal QTiltReading::yRotation() const |
| 69 | { |
| 70 | return d->yRotation; |
| 71 | } |
| 72 | |
| 73 | /*! |
| 74 | Sets yRotation to \a y. |
| 75 | */ |
| 76 | void QTiltReading::setYRotation(qreal y) |
| 77 | { |
| 78 | d->yRotation = y; |
| 79 | } |
| 80 | |
| 81 | /*! |
| 82 | \property QTiltReading::xRotation |
| 83 | \brief This property holds the amount of tilt on the X axis. |
| 84 | |
| 85 | */ |
| 86 | qreal QTiltReading::xRotation() const |
| 87 | { |
| 88 | return d->xRotation; |
| 89 | } |
| 90 | |
| 91 | /*! |
| 92 | Sets xRotation to \a x. |
| 93 | */ |
| 94 | void QTiltReading::setXRotation(qreal x) |
| 95 | { |
| 96 | d->xRotation = x; |
| 97 | } |
| 98 | |
| 99 | // ===================================================================== |
| 100 | |
| 101 | /*! |
| 102 | \class QTiltFilter |
| 103 | \ingroup sensors_filter |
| 104 | \inmodule QtSensors |
| 105 | \since 5.1 |
| 106 | |
| 107 | \brief The QTiltFilter class is a convenience wrapper around QSensorFilter. |
| 108 | |
| 109 | The only difference is that the filter() method features a pointer to QTiltReading |
| 110 | instead of QSensorReading. |
| 111 | */ |
| 112 | |
| 113 | /*! |
| 114 | \fn QTiltFilter::filter(QTiltReading *reading) |
| 115 | |
| 116 | Called when \a reading changes. Returns false to prevent the reading from propagating. |
| 117 | |
| 118 | \sa QSensorFilter::filter() |
| 119 | */ |
| 120 | |
| 121 | bool QTiltFilter::filter(QSensorReading *reading) |
| 122 | { |
| 123 | return filter(reading: static_cast<QTiltReading*>(reading)); |
| 124 | } |
| 125 | |
| 126 | char const * const QTiltSensor::type("QTiltSensor" ); |
| 127 | |
| 128 | /*! |
| 129 | \class QTiltSensor |
| 130 | \ingroup sensors_type |
| 131 | \inmodule QtSensors |
| 132 | \since 5.1 |
| 133 | |
| 134 | \brief The QTiltSensor class is a convenience wrapper around QSensor. |
| 135 | |
| 136 | The only behavioural difference is that this class sets the type properly.QMetaObject::invokeMethod(backend(), "calibrate"); |
| 137 | |
| 138 | This class also features a reading() function that returns a QTiltReading instead of a QSensorReading. |
| 139 | |
| 140 | For details about how the sensor works, see \l QTiltReading. |
| 141 | |
| 142 | \sa QTiltReading |
| 143 | */ |
| 144 | |
| 145 | /*! |
| 146 | \fn QTiltSensor::QTiltSensor(QObject *parent) |
| 147 | |
| 148 | Construct the sensor as a child of \a parent. |
| 149 | */ |
| 150 | QTiltSensor::QTiltSensor(QObject *parent) |
| 151 | : QSensor(QTiltSensor::type, parent) |
| 152 | { |
| 153 | } |
| 154 | |
| 155 | /*! |
| 156 | \fn QTiltSensor::~QTiltSensor() |
| 157 | |
| 158 | Destroy the sensor. Stops the sensor if it has not already been stopped. |
| 159 | */ |
| 160 | QTiltSensor::~QTiltSensor() |
| 161 | { |
| 162 | } |
| 163 | /*! |
| 164 | \fn QTiltSensor::reading() const |
| 165 | |
| 166 | Returns the reading class for this sensor. |
| 167 | |
| 168 | \sa QSensor::reading() |
| 169 | */ |
| 170 | |
| 171 | QTiltReading *QTiltSensor::reading() const |
| 172 | { |
| 173 | return static_cast<QTiltReading*>(QSensor::reading()); |
| 174 | } |
| 175 | |
| 176 | /*! |
| 177 | Calibrates the tilt sensor. Uses the current tilt angles as 0. |
| 178 | */ |
| 179 | void QTiltSensor::calibrate() |
| 180 | { |
| 181 | QMetaObject::invokeMethod(obj: backend(), member: "calibrate" , type: Qt::DirectConnection); |
| 182 | } |
| 183 | |
| 184 | QT_END_NAMESPACE |
| 185 | |
| 186 | #include "moc_qtiltsensor.cpp" |
| 187 | |