forked from SiriusDely/Cascades-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSensorDemo.qdoc
199 lines (137 loc) · 9.16 KB
/
SensorDemo.qdoc
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/****************************************************************************
**
** Copyright (C) 2012 Research In Motion Limited.
** All rights reserved.
** Contact: Research In Motion Ltd. (http://www.rim.com/company/contact/)
**
** This file is part of the examples of the BB10 Platform.
**
** 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.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms
** and conditions contained in a signed written agreement between you
** and Research In Motion Limited.
**
****************************************************************************/
/*!
\page SensorDemo
\example SensorDemo
\title Sensor Demo Example
\section1 Description
The Sensor Demo example is a collection of pages where each page demonstrate
how to retrieve and process data from a certain hardware sensor.
\div {class="centerAlign"}
\inlineimage sensordemo-example.png
\enddiv
\section1 Overview
In this example we'll learn how to use the most of the available sensors of the BB10 framework.
We'll retrieve data, process them and visualize them in various ways.
\section1 The UI
The UI of this sample application consists of six pages, all located in a \c TabbedPane. Each page covers the
usage of a certain sensor or a combination of sensors to fulfill a specific task.
\snippet SensorDemo/assets/main.qml 1
Each \c Tab has an ID, a title and an icon assigned. To keep the memory footprint of the application low,
we load the content of the single tab on demand whenever a tab is activated and unload the content when the
tab is hidden again. For this purpose we use the \c ControlDelegate which allows us to load/unload a \c Control
on-the-fly by modifying the 'delegateActive' property. As loading condition we check whether this tab is the active tab
of the TabbedPane.
\snippet SensorDemo/assets/main.qml 0
After the UI has been loaded completely, the supported orientations of the \c OrientationSupport object is set to 'All'
to allow the application to react on device rotations.
\section2 The Motion Sensor Page
\div {class="centerAlign"}
\inlineimage sensordemo-example1.png
\enddiv
The first page, which is implemented in 'motionalarm.qml', demonstrats how the \c Accelerometer sensor can be used to
show a warning whenever the user moves the device in any direction.
\snippet SensorDemo/assets/motionalarm.qml 0
The page contains a \c SystemSound object and the \c Accelerometer object as attached objects. The \c Accelerometer emits
the readingChanged() signal whenever new sensor values are available. In the signal handler 'onReadingChanged' we store the
coordinate values of the reading in custom properties (x, y and z) and test whether this vector has a length larger than 0.2.
If that's the case we declare it as a movement and play a sound. In any case we update the 'movement' property.
\snippet SensorDemo/assets/motionalarm.qml 1
The custom 'movement' property of the \c Accelerator object is used by a \c Label on this page to show a warning (when moved)
or a normal text. The color of the text depends on the 'movement' property as well.
\snippet SensorDemo/assets/motionalarm.qml 2
There are three additional \c{Label}s which show the x, y and z values of the current reading.
\section2 The Compass Page
\div {class="centerAlign"}
\inlineimage sensordemo-example2.png
\enddiv
The second page, which is implemented in 'compass.qml', demonstrats how the \c Compass sensor can be used to
implement a compass rose. Since the sensor data depend on the current orientation of the device, we use the \c OrientationHandler
and \c OrientationSensor classes as well to implement a proper behavior.
\snippet SensorDemo/assets/compass.qml 0
All three objects are created as attached objects to the page. Since we set the 'axesOrientationMode' of the \c Compass to
'UserOrientation', we have to update its 'userOrientation' property manually. We could have set it to 'AutomaticOrientation' instead,
then the \c Compass would adapt the axes orientation internally, but we do it manually here to show how it can be done.
The \c Compass object has a custom property 'azimuth' where the azimuth value of the last compass reading is stored in.
The \c OrientationSensor has also a custom property which stores whether the sensor detected that the device is hold face down.
\snippet SensorDemo/assets/compass.qml 1
The 'azimuth' property of the \c Compass is used by a \c Label to show the current value next to the compass rose.
\snippet SensorDemo/assets/compass.qml 2
The compass rose itself is an \c ImageView with its 'rotationZ' property bound against the 'azimuth' property. So whenever
the property changes, the \c ImageView is rotated automatically.
\section2 The Metal Detector Page
\div {class="centerAlign"}
\inlineimage sensordemo-example3.png
\enddiv
The third page, which is implemented in 'metalfinder.qml', demonstrats how the \c Magnetometer sensor can be used to
implement a simple metal detector. Since the magnetic field is influenced by metal objects, we compare the length of the
vector reported by the sensor against a baseline value and can calculate the distance to the metal object from that.
To report that to the user we utilize the \c VibrationController.
The \c Magnetometer and \c VibrationController are created as attached objects to the page.
\snippet SensorDemo/assets/metalfinder.qml 0
The \c Magnetometer has a couple of custom properties defined that are used to store the values of the last reading.
Whenever a new reading is reported, we calculate the length of the result value (x, y and z) and use it as magnitude
value. If there has no baseline be defined before, we use the magnitude as our new baseline. Afterwards we calculate
the intensity of the magnetic field distraction. If it is larger than 0 we are near to an metal object and start the
vibration.
\snippet SensorDemo/assets/metalfinder.qml 1
At all times the user can calibrate the \c Magnetometer to use the current magnitude as new baseline by clicking the
'Calibrate Metal Finder' button.
\snippet SensorDemo/assets/metalfinder.qml 2
The custom 'x', 'y' and 'z' properties of the \c Magnetometer object are used by the three \c{Label}s at the bottom
of the page to show the current values.
\section2 The Night Lamp Page
\div {class="centerAlign"}
\inlineimage sensordemo-example4.png
\enddiv
The fourth page, which is implemented in 'flashlight.qml', demonstrats how the \c AmbientLightSensor and \c LightSensor can
be used to implement a flashlight that reacts to its environment. The user can define two thresholds, one that defines the rotation
angle that is used to switch on the flahslight and one that defines the ambient light type that is used as trigger to switch
of the flashlight again.
\snippet SensorDemo/assets/flashlight.qml 0
The rotation is measured with the \c Gyroscope sensor that is created as attached object together with the \c AmbientLightSensor
and \c LightSensor. Additionally a \c Flashlight object is created, a custom C++ class that abstracts the access to the camera flash light.
The \c Flashlight object is used inside the onReadingChanged signal handler of the \c Gyroscope to toggle the light.
The \c LightSensor simply stores the read LUX value in a custom property.
\snippet SensorDemo/assets/flashlight.qml 1
This custom property is used by a \c Label at the bottom of the page.
\section2 The Collision Detection Page
\div {class="centerAlign"}
\inlineimage sensordemo-example5.png
\enddiv
The fifth page, which is implemented in 'collisiondetector.qml', demonstrats how the \c IRProximitySensor and \c ProximitySensor can
be used to test whether an object is near the front face of the device.
\snippet SensorDemo/assets/collisiondetector.qml 0
The \c IRProximitySensor measures the reflectance of the object and stores the value in a custom property. The \c ProximitySensor
checks whether the object is close enough to the device or not. If it is, we play a sound and start a fade animation on a \c Label.
\snippet SensorDemo/assets/collisiondetector.qml 1
The \c Label shows a warning if the object is too close.
\section2 The Rotation 3D Page
\div {class="centerAlign"}
\inlineimage sensordemo-example6.png
\enddiv
The sixth page, which is implemented in 'rotation3D.qml', demonstrats how the current values from the \c RotationSensor can be read.
\snippet SensorDemo/assets/rotation3D.qml 0
The \c RotationSensor is created as attached object of the page and it simply stores the measured x, y and z value in custom
properties.
\snippet SensorDemo/assets/rotation3D.qml 1
The properties are used by three \c{Label}s to show the values in the UI.
*/