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 // No Need
13 }
14
15 GridLayout {
16 columns: 2
17 rowSpacing: _rowSpacing
18 columnSpacing: _colSpacing
19
20 QGCLabel { text: qsTr("Serial Port") }
21 QGCComboBox {
22 id: commPortCombo
23 Layout.preferredWidth: _secondColumnWidth
24 enabled: QGroundControl.linkManager.serialPorts.length > 0
25
26 onActivated: (index) => {
27 if (index != -1) {
28 if (index >= QGroundControl.linkManager.serialPortStrings.length) {
29 // This item was adding at the end, must use added text as name
30 subEditConfig.portName = commPortCombo.textAt(index)
31 } else {
32 subEditConfig.portName = QGroundControl.linkManager.serialPorts[index]
33 }
34 }
35 }
36
37 Component.onCompleted: {
38 var index = -1
39 var serialPorts = [ ]
40 if (QGroundControl.linkManager.serialPortStrings.length !== 0) {
41 for (var i=0; i<QGroundControl.linkManager.serialPortStrings.length; i++) {
42 serialPorts.push(QGroundControl.linkManager.serialPortStrings[i])
43 }
44 if (subEditConfig.portDisplayName === "" && QGroundControl.linkManager.serialPorts.length > 0) {
45 subEditConfig.portName = QGroundControl.linkManager.serialPorts[0]
46 }
47 index = serialPorts.indexOf(subEditConfig.portDisplayName)
48 if (index === -1) {
49 serialPorts.push(subEditConfig.portName)
50 index = serialPorts.indexOf(subEditConfig.portName)
51 }
52 }
53 if (serialPorts.length === 0) {
54 serialPorts = [ qsTr("None Available") ]
55 index = 0
56 }
57 commPortCombo.model = serialPorts
58 commPortCombo.currentIndex = index
59 }
60 }
61
62 QGCLabel { text: qsTr("Baud Rate") }
63 QGCComboBox {
64 id: baudCombo
65 Layout.preferredWidth: _secondColumnWidth
66 model: QGroundControl.linkManager.serialBaudRates
67
68 onActivated: (index) => {
69 if (index != -1) {
70 subEditConfig.baud = parseInt(QGroundControl.linkManager.serialBaudRates[index])
71 }
72 }
73
74 Component.onCompleted: {
75 var baud = "57600"
76 if(subEditConfig != null) {
77 baud = subEditConfig.baud.toString()
78 }
79 var index = baudCombo.find(baud)
80 if (index === -1) {
81 console.warn(qsTr("Baud rate name not in combo box"), baud)
82 } else {
83 baudCombo.currentIndex = index
84 }
85 }
86 }
87 }
88
89 QGCCheckBox {
90 id: advancedSettings
91 text: qsTr("Advanced Settings")
92 checked: false
93 }
94
95 GridLayout {
96 columns: 2
97 rowSpacing: _rowSpacing
98 columnSpacing: _colSpacing
99 visible: advancedSettings.checked
100
101 QGCCheckBox {
102 Layout.columnSpan: 2
103 text: qsTr("Enable Flow Control")
104 checked: subEditConfig.flowControl !== 0
105 onCheckedChanged: subEditConfig.flowControl = checked ? 1 : 0
106 }
107
108 QGCCheckBox {
109 Layout.columnSpan: 2
110 text: qsTr("Force DTR Low")
111 checked: subEditConfig ? subEditConfig.dtrForceLow : false
112 onCheckedChanged: { if (subEditConfig) subEditConfig.dtrForceLow = checked }
113 }
114
115 QGCLabel { text: qsTr("Parity") }
116 QGCComboBox {
117 Layout.preferredWidth: _secondColumnWidth
118 model: [qsTr("None"), qsTr("Even"), qsTr("Odd")]
119
120 onActivated: (index) => {
121 // Hard coded values from qserialport.h
122 switch (index) {
123 case 0:
124 subEditConfig.parity = 0
125 break
126 case 1:
127 subEditConfig.parity = 2
128 break
129 case 2:
130 subEditConfig.parity = 3
131 break
132 }
133 }
134
135 Component.onCompleted: {
136 switch (subEditConfig.parity) {
137 case 0:
138 currentIndex = 0
139 break
140 case 2:
141 currentIndex = 1
142 break
143 case 3:
144 currentIndex = 2
145 break
146 default:
147 console.warn("Unknown parity", subEditConfig.parity)
148 break
149 }
150 }
151 }
152
153 QGCLabel { text: qsTr("Data Bits") }
154 QGCComboBox {
155 Layout.preferredWidth: _secondColumnWidth
156 model: [ "5", "6", "7", "8" ]
157 currentIndex: Math.max(Math.min(subEditConfig.dataBits - 5, 3), 0)
158 onActivated: (index) => { subEditConfig.dataBits = index + 5 }
159 }
160
161 QGCLabel { text: qsTr("Stop Bits") }
162 QGCComboBox {
163 Layout.preferredWidth: _secondColumnWidth
164 model: [ "1", "2" ]
165 currentIndex: Math.max(Math.min(subEditConfig.stopBits - 1, 1), 0)
166 onActivated: (index) => { subEditConfig.stopBits = index + 1 }
167 }
168 }
169}