blob: 43bf140a79c694f55c8b2f2121a1636d1e73155c (
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
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
200
201
202
203
204
205
206
207
208
209
210
211
212
|
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
/* Layout
mainWnd
/
---------------------------------------------------------------------------------
|--------------------------------------------------------------------------------
|| labelTitle |
|--------------------------------------------------------------------------------
|-------------------------------------------------------------------------------- <---- tiltLine
|--------------------------------------------------------------------------------
|| labelTilt |
|--------------------------------------------------------------------------------
| / accuracyRect / speedRect
|-------------------------------------------||----------------------------------|
|| Accuracy <----- textAccuracy || Speed <-----textSpeed |
|| value <- textAccuracyValue || value <- textSpeedValue |
|| ----------------- ------------------ || --------------- ---------------- |
|| | accuracyLower | | accuracyHigher | || | speedLower | | speedHigher | |
|| ----------------- ------------------ || --------------- ---------------- |
|------------------------------------------ ||----------------------------------|
| -----------
| |Calibrate| <------------------ calibrate
| -----------
| ---------
| |Degree | <-------------------- useRadian X Rotation: 0 <------------------ xrottext
| ---------
| ---------
| |Start | <-------------------- tiltStart Y Rotation: 0 <------------------ yrottext
| ---------
|-------------------------------------------------------------------------------- <---- ambientlightLine
|--------------------------------------------------------------------------------
|| labelAmbientLight |
|--------------------------------------------------------------------------------
| ---------
| |Start | <-------------------- ablStart Ambient light: - <--------------- abltext
| ---------
|-------------------------------------------------------------------------------- <---- proximityLine
|--------------------------------------------------------------------------------
|| labelProximityLight |
|--------------------------------------------------------------------------------
| ---------
| |Start | <-------------------- proxiStart Proximity: - <--------------- proxitext
| ---------
------------------------------------------------------------------------------
*/
//Import the declarative plugins
import QtQuick
import "components"
//! [0]
import QtSensors
//! [0]
ApplicationWindow {
anchors.fill: parent
// Sensor types used
//! [1]
TiltSensor {
id: tilt
active: false
}
//! [1]
AmbientLightSensor {
id: ambientlight
active: false
//! [5]
onReadingChanged: {
if (reading.lightLevel == AmbientLightReading.Dark)
ambientlighttext.text = "Ambient light: Dark";
else if (reading.lightLevel == AmbientLightReading.Twilight)
ambientlighttext.text = "Ambient light: Twilight";
else if (reading.lightLevel == AmbientLightReading.Light)
ambientlighttext.text = "Ambient light: Light";
else if (reading.lightLevel == AmbientLightReading.Bright)
ambientlighttext.text = "Ambient light: Bright";
else if (reading.lightLevel == AmbientLightReading.Sunny)
ambientlighttext.text = "Ambient light: Sunny";
else
ambientlighttext.text = "Ambient light: Unknown";
}
//! [5]
}
ProximitySensor {
id: proxi
active: false
}
Column {
spacing: 10
anchors.fill: parent
anchors.margins: 5
Text {
id: labelTitle
width: parent.width
horizontalAlignment: Text.AlignHCenter
font.pixelSize: 30
font.bold: true
text: "QML QtSensors"
}
// Tilt region
Divider { label: "TiltSensor" }
Row {
spacing: 20
width: parent.width
anchors.margins: 5
Button {
id: calibrate
height: 30
width: 80
text: "Calibrate"
onClicked: tilt.calibrate();
}
Text {
id: xrottext
height: 30
verticalAlignment: Text.AlignVCenter
//! [3]
text: "X Rotation: " + (tilt.reading ? tilt.reading.xRotation.toFixed(2) + "°" : "Unknown")
//! [3]
}
}
Row {
spacing: 20
width: parent.width
anchors.margins: 5
Button {
id: tiltStart
height: 30
width: 80
text: tilt.active ? "Stop" : "Start"
onClicked: {
//! [2]
tilt.active = (tiltStart.text === "Start");
//! [2]
}
}
Text {
id: yrottext
height: 30
verticalAlignment: Text.AlignVCenter
//! [4]
text: "Y Rotation: " + (tilt.reading ? tilt.reading.yRotation.toFixed(2) + "°" : "Unknown")
//! [4]
}
}
Divider { label: "AmbientLightSensor" }
Row {
spacing: 20
width: parent.width
anchors.margins: 5
Button{
id: ambientlightStart
height: 30
width: 80
text: ambientlight.active ? "Stop" : "Start"
onClicked: {
ambientlight.active = (ambientlightStart.text === "Start" ? true : false);
}
}
Text {
id: ambientlighttext
height: 30
verticalAlignment: Text.AlignVCenter
text: "Ambient light: Unknown"
}
}
// Proximity region
Divider { label: "ProximitySensor" }
Row {
spacing: 20
width: parent.width
anchors.margins: 5
Button {
id: proxiStart
height: 30
width: 80
text: proxi.active ? "Stop" : "Start"
onClicked: {
proxi.active = (proxiStart.text === "Start" ? true: false);
}
}
Text {
id: proxitext
height: 30
verticalAlignment: Text.AlignVCenter
//! [6]
text: "Proximity: " +
(proxi.active ? (proxi.reading.near ? "Near" : "Far") : "Unknown")
//! [6]
}
}
}
}
|