QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
PX4EscComponent.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Layouts
3
4import QGroundControl
5import QGroundControl.Controls
6import QGroundControl.FactControls
7
8import "PX4ConfigRows.js" as ConfigRows
9import "PX4EscRows.js" as EscRows
10
11SetupPage {
12 id: escPage
13 pageComponent: pageComponent
14
15 // Parameter values when the page first showed them, so a reboot is only flagged after a change
16 property var _initialValues: Object.create(null)
17
18 readonly property int _motorCount: {
19 const fact = _fact("CA_ROTOR_COUNT")
20 return fact && fact.rawValue > 0 ? fact.rawValue : 12
21 }
22 readonly property var _outputKinds: {
23 const protocols = []
24 for (const name of EscRows.timerParams()) {
25 const fact = _fact(name)
26 if (fact) {
27 protocols.push(fact.rawValue)
28 }
29 }
30 return EscRows.outputKinds(protocols)
31 }
32 readonly property var _rows: ConfigRows.visibleRows(
33 EscRows.escRows(_motorCount),
34 ({}),
35 function (name) { return controller.parameterExists(-1, name) })
36 readonly property var _groups: ConfigRows.groupRows(_rows)
37
38 function _fact(name) {
39 return controller.getParameterFact(-1, name, false)
40 }
41
42 function _rawValue(name) {
43 const fact = _fact(name)
44 return fact ? fact.rawValue : undefined
45 }
46
47 function _rowShown(row) {
48 return EscRows.rowShown(row, _outputKinds)
49 }
50
51 function _groupShown(group) {
52 return group.rows.some(row => _rowShown(row))
53 }
54
55 PX4EscController {
56 id: controller
57 // Reboot-required settings are marked on the page instead
58 suppressRebootMessage: true
59 }
60
61 QGCPalette {
62 id: qgcPal
63 }
64
65 QGCPopupDialogFactory {
66 id: escCalibrationDialogFactory
67 dialogComponent: escCalibrationDialogComponent
68 }
69
70 Component {
71 id: escCalibrationDialogComponent
72
73 ESCCalibrationDialog { }
74 }
75
76 Component {
77 id: pageComponent
78
79 ColumnLayout {
80 width: Math.max(availableWidth, implicitWidth)
81 spacing: _margins
82
83 ConfigRowsPanel {
84 ColumnLayout {
85 Layout.fillWidth: true
86 spacing: ScreenTools.defaultFontPixelHeight * 0.5
87 visible: EscRows.calibrationShown(escPage._outputKinds)
88
89 ConfigGroupHeader {
90 text: qsTr("Calibration")
91 }
92
93 ConfigRow {
94 objectName: "esc_row_calibration"
95 title: qsTr("PWM calibration")
96 active: true
97
98 ConfigNote {
99 text: qsTr("Teaches ESCs which take a PWM signal the full throttle range. DShot and DroneCAN ESCs do not need it.")
100 }
101
102 ConfigNote {
103 color: qgcPal.warningText
104 text: qsTr("Remove the propellers first. Use a USB connection, with the battery disconnected until calibration asks for it.")
105 }
106
107 cellsData: QGCCaptionCell {
108 QGCButton {
109 objectName: "esc_calibrateButton"
110 text: qsTr("Calibrate")
111 onClicked: escCalibrationDialogFactory.open()
112 }
113 }
114 }
115 }
116
117 ConfigRowGroups {
118 model: escPage._groups
119 groupShown: escPage._groupShown
120 objectNamePrefix: "esc"
121
122 rowDelegate: ConfigRow {
123 id: rowLayout
124 objectName: "esc_row_" + row.id
125 title: row.title
126 params: row.params
127 active: true
128 showSeparator: index > 0
129 visible: escPage._rowShown(row)
130
131 required property var modelData
132 required property int index
133
134 readonly property var row: modelData
135
136 ConfigNote {
137 text: rowLayout.row.description
138 }
139
140 cellsData: Repeater {
141 model: rowLayout.row.cells
142
143 ConfigParamCell {
144 cell: modelData
145 factFor: escPage._fact
146 initialValues: escPage._initialValues
147 objectNamePrefix: "esc"
148 visible: EscRows.cellShown(modelData, escPage._rawValue)
149
150 required property var modelData
151 }
152 }
153 }
154 }
155 }
156 }
157 }
158}