JoystickConfig.qml 36.8 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
9 10


11 12
import QtQuick          2.3
import QtQuick.Controls 1.2
13 14
import QtQuick.Dialogs  1.2

15
import QGroundControl               1.0
16 17 18 19
import QGroundControl.Palette       1.0
import QGroundControl.Controls      1.0
import QGroundControl.ScreenTools   1.0
import QGroundControl.Controllers   1.0
20
import QGroundControl.FactSystem    1.0
21
import QGroundControl.FactControls  1.0
22 23

/// Joystick Config
Don Gagne's avatar
Don Gagne committed
24 25 26 27 28 29
SetupPage {
    id:                 joystickPage
    pageComponent:      pageComponent
    pageName:           qsTr("Joystick")
    pageDescription:    qsTr("Joystick Setup is used to configure a calibrate joysticks.")

Jacob Walser's avatar
Jacob Walser committed
30 31 32 33 34 35 36 37 38 39
    Connections {
        target: joystickManager
        onAvailableJoysticksChanged: {
            if( joystickManager.joysticks.length == 0 ) {
                summaryButton.checked = true
                setupView.showSummaryPanel()
            }
        }
    }

Don Gagne's avatar
Don Gagne committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
    Component {
        id: pageComponent

        Item {
            width:  availableWidth
            height: Math.max(leftColumn.height, rightColumn.height)

            property bool controllerCompleted:      false
            property bool controllerAndViewReady:   false

            readonly property real labelToMonitorMargin: defaultTextWidth * 3

            property var _activeVehicle:    QGroundControl.multiVehicleManager.activeVehicle
            property var _activeJoystick:   joystickManager.activeJoystick

            JoystickConfigController {
                id:             controller
                factPanel:      joystickPage.viewPanel
                statusText:     statusText
                cancelButton:   cancelButton
                nextButton:     nextButton
                skipButton:     skipButton

                Component.onCompleted: {
                    controllerCompleted = true
                    if (joystickPage.completedSignalled) {
                        controllerAndViewReady = true
                        controller.start()
                    }
                }
70 71
            }

Don Gagne's avatar
Don Gagne committed
72 73 74 75 76 77
            Component.onCompleted: {
                if (controllerCompleted) {
                    controllerAndViewReady = true
                    controller.start()
                }
            }
78

Don Gagne's avatar
Don Gagne committed
79 80 81
            // Live axis monitor control component
            Component {
                id: axisMonitorDisplayComponent
82

Don Gagne's avatar
Don Gagne committed
83 84
                Item {
                    property int axisValue: 0
Gregory Dymarek's avatar
Gregory Dymarek committed
85
                    property int deadbandValue: 0
86

Don Gagne's avatar
Don Gagne committed
87
                    property color          __barColor:             qgcPal.windowShade
88

Don Gagne's avatar
Don Gagne committed
89 90 91 92 93 94 95 96
                    // Bar
                    Rectangle {
                        id:                     bar
                        anchors.verticalCenter: parent.verticalCenter
                        width:                  parent.width
                        height:                 parent.height / 2
                        color:                  __barColor
                    }
97

Gregory Dymarek's avatar
Gregory Dymarek committed
98 99 100 101 102 103 104 105
                    // Deadband
                    Rectangle {
                        id:                     deadbandBar
                        anchors.verticalCenter: parent.verticalCenter
                        x:                      _deadbandPosition
                        width:                  _deadbandWidth
                        height:                 parent.height / 2
                        color:                  "#8c161a"
106
                        visible:                controller.deadbandToggle
Gregory Dymarek's avatar
Gregory Dymarek committed
107 108 109 110 111 112

                        property real _percentDeadband:    ((2 * deadbandValue) / (32768.0 * 2))
                        property real _deadbandWidth:   parent.width * _percentDeadband
                        property real _deadbandPosition:   (parent.width - _deadbandWidth) / 2
                    }

Don Gagne's avatar
Don Gagne committed
113 114 115 116 117 118 119
                    // Center point
                    Rectangle {
                        anchors.horizontalCenter:   parent.horizontalCenter
                        width:                      defaultTextWidth / 2
                        height:                     parent.height
                        color:                      qgcPal.window
                    }
120

Don Gagne's avatar
Don Gagne committed
121 122 123 124 125 126 127 128 129 130 131 132 133
                    // Indicator
                    Rectangle {
                        anchors.verticalCenter: parent.verticalCenter
                        width:                  parent.height * 0.75
                        height:                 width
                        x:                      (reversed ? (parent.width - _indicatorPosition) : _indicatorPosition) - (width / 2)
                        radius:                 width / 2
                        color:                  qgcPal.text
                        visible:                mapped

                        property real _percentAxisValue:    ((axisValue + 32768.0) / (32768.0 * 2))
                        property real _indicatorPosition:   parent.width * _percentAxisValue
                    }
134

Don Gagne's avatar
Don Gagne committed
135 136 137 138 139 140 141
                    QGCLabel {
                        anchors.fill:           parent
                        horizontalAlignment:    Text.AlignHCenter
                        verticalAlignment:      Text.AlignVCenter
                        text:                   qsTr("Not Mapped")
                        visible:                !mapped
                    }
142

Don Gagne's avatar
Don Gagne committed
143 144 145 146 147 148 149 150
                    ColorAnimation {
                        id:         barAnimation
                        target:     bar
                        property:   "color"
                        from:       "yellow"
                        to:         __barColor
                        duration:   1500
                    }
151

Gregory Dymarek's avatar
Gregory Dymarek committed
152

Don Gagne's avatar
Don Gagne committed
153
                    // Axis value debugger
Gregory Dymarek's avatar
Gregory Dymarek committed
154
                    /*
Don Gagne's avatar
Don Gagne committed
155 156 157 158 159
                    QGCLabel {
                        anchors.fill: parent
                        text: axisValue
                    }
                    */
Gregory Dymarek's avatar
Gregory Dymarek committed
160

161
                }
Don Gagne's avatar
Don Gagne committed
162
            } // Component - axisMonitorDisplayComponent
163

Don Gagne's avatar
Don Gagne committed
164 165 166 167 168 169 170 171 172
            // Main view Qml starts here

            // Left side column
            Column {
                id:                     leftColumn
                anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
                anchors.left:           parent.left
                anchors.right:          rightColumn.left
                spacing:                10
173

Don Gagne's avatar
Don Gagne committed
174 175 176 177
                // Attitude Controls
                Column {
                    width:      parent.width
                    spacing:    5
178

Don Gagne's avatar
Don Gagne committed
179
                    QGCLabel { text: qsTr("Attitude Controls") }
180

Don Gagne's avatar
Don Gagne committed
181 182 183
                    Item {
                        width:  parent.width
                        height: defaultTextHeight * 2
184

Don Gagne's avatar
Don Gagne committed
185 186 187
                        QGCLabel {
                            id:     rollLabel
                            width:  defaultTextWidth * 10
188
                            text:   _activeVehicle.sub ? qsTr("Lateral") : qsTr("Roll")
Don Gagne's avatar
Don Gagne committed
189
                        }
190

Don Gagne's avatar
Don Gagne committed
191 192 193 194 195 196 197 198 199 200 201 202
                        Loader {
                            id:                 rollLoader
                            anchors.left:       rollLabel.right
                            anchors.right:      parent.right
                            height:             ScreenTools.defaultFontPixelHeight
                            width:              100
                            sourceComponent:    axisMonitorDisplayComponent

                            property real defaultTextWidth: ScreenTools.defaultFontPixelWidth
                            property bool mapped:           controller.rollAxisMapped
                            property bool reversed:         controller.rollAxisReversed
                        }
203

204 205 206 207 208
                        Connections {
                            target: _activeJoystick

                            onManualControl: rollLoader.item.axisValue = roll*32768.0
                        }
209 210
                    }

Don Gagne's avatar
Don Gagne committed
211 212 213
                    Item {
                        width:  parent.width
                        height: defaultTextHeight * 2
214

Don Gagne's avatar
Don Gagne committed
215 216 217
                        QGCLabel {
                            id:     pitchLabel
                            width:  defaultTextWidth * 10
218
                            text:   _activeVehicle.sub ? qsTr("Forward") : qsTr("Pitch")
Don Gagne's avatar
Don Gagne committed
219
                        }
220

Don Gagne's avatar
Don Gagne committed
221 222 223 224 225 226 227 228 229 230 231 232
                        Loader {
                            id:                 pitchLoader
                            anchors.left:       pitchLabel.right
                            anchors.right:      parent.right
                            height:             ScreenTools.defaultFontPixelHeight
                            width:              100
                            sourceComponent:    axisMonitorDisplayComponent

                            property real defaultTextWidth: ScreenTools.defaultFontPixelWidth
                            property bool mapped:           controller.pitchAxisMapped
                            property bool reversed:         controller.pitchAxisReversed
                        }
233

234 235 236 237 238
                        Connections {
                            target: _activeJoystick

                            onManualControl: pitchLoader.item.axisValue = pitch*32768.0
                        }
239 240
                    }

Don Gagne's avatar
Don Gagne committed
241 242 243
                    Item {
                        width:  parent.width
                        height: defaultTextHeight * 2
244

Don Gagne's avatar
Don Gagne committed
245 246 247 248 249
                        QGCLabel {
                            id:     yawLabel
                            width:  defaultTextWidth * 10
                            text:   qsTr("Yaw")
                        }
250

Don Gagne's avatar
Don Gagne committed
251 252 253 254 255 256 257 258 259 260 261 262
                        Loader {
                            id:                 yawLoader
                            anchors.left:       yawLabel.right
                            anchors.right:      parent.right
                            height:             ScreenTools.defaultFontPixelHeight
                            width:              100
                            sourceComponent:    axisMonitorDisplayComponent

                            property real defaultTextWidth: ScreenTools.defaultFontPixelWidth
                            property bool mapped:           controller.yawAxisMapped
                            property bool reversed:         controller.yawAxisReversed
                        }
263

264 265 266 267 268
                        Connections {
                            target: _activeJoystick

                            onManualControl: yawLoader.item.axisValue = yaw*32768.0
                        }
269 270
                    }

Don Gagne's avatar
Don Gagne committed
271 272 273
                    Item {
                        width:  parent.width
                        height: defaultTextHeight * 2
274

Don Gagne's avatar
Don Gagne committed
275 276 277 278 279
                        QGCLabel {
                            id:     throttleLabel
                            width:  defaultTextWidth * 10
                            text:   qsTr("Throttle")
                        }
280

Don Gagne's avatar
Don Gagne committed
281 282 283 284 285 286 287 288 289 290 291 292
                        Loader {
                            id:                 throttleLoader
                            anchors.left:       throttleLabel.right
                            anchors.right:      parent.right
                            height:             ScreenTools.defaultFontPixelHeight
                            width:              100
                            sourceComponent:    axisMonitorDisplayComponent

                            property real defaultTextWidth: ScreenTools.defaultFontPixelWidth
                            property bool mapped:           controller.throttleAxisMapped
                            property bool reversed:         controller.throttleAxisReversed
                        }
293

294 295 296 297 298
                        Connections {
                            target: _activeJoystick

                            onManualControl: throttleLoader.item.axisValue = (-2*throttle+1)*32768.0
                        }
299
                    }
Don Gagne's avatar
Don Gagne committed
300
                } // Column - Attitude Control labels
301

Don Gagne's avatar
Don Gagne committed
302 303 304
                // Command Buttons
                Row {
                    spacing: 10
305
                    visible: _activeJoystick.requiresCalibration
Don Gagne's avatar
Don Gagne committed
306 307 308 309

                    QGCButton {
                        id:     skipButton
                        text:   qsTr("Skip")
310

Don Gagne's avatar
Don Gagne committed
311
                        onClicked: controller.skipButtonClicked()
312 313
                    }

Don Gagne's avatar
Don Gagne committed
314 315 316
                    QGCButton {
                        id:     cancelButton
                        text:   qsTr("Cancel")
317

Don Gagne's avatar
Don Gagne committed
318 319
                        onClicked: controller.cancelButtonClicked()
                    }
320

Don Gagne's avatar
Don Gagne committed
321 322 323 324
                    QGCButton {
                        id:         nextButton
                        primary:    true
                        text:       qsTr("Calibrate")
325

Don Gagne's avatar
Don Gagne committed
326 327 328
                        onClicked: controller.nextButtonClicked()
                    }
                } // Row - Buttons
329

Don Gagne's avatar
Don Gagne committed
330 331 332 333 334
                // Status Text
                QGCLabel {
                    id:         statusText
                    width:      parent.width
                    wrapMode:   Text.WordWrap
335 336
                }

Don Gagne's avatar
Don Gagne committed
337 338 339 340 341
                Rectangle {
                    width:          parent.width
                    height:         1
                    border.color:   qgcPal.text
                    border.width:   1
342 343
                }

Don Gagne's avatar
Don Gagne committed
344 345 346 347
                // Settings
                Row {
                    width:      parent.width
                    spacing:    ScreenTools.defaultFontPixelWidth
348

Don Gagne's avatar
Don Gagne committed
349
                    // Left column settings
350
                    Column {
Don Gagne's avatar
Don Gagne committed
351
                        width:      parent.width / 2
352 353
                        spacing:    ScreenTools.defaultFontPixelHeight

Don Gagne's avatar
Don Gagne committed
354
                        QGCLabel { text: qsTr("Additional Joystick settings:") }
355

Don Gagne's avatar
Don Gagne committed
356 357 358
                        Column {
                            width:      parent.width
                            spacing:    ScreenTools.defaultFontPixelHeight
359 360


Don Gagne's avatar
Don Gagne committed
361
                            QGCCheckBox {
Jacob Walser's avatar
Jacob Walser committed
362
                                id:         enabledCheckBox
363 364
                                enabled:    _activeJoystick ? _activeJoystick.calibrated : false
                                text:       _activeJoystick ? _activeJoystick.calibrated ? qsTr("Enable joystick input") : qsTr("Enable not allowed (Calibrate First)") : ""
Don Gagne's avatar
Don Gagne committed
365
                                checked:    _activeVehicle.joystickEnabled
366

Don Gagne's avatar
Don Gagne committed
367
                                onClicked:  _activeVehicle.joystickEnabled = checked
Jacob Walser's avatar
Jacob Walser committed
368 369 370 371 372

                                Connections {
                                    target: joystickManager

                                    onActiveJoystickChanged: {
373
                                        if(_activeJoystick) {
Jacob Walser's avatar
Jacob Walser committed
374
                                            enabledCheckBox.checked = Qt.binding(function() { return _activeJoystick.calibrated && _activeVehicle.joystickEnabled })
375
                                        }
Jacob Walser's avatar
Jacob Walser committed
376 377
                                    }
                                }
378 379
                            }

Don Gagne's avatar
Don Gagne committed
380 381 382
                            Row {
                                width:      parent.width
                                spacing:    ScreenTools.defaultFontPixelWidth
383

Don Gagne's avatar
Don Gagne committed
384 385 386 387 388
                                QGCLabel {
                                    id:                 activeJoystickLabel
                                    anchors.baseline:   joystickCombo.baseline
                                    text:               qsTr("Active joystick:")
                                }
389

Don Gagne's avatar
Don Gagne committed
390 391 392 393 394 395 396 397 398 399 400 401 402 403
                                QGCComboBox {
                                    id:                 joystickCombo
                                    width:              parent.width - activeJoystickLabel.width - parent.spacing
                                    model:              joystickManager.joystickNames

                                    onActivated: joystickManager.activeJoystickName = textAt(index)

                                    Component.onCompleted: {
                                        var index = joystickCombo.find(joystickManager.activeJoystickName)
                                        if (index == -1) {
                                            console.warn(qsTr("Active joystick name not in combo"), joystickManager.activeJoystickName)
                                        } else {
                                            joystickCombo.currentIndex = index
                                        }
404
                                    }
Jacob Walser's avatar
Jacob Walser committed
405 406 407 408 409

                                    Connections {
                                        target: joystickManager
                                        onAvailableJoysticksChanged: {
                                            var index = joystickCombo.find(joystickManager.activeJoystickName)
410
                                            if (index >= 0) {
Jacob Walser's avatar
Jacob Walser committed
411 412 413 414
                                                joystickCombo.currentIndex = index
                                            }
                                        }
                                    }
415
                                }
416 417
                            }

Don Gagne's avatar
Don Gagne committed
418 419 420
                            Column {
                                spacing: ScreenTools.defaultFontPixelHeight / 3
                                visible: _activeVehicle.supportsThrottleModeCenterZero
421

Don Gagne's avatar
Don Gagne committed
422
                                ExclusiveGroup { id: throttleModeExclusiveGroup }
423

Don Gagne's avatar
Don Gagne committed
424 425 426
                                QGCRadioButton {
                                    exclusiveGroup: throttleModeExclusiveGroup
                                    text:           qsTr("Center stick is zero throttle")
427
                                    checked:        _activeJoystick ? _activeJoystick.throttleMode == 0 : false
428

Don Gagne's avatar
Don Gagne committed
429 430
                                    onClicked: _activeJoystick.throttleMode = 0
                                }
431

432
                                Row {
Gregory Dymarek's avatar
Gregory Dymarek committed
433
                                    x:          20
434 435
                                    width:      parent.width
                                    spacing:    ScreenTools.defaultFontPixelWidth
436
                                    visible:    _activeJoystick ? _activeJoystick.throttleMode == 0 : false
437 438 439

                                    QGCCheckBox {
                                        id:         accumulator
440
                                        checked:    _activeJoystick ? _activeJoystick.accumulator : false
Gregory Dymarek's avatar
Gregory Dymarek committed
441
                                        text:       qsTr("Spring loaded throttle smoothing")
442 443 444 445 446

                                        onClicked:  _activeJoystick.accumulator = checked
                                    }
                                }

Don Gagne's avatar
Don Gagne committed
447 448 449
                                QGCRadioButton {
                                    exclusiveGroup: throttleModeExclusiveGroup
                                    text:           qsTr("Full down stick is zero throttle")
450
                                    checked:        _activeJoystick ? _activeJoystick.throttleMode == 1 : false
451

Don Gagne's avatar
Don Gagne committed
452 453
                                    onClicked: _activeJoystick.throttleMode = 1
                                }
454 455
                            }

Don Gagne's avatar
Don Gagne committed
456 457
                            Column {
                                spacing: ScreenTools.defaultFontPixelHeight / 3
458

459 460 461 462 463 464 465 466 467 468 469
                                QGCLabel {
                                    id:                 expoSliderLabel
                                    text:               qsTr("Exponential:")
                                }

                                Row {
                                    QGCSlider {
                                        id: expoSlider
                                        minimumValue: 0
                                        maximumValue: 0.75

nanthony21's avatar
nanthony21 committed
470 471
                                        Component.onCompleted: value=-_activeJoystick.exponential
                                        onValueChanged: _activeJoystick.exponential=-value
472 473 474 475 476
                                     }

                                    QGCLabel {
                                        id:     expoSliderIndicator
                                        text:   expoSlider.value.toFixed(2)
477
                                    }
Don Gagne's avatar
Don Gagne committed
478
                                }
479 480
                            }

Don Gagne's avatar
Don Gagne committed
481 482 483 484
                            QGCCheckBox {
                                id:         advancedSettings
                                checked:    _activeVehicle.joystickMode != 0
                                text:       qsTr("Advanced settings (careful!)")
485

Don Gagne's avatar
Don Gagne committed
486 487 488 489
                                onClicked: {
                                    if (!checked) {
                                        _activeVehicle.joystickMode = 0
                                    }
490 491 492
                                }
                            }

Don Gagne's avatar
Don Gagne committed
493 494 495 496 497 498 499 500 501 502
                            Row {
                                width:      parent.width
                                spacing:    ScreenTools.defaultFontPixelWidth
                                visible:    advancedSettings.checked

                                QGCLabel {
                                    id:                 joystickModeLabel
                                    anchors.baseline:   joystickModeCombo.baseline
                                    text:               qsTr("Joystick mode:")
                                }
503

Don Gagne's avatar
Don Gagne committed
504 505 506 507 508
                                QGCComboBox {
                                    id:             joystickModeCombo
                                    currentIndex:   _activeVehicle.joystickMode
                                    width:          ScreenTools.defaultFontPixelWidth * 20
                                    model:          _activeVehicle.joystickModes
509

Don Gagne's avatar
Don Gagne committed
510 511
                                    onActivated: _activeVehicle.joystickMode = index
                                }
512
                            }
513 514 515 516 517 518 519 520 521 522 523 524 525 526

                            Row {
                                width:      parent.width
                                spacing:    ScreenTools.defaultFontPixelWidth
                                visible:    advancedSettings.checked

                                QGCCheckBox {
                                    id:         deadband
                                    checked:    controller.deadbandToggle
                                    text:       qsTr("Deadbands")

                                    onClicked:  controller.deadbandToggle = checked
                                }
                            }
527
                        }
Don Gagne's avatar
Don Gagne committed
528
                    } // Column - left column
529

Don Gagne's avatar
Don Gagne committed
530 531 532 533
                    // Right column settings
                    Column {
                        width:      parent.width / 2
                        spacing:    ScreenTools.defaultFontPixelHeight
534

Don Gagne's avatar
Don Gagne committed
535 536
                        Connections {
                            target: _activeJoystick
537

Don Gagne's avatar
Don Gagne committed
538 539 540 541 542 543 544
                            onRawButtonPressedChanged: {
                                if (buttonActionRepeater.itemAt(index)) {
                                    buttonActionRepeater.itemAt(index).pressed = pressed
                                }
                                if (jsButtonActionRepeater.itemAt(index)) {
                                    jsButtonActionRepeater.itemAt(index).pressed = pressed
                                }
545
                            }
546 547
                        }

Don Gagne's avatar
Don Gagne committed
548
                        QGCLabel { text: qsTr("Button actions:") }
549

Don Gagne's avatar
Don Gagne committed
550 551 552
                        Column {
                            width:      parent.width
                            spacing:    ScreenTools.defaultFontPixelHeight / 3
553

Don Gagne's avatar
Don Gagne committed
554 555 556
                            QGCLabel {
                                visible: _activeVehicle.manualControlReservedButtonCount != 0
                                text: qsTr("Buttons 0-%1 reserved for firmware use").arg(reservedButtonCount)
557

Don Gagne's avatar
Don Gagne committed
558 559
                                property int reservedButtonCount: _activeVehicle.manualControlReservedButtonCount == -1 ? _activeJoystick.totalButtonCount : _activeVehicle.manualControlReservedButtonCount
                            }
560

Don Gagne's avatar
Don Gagne committed
561 562
                            Repeater {
                                id:     buttonActionRepeater
563
                                model:  _activeJoystick ? _activeJoystick.totalButtonCount : 0
564

Don Gagne's avatar
Don Gagne committed
565 566 567
                                Row {
                                    spacing: ScreenTools.defaultFontPixelWidth
                                    visible: (_activeVehicle.manualControlReservedButtonCount == -1 ? false : modelData >= _activeVehicle.manualControlReservedButtonCount) && !_activeVehicle.supportsJSButton
568

Don Gagne's avatar
Don Gagne committed
569
                                    property bool pressed
570

Don Gagne's avatar
Don Gagne committed
571 572
                                    QGCCheckBox {
                                        anchors.verticalCenter:     parent.verticalCenter
573
                                        checked:                    _activeJoystick ? _activeJoystick.buttonActions[modelData] != "" : false
574

Don Gagne's avatar
Don Gagne committed
575 576
                                        onClicked: _activeJoystick.setButtonAction(modelData, checked ? buttonActionCombo.textAt(buttonActionCombo.currentIndex) : "")
                                    }
577

Don Gagne's avatar
Don Gagne committed
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593
                                    Rectangle {
                                        anchors.verticalCenter:     parent.verticalCenter
                                        width:                      ScreenTools.defaultFontPixelHeight * 1.5
                                        height:                     width
                                        border.width:               1
                                        border.color:               qgcPal.text
                                        color:                      pressed ? qgcPal.buttonHighlight : qgcPal.button


                                        QGCLabel {
                                            anchors.fill:           parent
                                            color:                  pressed ? qgcPal.buttonHighlightText : qgcPal.buttonText
                                            horizontalAlignment:    Text.AlignHCenter
                                            verticalAlignment:      Text.AlignVCenter
                                            text:                   modelData
                                        }
594 595
                                    }

Don Gagne's avatar
Don Gagne committed
596 597 598
                                    QGCComboBox {
                                        id:             buttonActionCombo
                                        width:          ScreenTools.defaultFontPixelWidth * 20
599
                                        model:          _activeJoystick ? _activeJoystick.actions : 0
600

Don Gagne's avatar
Don Gagne committed
601 602 603
                                        onActivated:            _activeJoystick.setButtonAction(modelData, textAt(index))
                                        Component.onCompleted:  currentIndex = find(_activeJoystick.buttonActions[modelData])
                                    }
604
                                }
Don Gagne's avatar
Don Gagne committed
605
                            } // Repeater
606 607 608

                            Row {
                                spacing: ScreenTools.defaultFontPixelWidth
609
                                visible: _activeVehicle.supportsJSButton
610

Don Gagne's avatar
Don Gagne committed
611 612 613 614
                                QGCLabel {
                                    horizontalAlignment:    Text.AlignHCenter
                                    width:                  ScreenTools.defaultFontPixelHeight * 1.5
                                    text:                   qsTr("#")
615 616
                                }

Don Gagne's avatar
Don Gagne committed
617 618 619
                                QGCLabel {
                                    width:                  ScreenTools.defaultFontPixelWidth * 15
                                    text:                   qsTr("Function: ")
620 621
                                }

Don Gagne's avatar
Don Gagne committed
622 623 624
                                QGCLabel {
                                    width:                  ScreenTools.defaultFontPixelWidth * 15
                                    text:                   qsTr("Shift Function: ")
625 626
                                }
                            } // Row
627

Don Gagne's avatar
Don Gagne committed
628 629
                            Repeater {
                                id:     jsButtonActionRepeater
630
                                model:  _activeJoystick ? _activeJoystick.totalButtonCount : 0
Don Gagne's avatar
Don Gagne committed
631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676

                                Row {
                                    spacing: ScreenTools.defaultFontPixelWidth
                                    visible: _activeVehicle.supportsJSButton

                                    property bool pressed

                                    Rectangle {
                                        anchors.verticalCenter:     parent.verticalCenter
                                        width:                      ScreenTools.defaultFontPixelHeight * 1.5
                                        height:                     width
                                        border.width:               1
                                        border.color:               qgcPal.text
                                        color:                      pressed ? qgcPal.buttonHighlight : qgcPal.button


                                        QGCLabel {
                                            anchors.fill:           parent
                                            color:                  pressed ? qgcPal.buttonHighlightText : qgcPal.buttonText
                                            horizontalAlignment:    Text.AlignHCenter
                                            verticalAlignment:      Text.AlignVCenter
                                            text:                   modelData
                                        }
                                    }

                                    FactComboBox {
                                        id:         mainJSButtonActionCombo
                                        width:      ScreenTools.defaultFontPixelWidth * 15
                                        fact:       controller.parameterExists(-1, "BTN"+index+"_FUNCTION") ? controller.getParameterFact(-1, "BTN" + index + "_FUNCTION") : null;
                                        indexModel: false
                                    }

                                    FactComboBox {
                                        id:         shiftJSButtonActionCombo
                                        width:      ScreenTools.defaultFontPixelWidth * 15
                                        fact:       controller.parameterExists(-1, "BTN"+index+"_SFUNCTION") ? controller.getParameterFact(-1, "BTN" + index + "_SFUNCTION") : null;
                                        indexModel: false
                                    }
                                } // Row
                            } // Repeater
                        } // Column
                    } // Column - right setting column
                } // Row - Settings
            } // Column - Left Main Column

            // Right side column
677
            Column {
Don Gagne's avatar
Don Gagne committed
678 679 680
                id:             rightColumn
                anchors.top:    parent.top
                anchors.right:  parent.right
681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696
                width:          Math.min(joystickPage.defaultTextWidth * 35, availableWidth * 0.4)
                spacing:        ScreenTools.defaultFontPixelHeight / 2

                Row {
                    spacing: ScreenTools.defaultFontPixelWidth

                    ExclusiveGroup { id: modeGroup }

                    QGCLabel {
                        text: "TX Mode:"
                    }

                    QGCRadioButton {
                        exclusiveGroup: modeGroup
                        text:           "1"
                        checked:        controller.transmitterMode == 1
697
                        enabled:        !controller.calibrating
698 699 700 701 702 703 704 705

                        onClicked: controller.transmitterMode = 1
                    }

                    QGCRadioButton {
                        exclusiveGroup: modeGroup
                        text:           "2"
                        checked:        controller.transmitterMode == 2
706
                        enabled:        !controller.calibrating
707 708 709 710 711 712 713 714

                        onClicked: controller.transmitterMode = 2
                    }

                    QGCRadioButton {
                        exclusiveGroup: modeGroup
                        text:           "3"
                        checked:        controller.transmitterMode == 3
715
                        enabled:        !controller.calibrating
716 717 718 719 720 721 722 723

                        onClicked: controller.transmitterMode = 3
                    }

                    QGCRadioButton {
                        exclusiveGroup: modeGroup
                        text:           "4"
                        checked:        controller.transmitterMode == 4
724
                        enabled:        !controller.calibrating
725 726 727 728

                        onClicked: controller.transmitterMode = 4
                    }
                }
Don Gagne's avatar
Don Gagne committed
729 730

                Image {
731
                    width:      parent.width
Don Gagne's avatar
Don Gagne committed
732 733 734 735
                    fillMode:   Image.PreserveAspectFit
                    smooth:     true
                    source:     controller.imageHelp
                }
736

Don Gagne's avatar
Don Gagne committed
737 738 739 740
                // Axis monitor
                Column {
                    width:      parent.width
                    spacing:    5
741

Don Gagne's avatar
Don Gagne committed
742
                    QGCLabel { text: qsTr("Axis Monitor") }
743

Don Gagne's avatar
Don Gagne committed
744 745 746 747 748 749 750
                    Connections {
                        target: controller

                        onAxisValueChanged: {
                            if (axisMonitorRepeater.itemAt(axis)) {
                                axisMonitorRepeater.itemAt(axis).loader.item.axisValue = value
                            }
751
                        }
752 753 754 755 756 757

                        onAxisDeadbandChanged: {
                            if (axisMonitorRepeater.itemAt(axis)) {
                                axisMonitorRepeater.itemAt(axis).loader.item.deadbandValue = value
                            }
                        }
758 759
                    }

Don Gagne's avatar
Don Gagne committed
760 761
                    Repeater {
                        id:     axisMonitorRepeater
762
                        model:  _activeJoystick ? _activeJoystick.axisCount : 0
Don Gagne's avatar
Don Gagne committed
763
                        width:  parent.width
764

Don Gagne's avatar
Don Gagne committed
765 766
                        Row {
                            spacing:    5
767

Don Gagne's avatar
Don Gagne committed
768 769
                            // Need this to get to loader from Connections above
                            property Item loader: theLoader
770

Don Gagne's avatar
Don Gagne committed
771 772 773 774
                            QGCLabel {
                                id:     axisLabel
                                text:   modelData
                            }
775

Don Gagne's avatar
Don Gagne committed
776 777 778 779 780 781 782 783 784 785 786
                            Loader {
                                id:                     theLoader
                                anchors.verticalCenter: axisLabel.verticalCenter
                                height:                 ScreenTools.defaultFontPixelHeight
                                width:                  200
                                sourceComponent:        axisMonitorDisplayComponent

                                property real defaultTextWidth:     ScreenTools.defaultFontPixelWidth
                                property bool mapped:               true
                                readonly property bool reversed:    false
                            }
787 788
                        }
                    }
Don Gagne's avatar
Don Gagne committed
789
                } // Column - Axis Monitor
790

Don Gagne's avatar
Don Gagne committed
791 792 793 794
                // Button monitor
                Column {
                    width:      parent.width
                    spacing:    ScreenTools.defaultFontPixelHeight
795

Don Gagne's avatar
Don Gagne committed
796
                    QGCLabel { text: qsTr("Button Monitor") }
797

Don Gagne's avatar
Don Gagne committed
798 799
                    Connections {
                        target: _activeJoystick
800

Don Gagne's avatar
Don Gagne committed
801 802 803 804
                        onRawButtonPressedChanged: {
                            if (buttonMonitorRepeater.itemAt(index)) {
                                buttonMonitorRepeater.itemAt(index).pressed = pressed
                            }
805 806 807
                        }
                    }

Don Gagne's avatar
Don Gagne committed
808 809 810
                    Flow {
                        width:      parent.width
                        spacing:    -1
811

Don Gagne's avatar
Don Gagne committed
812 813
                        Repeater {
                            id:     buttonMonitorRepeater
814
                            model:  _activeJoystick ? _activeJoystick.totalButtonCount : 0
815

Don Gagne's avatar
Don Gagne committed
816 817 818 819 820 821
                            Rectangle {
                                width:          ScreenTools.defaultFontPixelHeight * 1.2
                                height:         width
                                border.width:   1
                                border.color:   qgcPal.text
                                color:          pressed ? qgcPal.buttonHighlight : qgcPal.button
822

Don Gagne's avatar
Don Gagne committed
823
                                property bool pressed
824

Don Gagne's avatar
Don Gagne committed
825 826 827 828 829 830 831
                                QGCLabel {
                                    anchors.fill:           parent
                                    color:                  pressed ? qgcPal.buttonHighlightText : qgcPal.buttonText
                                    horizontalAlignment:    Text.AlignHCenter
                                    verticalAlignment:      Text.AlignVCenter
                                    text:                   modelData
                                }
832
                            }
Don Gagne's avatar
Don Gagne committed
833 834 835 836 837 838 839
                        } // Repeater
                    } // Row
                } // Column - Axis Monitor
            } // Column - Right Column
        } // Item
    } // Component - pageComponent
} // SetupPage
Gregory Dymarek's avatar
Gregory Dymarek committed
840 841