QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
JoystickIndicator.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Layouts
3
4import QGroundControl
5import QGroundControl.Controls
6
7// Joystick Indicator
8Item {
9 id: control
10 width: joystickIcon.width * 1.1
11 anchors.top: parent.top
12 anchors.bottom: parent.bottom
13
14 property bool showIndicator: _activeJoystick
15 property var _activeJoystick: joystickManager.activeJoystick
16 property bool _joystickEnabled: globals.activeVehicle && joystickManager.activeJoystickEnabledForActiveVehicle
17
18 QGCPalette { id: qgcPal }
19
20 Component {
21 id: joystickInfoPage
22
23 ToolIndicatorPage {
24 showExpand: true
25
26 contentComponent: SettingsGroupLayout {
27 heading: _activeJoystick ? _activeJoystick.name : qsTr("Joystick")
28
29 GridLayout {
30 columns: 2
31 columnSpacing: ScreenTools.defaultFontPixelWidth * 2
32
33 QGCLabel { text: qsTr("Enabled:") }
34 QGCLabel {
35 text: {
36 if (!globals.activeVehicle)
37 return qsTr("No Vehicle")
38 return _joystickEnabled ? qsTr("Yes") : qsTr("No")
39 }
40 color: {
41 if (!globals.activeVehicle)
42 return qgcPal.buttonText
43 return _joystickEnabled ? qgcPal.buttonText : "orange"
44 }
45 }
46
47 QGCLabel { text: qsTr("Type:") }
48 QGCLabel {
49 text: _activeJoystick ? (_activeJoystick.isGamepad ? _activeJoystick.gamepadType || qsTr("Gamepad") : qsTr("Joystick")) : ""
50 }
51
52 QGCLabel {
53 text: qsTr("Connection:")
54 visible: _activeJoystick && _activeJoystick.connectionType && _activeJoystick.connectionType !== "Unknown" && _activeJoystick.connectionType !== "Invalid"
55 }
56 QGCLabel {
57 text: _activeJoystick ? _activeJoystick.connectionType : ""
58 visible: _activeJoystick && _activeJoystick.connectionType && _activeJoystick.connectionType !== "Unknown" && _activeJoystick.connectionType !== "Invalid"
59 }
60
61 QGCLabel { text: qsTr("Inputs:") }
62 QGCLabel {
63 text: {
64 if (!_activeJoystick) return ""
65 var parts = [qsTr("%1 axes").arg(_activeJoystick.axisCount), qsTr("%1 buttons").arg(_activeJoystick.buttonCount)]
66 if (_activeJoystick.ballCount > 0) parts.push(qsTr("%1 balls").arg(_activeJoystick.ballCount))
67 if (_activeJoystick.touchpadCount() > 0) parts.push(qsTr("%1 touchpads").arg(_activeJoystick.touchpadCount()))
68 return parts.join(", ")
69 }
70 }
71
72 QGCLabel {
73 text: qsTr("Battery:")
74 visible: _activeJoystick && _activeJoystick.batteryPercent >= 0
75 }
76 QGCLabel {
77 text: {
78 if (!_activeJoystick || _activeJoystick.batteryPercent < 0) return ""
79 var batteryText = qsTr("%1%").arg(_activeJoystick.batteryPercent)
80 if (_activeJoystick.powerState) batteryText += " (" + _activeJoystick.powerState + ")"
81 return batteryText
82 }
83 color: _activeJoystick && _activeJoystick.batteryPercent < 20 ? "red" : qgcPal.buttonText
84 visible: _activeJoystick && _activeJoystick.batteryPercent >= 0
85 }
86
87 QGCLabel {
88 text: qsTr("Features:")
89 visible: _activeJoystick && (_activeJoystick.hasRumble || _activeJoystick.hasLED || _activeJoystick.hasGyroscope() || _activeJoystick.hasAccelerometer())
90 }
91 QGCLabel {
92 property var features: {
93 var list = []
94 if (_activeJoystick) {
95 if (_activeJoystick.hasRumble) list.push(qsTr("Rumble"))
96 if (_activeJoystick.hasRumbleTriggers) list.push(qsTr("Trigger Rumble"))
97 if (_activeJoystick.hasLED) list.push(qsTr("LED"))
98 if (_activeJoystick.hasGyroscope()) list.push(qsTr("Gyro"))
99 if (_activeJoystick.hasAccelerometer()) list.push(qsTr("Accel"))
100 }
101 return list.join(", ")
102 }
103 text: features
104 visible: _activeJoystick && (_activeJoystick.hasRumble || _activeJoystick.hasLED || _activeJoystick.hasGyroscope() || _activeJoystick.hasAccelerometer())
105 }
106
107 QGCLabel {
108 text: qsTr("Player:")
109 visible: _activeJoystick && _activeJoystick.playerIndex >= 0
110 }
111 QGCLabel {
112 text: _activeJoystick ? (_activeJoystick.playerIndex + 1).toString() : ""
113 visible: _activeJoystick && _activeJoystick.playerIndex >= 0
114 }
115 }
116 }
117
118 expandedComponent: SettingsGroupLayout {
119 heading: qsTr("Device Details")
120
121 GridLayout {
122 columns: 2
123 columnSpacing: ScreenTools.defaultFontPixelWidth * 2
124
125 QGCLabel {
126 text: qsTr("Device Type:")
127 visible: _activeJoystick && _activeJoystick.deviceType
128 }
129 QGCLabel {
130 text: _activeJoystick ? _activeJoystick.deviceType : ""
131 visible: _activeJoystick && _activeJoystick.deviceType
132 }
133
134 QGCLabel {
135 text: qsTr("Vendor/Product:")
136 visible: _activeJoystick && _activeJoystick.vendorId > 0
137 }
138 QGCLabel {
139 text: _activeJoystick ? "0x%1 / 0x%2".arg(_activeJoystick.vendorId.toString(16).toUpperCase().padStart(4, '0')).arg(_activeJoystick.productId.toString(16).toUpperCase().padStart(4, '0')) : ""
140 visible: _activeJoystick && _activeJoystick.vendorId > 0
141 }
142
143 QGCLabel {
144 text: qsTr("Serial:")
145 visible: _activeJoystick && _activeJoystick.serial
146 }
147 QGCLabel {
148 text: _activeJoystick ? _activeJoystick.serial : ""
149 visible: _activeJoystick && _activeJoystick.serial
150 }
151
152 QGCLabel {
153 text: qsTr("Firmware:")
154 visible: _activeJoystick && _activeJoystick.firmwareVersion > 0
155 }
156 QGCLabel {
157 text: _activeJoystick ? _activeJoystick.firmwareVersion.toString() : ""
158 visible: _activeJoystick && _activeJoystick.firmwareVersion > 0
159 }
160
161 QGCLabel {
162 text: qsTr("Path:")
163 visible: _activeJoystick && _activeJoystick.path
164 }
165 QGCLabel {
166 text: _activeJoystick ? _activeJoystick.path : ""
167 visible: _activeJoystick && _activeJoystick.path
168 elide: Text.ElideMiddle
169 Layout.maximumWidth: ScreenTools.defaultFontPixelWidth * 20
170 }
171
172 QGCLabel {
173 text: qsTr("GUID:")
174 visible: _activeJoystick && _activeJoystick.guid
175 }
176 QGCLabel {
177 text: _activeJoystick ? _activeJoystick.guid : ""
178 visible: _activeJoystick && _activeJoystick.guid
179 font.family: "monospace"
180 font.pixelSize: ScreenTools.smallFontPointSize
181 elide: Text.ElideMiddle
182 Layout.maximumWidth: ScreenTools.defaultFontPixelWidth * 20
183 }
184
185 QGCLabel {
186 text: qsTr("Virtual:")
187 visible: _activeJoystick && _activeJoystick.isVirtual
188 }
189 QGCLabel {
190 text: qsTr("Yes")
191 visible: _activeJoystick && _activeJoystick.isVirtual
192 }
193
194 QGCLabel {
195 text: qsTr("LED Types:")
196 visible: _activeJoystick && (_activeJoystick.hasMonoLED() || _activeJoystick.hasRGBLED() || _activeJoystick.hasPlayerLED())
197 }
198 QGCLabel {
199 property var ledTypes: {
200 var list = []
201 if (_activeJoystick) {
202 if (_activeJoystick.hasMonoLED()) list.push(qsTr("Mono"))
203 if (_activeJoystick.hasRGBLED()) list.push(qsTr("RGB"))
204 if (_activeJoystick.hasPlayerLED()) list.push(qsTr("Player"))
205 }
206 return list.join(", ")
207 }
208 text: ledTypes
209 visible: _activeJoystick && (_activeJoystick.hasMonoLED() || _activeJoystick.hasRGBLED() || _activeJoystick.hasPlayerLED())
210 }
211
212 QGCLabel {
213 text: qsTr("Haptic:")
214 visible: _activeJoystick && _activeJoystick.hasHaptic()
215 }
216 QGCLabel {
217 text: _activeJoystick && _activeJoystick.hasHaptic() ? qsTr("%1 effects").arg(_activeJoystick.hapticEffectsCount()) : ""
218 visible: _activeJoystick && _activeJoystick.hasHaptic()
219 }
220
221 QGCLabel {
222 text: qsTr("Motion Sensors:")
223 visible: _activeJoystick && (_activeJoystick.hasGyroscope() || _activeJoystick.hasAccelerometer())
224 }
225 QGCLabel {
226 property var sensors: {
227 var list = []
228 if (_activeJoystick) {
229 if (_activeJoystick.hasGyroscope()) {
230 var gyroRate = _activeJoystick.gyroscopeDataRate()
231 list.push(gyroRate > 0 ? qsTr("Gyro (%1 Hz)").arg(gyroRate.toFixed(0)) : qsTr("Gyro"))
232 }
233 if (_activeJoystick.hasAccelerometer()) {
234 var accelRate = _activeJoystick.accelerometerDataRate()
235 list.push(accelRate > 0 ? qsTr("Accel (%1 Hz)").arg(accelRate.toFixed(0)) : qsTr("Accel"))
236 }
237 }
238 return list.join(", ")
239 }
240 text: sensors
241 visible: _activeJoystick && (_activeJoystick.hasGyroscope() || _activeJoystick.hasAccelerometer())
242 }
243 }
244 }
245 }
246 }
247
248 QGCColoredImage {
249 id: joystickIcon
250 width: height
251 anchors.top: parent.top
252 anchors.bottom: parent.bottom
253 sourceSize.height: height
254 source: "/qmlimages/Joystick.png"
255 fillMode: Image.PreserveAspectFit
256 color: {
257 if (!globals.activeVehicle) {
258 return qgcPal.buttonText
259 }
260 if (_joystickEnabled) {
261 return qgcPal.buttonText
262 }
263 return "orange"
264 }
265 }
266
267 QGCMouseArea {
268 fillItem: joystickIcon
269 onClicked: mainWindow.showIndicatorDrawer(joystickInfoPage, control)
270 }
271}