QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
EscIndicator.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Layouts
3
4import QGroundControl
5import QGroundControl.Controls
6
7Item {
8 id: control
9 anchors.top: parent.top
10 anchors.bottom: parent.bottom
11 width: escIndicatorRow.width
12
13 property bool showIndicator: _escs.count > 0
14
15 property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
16 property var _escs: _activeVehicle ? _activeVehicle.escs : null
17
18 // ESC status properties derived from vehicle data
19 property int _motorCount: _escs && _escs.count > 0 ? _escs.get(0).count.rawValue : 0
20 property int _onlineBitmask: _escs && _escs.count > 0? _escs.get(0).info.rawValue : 0
21
22 property int _onlineMotorCount: _getOnlineMotorCount()
23 property bool _escHealthy: _getEscHealthStatus()
24
25 function _getOnlineMotorCount() {
26 if (_motorCount === 0) return 0;
27
28 let count = 0;
29 let mask = _onlineBitmask;
30
31 // Count all set bits in the bitmask
32 while (mask) {
33 count += mask & 1;
34 mask >>= 1;
35 }
36
37 return count;
38 }
39
40 function _getEscHealthStatus() {
41 // Health is good if all expected motors are online and have no failure flags
42 if (_onlineMotorCount !== _motorCount) return false
43
44 // Check failure flags for each motor (4 per group)
45 for (let index = 0; index < 4; index++) {
46 if ((_onlineBitmask & (1 << index)) !== 0) { // Motor is online
47 if (_escs.get(index).failureFlags > 0) { // Any failure flag set means unhealthy
48 return false
49 }
50 }
51 }
52
53 return true
54 }
55
56 function getEscStatusColor() {
57 return _escHealthy ? qgcPal.colorGreen : qgcPal.colorRed
58 }
59
60 QGCPalette { id: qgcPal }
61
62 Row {
63 id: escIndicatorRow
64 anchors.top: parent.top
65 anchors.bottom: parent.bottom
66 spacing: ScreenTools.defaultFontPixelWidth / 2
67
68 QGCColoredImage {
69 id: escIcon
70 width: height
71 anchors.top: parent.top
72 anchors.bottom: parent.bottom
73 source: "/qmlimages/EscIndicator.svg"
74 fillMode: Image.PreserveAspectFit
75 sourceSize.height: height
76 color: qgcPal.windowTransparentText
77 }
78
79 Column {
80 id: escValuesColumn
81 anchors.verticalCenter: parent.verticalCenter
82 spacing: 0
83
84 QGCLabel {
85 anchors.horizontalCenter: parent.horizontalCenter
86 color: qgcPal.windowTransparentText
87 text: _onlineMotorCount.toString()
88 font.pointSize: ScreenTools.smallFontPointSize
89 }
90
91 QGCLabel {
92 color: getEscStatusColor()
93 text: _escHealthy ? qsTr("OK") : qsTr("ERR")
94 font.pointSize: ScreenTools.smallFontPointSize
95 }
96 }
97 }
98
99 MouseArea {
100 anchors.fill: parent
101 onClicked: mainWindow.showIndicatorDrawer(escIndicatorPage, control)
102 }
103
104 Component {
105 id: escIndicatorPage
106
107 EscIndicatorPage { }
108 }
109}