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

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