JoystickConfig.qml 40 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.")

dheideman's avatar
dheideman committed
30 31
    readonly property real _maxButtons: 16

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

Don Gagne's avatar
Don Gagne committed
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 70 71
    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()
                    }
                }
72 73
            }

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

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

Don Gagne's avatar
Don Gagne committed
85 86
                Item {
                    property int axisValue: 0
Gregory Dymarek's avatar
Gregory Dymarek committed
87
                    property int deadbandValue: 0
88
                    property bool narrowIndicator: false
89
                    property color deadbandColor: "#8c161a"
90

Don Gagne's avatar
Don Gagne committed
91
                    property color          __barColor:             qgcPal.windowShade
92

Don Gagne's avatar
Don Gagne committed
93 94 95 96 97 98 99 100
                    // Bar
                    Rectangle {
                        id:                     bar
                        anchors.verticalCenter: parent.verticalCenter
                        width:                  parent.width
                        height:                 parent.height / 2
                        color:                  __barColor
                    }
101

Gregory Dymarek's avatar
Gregory Dymarek committed
102 103 104 105 106 107 108
                    // Deadband
                    Rectangle {
                        id:                     deadbandBar
                        anchors.verticalCenter: parent.verticalCenter
                        x:                      _deadbandPosition
                        width:                  _deadbandWidth
                        height:                 parent.height / 2
109
                        color:                  deadbandColor
110
                        visible:                controller.deadbandToggle
Gregory Dymarek's avatar
Gregory Dymarek committed
111 112 113 114 115 116

                        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
117 118 119 120 121 122 123
                    // Center point
                    Rectangle {
                        anchors.horizontalCenter:   parent.horizontalCenter
                        width:                      defaultTextWidth / 2
                        height:                     parent.height
                        color:                      qgcPal.window
                    }
124

Don Gagne's avatar
Don Gagne committed
125 126 127
                    // Indicator
                    Rectangle {
                        anchors.verticalCenter: parent.verticalCenter
128 129
                        width:                  parent.narrowIndicator ?  height/6 : height
                        height:                 parent.height * 0.75
Don Gagne's avatar
Don Gagne committed
130 131 132 133 134 135 136 137
                        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
                    }
138

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

Don Gagne's avatar
Don Gagne committed
147 148 149 150 151 152 153 154
                    ColorAnimation {
                        id:         barAnimation
                        target:     bar
                        property:   "color"
                        from:       "yellow"
                        to:         __barColor
                        duration:   1500
                    }
155

Gregory Dymarek's avatar
Gregory Dymarek committed
156

Don Gagne's avatar
Don Gagne committed
157
                    // Axis value debugger
Gregory Dymarek's avatar
Gregory Dymarek committed
158
                    /*
Don Gagne's avatar
Don Gagne committed
159 160 161 162 163
                    QGCLabel {
                        anchors.fill: parent
                        text: axisValue
                    }
                    */
Gregory Dymarek's avatar
Gregory Dymarek committed
164

165
                }
Don Gagne's avatar
Don Gagne committed
166
            } // Component - axisMonitorDisplayComponent
167

Don Gagne's avatar
Don Gagne committed
168 169 170 171 172 173 174 175 176
            // 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
177

Don Gagne's avatar
Don Gagne committed
178 179 180 181
                // Attitude Controls
                Column {
                    width:      parent.width
                    spacing:    5
182

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

Don Gagne's avatar
Don Gagne committed
185 186 187
                    Item {
                        width:  parent.width
                        height: defaultTextHeight * 2
188

Don Gagne's avatar
Don Gagne committed
189 190 191
                        QGCLabel {
                            id:     rollLabel
                            width:  defaultTextWidth * 10
192
                            text:   _activeVehicle.sub ? qsTr("Lateral") : qsTr("Roll")
Don Gagne's avatar
Don Gagne committed
193
                        }
194

Don Gagne's avatar
Don Gagne committed
195 196 197 198 199 200 201 202 203 204 205 206
                        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
                        }
207

208 209 210 211 212
                        Connections {
                            target: _activeJoystick

                            onManualControl: rollLoader.item.axisValue = roll*32768.0
                        }
213 214
                    }

