QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
SerialSettings.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Layouts
4
5import QGroundControl
6import QGroundControl.Controls
7
8ColumnLayout {
9 spacing: _rowSpacing
10
11 function saveSettings() {
12 if (baudCombo.isCustomBaud) {
13 var baud = parseInt(customBaudField.text)
14 if (baud > 0) {
15 subEditConfig.baud = baud
16 }
17 }
18 }
19
20 GridLayout {
21 columns: 2
22 rowSpacing: _rowSpacing
23 columnSpacing: _colSpacing
24
25 QGCLabel { text: qsTr("Serial Port") }
26 QGCComboBox {
27 id: commPortCombo
28 Layout.preferredWidth: _secondColumnWidth
29 enabled: QGroundControl.linkManager.serialPorts.length > 0
30
31 onActivated: (index) => {
32 if (index != -1) {
33 if (index >= QGroundControl.linkManager.serialPortStrings.length) {
34 // This item was adding at the end, must use added text as name
35 subEditConfig.portName = commPortCombo.textAt(index)
36 } else {
37 subEditConfig.portName = QGroundControl.linkManager.serialPorts[index]
38 }
39 }
40 }
41
42 Component.onCompleted: {
43 var index = -1
44 var serialPorts = [ ]
45 if (QGroundControl.linkManager.serialPortStrings.length !== 0) {
46 for (var i=0; i<QGroundControl.linkManager.serialPortStrings.length; i++) {
47 serialPorts.push(QGroundControl.linkManager.serialPortStrings[i])
48 }
49 if (subEditConfig.portDisplayName === "" && QGroundControl.linkManager.serialPorts.length > 0) {
50 subEditConfig.portName = QGroundControl.linkManager.serialPorts[0]
51 }
52 index = serialPorts.indexOf(subEditConfig.portDisplayName)
53 if (index === -1) {
54 serialPorts.push(subEditConfig.portName)
55 index = serialPorts.indexOf(subEditConfig.portName)
56 }
57 }
58 if (serialPorts.length === 0) {
59 serialPorts = [ qsTr("None Available") ]
60 index = 0
61 }
62 commPortCombo.model = serialPorts
63 commPortCombo.currentIndex = index
64 }
65 }
66
67 QGCLabel { text: qsTr("Baud Rate") }
68 QGCComboBox {
69 id: baudCombo
70 Layout.preferredWidth: _secondColumnWidth
71
72 readonly property string _customLabel: qsTr("Custom")
73 readonly property bool isCustomBaud: currentText === _customLabel
74
75 onActivated: (index) => {
76 if (index !== -1 && !isCustomBaud) {
77 subEditConfig.baud = parseInt(currentText)
78 }
79 }
80
81 Component.onCompleted: {
82 var rates = QGroundControl.linkManager.serialBaudRates.slice()
83 rates.push(_customLabel)
84 model = rates
85
86 var baud = subEditConfig ? subEditConfig.baud.toString() : "57600"
87 var index = baudCombo.find(baud)
88 if (index === -1) {
89 baudCombo.currentIndex = baudCombo.count - 1
90 customBaudField.text = baud
91 } else {
92 baudCombo.currentIndex = index
93 }
94 }
95 }
96
97 QGCLabel {
98 text: qsTr("Custom Baud Rate")
99 visible: baudCombo.isCustomBaud
100 }
101 QGCTextField {
102 id: customBaudField
103 Layout.preferredWidth: _secondColumnWidth
104 visible: baudCombo.isCustomBaud
105 numericValuesOnly: true
106 validator: IntValidator { bottom: 1 }
107 onEditingFinished: {
108 if (!baudCombo.isCustomBaud) return
109 var baud = parseInt(text)
110 if (baud > 0) {
111 subEditConfig.baud = baud
112 }
113 }
114 }
115 }
116
117 QGCCheckBox {
118 id: advancedSettings
119 text: qsTr("Advanced Settings")
120 checked: false
121 }
122
123 GridLayout {
124 columns: 2
125 rowSpacing: _rowSpacing
126 columnSpacing: _colSpacing
127 visible: advancedSettings.checked
128
129 QGCCheckBox {
130 Layout.columnSpan: 2
131 text: qsTr("Enable Flow Control")
132 checked: subEditConfig.flowControl !== 0
133 onCheckedChanged: subEditConfig.flowControl = checked ? 1 : 0
134 }
135
136 QGCCheckBox {
137 Layout.columnSpan: 2
138 text: qsTr("Force DTR Low")
139 checked: subEditConfig ? subEditConfig.dtrForceLow : false
140 onCheckedChanged: { if (subEditConfig) subEditConfig.dtrForceLow = checked }
141 }
142
143 QGCLabel { text: qsTr("Parity") }
144 QGCComboBox {
145 Layout.preferredWidth: _secondColumnWidth
146 model: [qsTr("None"), qsTr("Even"), qsTr("Odd")]
147
148 onActivated: (index) => {
149 // Hard coded values from qserialport.h
150 switch (index) {
151 case 0:
152 subEditConfig.parity = 0
153 break
154 case 1:
155 subEditConfig.parity = 2
156 break
157 case 2:
158 subEditConfig.parity = 3
159 break
160 }
161 }
162
163 Component.onCompleted: {
164 switch (subEditConfig.parity) {
165 case 0:
166 currentIndex = 0
167 break
168 case 2:
169 currentIndex = 1
170 break
171 case 3:
172 currentIndex = 2
173 break
174 default:
175 console.warn("Unknown parity", subEditConfig.parity)
176 break
177 }
178 }
179 }
180
181 QGCLabel { text: qsTr("Data Bits") }
182 QGCComboBox {
183 Layout.preferredWidth: _secondColumnWidth
184 model: [ "5", "6", "7", "8" ]
185 currentIndex: Math.max(Math.min(subEditConfig.dataBits - 5, 3), 0)
186 onActivated: (index) => { subEditConfig.dataBits = index + 5 }
187 }
188
189 QGCLabel { text: qsTr("Stop Bits") }
190 QGCComboBox {
191 Layout.preferredWidth: _secondColumnWidth
192 model: [ "1", "2" ]
193 currentIndex: Math.max(Math.min(subEditConfig.stopBits - 1, 1), 0)
194 onActivated: (index) => { subEditConfig.stopBits = index + 1 }
195 }
196 }
197}