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 "qtiltsensor.h"
5#include "qtiltsensor_p.h"
6
7#include "qsensorbackend.h"
8
9#include <QtCore/QMetaObject>
10
11QT_BEGIN_NAMESPACE
12
13IMPLEMENT_READING(QTiltReading)
14
15/*!
16 \class QTiltReading
17 \ingroup sensors_reading
18 \inmodule QtSensors
19 \since 5.1
20
21 \brief The QTiltReading class holds readings from the tilt sensor.
22
23 The tilt sensor reports the angle of tilt in degrees of the device along the X and Y plane.
24
25*/
26
27
28/*!
29 \property QTiltReading::yRotation
30 \brief This property holds the amount of tilt on the Y axis,
31 measured in degrees.
32*/
33qreal QTiltReading::yRotation() const
34{
35 return d->yRotation;
36}
37
38/*!
39 Sets yRotation to \a y degrees.
40*/
41void QTiltReading::setYRotation(qreal y)
42{
43 d->yRotation = y;
44}
45
46/*!
47 \property QTiltReading::xRotation
48 \brief This property holds the amount of tilt on the X axis,
49 measured in degrees.
50
51*/
52qreal QTiltReading::xRotation() const
53{
54 return d->xRotation;
55}
56
57/*!
58 Sets xRotation to \a x degrees.
59*/
60void QTiltReading::setXRotation(qreal x)
61{
62 d->xRotation = x;
63}
64
65// =====================================================================
66
67/*!
68 \class QTiltFilter
69 \ingroup sensors_filter
70 \inmodule QtSensors
71 \since 5.1
72
73 \brief The QTiltFilter class is a convenience wrapper around QSensorFilter.
74
75 The only difference is that the filter() method features a pointer to QTiltReading
76 instead of QSensorReading.
77*/
78
79/*!
80 \fn QTiltFilter::filter(QTiltReading *reading)
81
82 Called when \a reading changes. Returns false to prevent the reading from propagating.
83
84 \sa QSensorFilter::filter()
85*/
86
87bool QTiltFilter::filter(QSensorReading *reading)
88{
89 return filter(reading: static_cast<QTiltReading*>(reading));
90}
91
92char const * const QTiltSensor::sensorType("QTiltSensor");
93
94/*!
95 \class QTiltSensor
96 \ingroup sensors_type
97 \inmodule QtSensors
98 \since 5.1
99
100 \brief The QTiltSensor class is a convenience wrapper around QSensor.
101
102 The only behavioural difference is that this class sets the type properly.
103
104 This class also features a reading() function that returns a QTiltReading instead of a QSensorReading.
105
106 For details about how the sensor works, see \l QTiltReading.
107
108 \sa QTiltReading
109*/
110
111/*!
112 \fn QTiltSensor::QTiltSensor(QObject *parent)
113
114 Construct the sensor as a child of \a parent.
115*/
116QTiltSensor::QTiltSensor(QObject *parent)
117 : QSensor(QTiltSensor::sensorType, parent)
118{
119}
120
121/*!
122 \fn QTiltSensor::~QTiltSensor()
123
124 Destroy the sensor. Stops the sensor if it has not already been stopped.
125*/
126QTiltSensor::~QTiltSensor()
127{
128}
129/*!
130 \fn QTiltSensor::reading() const
131
132 Returns the reading class for this sensor.
133
134 \sa QSensor::reading()
135*/
136
137QTiltReading *QTiltSensor::reading() const
138{
139 return static_cast<QTiltReading*>(QSensor::reading());
140}
141
142/*!
143 Calibrates the tilt sensor. Uses the current tilt angles as 0 degrees.
144 */
145void QTiltSensor::calibrate()
146{
147 QMetaObject::invokeMethod(obj: backend(), member: "calibrate", c: Qt::DirectConnection);
148}
149
150QT_END_NAMESPACE
151
152#include "moc_qtiltsensor.cpp"
153

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