Don Gagne's avatar
Don Gagne committed
215 216 217
                    Item {
                        width:  parent.width
                        height: defaultTextHeight * 2
218

Don Gagne's avatar
Don Gagne committed
219 220 221
                        QGCLabel {
                            id:     pitchLabel
                            width:  defaultTextWidth * 10
222
                            text:   _activeVehicle.sub ? qsTr("Forward") : qsTr("Pitch")
Don Gagne's avatar
Don Gagne committed
223
                        }
224

Don Gagne's avatar
Don Gagne committed
225 226 227 228 229 230 231 232 233 234 235 236
                        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
                        }
237

238 239 240 241 242
                        Connections {
                            target: _activeJoystick

                            onManualControl: pitchLoader.item.axisValue = pitch*32768.0
                        }
243 244
                    }

Don Gagne's avatar
Don Gagne committed
245 246 247
                    Item {
                        width:  parent.width
                        height: defaultTextHeight * 2
248

Don Gagne's avatar
Don Gagne committed
249 250 251 252 253
                        QGCLabel {
                            id:     yawLabel
                            width:  defaultTextWidth * 10
                            text:   qsTr("Yaw")
                        }
254

Don Gagne's avatar
Don Gagne committed
255 256 257 258 259 260 261 262 263 264 265 266
                        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
                        }
267

268 269 270 271 272
                        Connections {
                            target: _activeJoystick

                            onManualControl: yawLoader.item.axisValue = yaw*32768.0
                        }
273 274
                    }

Don Gagne's avatar
Don Gagne committed
275 276 277
                    Item {
                        width:  parent.width
                        height: defaultTextHeight * 2
278

Don Gagne's avatar
Don Gagne committed
279 280 281 282 283
                        QGCLabel {
                            id:     throttleLabel
                            width:  defaultTextWidth * 10
                            text:   qsTr("Throttle")
                        }
284

Don Gagne's avatar
Don Gagne committed
285 286 287 288 289 290 291 292 293 294 295 296
                        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
                        }
297

298 299 300
                        Connections {
                            target: _activeJoystick

301
                            onManualControl: throttleLoader.item.axisValue = _activeJoystick.negativeThrust ? -throttle*32768.0 : (-2*throttle+1)*32768.0
302
                        }
303
                    }
Don Gagne's avatar
Don Gagne committed
304
                } // Column - Attitude Control labels
305

Don Gagne's avatar
Don Gagne committed
306 307 308
                // Command Buttons
                Row {
                    spacing: 10
309
                    visible: _activeJoystick.requiresCalibration
Don Gagne's avatar
Don Gagne committed
310 311 312 313

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

Don Gagne's avatar
Don Gagne committed
315
                        onClicked: controller.skipButtonClicked()
316 317
                    }

Don Gagne's avatar
Don Gagne committed
318 319 320
                    QGCButton {
                        id:     cancelButton
                        text:   qsTr("Cancel")
321

Don Gagne's avatar
Don Gagne committed
322 323
                        onClicked: controller.cancelButtonClicked()
                    }
324

Don Gagne's avatar
Don Gagne committed
325 326 327 328
                    QGCButton {
                        id:         nextButton
                        primary:    true
                        text:       qsTr("Calibrate")
329

Don Gagne's avatar
Don Gagne committed
330 331 332
                        onClicked: controller.nextButtonClicked()
                    }
                } // Row - Buttons
333

Don Gagne's avatar
Don Gagne committed
334 335 336 337 338
                // Status Text
                QGCLabel {
                    id:         statusText
                    width:      parent.width
                    wrapMode:   Text.WordWrap
339 340
                }

