FlightModesComponent.qml 42.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*=====================================================================

 QGroundControl Open Source Ground Control Station

 (c) 2009 - 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>

 This file is part of the QGROUNDCONTROL project

 QGROUNDCONTROL is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 QGROUNDCONTROL is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.

 ======================================================================*/

Don Gagne's avatar
Don Gagne committed
24 25 26 27 28 29 30 31 32
import QtQuick 2.2
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2

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
33
import QGroundControl.ScreenTools 1.0
Don Gagne's avatar
Don Gagne committed
34 35 36

Item {
    Loader {
Don Gagne's avatar
Don Gagne committed
37 38 39 40 41
        id:                 loader
        anchors.fill:       parent
        sourceComponent:    controller.validConfiguration ? validComponent : invalidComponent

        property FlightModesComponentController controller: FlightModesComponentController { factPanel: loader.item }
Don Gagne's avatar
Don Gagne committed
42 43 44 45 46 47 48 49 50
        property QGCPalette qgcPal: QGCPalette { colorGroupEnabled: true }
        property bool loading: true

        onLoaded: loading = false
    }

    Component {
        id: validComponent

51
        FactPanel {
Don Gagne's avatar
Don Gagne committed
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
            property Fact rc_map_throttle:      controller.getParameterFact(-1, "RC_MAP_THROTTLE")
            property Fact rc_map_yaw:           controller.getParameterFact(-1, "RC_MAP_YAW")
            property Fact rc_map_pitch:         controller.getParameterFact(-1, "RC_MAP_PITCH")
            property Fact rc_map_roll:          controller.getParameterFact(-1, "RC_MAP_ROLL")
            property Fact rc_map_flaps:         controller.getParameterFact(-1, "RC_MAP_FLAPS")
            property Fact rc_map_aux1:          controller.getParameterFact(-1, "RC_MAP_AUX1")
            property Fact rc_map_aux2:          controller.getParameterFact(-1, "RC_MAP_AUX2")

            property Fact rc_map_mode_sw:       controller.getParameterFact(-1, "RC_MAP_MODE_SW")
            property Fact rc_map_posctl_sw:     controller.getParameterFact(-1, "RC_MAP_POSCTL_SW")
            property Fact rc_map_return_sw:     controller.getParameterFact(-1, "RC_MAP_RETURN_SW")
            property Fact rc_map_offboard_sw:   controller.getParameterFact(-1, "RC_MAP_OFFB_SW")
            property Fact rc_map_loiter_sw:     controller.getParameterFact(-1, "RC_MAP_LOITER_SW")

            property Fact rc_assist_th:         controller.getParameterFact(-1, "RC_ASSIST_TH")
            property Fact rc_posctl_th:         controller.getParameterFact(-1, "RC_POSCTL_TH")
            property Fact rc_auto_th:           controller.getParameterFact(-1, "RC_AUTO_TH")
            property Fact rc_loiter_th:         controller.getParameterFact(-1, "RC_LOITER_TH")
            property Fact rc_return_th:         controller.getParameterFact(-1, "RC_RETURN_TH")
            property Fact rc_offboard_th:       controller.getParameterFact(-1, "RC_OFFB_TH")

            property Fact rc_th_user:           controller.getParameterFact(-1, "RC_TH_USER")
Don Gagne's avatar
Don Gagne committed
74 75 76 77 78 79 80 81 82 83 84 85

            property int throttleChannel:   rc_map_throttle.value
            property int yawChannel:        rc_map_yaw.value
            property int pitchChannel:      rc_map_pitch.value
            property int rollChannel:       rc_map_roll.value
            property int flapsChannel:      rc_map_flaps.value
            property int aux1Channel:       rc_map_aux1.value
            property int aux2Channel:       rc_map_aux2.value

            property int modeChannel:       rc_map_mode_sw.value
            property int posCtlChannel:     rc_map_posctl_sw.value
            property int returnChannel:     rc_map_return_sw.value
86
            property int offboardChannel:   rc_map_offboard_sw.value
Don Gagne's avatar
Don Gagne committed
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
            property int loiterChannel:     rc_map_loiter_sw.value

            property real rcThUserValue: rc_th_user.value

            readonly property int channelCount: controller.channelCount

            property bool inRedistribution: false

            readonly property int tileWidth: 150
            readonly property int tileHeight: 30

            readonly property int progressBarHeight: 200

            anchors.fill: parent

            Component {
                id: dragHandle

                Item {
                    id:     outerItem
                    width:  parent.width
                    height: parent.height

                    Column {
                        x: 4
                        y: 4
                        spacing: 3

                        Repeater {
                            model: (outerItem.height - 8) / 4
                            Rectangle {
                                color: qgcPal.text
                                width: 15
                                height: 1
                            }
                        }
                    }
                }
            }

            // This component is used to create draggable tiles for unassigned mode switches. It also
            // creates the drop area for dragging an assigned mode switch tile back to an unassigned state.
            // The following properties must be set in the Loader:
            //  tileLabel - label for tile
            //  tileParam - parameter to load from
            //  tileDragEnabled - true: this tile can be dragged
            Component {
                id: unassignedModeTileComponent

                Rectangle {
Don Gagne's avatar
Don Gagne committed
137
                    property Fact fact: controller.getParameterFact(-1, tileParam)
Don Gagne's avatar
Don Gagne committed
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
                    property bool dragEnabled: fact.value == 0

                    id:             outerRect
                    width:          tileWidth
                    height:         tileHeight
                    color:          qgcPal.windowShadeDark
                    border.width:   dragEnabled ? 1 : 0
                    border.color:   qgcPal.text

                    Drag.active:    mouseArea.drag.active
                    Drag.hotSpot.x: width / 2
                    Drag.hotSpot.y: height / 2
                    Drag.keys:      [ "unassigned"]

                    states: [
                        State {
                            when: dropArea.containsDrag
                            PropertyChanges {
                                target: outerRect
                                color: "red"
                            }
                        }
                    ]

                    Loader {
                        width: parent.width
                        height: parent.height
                        visible: dragEnabled
                        sourceComponent: dragHandle
                    }

                    QGCLabel {
                        width:                  parent.width
                        height:                 parent.height
                        text:                   tileLabel
                        enabled:                dragEnabled
                        horizontalAlignment:    Text.AlignHCenter
                        verticalAlignment:      Text.AlignVCenter
                    }

                    MouseArea {
                        id:             mouseArea
                        width:          parent.width
                        height:         parent.height
                        drag.target:    dragEnabled ? parent : null

                        onReleased: {
                            // Move tile back to original position
                            parent.x = 0; parent.y = 0;

                            // If dropped over a channel target remap switch
                            if (parent.Drag.target && parent.Drag.target.dropAllowed) {
190 191 192
                                if (!singleSwitchRequired || parent.Drag.target.unassignedChannel) {
                                    fact.value = parent.Drag.target.channel
                                }
Don Gagne's avatar
Don Gagne committed
193 194 195 196 197 198
                            }
                        }
                    }

                    DropArea {
                        // This will cause to tile to go back to unassigned if dropped here
199 200 201 202
                        readonly property int channel:      0
                        property bool dropAllowed:          true
                        property bool unassignedChannel:    true

Don Gagne's avatar
Don Gagne committed
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222

                        id:     dropArea
                        width:  parent.width
                        height: parent.height

                        keys: [ "assigned" ]
                    }
                }
            }

            // This component is used to create draggable tiles for currently assigned mode switches. The following
            // properties must be set in the Loader:
            //  tileLabel - label for tile
            //  tileVisible - visibility for tile
            //  tileDragEnabled - true: this tile can be dragged
            //  tileParam - parameter to load from
            Component {
                id: assignedModeTileComponent

                Rectangle {
Don Gagne's avatar
Don Gagne committed
223 224
                    Fact{ id: nullFact }
                    property Fact fact: tileDragEnabled ? controller.getParameterFact(-1, tileParam) : nullFact
Don Gagne's avatar
Don Gagne committed
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265

                    width:          tileWidth
                    height:         tileHeight
                    color:          qgcPal.windowShadeDark
                    border.width:   tileDragEnabled ? 1 : 0
                    border.color:   qgcPal.text
                    visible:        tileVisible

                    Drag.active:    mouseArea.drag.active
                    Drag.hotSpot.x: width / 2
                    Drag.hotSpot.y: height / 2
                    Drag.keys:      [ "assigned" ]

                    Loader {
                        width: parent.width
                        height: parent.height
                        visible: tileDragEnabled
                        sourceComponent: dragHandle
                    }

                    QGCLabel {
                        width:                  parent.width
                        height:                 parent.height
                        enabled:                tileDragEnabled
                        horizontalAlignment:    Text.AlignHCenter
                        verticalAlignment:      Text.AlignVCenter
                        text:                   tileLabel
                    }

                    MouseArea {
                        id:             mouseArea
                        width:          parent.width
                        height:         parent.height
                        drag.target:    tileDragEnabled ? parent : null

                        onReleased: {
                            // Move tile back to original position
                            parent.x = 0; parent.y = 0;

                            // If dropped over a channel target remap switch
                            if (parent.Drag.target && parent.Drag.target.dropAllowed) {
266 267 268
                                if (!singleSwitchRequired || parent.Drag.target.unassignedChannel) {
                                    fact.value = parent.Drag.target.channel
                                }
Don Gagne's avatar
Don Gagne committed
269 270 271 272 273 274 275 276
                            }
                        }
                    }
                }
            }

            onModeChannelChanged: if (!inRedistribution) redistributeThresholds()
            onReturnChannelChanged: if (!inRedistribution) redistributeThresholds()
277
            onOffboardChannelChanged: if (!inRedistribution) redistributeThresholds()
Don Gagne's avatar
Don Gagne committed
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
            onLoiterChannelChanged: if (!inRedistribution) redistributeThresholds()
            onPosCtlChannelChanged: if (!inRedistribution) redistributeThresholds()
            onRcThUserValue: if (!inRedistribution) redistributeThresholds()

            function redistributeThresholds() {
                if (loading || rcThUserValue != 0) {
                    // User is specifying thresholds, do not auto-calculate
                    return
                }

                if (modeChannel != 0) {
                    var positions = 3  // Manual/Assist/Auto always exist

                    var loiterOnModeSwitch = modeChannel == loiterChannel
                    var posCtlOnModeSwitch = modeChannel == posCtlChannel

                    positions += loiterOnModeSwitch ? 1 : 0
                    positions += posCtlOnModeSwitch ? 1 : 0

                    var increment = 1.0 / positions
                    var currentThreshold = 0.0

                    // Make sure we don't re-enter
                    inRedistribution = true

                    currentThreshold += increment
                    rc_assist_th.value = currentThreshold
                    if (posCtlOnModeSwitch) {
                        currentThreshold += increment
                        rc_posctl_th.value = currentThreshold
                    }
                    currentThreshold += increment
                    rc_auto_th.value = currentThreshold
                    if (loiterOnModeSwitch) {
                        currentThreshold += increment
                        rc_loiter_th.value = currentThreshold
                    }

                    inRedistribution = false
                }

319
                if (returnChannel != 0) {
Don Gagne's avatar
Don Gagne committed
320 321
                    inRedistribution = true

322 323 324
                    // If only two positions don't set threshold at midrange. Setting to 0.25
                    // allows for this channel to work with either two or three position switch
                    rc_return_th.value = 0.25
Don Gagne's avatar
Don Gagne committed
325 326 327 328

                    inRedistribution = false
                }

329 330 331
                if (offboardChannel != 0) {
                    inRedistribution = true

Don Gagne's avatar
Don Gagne committed
332 333
                    // If only two positions don't set threshold at midrange. Setting to 0.25
                    // allows for this channel to work with either two or three position switch
334
                    rc_offboard_th.value = 0.25
Don Gagne's avatar
Don Gagne committed
335

336 337
                    inRedistribution = false
                }
Don Gagne's avatar
Don Gagne committed
338

339
                if (loiterChannel != 0 && loiterChannel != modeChannel) {
Don Gagne's avatar
Don Gagne committed
340 341
                    inRedistribution = true

342 343 344
                    // If only two positions don't set threshold at midrange. Setting to 0.25
                    // allows for this channel to work with either two or three position switch
                    rc_loiter_th.value = 0.25
Don Gagne's avatar
Don Gagne committed
345 346 347 348 349 350 351

                    inRedistribution = false
                }

                if (posCtlChannel != 0 & posCtlChannel != modeChannel) {
                    inRedistribution = true

352 353 354
                    // If only two positions don't set threshold at midrange. Setting to 0.25
                    // allows for this channel to work with either two or three position switch
                    rc_posctl_th.value = 0.25
Don Gagne's avatar
Don Gagne committed
355 356 357 358 359 360 361 362 363 364

                    inRedistribution = false
                }
            }

            Column {
                anchors.fill: parent

                QGCLabel {
                    text: "FLIGHT MODES CONFIG"
Don Gagne's avatar
Don Gagne committed
365
                    font.pointSize: ScreenTools.largeFontPointSize
Don Gagne's avatar
Don Gagne committed
366 367 368 369 370 371
                }

                Item { height: 20; width: 10 } // spacer

                QGCLabel {
                    width: parent.width
372 373 374 375
                    text: "The Main Mode, Loiter and PostCtl switches can be assigned to any channel which is not currently being used for attitude control. The Return and Offboard switches must be assigned to their seperate channel. " +
                            "All channels are displayed below. " +
                            "You can drag Flight Modes from the Flight Modes section below to a channel and drop it there. You can also drag switches assigned to a channel " +
                            "to another channel or back to the Unassigned Switches section. The Switch Display section at the very bottom will show you the results of your Flight Mode setup."
Don Gagne's avatar
Don Gagne committed
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
                    wrapMode: Text.WordWrap
                }

                Item { height: 20; width: 10 } // spacer

                QGCLabel {
                    text: "Channel Assignments"
                }
                Flow {
                    width: parent.width
                    spacing: 5

                    Repeater {
                        model: channelCount

                        Rectangle {
                            property int channel:           modelData + 1
                            property bool throttleMapped:   channel == throttleChannel
                            property bool yawMapped:        channel == yawChannel
                            property bool pitchMapped:      channel == pitchChannel
                            property bool rollMapped:       channel == rollChannel
                            property bool flapsMapped:      channel == flapsChannel
                            property bool aux1Mapped:       channel == aux1Channel
                            property bool aux2Mapped:       channel == aux2Channel

                            property bool modeMapped:       channel == modeChannel
                            property bool posCtlMapped:     channel == posCtlChannel
                            property bool returnMapped:     channel == returnChannel
404
                            property bool offboardMapped:   channel == offboardChannel
Don Gagne's avatar
Don Gagne committed
405 406 407
                            property bool loiterMapped:     channel == loiterChannel

                            property bool nonFlightModeMapping: throttleMapped | yawMapped | pitchMapped | rollMapped | flapsMapped | aux1Mapped | aux2Mapped
408 409
                            property bool unassignedMapping: !(nonFlightModeMapping | modeMapped | posCtlMapped | returnMapped | offboardMapped | loiterMapped)
                            property bool singleSwitchMapping: returnMapped | offboardMapped
Don Gagne's avatar
Don Gagne committed
410 411 412 413 414 415 416 417 418

                            id:     channelTarget
                            width:  tileWidth
                            height: channelCol.implicitHeight

                            color:  qgcPal.windowShadeDark

                            states: [
                                State {
419
                                    when: dropArea.containsDrag && dropArea.dropAllowed && (!dropArea.drag.source.singleSwitchRequired || dropArea.unassignedChannel)
Don Gagne's avatar
Don Gagne committed
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
                                    PropertyChanges {
                                        target: channelHeader
                                        color: "red"
                                    }
                                }
                            ]

                            Column {
                                id:         channelCol
                                spacing:    3

                                Rectangle {
                                    id: channelHeader
                                    width:  tileWidth
                                    height: tileHeight
                                    color:  qgcPal.windowShade

                                    QGCLabel {
                                        verticalAlignment:      Text.AlignVCenter
                                        horizontalAlignment:    Text.AlignHCenter
                                        text:                   "Channel " + (modelData + 1) + (nonFlightModeMapping ? ": Unavailable" : "")
                                    }
                                }
                                Loader {
                                    property string tileLabel:      "Available"
                                    property bool tileVisible:      visible
                                    property bool tileDragEnabled:  false

                                    visible:            unassignedMapping
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
                                    property string tileLabel:      "Throttle"
                                    property bool tileVisible:      visible
                                    property bool tileDragEnabled:  false

                                    visible:            throttleMapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
                                    property string tileLabel:      "Yaw"
                                    property bool tileVisible:      visible
                                    property bool tileDragEnabled:  false

                                    visible:            yawMapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
                                    property string tileLabel:      "Pitch"
                                    property bool tileVisible:      visible
                                    property bool tileDragEnabled:  false

                                    visible:            pitchMapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
                                    property string tileLabel:      "Roll"
                                    property bool tileVisible:      visible
                                    property bool tileDragEnabled:  false

                                    visible:            rollMapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
                                    property string tileLabel:      "Flaps Switch"
                                    property bool tileVisible:      visible
                                    property bool tileDragEnabled:  false

                                    visible:            flapsMapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
                                    property string tileLabel:      "Aux1 Switch"
                                    property bool tileVisible:      visible
                                    property bool tileDragEnabled:  false

                                    visible:            aux1Mapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
                                    property string tileLabel:      "Aux2 Switch"
                                    property bool tileVisible:      visible
                                    property bool tileDragEnabled:  false

                                    visible:            aux2Mapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
508 509 510 511 512
                                    property string tileLabel:          "Main Mode"
                                    property bool tileVisible:          visible
                                    property bool tileDragEnabled:      true
                                    property string tileParam:          "RC_MAP_MODE_SW"
                                    property bool singleSwitchRequired: false
Don Gagne's avatar
Don Gagne committed
513 514 515 516 517

                                    visible:            modeMapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
518 519 520 521 522
                                    property string tileLabel:          "Return"
                                    property bool tileVisible:          visible
                                    property bool tileDragEnabled:      true
                                    property string tileParam:          "RC_MAP_RETURN_SW"
                                    property bool singleSwitchRequired: true
Don Gagne's avatar
Don Gagne committed
523 524 525 526 527

                                    visible:            returnMapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542
                                    property string tileLabel:          "Offboard"
                                    property bool tileVisible:          visible
                                    property bool tileDragEnabled:      true
                                    property string tileParam:          "RC_MAP_OFFB_SW"
                                    property bool singleSwitchRequired: true

                                    visible:            offboardMapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
                                    property string tileLabel:          "Loiter"
                                    property bool tileVisible:          visible
                                    property bool tileDragEnabled:      true
                                    property string tileParam:          "RC_MAP_LOITER_SW"
                                    property bool singleSwitchRequired: false
Don Gagne's avatar
Don Gagne committed
543 544 545 546 547

                                    visible:            loiterMapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
548 549 550 551 552
                                    property string tileLabel:          "PosCtl"
                                    property bool tileVisible:          visible
                                    property bool tileDragEnabled:      true
                                    property string tileParam:          "RC_MAP_POSCTL_SW"
                                    property bool singleSwitchRequired: false
Don Gagne's avatar
Don Gagne committed
553 554 555 556 557 558 559 560

                                    visible:            posCtlMapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                            }

                            DropArea {
                                // Drops are not allowed on channels which are mapped to non-flight mode switches
561 562
                                property bool dropAllowed: !nonFlightModeMapping && !singleSwitchMapping
                                property bool unassignedChannel: unassignedMapping
Don Gagne's avatar
Don Gagne committed
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592
                                property int channel: parent.channel

                                id:     dropArea
                                width:  parent.width
                                height: parent.height

                                keys: [ "unassigned", "assigned" ]
                            }
                        }
                    }
                }

                Item { height: 20; width: 10 } // spacer

                Row {
                    spacing: 5

                    QGCLabel {
                        text: "Flight Modes"
                    }
                    QGCLabel {
                        text: "(Mode Switch must be assigned to channel before flight is allowed)"
                        visible: rc_map_mode_sw.value == 0
                    }
                }
                Flow {
                    width: parent.width
                    spacing: 5

                    Loader {
593 594 595 596 597 598 599 600 601 602
                        property string tileLabel:          "Main Mode"
                        property string tileParam:          "RC_MAP_MODE_SW"
                        property bool singleSwitchRequired: false
                        sourceComponent:                    unassignedModeTileComponent
                    }
                    Loader {
                        property string tileLabel:          "Loiter"
                        property string tileParam:          "RC_MAP_LOITER_SW"
                        property bool singleSwitchRequired: false
                        sourceComponent:                    unassignedModeTileComponent
Don Gagne's avatar
Don Gagne committed
603 604
                    }
                    Loader {
605 606 607 608
                        property string tileLabel:          "PosCtl"
                        property string tileParam:          "RC_MAP_POSCTL_SW"
                        property bool singleSwitchRequired: false
                        sourceComponent:                    unassignedModeTileComponent
Don Gagne's avatar
Don Gagne committed
609 610
                    }
                    Loader {
611 612 613 614
                        property string tileLabel:          "Return"
                        property string tileParam:          "RC_MAP_RETURN_SW"
                        property bool singleSwitchRequired: true
                        sourceComponent:                    unassignedModeTileComponent
Don Gagne's avatar
Don Gagne committed
615 616
                    }
                    Loader {
617 618 619 620
                        property string tileLabel:          "Offboard"
                        property string tileParam:          "RC_MAP_OFFB_SW"
                        property bool singleSwitchRequired: true
                        sourceComponent:                    unassignedModeTileComponent
Don Gagne's avatar
Don Gagne committed
621 622 623 624 625 626
                    }
                }

                Item { height: 20; width: 10 } // spacer

                FactCheckBox {
Don Gagne's avatar
Don Gagne committed
627
                    checkedValue:   0
Don Gagne's avatar
Don Gagne committed
628
                    uncheckedValue: 1
Don Gagne's avatar
Don Gagne committed
629 630
                    fact:           rc_th_user
                    text:           "Allow setup to generate the thresholds for the flight mode positions within a switch (recommended)"
Don Gagne's avatar
Don Gagne committed
631 632 633 634 635 636 637 638 639 640 641
                }

                Item { height: 20; width: 10 } // spacer

                Row {
                spacing: 20

                    QGCLabel {
                        text: "Switch Display"
                    }
                    QGCCheckBox {
Don Gagne's avatar
Don Gagne committed
642 643 644
                        checked:    controller.sendLiveRCSwitchRanges
                        text:       "Show live RC display"

Don Gagne's avatar
Don Gagne committed
645 646 647 648 649 650 651 652 653
                        onClicked: {
                            controller.sendLiveRCSwitchRanges = checked
                        }
                    }
                }

                Item { height: 20; width: 10 } // spacer

                Row {
Don Gagne's avatar
Don Gagne committed
654 655 656 657 658
                    property bool modeSwitchVisible:        modeChannel != 0
                    property bool loiterSwitchVisible:      loiterChannel != 0 && loiterChannel != modeChannel && loiterChannel != returnChannel
                    property bool posCtlSwitchVisible:      posCtlChannel != 0 && posCtlChannel != modeChannel
                    property bool returnSwitchVisible:      returnChannel != 0
                    property bool offboardSwitchVisible:    offboardChannel != 0
Don Gagne's avatar
Don Gagne committed
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745

                    width:      parent.width
                    spacing:    20

                    Column {
                        visible: parent.modeSwitchVisible

                        QGCLabel { text: "Mode Switch" }

                        Row {
                            Item {
                                height: progressBarHeight
                                width:  150

                                QGCLabel {
                                    width:                  parent.width
                                    y:                      (parent.height * (1.0 - rc_auto_th.value)) - (implicitHeight / 2)
                                    visible:                modeChannel != returnChannel && modeChannel != loiterChannel
                                    horizontalAlignment:    Text.AlignRight
                                    text:                   "Auto"
                                }

                                QGCLabel {
                                    width:                  parent.width
                                    y:                      (parent.height * (1.0 - rc_loiter_th.value)) - (implicitHeight / 2)
                                    visible:                modeChannel == loiterChannel
                                    horizontalAlignment:    Text.AlignRight
                                    text:                   "Auto: Loiter"
                                }

                                QGCLabel {
                                    width:                  parent.width
                                    y:                      (parent.height * (1.0 - rc_auto_th.value)) - (implicitHeight / 2)
                                    visible:                modeChannel == loiterChannel
                                    horizontalAlignment:    Text.AlignRight
                                    text:                   "Auto: Mission"
                                }

                                QGCLabel {
                                    width:                  parent.width
                                    y:                      (parent.height * (1.0 - rc_auto_th.value)) - (implicitHeight / 2)
                                    visible:                modeChannel == returnChannel && modeChannel != loiterChannel
                                    horizontalAlignment:    Text.AlignRight
                                    text:                   "Auto: Loiter/Mission"
                                }

                                QGCLabel {
                                    width:                  parent.width
                                    y:                      (parent.height * (1.0 - rc_assist_th.value)) - (implicitHeight / 2)
                                    visible:                modeChannel != posCtlChannel
                                    horizontalAlignment:    Text.AlignRight
                                    text:                   "Assist"
                                }

                                QGCLabel {
                                    width:                  parent.width
                                    y:                      (parent.height * (1.0 - rc_posctl_th.value)) - (implicitHeight / 2)
                                    visible:                modeChannel == posCtlChannel
                                    horizontalAlignment:    Text.AlignRight
                                    text:                   "Assist: PosCtl"
                                }

                                QGCLabel {
                                    width:                  parent.width
                                    y:                      (parent.height * (1.0 - rc_assist_th.value)) - (implicitHeight / 2)
                                    visible:                modeChannel == posCtlChannel
                                    horizontalAlignment:    Text.AlignRight
                                    text:                   "Assist: AltCtl"
                                }

                                QGCLabel {
                                    width:              parent.width
                                    y:                  parent.height - (implicitHeight / 2)
                                    text:               "Manual"
                                    horizontalAlignment: Text.AlignRight
                                }
                            }

                            ProgressBar {
                                height:         progressBarHeight
                                orientation:    Qt.Vertical
                                value:          controller.modeSwitchLiveRange
                            }
                        }
                    }

                    Column {
746
                        visible: parent.loiterSwitchVisible
Don Gagne's avatar
Don Gagne committed
747

748
                        QGCLabel { text: "Loiter Switch" }
Don Gagne's avatar
Don Gagne committed
749 750 751 752 753 754 755 756

                        Row {
                            Item {
                                height: progressBarHeight
                                width:  150

                                QGCLabel {
                                    width:                  parent.width
757
                                    y:                      (parent.height * (1.0 - rc_loiter_th.value)) - (implicitHeight / 2)
Don Gagne's avatar
Don Gagne committed
758
                                    horizontalAlignment:    Text.AlignRight
759
                                    text:                   "Auto: Loiter"
Don Gagne's avatar
Don Gagne committed
760 761 762 763
                                }

                                QGCLabel {
                                    width:                  parent.width
764
                                    y:                      parent.height - (implicitHeight / 2)
Don Gagne's avatar
Don Gagne committed
765
                                    horizontalAlignment:    Text.AlignRight
766
                                    text:                   "Auto: Mission"
Don Gagne's avatar
Don Gagne committed
767
                                }
768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786
                            }

                            ProgressBar {
                                height:         progressBarHeight
                                orientation:    Qt.Vertical
                                value:          controller.loiterSwitchLiveRange
                            }
                        }
                    }

                    Column {
                        visible: parent.posCtlSwitchVisible

                        QGCLabel { text: "PosCtl Switch" }

                        Row {
                            Item {
                                height: progressBarHeight
                                width:  150
Don Gagne's avatar
Don Gagne committed
787 788 789

                                QGCLabel {
                                    width:                  parent.width
790
                                    y:                      (parent.height * (1.0 - rc_posctl_th.value)) - (implicitHeight / 2)
Don Gagne's avatar
Don Gagne committed
791
                                    horizontalAlignment:    Text.AlignRight
792
                                    text:                   "Assist: PosCtl"
Don Gagne's avatar
Don Gagne committed
793 794 795 796 797 798
                                }

                                QGCLabel {
                                    width:                  parent.width
                                    y:                      parent.height - (implicitHeight / 2)
                                    horizontalAlignment:    Text.AlignRight
799
                                    text:                   "Assist: AltCtl"
Don Gagne's avatar
Don Gagne committed
800 801 802 803 804 805
                                }
                            }

                            ProgressBar {
                                height:         progressBarHeight
                                orientation:    Qt.Vertical
806
                                value:          controller.posCtlSwitchLiveRange
Don Gagne's avatar
Don Gagne committed
807 808 809 810 811
                            }
                        }
                    }

                    Column {
812
                        visible: parent.returnSwitchVisible
Don Gagne's avatar
Don Gagne committed
813

814
                        QGCLabel { text: "Return Switch" }
Don Gagne's avatar
Don Gagne committed
815 816 817 818 819 820 821 822

                        Row {
                            Item {
                                height: progressBarHeight
                                width:  150

                                QGCLabel {
                                    width:                  parent.width
823
                                    y:                      (parent.height * (1.0 - rc_return_th.value)) - (implicitHeight / 2)
Don Gagne's avatar
Don Gagne committed
824
                                    horizontalAlignment:    Text.AlignRight
825
                                    text:                   "Return"
Don Gagne's avatar
Don Gagne committed
826 827 828 829 830
                                }

                                QGCLabel {
                                    width:                  parent.width
                                    y:                      parent.height - (implicitHeight / 2)
831
                                    visible:                returnChannel != loiterChannel
Don Gagne's avatar
Don Gagne committed
832
                                    horizontalAlignment:    Text.AlignRight
833
                                    text:                   "Return Off"
Don Gagne's avatar
Don Gagne committed
834 835 836 837 838 839
                                }
                            }

                            ProgressBar {
                                height:         progressBarHeight
                                orientation:    Qt.Vertical
840
                                value:          controller.returnSwitchLiveRange
Don Gagne's avatar
Don Gagne committed
841 842 843 844 845
                            }
                        }
                    }

                    Column {
846
                        visible: parent.offboardSwitchVisible
Don Gagne's avatar
Don Gagne committed
847

848
                        QGCLabel { text: "Offboard Switch" }
Don Gagne's avatar
Don Gagne committed
849 850 851 852 853 854 855 856

                        Row {
                            Item {
                                height: progressBarHeight
                                width:  150

                                QGCLabel {
                                    width:                  parent.width
857
                                    y:                      (parent.height * (1.0 - rc_return_th.value)) - (implicitHeight / 2)
Don Gagne's avatar
Don Gagne committed
858
                                    horizontalAlignment:    Text.AlignRight
859
                                    text:                   "Offboad"
Don Gagne's avatar
Don Gagne committed
860 861 862 863 864
                                }

                                QGCLabel {
                                    width:                  parent.width
                                    y:                      parent.height - (implicitHeight / 2)
865
                                    visible:                returnChannel != loiterChannel
Don Gagne's avatar
Don Gagne committed
866
                                    horizontalAlignment:    Text.AlignRight
867
                                    text:                   "Offboard Off"
Don Gagne's avatar
Don Gagne committed
868 869 870 871 872 873
                                }
                            }

                            ProgressBar {
                                height:         progressBarHeight
                                orientation:    Qt.Vertical
874
                                value:          controller.offboardSwitchLiveRange
Don Gagne's avatar
Don Gagne committed
875 876 877 878 879 880 881 882 883 884 885
                            }
                        }
                    }
                }
            }
        }
    }

    Component {
        id: invalidComponent

Don Gagne's avatar
Don Gagne committed
886
        FactPanel {
Don Gagne's avatar
Don Gagne committed
887 888 889 890 891 892 893 894 895
            anchors.fill: parent
            color: qgcPal.window

            Column {
                width: parent.width
                spacing: 20

                QGCLabel {
                    text: "FLIGHT MODES CONFIG"
896
                    font.pointSize: ScreenTools.fontPointFactor * (20);
Don Gagne's avatar
Don Gagne committed
897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914
                }

                QGCLabel {
                    width:      parent.width
                    wrapMode:   Text.WordWrap
                    text:       "There are errors in your current configuration which will need to be fixed before you can used Flight Config setup. " +
                                "You will need to change Parameters directly using Parameters Setup to remove these errors."
                }

                QGCLabel {
                    width:      parent.width
                    wrapMode:   Text.WordWrap
                    text:       controller.configurationErrors
                }
            }
        }
    }
}