summaryrefslogtreecommitdiffstats
path: root/doc/src/examples/sensors.qdoc
blob: 3363642bd50f2ceb934f9b739400c9ca30e13273 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Free Documentation License
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of this
** file.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
    \example sensors/grueplugin
    \title Grue Plugin

    The Grue plugin example demonstrates the creation of a new sensor type,
    a sensor backend and plugin for the sensors library. Related to this example
    is the \l{sensors/grueapp}{Grue Application} example.

    \tableofcontents

    \section1 Grue Sensor Type

    The files for this are:

    \list
    \o gruesensor.h
    \o gruesensor_p.h
    \o gruesensor.cpp
    \endlist

    First up is the sensor type. This is the interface for sensors that report
    on your likelihood of being eaten by a Grue. Such sensors are very important
    to adventurers, particularly if they are going into dark places as this is
    where Grues live.

    The interface is a simple one. It provides only 1 piece of information, your
    chance of being eaten. For the details on how this is property should be
    interpreted please see the documentation in gruesensor.cpp.

    This example was created using the make_sensor.pl script which can be found in
    src/sensors. As such, it contains some generated code that defines the convenience
    classes GrueFilter and GrueSensor.

    \section1 Grue Sensor Backend

    The files for this are:

    \list
    \o gruesensorimpl.h
    \o gruesensorimpl.cpp
    \endlist

    The Grue sensor needs a backend before it can be used. The backend provided
    is rather basic and it relies on some kind of light sensor to work but it
    gets the job done. If new hardware that can detect the actual presence of Grues
    becomes available a backend could be created that supports this hardware and
    applications using the Grue sensor would be able to use it without any changes.

    There are a few mandatory parts to a backend. They are the start and stop methods
    and the setReading call. The start and stop methods are used to start and stop
    any underlying hardware. In the case of this backend they start and stop a
    light sensor. In the start method, the backend should be sure to call the
    sensorStopped() or sensorBusy() methods if it cannot start.

    \snippet ../../examples/sensors/grueplugin/gruesensorimpl.cpp start

    The setReading method is needed so that the sensors library knows where the
    readings are coming from. This backend has a local copy of the reading so
    it passes a pointer to the function.

    \snippet ../../examples/sensors/grueplugin/gruesensorimpl.cpp setReading

    However it is also possible to pass null to the setReading method in which
    case the sensors library will create an instance and return a pointer.

    \code
    // Create a reading instance for us to use
    m_reading = setReading<GrueSensorReading>(0);
    \endcode

    The Grue sensor backend also supplies some metadata.

    The backend checks 2 things, how dark it is and how long you have been in the dark.
    It uses the readingChanged() signal to know when to check the light sensor's
    value. Once it is dark, it uses a timer to increase your chance of being eaten.

    \section1 Grue Sensor Plugin

    The files for this are:

    \list
    \o main.cpp
    \endlist

    The Grue sensor backend is delivered as a plugin. The plugin has a factory object
    that registers the types available and does the actual instantiation of the backend.

    \sa {sensors/grueapp}{Grue Application}
*/


/*!
    \example sensors/grueapp
    \title Grue Application

    The Grue application example demonstrates the use of the Grue sensor which
    was defined and implemented by the \l{sensors/grueplugin}{Grue Plugin} example.
    The Grue application is a commandline application. It is significant to note that
    there is no link-time dependency on the Grue plugin. The Grue application uses
    the generic access feature of the Sensors API.

    \sa {sensors/grueplugin}{Grue Plugin}
*/


/*!
    \example sensors/cubehouse
    \title Cube House

    \image cubehouse.png

    The Cube House example demonstrates the use of the accelerometer to drive a camera
    to create a pseudo-3D effect. It also demonstrates the use of a filter to smooth
    out the accelerometer values.

    The accelerometer is created and the filter is added.

    \snippet ../../examples/sensors/cubehouse/view.cpp accelerometer

    When new values are available, the view is recalculated.

    \snippet ../../examples/sensors/cubehouse/view.cpp accelerometer2

    The filter is defined like this.

    \snippet ../../examples/sensors/cubehouse/view.cpp smoothed
*/


/*!
    \example sensors/sensor_explorer
    \title Sensor Explorer

    \image sensor_explorer.png

    The Sensor Explorer example demonstrates how to read the meta-data of available sensors.
    It was designed as a debugging aid.
*/