Don Gagne's avatar
Don Gagne committed
341 342 343 344 345
                Rectangle {
                    width:          parent.width
                    height:         1
                    border.color:   qgcPal.text
                    border.width:   1
346 347
                }

Don Gagne's avatar
Don Gagne committed
348 349 350 351
                // Settings
                Row {
                    width:      parent.width
                    spacing:    ScreenTools.defaultFontPixelWidth
352

Don Gagne's avatar
Don Gagne committed
353
                    // Left column settings
354
                    Column {
Don Gagne's avatar
Don Gagne committed
355
                        width:      parent.width / 2
356 357
                        spacing:    ScreenTools.defaultFontPixelHeight

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

Don Gagne's avatar
Don Gagne committed
360 361 362
                        Column {
                            width:      parent.width
                            spacing:    ScreenTools.defaultFontPixelHeight
363 364


Don Gagne's avatar
Don Gagne committed
365
                            QGCCheckBox {
Jacob Walser's avatar
Jacob Walser committed
366
                                id:         enabledCheckBox
367 368
                                enabled:    _activeJoystick ? _activeJoystick.calibrated : false
                                text:       _activeJoystick ? _activeJoystick.calibrated ? qsTr("Enable joystick input") : qsTr("Enable not allowed (Calibrate First)") : ""
369
                                checked:    _activeJoystick.outputEnabled
370

371
                                onClicked:  _activeJoystick.outputEnabled = checked
Jacob Walser's avatar
Jacob Walser committed
372 373 374 375 376

                                Connections {
                                    target: joystickManager

                                    onActiveJoystickChanged: {
377
                                        if(_activeJoystick) {
Jacob Walser's avatar
Jacob Walser committed
378
                                            enabledCheckBox.checked = Qt.binding(function() { return _activeJoystick.calibrated && _activeVehicle.joystickEnabled })
379
                                        }
Jacob Walser's avatar
Jacob Walser committed
380 381
                                    }
                                }
382 383
                            }

Don Gagne's avatar
Don Gagne committed
384 385 386
                            Row {
                                width:      parent.width
                                spacing:    ScreenTools.defaultFontPixelWidth
387

Don Gagne's avatar
Don Gagne committed
388 389 390 391 392
                                QGCLabel {
                                    id:                 activeJoystickLabel
                                    anchors.baseline:   joystickCombo.baseline
                                    text:               qsTr("Active joystick:")
                                }
393

Don Gagne's avatar
Don Gagne committed
394 395 396 397 398 399 400 401 402 403 404 405 406 407
                                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
                                        }
408
                                    }
Jacob Walser's avatar
Jacob Walser committed
409 410 411 412 413

                                    Connections {
                                        target: joystickManager
                                        onAvailableJoysticksChanged: {
                                            var index = joystickCombo.find(joystickManager.activeJoystickName)
414
                                            if (index >= 0) {
Jacob Walser's avatar
Jacob Walser committed
415 416 417 418
                                                joystickCombo.currentIndex = index
                                            }
                                        }
                                    }
419
                                }
420 421
                            }

