| 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 "qmlgyroscope_p.h" |
| 5 | #include <QtSensors/QGyroscope> |
| 6 | |
| 7 | /*! |
| 8 | \qmltype Gyroscope |
| 9 | //! \nativetype QmlGyroscope |
| 10 | \ingroup qml-sensors_type |
| 11 | \inqmlmodule QtSensors |
| 12 | \since QtSensors 5.0 |
| 13 | \inherits Sensor |
| 14 | \brief The Gyroscope element reports on rotational acceleration |
| 15 | around the X, Y and Z axes. |
| 16 | |
| 17 | This element wraps the QGyroscope class. Please see the documentation for |
| 18 | QGyroscope for details. |
| 19 | |
| 20 | \sa GyroscopeReading |
| 21 | */ |
| 22 | |
| 23 | QmlGyroscope::QmlGyroscope(QObject *parent) |
| 24 | : QmlSensor(parent) |
| 25 | , m_sensor(new QGyroscope(this)) |
| 26 | { |
| 27 | } |
| 28 | |
| 29 | QmlGyroscope::~QmlGyroscope() |
| 30 | { |
| 31 | } |
| 32 | |
| 33 | QmlSensorReading *QmlGyroscope::createReading() const |
| 34 | { |
| 35 | return new QmlGyroscopeReading(m_sensor); |
| 36 | } |
| 37 | |
| 38 | QSensor *QmlGyroscope::sensor() const |
| 39 | { |
| 40 | return m_sensor; |
| 41 | } |
| 42 | |
| 43 | /*! |
| 44 | \qmltype GyroscopeReading |
| 45 | //! \nativetype QmlGyroscopeReading |
| 46 | \ingroup qml-sensors_reading |
| 47 | \inqmlmodule QtSensors |
| 48 | \since QtSensors 5.0 |
| 49 | \inherits SensorReading |
| 50 | \brief The GyroscopeReading element holds the most recent Gyroscope reading. |
| 51 | |
| 52 | The GyroscopeReading element holds the most recent Gyroscope reading. |
| 53 | |
| 54 | This element wraps the QGyroscopeReading class. Please see the documentation for |
| 55 | QGyroscopeReading for details. |
| 56 | |
| 57 | This element cannot be directly created. |
| 58 | */ |
| 59 | |
| 60 | QmlGyroscopeReading::QmlGyroscopeReading(QGyroscope *sensor) |
| 61 | : m_sensor(sensor) |
| 62 | { |
| 63 | } |
| 64 | |
| 65 | QmlGyroscopeReading::~QmlGyroscopeReading() |
| 66 | { |
| 67 | } |
| 68 | |
| 69 | /*! |
| 70 | \qmlproperty real GyroscopeReading::x |
| 71 | This property holds the angular velocity around the x axis. |
| 72 | |
| 73 | Please see QGyroscopeReading::x for information about this property. |
| 74 | */ |
| 75 | |
| 76 | qreal QmlGyroscopeReading::x() const |
| 77 | { |
| 78 | return m_x; |
| 79 | } |
| 80 | |
| 81 | QBindable<qreal> QmlGyroscopeReading::bindableX() const |
| 82 | { |
| 83 | return &m_x; |
| 84 | } |
| 85 | |
| 86 | /*! |
| 87 | \qmlproperty real GyroscopeReading::y |
| 88 | This property holds the angular velocity around the y axis. |
| 89 | |
| 90 | Please see QGyroscopeReading::y for information about this property. |
| 91 | */ |
| 92 | |
| 93 | qreal QmlGyroscopeReading::y() const |
| 94 | { |
| 95 | return m_y; |
| 96 | } |
| 97 | |
| 98 | QBindable<qreal> QmlGyroscopeReading::bindableY() const |
| 99 | { |
| 100 | return &m_y; |
| 101 | } |
| 102 | |
| 103 | /*! |
| 104 | \qmlproperty real GyroscopeReading::z |
| 105 | This property holds the angular velocity around the z axis. |
| 106 | |
| 107 | Please see QGyroscopeReading::z for information about this property. |
| 108 | */ |
| 109 | |
| 110 | qreal QmlGyroscopeReading::z() const |
| 111 | { |
| 112 | return m_z; |
| 113 | } |
| 114 | |
| 115 | QBindable<qreal> QmlGyroscopeReading::bindableZ() const |
| 116 | { |
| 117 | return &m_z; |
| 118 | } |
| 119 | |
| 120 | QSensorReading *QmlGyroscopeReading::reading() const |
| 121 | { |
| 122 | return m_sensor->reading(); |
| 123 | } |
| 124 | |
| 125 | void QmlGyroscopeReading::readingUpdate() |
| 126 | { |
| 127 | m_x = m_sensor->reading()->x(); |
| 128 | m_y = m_sensor->reading()->y(); |
| 129 | m_z = m_sensor->reading()->z(); |
| 130 | } |
| 131 | |