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