Don Gagne's avatar
Don Gagne committed
422 423 424
                            Column {
                                spacing: ScreenTools.defaultFontPixelHeight / 3
                                visible: _activeVehicle.supportsThrottleModeCenterZero
425

Don Gagne's avatar
Don Gagne committed
426
                                ExclusiveGroup { id: throttleModeExclusiveGroup }
427

Don Gagne's avatar
Don Gagne committed
428 429 430
                                QGCRadioButton {
                                    exclusiveGroup: throttleModeExclusiveGroup
                                    text:           qsTr("Center stick is zero throttle")
431
                                    checked:        _activeJoystick ? _activeJoystick.throttleMode == 0 : false
432

Don Gagne's avatar
Don Gagne committed
433 434
                                    onClicked: _activeJoystick.throttleMode = 0
                                }
435

436
                                Row {
Gregory Dymarek's avatar
Gregory Dymarek committed
437
                                    x:          20
438 439
                                    width:      parent.width
                                    spacing:    ScreenTools.defaultFontPixelWidth
440
                                    visible:    _activeJoystick ? _activeJoystick.throttleMode == 0 : false
441 442 443

                                    QGCCheckBox {
                                        id:         accumulator
444
                                        checked:    _activeJoystick ? _activeJoystick.accumulator : false
Gregory Dymarek's avatar
Gregory Dymarek committed
445
                                        text:       qsTr("Spring loaded throttle smoothing")
446 447 448 449 450

                                        onClicked:  _activeJoystick.accumulator = checked
                                    }
                                }

Don Gagne's avatar
Don Gagne committed
451 452 453
                                QGCRadioButton {
                                    exclusiveGroup: throttleModeExclusiveGroup
                                    text:           qsTr("Full down stick is zero throttle")
454
                                    checked:        _activeJoystick ? _activeJoystick.throttleMode == 1 : false
455

Don Gagne's avatar
Don Gagne committed
456 457
                                    onClicked: _activeJoystick.throttleMode = 1
                                }
458 459

                                QGCCheckBox {
460
                                    visible:        _activeVehicle.supportsNegativeThrust
461 462
                                    id:             negativeThrust
                                    text:           qsTr("Allow negative Thrust")
463
                                    enabled:        _activeJoystick.negativeThrust = _activeVehicle.supportsNegativeThrust
464
                                    checked:        _activeJoystick ? _activeJoystick.negativeThrust : false
465
                                    onClicked:      _activeJoystick.negativeThrust = checked
466
                                }
467 468
                            }

Don Gagne's avatar
Don Gagne committed
469 470
                            Column {
                                spacing: ScreenTools.defaultFontPixelHeight / 3
471

472 473 474 475 476 477 478 479 480 481 482
                                QGCLabel {
                                    id:                 expoSliderLabel
                                    text:               qsTr("Exponential:")
                                }

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

nanthony21's avatar
nanthony21 committed
483 484
                                        Component.onCompleted: value=-_activeJoystick.exponential
                                        onValueChanged: _activeJoystick.exponential=-value
485 486 487 488 489
                                     }

                                    QGCLabel {
                                        id:     expoSliderIndicator
                                        text:   expoSlider.value.toFixed(2)
490
                                    }
Don Gagne's avatar
Don Gagne committed
491
                                }
492 493
                            }

Don Gagne's avatar
Don Gagne committed
494 495 496 497
                            QGCCheckBox {
                                id:         advancedSettings
                                checked:    _activeVehicle.joystickMode != 0
                                text:       qsTr("Advanced settings (careful!)")
498

Don Gagne's avatar
Don Gagne committed
499 500 501 502
                                onClicked: {
                                    if (!checked) {
                                        _activeVehicle.joystickMode = 0
                                    }
503 504 505
                                }
                            }

Don Gagne's avatar
Don Gagne committed
506 507 508 509 510 511 512 513 514 515
                            Row {
                                width:      parent.width
                                spacing:    ScreenTools.defaultFontPixelWidth
                                visible:    advancedSettings.checked

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

Don Gagne's avatar
Don Gagne committed
517 518 519 520 521
                                QGCComboBox {
                                    id:             joystickModeCombo
                                    currentIndex:   _activeVehicle.joystickMode
                                    width:          ScreenTools.defaultFontPixelWidth * 20
                                    model:          _activeVehicle.joystickModes
522

Don Gagne's avatar
Don Gagne committed
523 524
                                    onActivated: _activeVehicle.joystickMode = index
                                }
525
                            }
