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