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