526 527 528 529 530 531 532 533 534 535 536 537 538 539

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

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

                                    onClicked:  controller.deadbandToggle = checked
                                }
                            }
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
                            Row{
                                width: parent.width
                                spacing: ScreenTools.defaultFontPixelWidth
                                visible: advancedSettings.checked
                                QGCLabel{
                                    width:       parent.width * 0.85
                                    font.pointSize:     ScreenTools.smallFontPointSize
                                    wrapMode:           Text.WordWrap
                                    text:   qsTr("Deadband can be set during the first ") +
                                            qsTr("step of calibration by gently wiggling each axis. ") +
                                            qsTr("Deadband can also be adjusted by clicking and ") +
                                            qsTr("dragging vertically on the corresponding axis monitor.")
                                    visible: controller.deadbandToggle
                                }
                            }
555
                        }
Don Gagne's avatar
Don Gagne committed
556
                    } // Column - left column
557

Don Gagne's avatar
Don Gagne committed
558 559 560 561
                    // Right column settings
                    Column {
                        width:      parent.width / 2
                        spacing:    ScreenTools.defaultFontPixelHeight
562

Don Gagne's avatar
Don Gagne committed
563 564
                        Connections {
                            target: _activeJoystick
565

Don Gagne's avatar
Don Gagne committed
566 567 568 569 570 571 572
                            onRawButtonPressedChanged: {
                                if (buttonActionRepeater.itemAt(index)) {
                                    buttonActionRepeater.itemAt(index).pressed = pressed
                                }
                                if (jsButtonActionRepeater.itemAt(index)) {
                                    jsButtonActionRepeater.itemAt(index).pressed = pressed
                                }
573
                            }
574 575
                        }

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

Don Gagne's avatar
Don Gagne committed
578 579 580
                        Column {
                            width:      parent.width
                            spacing:    ScreenTools.defaultFontPixelHeight / 3
581

Don Gagne's avatar
Don Gagne committed
582 583 584
                            QGCLabel {
                                visible: _activeVehicle.manualControlReservedButtonCount != 0
                                text: qsTr("Buttons 0-%1 reserved for firmware use").arg(reservedButtonCount)
585

Don Gagne's avatar
Don Gagne committed
586 587
                                property int reservedButtonCount: _activeVehicle.manualControlReservedButtonCount == -1 ? _activeJoystick.totalButtonCount : _activeVehicle.manualControlReservedButtonCount
                            }
588

Don Gagne's avatar
Don Gagne committed
589 590
                            Repeater {
                                id:     buttonActionRepeater
dheideman's avatar
dheideman committed
591
                                model:  _activeJoystick ? Math.min(_activeJoystick.totalButtonCount, _maxButtons) : 0
592

Don Gagne's avatar
Don Gagne committed
593 594 595
                                Row {
                                    spacing: ScreenTools.defaultFontPixelWidth
                                    visible: (_activeVehicle.manualControlReservedButtonCount == -1 ? false : modelData >= _activeVehicle.manualControlReservedButtonCount) && !_activeVehicle.supportsJSButton
596

Don Gagne's avatar
Don Gagne committed
597
                                    property bool pressed
598

Don Gagne's avatar
Don Gagne committed
599 600
                                    QGCCheckBox {
                                        anchors.verticalCenter:     parent.verticalCenter
601
                                        checked:                    _activeJoystick ? _activeJoystick.buttonActions[modelData] != "" : false
602

Don Gagne's avatar
Don Gagne committed
603 604
                                        onClicked: _activeJoystick.setButtonAction(modelData, checked ? buttonActionCombo.textAt(buttonActionCombo.currentIndex) : "")
                                    }
605

Don Gagne's avatar
Don Gagne committed
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621
                                    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
                                        }
622 623
                                    }

Don Gagne's avatar
Don Gagne committed
624 625 626
                                    QGCComboBox {
                                        id:             buttonActionCombo
                                        width:          ScreenTools.defaultFontPixelWidth * 20
627
                                        model:          _activeJoystick ? _activeJoystick.actions : 0
628

Don Gagne's avatar
Don Gagne committed
629 630 631
                                        onActivated:            _activeJoystick.setButtonAction(modelData, textAt(index))
                                        Component.onCompleted:  currentIndex = find(_activeJoystick.buttonActions[modelData])
                                    }
632
                                }
Don Gagne's avatar
Don Gagne committed
633
                            } // Repeater
