| 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 "qgyroscope.h" |
| 5 | #include "qgyroscope_p.h" |
| 6 | |
| 7 | QT_BEGIN_NAMESPACE |
| 8 | |
| 9 | IMPLEMENT_READING(QGyroscopeReading) |
| 10 | |
| 11 | /*! |
| 12 | \class QGyroscopeReading |
| 13 | \ingroup sensors_reading |
| 14 | \inmodule QtSensors |
| 15 | \since 5.1 |
| 16 | |
| 17 | \brief The QGyroscopeReading class represents one reading from the |
| 18 | gyroscope sensor. |
| 19 | |
| 20 | \section2 QGyroscopeReading Units |
| 21 | |
| 22 | The reading contains 3 values, measured in degrees per second that define |
| 23 | the movement of the device around the x, y and z axes. Unlike QRotationReading, |
| 24 | the values represent the current angular velocity rather than a fixed rotation. |
| 25 | The measurements are in degrees per second. |
| 26 | |
| 27 | \image sensors-coordinates3.jpg |
| 28 | */ |
| 29 | |
| 30 | /*! |
| 31 | \property QGyroscopeReading::x |
| 32 | \brief the angular velocity around the x axis. |
| 33 | |
| 34 | Measured as degrees per second. |
| 35 | \sa {QGyroscopeReading Units} |
| 36 | */ |
| 37 | |
| 38 | qreal QGyroscopeReading::x() const |
| 39 | { |
| 40 | return d->x; |
| 41 | } |
| 42 | |
| 43 | /*! |
| 44 | Sets the angular velocity around the x axis to \a x. |
| 45 | */ |
| 46 | void QGyroscopeReading::setX(qreal x) |
| 47 | { |
| 48 | d->x = x; |
| 49 | } |
| 50 | |
| 51 | /*! |
| 52 | \property QGyroscopeReading::y |
| 53 | \brief the angular velocity around the y axis. |
| 54 | |
| 55 | Measured as degrees per second. |
| 56 | \sa {QGyroscopeReading Units} |
| 57 | */ |
| 58 | |
| 59 | qreal QGyroscopeReading::y() const |
| 60 | { |
| 61 | return d->y; |
| 62 | } |
| 63 | |
| 64 | /*! |
| 65 | Sets the angular velocity around the y axis to \a y. |
| 66 | */ |
| 67 | void QGyroscopeReading::setY(qreal y) |
| 68 | { |
| 69 | d->y = y; |
| 70 | } |
| 71 | |
| 72 | /*! |
| 73 | \property QGyroscopeReading::z |
| 74 | \brief the angular velocity around the z axis. |
| 75 | |
| 76 | Measured as degrees per second. |
| 77 | \sa {QGyroscopeReading Units} |
| 78 | */ |
| 79 | |
| 80 | qreal QGyroscopeReading::z() const |
| 81 | { |
| 82 | return d->z; |
| 83 | } |
| 84 | |
| 85 | /*! |
| 86 | Sets the angular velocity around the z axis to \a z. |
| 87 | */ |
| 88 | void QGyroscopeReading::setZ(qreal z) |
| 89 | { |
| 90 | d->z = z; |
| 91 | } |
| 92 | |
| 93 | // ===================================================================== |
| 94 | |
| 95 | /*! |
| 96 | \class QGyroscopeFilter |
| 97 | \ingroup sensors_filter |
| 98 | \inmodule QtSensors |
| 99 | \since 5.1 |
| 100 | |
| 101 | \brief The QGyroscopeFilter class is a convenience wrapper around QSensorFilter. |
| 102 | |
| 103 | The only difference is that the filter() method features a pointer to QGyroscopeReading |
| 104 | instead of QSensorReading. |
| 105 | */ |
| 106 | |
| 107 | /*! |
| 108 | \fn QGyroscopeFilter::filter(QGyroscopeReading *reading) |
| 109 | |
| 110 | Called when \a reading changes. Returns false to prevent the reading from propagating. |
| 111 | |
| 112 | \sa QSensorFilter::filter() |
| 113 | */ |
| 114 | |
| 115 | bool QGyroscopeFilter::filter(QSensorReading *reading) |
| 116 | { |
| 117 | return filter(reading: static_cast<QGyroscopeReading*>(reading)); |
| 118 | } |
| 119 | |
| 120 | char const * const QGyroscope::sensorType("QGyroscope" ); |
| 121 | |
| 122 | /*! |
| 123 | \class QGyroscope |
| 124 | \ingroup sensors_type |
| 125 | \inmodule QtSensors |
| 126 | \since 5.1 |
| 127 | |
| 128 | \brief The QGyroscope class is a convenience wrapper around QSensor. |
| 129 | |
| 130 | The only behavioural difference is that this class sets the type properly. |
| 131 | |
| 132 | This class also features a reading() function that returns a QGyroscopeReading instead of a QSensorReading. |
| 133 | |
| 134 | For details about how the sensor works, see \l QGyroscopeReading. |
| 135 | |
| 136 | \sa QGyroscopeReading |
| 137 | */ |
| 138 | |
| 139 | /*! |
| 140 | Construct the sensor as a child of \a parent. |
| 141 | */ |
| 142 | QGyroscope::QGyroscope(QObject *parent) |
| 143 | : QSensor(QGyroscope::sensorType, parent) |
| 144 | { |
| 145 | } |
| 146 | |
| 147 | /*! |
| 148 | Destroy the sensor. Stops the sensor if it has not already been stopped. |
| 149 | */ |
| 150 | QGyroscope::~QGyroscope() |
| 151 | { |
| 152 | } |
| 153 | |
| 154 | /*! |
| 155 | \fn QGyroscope::reading() const |
| 156 | |
| 157 | Returns the reading class for this sensor. |
| 158 | |
| 159 | \sa QSensor::reading() |
| 160 | */ |
| 161 | |
| 162 | QGyroscopeReading *QGyroscope::reading() const |
| 163 | { |
| 164 | return static_cast<QGyroscopeReading*>(QSensor::reading()); |
| 165 | } |
| 166 | |
| 167 | QT_END_NAMESPACE |
| 168 | |
| 169 | #include "moc_qgyroscope.cpp" |
| 170 | |