QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
APMAutoTuneChannelSelector.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
9ColumnLayout {
10 id: root
11
12 required property var controller
13
14 property Fact _ch7Opt: controller.getParameterFact(-1, "RC7_OPTION")
15 property Fact _ch8Opt: controller.getParameterFact(-1, "RC8_OPTION")
16 property Fact _ch9Opt: controller.getParameterFact(-1, "RC9_OPTION")
17 property Fact _ch10Opt: controller.getParameterFact(-1, "RC10_OPTION")
18 property Fact _ch11Opt: controller.getParameterFact(-1, "RC11_OPTION")
19 property Fact _ch12Opt: controller.getParameterFact(-1, "RC12_OPTION")
20
21 readonly property int _firstOptionChannel: 7
22 readonly property int _lastOptionChannel: 12
23
24 property int _autoTuneSwitchChannelIndex: 0
25 readonly property int _autoTuneOption: 17
26
27 Component.onCompleted: calcAutoTuneChannel()
28
29 function calcAutoTuneChannel() {
30 _autoTuneSwitchChannelIndex = 0
31 for (let channel = _firstOptionChannel; channel <= _lastOptionChannel; channel++) {
32 let optionFact = controller.getParameterFact(-1, "RC" + channel + "_OPTION")
33 if (optionFact.value === _autoTuneOption) {
34 _autoTuneSwitchChannelIndex = channel - _firstOptionChannel + 1
35 break
36 }
37 }
38 }
39
40 function setChannelAutoTuneOption(channel) {
41 for (let optionChannel = _firstOptionChannel; optionChannel <= _lastOptionChannel; optionChannel++) {
42 let optionFact = controller.getParameterFact(-1, "RC" + optionChannel + "_OPTION")
43 if (optionFact.value === _autoTuneOption) {
44 optionFact.value = 0
45 }
46 }
47 if (channel !== 0) {
48 let optionFact = controller.getParameterFact(-1, "RC" + channel + "_OPTION")
49 optionFact.value = _autoTuneOption
50 }
51 }
52
53 Connections { target: _ch7Opt; function onValueChanged() { calcAutoTuneChannel() } }
54 Connections { target: _ch8Opt; function onValueChanged() { calcAutoTuneChannel() } }
55 Connections { target: _ch9Opt; function onValueChanged() { calcAutoTuneChannel() } }
56 Connections { target: _ch10Opt; function onValueChanged() { calcAutoTuneChannel() } }
57 Connections { target: _ch11Opt; function onValueChanged() { calcAutoTuneChannel() } }
58 Connections { target: _ch12Opt; function onValueChanged() { calcAutoTuneChannel() } }
59
60 LabelledComboBox {
61 Layout.fillWidth: true
62 comboBoxPreferredWidth: ScreenTools.defaultFontPixelWidth * 30
63 label: qsTr("Channel for AutoTune switch:")
64 model: [qsTr("None"), qsTr("Channel 7"), qsTr("Channel 8"), qsTr("Channel 9"), qsTr("Channel 10"), qsTr("Channel 11"), qsTr("Channel 12")]
65 currentIndex: _autoTuneSwitchChannelIndex
66
67 onActivated: (index) => {
68 let channel = index
69 if (channel > 0) {
70 channel += 6
71 }
72 setChannelAutoTuneOption(channel)
73 }
74 }
75}