QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
PX4FlightModes.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Layouts
4
5import QGroundControl
6import QGroundControl.FactControls
7import QGroundControl.Controls
8
9SetupPage {
10 pageComponent: pageComponent
11 Component {
12 id: pageComponent
13
14 Item {
15 id: root
16 width: availableWidth
17 height: availableHeight
18
19 property string sectionNameFilter: ""
20
21 property real _margins: ScreenTools.defaultFontPixelHeight / 2
22 property var _switchNameList: [ "RC_MAP_ARM_SW", "RC_MAP_GEAR_SW", "RC_MAP_KILL_SW", "RC_MAP_LOITER_SW", "RC_MAP_OFFB_SW", "RC_MAP_RETURN_SW" ]
23 property var _switchTHList: [ "RC_ARMSWITCH_TH", "RC_GEAR_TH", "RC_KILLSWITCH_TH", "RC_LOITER_TH", "RC_OFFB_TH", "RC_RETURN_TH" ]
24
25 readonly property real _channelComboWidth: ScreenTools.defaultFontPixelWidth * 13
26
27 Component.onCompleted: {
28 if (controller.vehicle.vtol) {
29 _switchNameList.push("RC_MAP_TRANS_SW")
30 _switchTHList.push("RC_TRANS_TH")
31 }
32 if (controller.vehicle.fixedWing) {
33 _switchNameList.push("RC_MAP_FLAPS")
34 _switchTHList.push("")
35 }
36 switchRepeater.model = _switchNameList
37 }
38
39 PX4SimpleFlightModesController {
40 id: controller
41 }
42
43 QGCFlickable {
44 anchors.fill: parent
45 clip: true
46 contentWidth: column2.x + column2.width
47 contentHeight: Math.max(column1.height, column2.height)
48
49 Column {
50 id: column1
51 spacing: _margins
52
53 Row {
54 id: settingsRow
55 spacing: _margins
56
57 Column {
58 id: flightModeSettingsColumn
59 spacing: _margins
60 visible: sectionNameFilter === "" || sectionNameFilter === qsTr("Flight Modes")
61
62 QGCLabel {
63 id: flightModeLabel
64 text: qsTr("Flight Mode Settings")
65 font.bold: true
66 }
67
68 Rectangle {
69 id: flightModeSettings
70 width: flightModeColumn.width + (_margins * 2)
71 height: flightModeColumn.height + ScreenTools.defaultFontPixelHeight
72 color: qgcPal.windowShade
73
74 GridLayout {
75 id: flightModeColumn
76 anchors.margins: ScreenTools.defaultFontPixelWidth
77 anchors.left: parent.left
78 anchors.top: parent.top
79 rows: 7
80 rowSpacing: ScreenTools.defaultFontPixelWidth / 2
81 columnSpacing: rowSpacing
82 flow: GridLayout.TopToBottom
83
84 QGCLabel {
85 Layout.fillWidth: true
86 text: qsTr("Mode Channel")
87 }
88
89 Repeater {
90 model: 6
91
92 QGCLabel {
93 Layout.fillWidth: true
94 text: qsTr("Flight Mode %1").arg(modelData + 1)
95 color: (controller.activeFlightMode - 1) == index ? "yellow" : qgcPal.text
96 }
97 }
98
99 FactComboBox {
100 Layout.fillWidth: true
101 fact: controller.getParameterFact(-1, "RC_MAP_FLTMODE")
102 indexModel: false
103 sizeToContents: true
104 }
105
106 Repeater {
107 model: 6
108
109 FactComboBox {
110 Layout.fillWidth: true
111 fact: controller.getParameterFact(-1, "COM_FLTMODE" + (modelData + 1))
112 indexModel: false
113 sizeToContents: true
114 }
115 }
116 }
117 } // Rectangle - Flight Modes
118 } // Column - Flight mode settings
119
120 Column {
121 id: column2
122 spacing: _margins
123 visible: sectionNameFilter === "" || sectionNameFilter === qsTr("Switch Settings")
124
125 QGCLabel {
126 text: qsTr("Switch Settings")
127 font.bold: true
128 }
129
130 Rectangle {
131 id: switchSettingsRect
132 width: switchSettingsGrid.width + (_margins * 2)
133 height: switchSettingsGrid.height + ScreenTools.defaultFontPixelHeight
134 color: qgcPal.windowShade
135
136 GridLayout {
137 id: switchSettingsGrid
138 anchors.margins: ScreenTools.defaultFontPixelWidth
139 anchors.left: parent.left
140 anchors.top: parent.top
141 columns: 2
142 columnSpacing: ScreenTools.defaultFontPixelWidth
143
144 Repeater {
145 id: switchRepeater
146
147 RowLayout {
148 spacing: ScreenTools.defaultFontPixelWidth
149 Layout.fillWidth: true
150
151 property string thFactName: _switchTHList[index]
152 property bool thFactExists: thFactName !== ""
153 property Fact swFact: controller.getParameterFact(-1, modelData)
154 property Fact thFact: thFactExists ? controller.getParameterFact(-1, thFactName) : null
155 property real thValue: thFactExists ? thFact.rawValue : 0.5
156 property real thPWM: 1000 + (1000 * thValue)
157 property int swChannel: swFact.rawValue - 1
158 property bool swActive: swChannel < 0 ?
159 false :
160 (thValue >= 0 ?
161 (controller.rcChannelValues[swChannel] > thPWM) :
162 (controller.rcChannelValues[swChannel] <= thPWM))
163 QGCLabel {
164 text: swFact.shortDescription
165 Layout.fillWidth: true
166 color: swActive ? "yellow" : qgcPal.text
167 }
168
169 FactComboBox {
170 Layout.preferredWidth: _channelComboWidth
171 fact: swFact
172 indexModel: false
173 }
174 }
175 }
176 }
177 } // Rectangle
178
179 RCChannelMonitor {
180 width: switchSettingsRect.width
181 twoColumn: true
182 }
183 } // Column - Switch settings
184 } // Row - Settings
185 }
186 }
187 }
188 }
189}