634 635 636

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

Don Gagne's avatar
Don Gagne committed
639 640 641 642
                                QGCLabel {
                                    horizontalAlignment:    Text.AlignHCenter
                                    width:                  ScreenTools.defaultFontPixelHeight * 1.5
                                    text:                   qsTr("#")
643 644
                                }

Don Gagne's avatar
Don Gagne committed
645 646 647
                                QGCLabel {
                                    width:                  ScreenTools.defaultFontPixelWidth * 15
                                    text:                   qsTr("Function: ")
648 649
                                }

Don Gagne's avatar
Don Gagne committed
650 651 652
                                QGCLabel {
                                    width:                  ScreenTools.defaultFontPixelWidth * 15
                                    text:                   qsTr("Shift Function: ")
653 654
                                }
                            } // Row
655

Don Gagne's avatar
Don Gagne committed
656 657
                            Repeater {
                                id:     jsButtonActionRepeater
dheideman's avatar
dheideman committed
658
                                model:  _activeJoystick ? Math.min(_activeJoystick.totalButtonCount, _maxButtons) : 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

                                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
705
            Column {
Don Gagne's avatar
Don Gagne committed
706 707 708
                id:             rightColumn
                anchors.top:    parent.top
                anchors.right:  parent.right
709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724
                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
725
                        enabled:        !controller.calibrating
726 727 728 729 730 731 732 733

                        onClicked: controller.transmitterMode = 1
                    }

                    QGCRadioButton {
                        exclusiveGroup: modeGroup
                        text:           "2"
                        checked:        controller.transmitterMode == 2
734
                        enabled:        !controller.calibrating
735 736 737 738 739 740 741 742

                        onClicked: controller.transmitterMode = 2
                    }

                    QGCRadioButton {
                        exclusiveGroup: modeGroup
                        text:           "3"
                        checked:        controller.transmitterMode == 3
743
                        enabled:        !controller.calibrating
744 745 746 747 748 749 750 751

                        onClicked: controller.transmitterMode = 3
                    }

                    QGCRadioButton {
                        exclusiveGroup: modeGroup
                        text:           "4"
                        checked:        controller.transmitterMode == 4
752
                        enabled:        !controller.calibrating
753 754 755 756

                        onClicked: controller.transmitterMode = 4
                    }
                }
Don Gagne's avatar
Don Gagne committed
757 758

                Image {
759
                    width:      parent.width
Don Gagne's avatar
Don Gagne committed
760 761 762 763
                    fillMode:   Image.PreserveAspectFit
                    smooth:     true
                    source:     controller.imageHelp
                }
764

