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 "qcompass.h"
41#include "qcompass_p.h"
42
43QT_BEGIN_NAMESPACE
44
45IMPLEMENT_READING(QCompassReading)
46
47/*!
48 \class QCompassReading
49 \ingroup sensors_reading
50 \inmodule QtSensors
51 \since 5.1
52
53 \brief The QCompassReading class represents one reading from a
54 compass.
55
56 \section2 QCompassReading Units
57 The compass returns the azimuth of the device as degrees from
58 magnetic north in a clockwise direction based on the top of the device,
59 as defined by QScreen::nativeOrientation.
60 There is also a value to indicate the calibration status of the device.
61 If the device is not calibrated the azimuth may not be accurate.
62
63 Digital compasses are susceptible to magnetic interference and may need
64 calibration after being placed near anything that emits a magnetic force.
65 Accuracy of the compass can be affected by any ferrous materials that are nearby.
66
67 The calibration status of the device is measured as a number from 0 to 1.
68 A value of 1 is the highest level that the device can support and 0 is
69 the worst.
70*/
71
72/*!
73 \property QCompassReading::azimuth
74 \brief the azimuth of the device.
75
76 Measured in degrees from magnetic north in a clockwise direction based on
77 the top of the device, as defined by QScreen::nativeOrientation.
78 \sa {QCompassReading Units}
79*/
80
81qreal QCompassReading::azimuth() const
82{
83 return d->azimuth;
84}
85
86/*!
87 Sets the \a azimuth of the device.
88
89 \sa {QCompassReading Units}
90*/
91void QCompassReading::setAzimuth(qreal azimuth)
92{
93 d->azimuth = azimuth;
94}
95
96/*!
97 \property QCompassReading::calibrationLevel
98 \brief the calibration level of the reading.
99
100 Measured as a value from 0 to 1 with higher values being better.
101 \sa {QCompassReading Units}
102*/
103
104qreal QCompassReading::calibrationLevel() const
105{
106 return d->calibrationLevel;
107}
108
109/*!
110 Sets the calibration level of the reading to \a calibrationLevel.
111*/
112void QCompassReading::setCalibrationLevel(qreal calibrationLevel)
113{
114 d->calibrationLevel = calibrationLevel;
115}
116
117// =====================================================================
118
119/*!
120 \class QCompassFilter
121 \ingroup sensors_filter
122 \inmodule QtSensors
123 \since 5.1
124
125 \brief The QCompassFilter class is a convenience wrapper around QSensorFilter.
126
127 The only difference is that the filter() method features a pointer to QCompassReading
128 instead of QSensorReading.
129*/
130
131/*!
132 \fn QCompassFilter::filter(QCompassReading *reading)
133
134 Called when \a reading changes. Returns false to prevent the reading from propagating.
135
136 \sa QSensorFilter::filter()
137*/
138
139bool QCompassFilter::filter(QSensorReading *reading)
140{
141 return filter(reading: static_cast<QCompassReading*>(reading));
142}
143
144char const * const QCompass::type("QCompass");
145
146/*!
147 \class QCompass
148 \ingroup sensors_type
149 \inmodule QtSensors
150 \since 5.1
151
152 \brief The QCompass class is a convenience wrapper around QSensor.
153
154 The only behavioural difference is that this class sets the type properly.
155
156 This class also features a reading() function that returns a QCompassReading instead of a QSensorReading.
157
158 For details about how the sensor works, see \l QCompassReading.
159
160 \sa QCompassReading
161*/
162
163/*!
164 Construct the sensor as a child of \a parent.
165*/
166QCompass::QCompass(QObject *parent)
167 : QSensor(QCompass::type, parent)
168{
169}
170
171/*!
172 Destroy the sensor. Stops the sensor if it has not already been stopped.
173*/
174QCompass::~QCompass()
175{
176}
177
178/*!
179 \fn QCompass::reading() const
180
181 Returns the reading class for this sensor.
182
183 \sa QSensor::reading()
184*/
185
186QCompassReading *QCompass::reading() const
187{
188 return static_cast<QCompassReading*>(QSensor::reading());
189}
190
191QT_END_NAMESPACE
192
193#include "moc_qcompass.cpp"
194

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