PX4SimpleFlightModes.qml 8.85 KB
Newer Older
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
Don Gagne's avatar
Don Gagne committed
9

10 11 12
import QtQuick          2.3
import QtQuick.Controls 1.2
import QtQuick.Layouts  1.2
Don Gagne's avatar
Don Gagne committed
13 14 15 16 17 18 19 20 21 22 23

import QGroundControl.FactSystem    1.0
import QGroundControl.FactControls  1.0
import QGroundControl.Palette       1.0
import QGroundControl.Controls      1.0
import QGroundControl.Controllers   1.0
import QGroundControl.ScreenTools   1.0

Item {
    id: root

24 25 26 27
    property real _margins:             ScreenTools.defaultFontPixelHeight / 2
    property var  _switchNameList:      [ "ACRO", "ARM", "GEAR", "KILL", "LOITER", "OFFB", "POSCTL", "RATT", "RETURN", "STAB" ]
    property var  _switchFactList:      [ ]
    property var  _switchTHFactList:    [ ]
Don Gagne's avatar
Don Gagne committed
28

Don Gagne's avatar
Don Gagne committed
29 30
    readonly property real _flightModeComboWidth:   ScreenTools.defaultFontPixelWidth * 13
    readonly property real _channelComboWidth:      ScreenTools.defaultFontPixelWidth * 13
31

32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
    Component.onCompleted: {
        if (controller.vehicle.fixedWing) {
            _switchNameList.push("MAN")
        }
        if (controller.vehicle.vtol) {
            _switchNameList.push("TRANS")
        }
        for (var i=0; i<_switchNameList.length; i++) {
            _switchFactList.push("RC_MAP_" + _switchNameList[i] + "_SW")
            _switchTHFactList.push("RC_" + _switchNameList[i] + "_TH")
        }
        if (controller.vehicle.fixedWing) {
            _switchFactList.push("RC_MAP_FLAPS")
            _switchTHFactList.push("")
        }
        switchRepeater.model = _switchFactList
    }

Don Gagne's avatar
Don Gagne committed
50 51 52 53 54 55 56
    PX4SimpleFlightModesController {
        id:         controller
    }

    QGCFlickable {
        anchors.fill:   parent
        clip:           true
Don Gagne's avatar
Don Gagne committed
57 58
        contentWidth:   column2.x + column2.width
        contentHeight:  Math.max(column1.height, column2.height)
Don Gagne's avatar
Don Gagne committed
59 60

        Column {
Don Gagne's avatar
Don Gagne committed
61
            id:         column1
Don Gagne's avatar
Don Gagne committed
62 63
            spacing:    _margins

Don Gagne's avatar
Don Gagne committed
64 65 66
            Row {
                id:         settingsRow
                spacing:    _margins
Don Gagne's avatar
Don Gagne committed
67 68

                Column {
Don Gagne's avatar
Don Gagne committed
69 70 71 72 73
                    id:     flightModeSettingsColumn
                    spacing: _margins

                    QGCLabel {
                        id:             flightModeLabel
74
                        text:           qsTr("Flight Mode Settings")
75
                        font.family:    ScreenTools.demiboldFontFamily
Don Gagne's avatar
Don Gagne committed
76 77 78 79 80 81 82 83
                    }

                    Rectangle {
                        id:                 flightModeSettings
                        width:              flightModeColumn.width + (_margins * 2)
                        height:             flightModeColumn.height + ScreenTools.defaultFontPixelHeight
                        color:              qgcPal.windowShade

84
                        GridLayout {
Don Gagne's avatar
Don Gagne committed
85 86 87 88
                            id:                 flightModeColumn
                            anchors.margins:    ScreenTools.defaultFontPixelWidth
                            anchors.left:       parent.left
                            anchors.top:        parent.top
89 90 91 92
                            rows:               7
                            rowSpacing:         ScreenTools.defaultFontPixelWidth / 2
                            columnSpacing:      rowSpacing
                            flow:               GridLayout.TopToBottom
Don Gagne's avatar
Don Gagne committed
93

94
                            QGCLabel {
95
                                Layout.fillWidth:   true
96 97 98 99 100
                                text:               qsTr("Mode Channel")
                            }

                            Repeater {
                                model:  6
Don Gagne's avatar
Don Gagne committed
101 102

                                QGCLabel {
103
                                    Layout.fillWidth:   true
104
                                    text:               qsTr("Flight Mode %1").arg(modelData + 1)
105
                                    color:              (controller.activeFlightMode - 1) == index ? "yellow" : qgcPal.text
Don Gagne's avatar
Don Gagne committed
106
                                }
107
                            }
Don Gagne's avatar
Don Gagne committed
108

109 110 111 112 113
                            FactComboBox {
                                Layout.fillWidth:   true
                                fact:               controller.getParameterFact(-1, "RC_MAP_FLTMODE")
                                indexModel:         false
                                sizeToContents:     true
Don Gagne's avatar
Don Gagne committed
114
                            }
Don Gagne's avatar
Don Gagne committed
115

Don Gagne's avatar
Don Gagne committed
116 117
                            Repeater {
                                model:  6
Don Gagne's avatar
Don Gagne committed
118

119
                                FactComboBox {
120
                                    Layout.fillWidth:   true
121 122 123
                                    fact:               controller.getParameterFact(-1, "COM_FLTMODE" + (modelData + 1))
                                    indexModel:         false
                                    sizeToContents:     true
Don Gagne's avatar
Don Gagne committed
124
                                }
125 126
                            }
                        }
Don Gagne's avatar
Don Gagne committed
127 128 129 130
                    } // Rectangle - Flight Modes
                } // Column - Flight mode settings

                Column {
Don Gagne's avatar
Don Gagne committed
131 132
                    id:         column2
                    spacing:    _margins
Don Gagne's avatar
Don Gagne committed
133 134

                    QGCLabel {
135
                        text:           qsTr("Switch Settings")
136
                        font.family:    ScreenTools.demiboldFontFamily
Don Gagne's avatar
Don Gagne committed
137 138 139
                    }

                    Rectangle {
Don Gagne's avatar
Don Gagne committed
140
                        id:     switchSettingsRect
141 142
                        width:  switchSettingsGrid.width + (_margins * 2)
                        height: switchSettingsGrid.height + ScreenTools.defaultFontPixelHeight
Don Gagne's avatar
Don Gagne committed
143 144
                        color:  qgcPal.windowShade

145 146
                        GridLayout {
                            id:                 switchSettingsGrid
Don Gagne's avatar
Don Gagne committed
147 148 149
                            anchors.margins:    ScreenTools.defaultFontPixelWidth
                            anchors.left:       parent.left
                            anchors.top:        parent.top
150 151
                            columns:            2
                            columnSpacing:      ScreenTools.defaultFontPixelWidth
Don Gagne's avatar
Don Gagne committed
152

153
                            Repeater {
154
                                id: switchRepeater
Don Gagne's avatar
Don Gagne committed
155

156 157 158
                                RowLayout {
                                    spacing:            ScreenTools.defaultFontPixelWidth
                                    Layout.fillWidth:   true
Don Gagne's avatar
Don Gagne committed
159

160 161 162 163 164 165 166 167 168 169 170 171
                                    property string thFactName:     _switchTHFactList[index]
                                    property bool   thFactExists:   thFactName == ""
                                    property Fact   swFact:         controller.getParameterFact(-1, modelData)
                                    property Fact   thFact:         thFactExists ? controller.getParameterFact(-1, thFactName) : null
                                    property real   thValue:        thFactExists ? thFact.rawValue : 0.5
                                    property real   thPWM:          1000 + (1000 * thValue)
                                    property int    swChannel:      swFact.rawValue - 1
                                    property bool   swActive:       swChannel < 0 ?
                                                                        false :
                                                                        (thValue >= 0 ?
                                                                             (controller.rcChannelValues[swChannel] > thPWM) :
                                                                             (controller.rcChannelValues[swChannel] <= thPWM))
172
                                    QGCLabel {
173
                                        text:               swFact.shortDescription
174
                                        Layout.fillWidth:   true
175
                                        color:              swActive ? "yellow" : qgcPal.text
176 177 178 179
                                    }

                                    FactComboBox {
                                        Layout.preferredWidth:  _channelComboWidth
180
                                        fact:                   swFact
181 182
                                        indexModel:             false
                                    }
Don Gagne's avatar
Don Gagne committed
183 184
                                }
                            }
Don Gagne's avatar
Don Gagne committed
185 186
                        } // Column
                    } // Rectangle
Don Gagne's avatar
Don Gagne committed
187 188

                    RCChannelMonitor {
189 190
                        width:      switchSettingsRect.width
                        twoColumn:  true
Don Gagne's avatar
Don Gagne committed
191
                    }
Don Gagne's avatar
Don Gagne committed
192 193
                } // Column - Switch settings
            } // Row - Settings
Don Gagne's avatar
Don Gagne committed
194 195

            QGCButton {
Don Gagne's avatar
Don Gagne committed
196
                text: "Use Multi Channel Mode Selection"
Don Gagne's avatar
Don Gagne committed
197 198 199 200 201
                onClicked: {
                    controller.getParameterFact(-1, "RC_MAP_MODE_SW").value = 5
                    controller.getParameterFact(-1, "RC_MAP_FLTMODE").value = 0
                }
            }
202 203 204
        }
    }
}