Don Gagne's avatar
Don Gagne committed
765 766 767 768
                // Axis monitor
                Column {
                    width:      parent.width
                    spacing:    5
769

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

Don Gagne's avatar
Don Gagne committed
772 773 774 775 776 777 778
                    Connections {
                        target: controller

                        onAxisValueChanged: {
                            if (axisMonitorRepeater.itemAt(axis)) {
                                axisMonitorRepeater.itemAt(axis).loader.item.axisValue = value
                            }
779
                        }
780 781 782 783 784 785

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

Don Gagne's avatar
Don Gagne committed
788 789
                    Repeater {
                        id:     axisMonitorRepeater
790
                        model:  _activeJoystick ? _activeJoystick.axisCount : 0
Don Gagne's avatar
Don Gagne committed
791
                        width:  parent.width
792

Don Gagne's avatar
Don Gagne committed
793 794
                        Row {
                            spacing:    5
795

Don Gagne's avatar
Don Gagne committed
796 797
                            // Need this to get to loader from Connections above
                            property Item loader: theLoader
798

Don Gagne's avatar
Don Gagne committed
799 800 801 802
                            QGCLabel {
                                id:     axisLabel
                                text:   modelData
                            }
803

Don Gagne's avatar
Don Gagne committed
804 805 806 807 808 809
                            Loader {
                                id:                     theLoader
                                anchors.verticalCenter: axisLabel.verticalCenter
                                height:                 ScreenTools.defaultFontPixelHeight
                                width:                  200
                                sourceComponent:        axisMonitorDisplayComponent
810
                                Component.onCompleted:  item.narrowIndicator = true
Don Gagne's avatar
Don Gagne committed
811 812 813 814

                                property real defaultTextWidth:     ScreenTools.defaultFontPixelWidth
                                property bool mapped:               true
                                readonly property bool reversed:    false
815 816 817 818 819


                                MouseArea {
                                    id:             deadbandMouseArea
                                    anchors.fill:   parent.item
820
                                    enabled:        controller.deadbandToggle
821 822 823 824 825

                                    property real startY

                                    onPressed: {
                                        startY = mouseY
826
                                        parent.item.deadbandColor = "#3C6315"
827 828 829 830 831 832 833 834
                                    }
                                    onPositionChanged: {
                                        var newValue = parent.item.deadbandValue + (startY - mouseY)*15
                                        if ((newValue > 0) && (newValue <32768)){parent.item.deadbandValue=newValue;}
                                        startY = mouseY
                                    }
                                    onReleased: {
                                        controller.setDeadbandValue(modelData,parent.item.deadbandValue)
835
                                        parent.item.deadbandColor = "#8c161a"
836 837
                                    }
                                }
Don Gagne's avatar
Don Gagne committed
838
                            }
839

840 841
                        }
                    }
Don Gagne's avatar
Don Gagne committed
842
                } // Column - Axis Monitor
843

Don Gagne's avatar
Don Gagne committed
844 845 846 847
                // Button monitor
                Column {
                    width:      parent.width
                    spacing:    ScreenTools.defaultFontPixelHeight
848

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

Don Gagne's avatar
Don Gagne committed
851 852
                    Connections {
                        target: _activeJoystick
853

Don Gagne's avatar
Don Gagne committed
854 855 856 857
                        onRawButtonPressedChanged: {
                            if (buttonMonitorRepeater.itemAt(index)) {
                                buttonMonitorRepeater.itemAt(index).pressed = pressed
                            }
858 859 860
                        }
                    }

Don Gagne's avatar
Don Gagne committed
861 862 863
                    Flow {
                        width:      parent.width
                        spacing:    -1
864

Don Gagne's avatar
Don Gagne committed
865 866
                        Repeater {
                            id:     buttonMonitorRepeater
867
                            model:  _activeJoystick ? _activeJoystick.totalButtonCount : 0
868

Don Gagne's avatar
Don Gagne committed
869 870 871 872 873 874
                            Rectangle {
                                width:          ScreenTools.defaultFontPixelHeight * 1.2
                                height:         width
                                border.width:   1
                                border.color:   qgcPal.text
                                color:          pressed ? qgcPal.buttonHighlight : qgcPal.button
875

Don Gagne's avatar
Don Gagne committed
876
                                property bool pressed
877

Don Gagne's avatar
Don Gagne committed
878 879 880 881 882 883 884
                                QGCLabel {
                                    anchors.fill:           parent
                                    color:                  pressed ? qgcPal.buttonHighlightText : qgcPal.buttonText
                                    horizontalAlignment:    Text.AlignHCenter
                                    verticalAlignment:      Text.AlignVCenter
                                    text:                   modelData
                                }
885
                            }
Don Gagne's avatar
Don Gagne committed
886 887 888 889 890 891 892
                        } // Repeater
                    } // Row
                } // Column - Axis Monitor
            } // Column - Right Column
        } // Item
    } // Component - pageComponent
} // SetupPage
Gregory Dymarek's avatar
Gregory Dymarek committed
893 894