JoystickConfig.qml 40.6 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
    Component {
        id: pageComponent

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

49
            readonly property real labelToMonitorMargin: ScreenTools.defaultFontPixelWidth * 3
Don Gagne's avatar
Don Gagne committed
50 51 52

            property var _activeJoystick:   joystickManager.activeJoystick

53
            function setupPageCompleted() {
54 55 56
                controller.start()
            }

Don Gagne's avatar
Don Gagne committed
57 58 59 60 61 62 63
            JoystickConfigController {
                id:             controller
                statusText:     statusText
                cancelButton:   cancelButton
                nextButton:     nextButton
                skipButton:     skipButton
            }
64

Don Gagne's avatar
Don Gagne committed
65 66 67
            // Live axis monitor control component
            Component {
                id: axisMonitorDisplayComponent
68

Don Gagne's avatar
Don Gagne committed
69 70
                Item {
                    property int axisValue: 0
Gregory Dymarek's avatar
Gregory Dymarek committed
71
                    property int deadbandValue: 0
72
                    property bool narrowIndicator: false
73
                    property color deadbandColor: "#8c161a"
74

Don Gagne's avatar
Don Gagne committed
75
                    property color          __barColor:             qgcPal.windowShade
76

Don Gagne's avatar
Don Gagne committed
77 78 79 80 81 82 83 84
                    // Bar
                    Rectangle {
                        id:                     bar
                        anchors.verticalCenter: parent.verticalCenter
                        width:                  parent.width
                        height:                 parent.height / 2
                        color:                  __barColor
                    }
85

Gregory Dymarek's avatar
Gregory Dymarek committed
86 87 88 89 90 91 92
                    // Deadband
                    Rectangle {
                        id:                     deadbandBar
                        anchors.verticalCenter: parent.verticalCenter
                        x:                      _deadbandPosition
                        width:                  _deadbandWidth
                        height:                 parent.height / 2
93
                        color:                  deadbandColor
94
                        visible:                controller.deadbandToggle
Gregory Dymarek's avatar
Gregory Dymarek committed
95 96 97 98 99 100

                        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
101 102 103
                    // Center point
                    Rectangle {
                        anchors.horizontalCenter:   parent.horizontalCenter
104
                        width:                      ScreenTools.defaultFontPixelWidth / 2
Don Gagne's avatar
Don Gagne committed
105 106 107
                        height:                     parent.height
                        color:                      qgcPal.window
                    }
108

Don Gagne's avatar
Don Gagne committed
109 110 111
                    // Indicator
                    Rectangle {
                        anchors.verticalCenter: parent.verticalCenter
112 113
                        width:                  parent.narrowIndicator ?  height/6 : height
                        height:                 parent.height * 0.75
Don Gagne's avatar
Don Gagne committed
114 115 116 117 118 119 120 121
                        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
                    }
122

Don Gagne's avatar
Don Gagne committed
123 124 125 126 127 128 129
                    QGCLabel {
                        anchors.fill:           parent
                        horizontalAlignment:    Text.AlignHCenter
                        verticalAlignment:      Text.AlignVCenter
                        text:                   qsTr("Not Mapped")
                        visible:                !mapped
                    }
130

Don Gagne's avatar
Don Gagne committed
131 132 133 134 135 136 137 138
                    ColorAnimation {
                        id:         barAnimation
                        target:     bar
                        property:   "color"
                        from:       "yellow"
                        to:         __barColor
                        duration:   1500
                    }
139

Gregory Dymarek's avatar
Gregory Dymarek committed
140

Don Gagne's avatar
Don Gagne committed
141
                    // Axis value debugger
Gregory Dymarek's avatar
Gregory Dymarek committed
142
                    /*
Don Gagne's avatar
Don Gagne committed
143 144 145 146 147
                    QGCLabel {
                        anchors.fill: parent
                        text: axisValue
                    }
                    */
Gregory Dymarek's avatar
Gregory Dymarek committed
148

149
                }
Don Gagne's avatar
Don Gagne committed
150
            } // Component - axisMonitorDisplayComponent
151

Don Gagne's avatar
Don Gagne committed
152 153 154 155 156 157 158 159 160
            // 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
161

Don Gagne's avatar
Don Gagne committed
162 163 164 165
                // Attitude Controls
                Column {
                    width:      parent.width
                    spacing:    5
166

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

Don Gagne's avatar
Don Gagne committed
169 170 171
                    Item {
                        width:  parent.width
                        height: defaultTextHeight * 2
172

Don Gagne's avatar
Don Gagne committed
173 174
                        QGCLabel {
                            id:     rollLabel
175
                            width:  ScreenTools.defaultFontPixelWidth * 10
176
                            text:   activeVehicle.sub ? qsTr("Lateral") : qsTr("Roll")
Don Gagne's avatar
Don Gagne committed
177
                        }
178

Don Gagne's avatar
Don Gagne committed
179 180 181 182 183 184 185 186
                        Loader {
                            id:                 rollLoader
                            anchors.left:       rollLabel.right
                            anchors.right:      parent.right
                            height:             ScreenTools.defaultFontPixelHeight
                            width:              100
                            sourceComponent:    axisMonitorDisplayComponent

187 188
                            property bool mapped:   controller.rollAxisMapped
                            property bool reversed: controller.rollAxisReversed
Don Gagne's avatar
Don Gagne committed
189
                        }
190

191 192 193 194 195
                        Connections {
                            target: _activeJoystick

                            onManualControl: rollLoader.item.axisValue = roll*32768.0
                        }
196 197
                    }

Don Gagne's avatar
Don Gagne committed
198 199 200
                    Item {
                        width:  parent.width
                        height: defaultTextHeight * 2
201

Don Gagne's avatar
Don Gagne committed
202 203
                        QGCLabel {
                            id:     pitchLabel
204
                            width:  ScreenTools.defaultFontPixelWidth * 10
205
                            text:   activeVehicle.sub ? qsTr("Forward") : qsTr("Pitch")
Don Gagne's avatar
Don Gagne committed
206
                        }
207

Don Gagne's avatar
Don Gagne committed
208 209 210 211 212 213 214 215 216 217 218
                        Loader {
                            id:                 pitchLoader
                            anchors.left:       pitchLabel.right
                            anchors.right:      parent.right
                            height:             ScreenTools.defaultFontPixelHeight
                            width:              100
                            sourceComponent:    axisMonitorDisplayComponent

                            property bool mapped:           controller.pitchAxisMapped
                            property bool reversed:         controller.pitchAxisReversed
                        }
219

220 221 222 223 224
                        Connections {
                            target: _activeJoystick

                            onManualControl: pitchLoader.item.axisValue = pitch*32768.0
                        }
225 226
                    }

Don Gagne's avatar
Don Gagne committed
227 228 229
                    Item {
                        width:  parent.width
                        height: defaultTextHeight * 2
230

Don Gagne's avatar
Don Gagne committed
231 232
                        QGCLabel {
                            id:     yawLabel
233
                            width:  ScreenTools.defaultFontPixelWidth * 10
Don Gagne's avatar
Don Gagne committed
234 235
                            text:   qsTr("Yaw")
                        }
236

Don Gagne's avatar
Don Gagne committed
237 238 239 240 241 242 243 244 245 246 247
                        Loader {
                            id:                 yawLoader
                            anchors.left:       yawLabel.right
                            anchors.right:      parent.right
                            height:             ScreenTools.defaultFontPixelHeight
                            width:              100
                            sourceComponent:    axisMonitorDisplayComponent

                            property bool mapped:           controller.yawAxisMapped
                            property bool reversed:         controller.yawAxisReversed
                        }
248

249 250 251 252 253
                        Connections {
                            target: _activeJoystick

                            onManualControl: yawLoader.item.axisValue = yaw*32768.0
                        }
254 255
                    }

Don Gagne's avatar
Don Gagne committed
256 257 258
                    Item {
                        width:  parent.width
                        height: defaultTextHeight * 2
259

Don Gagne's avatar
Don Gagne committed
260 261
                        QGCLabel {
                            id:     throttleLabel
262
                            width:  ScreenTools.defaultFontPixelWidth * 10
Don Gagne's avatar
Don Gagne committed
263 264
                            text:   qsTr("Throttle")
                        }
265

Don Gagne's avatar
Don Gagne committed
266 267 268 269 270 271 272 273 274 275 276
                        Loader {
                            id:                 throttleLoader
                            anchors.left:       throttleLabel.right
                            anchors.right:      parent.right
                            height:             ScreenTools.defaultFontPixelHeight
                            width:              100
                            sourceComponent:    axisMonitorDisplayComponent

                            property bool mapped:           controller.throttleAxisMapped
                            property bool reversed:         controller.throttleAxisReversed
                        }
277

278 279 280
                        Connections {
                            target: _activeJoystick

281
                            onManualControl: throttleLoader.item.axisValue = _activeJoystick.negativeThrust ? -throttle*32768.0 : (-2*throttle+1)*32768.0
282
                        }
283
                    }
Don Gagne's avatar
Don Gagne committed
284
                } // Column - Attitude Control labels
285

Don Gagne's avatar
Don Gagne committed
286 287 288
                // Command Buttons
                Row {
                    spacing: 10
289
                    visible: _activeJoystick.requiresCalibration
Don Gagne's avatar
Don Gagne committed
290 291 292 293

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

Don Gagne's avatar
Don Gagne committed
295
                        onClicked: controller.skipButtonClicked()
296 297
                    }

Don Gagne's avatar
Don Gagne committed
298 299 300
                    QGCButton {
                        id:     cancelButton
                        text:   qsTr("Cancel")
301

Don Gagne's avatar
Don Gagne committed
302 303
                        onClicked: controller.cancelButtonClicked()
                    }
304

Don Gagne's avatar
Don Gagne committed
305 306 307 308
                    QGCButton {
                        id:         nextButton
                        primary:    true
                        text:       qsTr("Calibrate")
309

Don Gagne's avatar
Don Gagne committed
310 311 312
                        onClicked: controller.nextButtonClicked()
                    }
                } // Row - Buttons
313

Don Gagne's avatar
Don Gagne committed
314 315 316 317 318
                // Status Text
                QGCLabel {
                    id:         statusText
                    width:      parent.width
                    wrapMode:   Text.WordWrap
319 320
                }

Don Gagne's avatar
Don Gagne committed
321 322 323 324 325
                Rectangle {
                    width:          parent.width
                    height:         1
                    border.color:   qgcPal.text
                    border.width:   1
326 327
                }

Don Gagne's avatar
Don Gagne committed
328 329 330 331
                // Settings
                Row {
                    width:      parent.width
                    spacing:    ScreenTools.defaultFontPixelWidth
332

Don Gagne's avatar
Don Gagne committed
333
                    // Left column settings
334
                    Column {
Don Gagne's avatar
Don Gagne committed
335
                        width:      parent.width / 2
336 337
                        spacing:    ScreenTools.defaultFontPixelHeight

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

Don Gagne's avatar
Don Gagne committed
340 341 342
                        Column {
                            width:      parent.width
                            spacing:    ScreenTools.defaultFontPixelHeight
343 344


Don Gagne's avatar
Don Gagne committed
345
                            QGCCheckBox {
Jacob Walser's avatar
Jacob Walser committed
346
                                id:         enabledCheckBox
347 348
                                enabled:    _activeJoystick ? _activeJoystick.calibrated : false
                                text:       _activeJoystick ? _activeJoystick.calibrated ? qsTr("Enable joystick input") : qsTr("Enable not allowed (Calibrate First)") : ""
349 350
                                onClicked:  activeVehicle.joystickEnabled = checked
                                Component.onCompleted: checked = activeVehicle.joystickEnabled
351 352

                                Connections {
353
                                    target: activeVehicle
354 355

                                    onJoystickEnabledChanged: {
356
                                        enabledCheckBox.checked = activeVehicle.joystickEnabled
357 358
                                    }
                                }
359

Jacob Walser's avatar
Jacob Walser committed
360 361 362 363
                                Connections {
                                    target: joystickManager

                                    onActiveJoystickChanged: {
364
                                        if(_activeJoystick) {
365
                                            enabledCheckBox.checked = Qt.binding(function() { return _activeJoystick.calibrated && activeVehicle.joystickEnabled })
366
                                        }
Jacob Walser's avatar
Jacob Walser committed
367 368
                                    }
                                }
369 370
                            }

Don Gagne's avatar
Don Gagne committed
371 372 373
                            Row {
                                width:      parent.width
                                spacing:    ScreenTools.defaultFontPixelWidth
374

Don Gagne's avatar
Don Gagne committed
375 376 377 378 379
                                QGCLabel {
                                    id:                 activeJoystickLabel
                                    anchors.baseline:   joystickCombo.baseline
                                    text:               qsTr("Active joystick:")
                                }
380

Don Gagne's avatar
Don Gagne committed
381 382 383 384 385 386 387 388 389 390 391 392 393 394
                                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
                                        }
395
                                    }
Jacob Walser's avatar
Jacob Walser committed
396 397 398 399 400

                                    Connections {
                                        target: joystickManager
                                        onAvailableJoysticksChanged: {
                                            var index = joystickCombo.find(joystickManager.activeJoystickName)
401
                                            if (index >= 0) {
Jacob Walser's avatar
Jacob Walser committed
402 403 404 405
                                                joystickCombo.currentIndex = index
                                            }
                                        }
                                    }
406
                                }
407 408
                            }

Don Gagne's avatar
Don Gagne committed
409 410
                            Column {
                                spacing: ScreenTools.defaultFontPixelHeight / 3
411
                                visible: activeVehicle.supportsThrottleModeCenterZero
412

Don Gagne's avatar
Don Gagne committed
413
                                ExclusiveGroup { id: throttleModeExclusiveGroup }
414

Don Gagne's avatar
Don Gagne committed
415 416 417
                                QGCRadioButton {
                                    exclusiveGroup: throttleModeExclusiveGroup
                                    text:           qsTr("Center stick is zero throttle")
418
                                    checked:        _activeJoystick ? _activeJoystick.throttleMode == 0 : false
419

Don Gagne's avatar
Don Gagne committed
420 421
                                    onClicked: _activeJoystick.throttleMode = 0
                                }
422

423
                                Row {
Gregory Dymarek's avatar
Gregory Dymarek committed
424
                                    x:          20
425 426
                                    width:      parent.width
                                    spacing:    ScreenTools.defaultFontPixelWidth
427
                                    visible:    _activeJoystick ? _activeJoystick.throttleMode == 0 : false
428 429 430

                                    QGCCheckBox {
                                        id:         accumulator
431
                                        checked:    _activeJoystick ? _activeJoystick.accumulator : false
Gregory Dymarek's avatar
Gregory Dymarek committed
432
                                        text:       qsTr("Spring loaded throttle smoothing")
433 434 435 436 437

                                        onClicked:  _activeJoystick.accumulator = checked
                                    }
                                }

Don Gagne's avatar
Don Gagne committed
438 439 440
                                QGCRadioButton {
                                    exclusiveGroup: throttleModeExclusiveGroup
                                    text:           qsTr("Full down stick is zero throttle")
441
                                    checked:        _activeJoystick ? _activeJoystick.throttleMode == 1 : false
442

Don Gagne's avatar
Don Gagne committed
443 444
                                    onClicked: _activeJoystick.throttleMode = 1
                                }
445 446

                                QGCCheckBox {
447
                                    visible:        activeVehicle.supportsNegativeThrust
448 449
                                    id:             negativeThrust
                                    text:           qsTr("Allow negative Thrust")
450
                                    enabled:        _activeJoystick.negativeThrust = activeVehicle.supportsNegativeThrust
451
                                    checked:        _activeJoystick ? _activeJoystick.negativeThrust : false
452
                                    onClicked:      _activeJoystick.negativeThrust = checked
453
                                }
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
                            QGCCheckBox {
                                id:         advancedSettings
483
                                checked:    activeVehicle.joystickMode != 0
Don Gagne's avatar
Don Gagne committed
484
                                text:       qsTr("Advanced settings (careful!)")
485

Don Gagne's avatar
Don Gagne committed
486 487
                                onClicked: {
                                    if (!checked) {
488
                                        activeVehicle.joystickMode = 0
Don Gagne's avatar
Don Gagne committed
489
                                    }
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
                                QGCComboBox {
                                    id:             joystickModeCombo
506
                                    currentIndex:   activeVehicle.joystickMode
Don Gagne's avatar
Don Gagne committed
507
                                    width:          ScreenTools.defaultFontPixelWidth * 20
508
                                    model:          activeVehicle.joystickModes
509

510
                                    onActivated: activeVehicle.joystickMode = index
Don Gagne's avatar
Don Gagne committed
511
                                }
512
                            }
513

514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
                            Row {
                                width:      parent.width
                                spacing:    ScreenTools.defaultFontPixelWidth
                                visible:    advancedSettings.checked
                                QGCLabel {
                                    text:       qsTr("Message frequency (Hz):")
                                    anchors.verticalCenter: parent.verticalCenter
                                }
                                QGCTextField {
                                    text:       _activeJoystick.frequency
                                    validator:  DoubleValidator { bottom: 0.25; top: 100.0; }
                                    inputMethodHints: Qt.ImhFormattedNumbersOnly
                                    onEditingFinished: {
                                        _activeJoystick.frequency = parseFloat(text)
                                    }
                                }
                            }

532 533 534 535 536 537
                            Row {
                                width:      parent.width
                                spacing:    ScreenTools.defaultFontPixelWidth
                                visible:    advancedSettings.checked
                                QGCCheckBox {
                                    id:         joystickCircleCorrection
538
                                    checked:    activeVehicle.joystickMode != 0
539 540 541 542 543 544 545 546 547
                                    text:       qsTr("Enable circle correction")

                                    Component.onCompleted: checked = _activeJoystick.circleCorrection
                                    onClicked: {
                                        _activeJoystick.circleCorrection = checked
                                    }
                                }
                            }

548 549 550 551 552 553 554 555 556 557 558 559 560
                            Row {
                                width:      parent.width
                                spacing:    ScreenTools.defaultFontPixelWidth
                                visible:    advancedSettings.checked

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

                                    onClicked:  controller.deadbandToggle = checked
                                }
                            }
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575
                            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
                                }
                            }
576
                        }
Don Gagne's avatar
Don Gagne committed
577
                    } // Column - left column
578

Don Gagne's avatar
Don Gagne committed
579 580 581 582
                    // Right column settings
                    Column {
                        width:      parent.width / 2
                        spacing:    ScreenTools.defaultFontPixelHeight
583

Don Gagne's avatar
Don Gagne committed
584 585
                        Connections {
                            target: _activeJoystick
586

Don Gagne's avatar
Don Gagne committed
587 588 589 590 591 592 593
                            onRawButtonPressedChanged: {
                                if (buttonActionRepeater.itemAt(index)) {
                                    buttonActionRepeater.itemAt(index).pressed = pressed
                                }
                                if (jsButtonActionRepeater.itemAt(index)) {
                                    jsButtonActionRepeater.itemAt(index).pressed = pressed
                                }
594
                            }
595 596
                        }

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

Don Gagne's avatar
Don Gagne committed
599 600 601
                        Column {
                            width:      parent.width
                            spacing:    ScreenTools.defaultFontPixelHeight / 3
602

Don Gagne's avatar
Don Gagne committed
603 604
                            Repeater {
                                id:     buttonActionRepeater
dheideman's avatar
dheideman committed
605
                                model:  _activeJoystick ? Math.min(_activeJoystick.totalButtonCount, _maxButtons) : 0
606

Don Gagne's avatar
Don Gagne committed
607 608
                                Row {
                                    spacing: ScreenTools.defaultFontPixelWidth
609
                                    visible: !activeVehicle.supportsJSButton
610

Don Gagne's avatar
Don Gagne committed
611
                                    property bool pressed
612

Don Gagne's avatar
Don Gagne committed
613 614
                                    QGCCheckBox {
                                        anchors.verticalCenter:     parent.verticalCenter
615
                                        checked:                    _activeJoystick ? _activeJoystick.buttonActions[modelData] != "" : false
616

Don Gagne's avatar
Don Gagne committed
617 618
                                        onClicked: _activeJoystick.setButtonAction(modelData, checked ? buttonActionCombo.textAt(buttonActionCombo.currentIndex) : "")
                                    }
619

Don Gagne's avatar
Don Gagne committed
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
                                    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
                                        }
636 637
                                    }

Don Gagne's avatar
Don Gagne committed
638 639 640
                                    QGCComboBox {
                                        id:             buttonActionCombo
                                        width:          ScreenTools.defaultFontPixelWidth * 20
641
                                        model:          _activeJoystick ? _activeJoystick.actions : 0
642

Don Gagne's avatar
Don Gagne committed
643 644 645
                                        onActivated:            _activeJoystick.setButtonAction(modelData, textAt(index))
                                        Component.onCompleted:  currentIndex = find(_activeJoystick.buttonActions[modelData])
                                    }
646
                                }
Don Gagne's avatar
Don Gagne committed
647
                            } // Repeater
648 649 650

                            Row {
                                spacing: ScreenTools.defaultFontPixelWidth
651
                                visible: activeVehicle.supportsJSButton
652

Don Gagne's avatar
Don Gagne committed
653 654 655 656
                                QGCLabel {
                                    horizontalAlignment:    Text.AlignHCenter
                                    width:                  ScreenTools.defaultFontPixelHeight * 1.5
                                    text:                   qsTr("#")
657 658
                                }

Don Gagne's avatar
Don Gagne committed
659 660 661
                                QGCLabel {
                                    width:                  ScreenTools.defaultFontPixelWidth * 15
                                    text:                   qsTr("Function: ")
662 663
                                }

Don Gagne's avatar
Don Gagne committed
664 665 666
                                QGCLabel {
                                    width:                  ScreenTools.defaultFontPixelWidth * 15
                                    text:                   qsTr("Shift Function: ")
667 668
                                }
                            } // Row
669

Don Gagne's avatar
Don Gagne committed
670 671
                            Repeater {
                                id:     jsButtonActionRepeater
dheideman's avatar
dheideman committed
672
                                model:  _activeJoystick ? Math.min(_activeJoystick.totalButtonCount, _maxButtons) : 0
Don Gagne's avatar
Don Gagne committed
673 674 675

                                Row {
                                    spacing: ScreenTools.defaultFontPixelWidth
676
                                    visible: activeVehicle.supportsJSButton
Don Gagne's avatar
Don Gagne committed
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718

                                    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
719
            Column {
Don Gagne's avatar
Don Gagne committed
720 721 722
                id:             rightColumn
                anchors.top:    parent.top
                anchors.right:  parent.right
723
                width:          Math.min(joystickPage.ScreenTools.defaultFontPixelWidth * 35, availableWidth * 0.4)
724 725 726 727 728 729 730 731 732 733 734 735 736 737 738
                spacing:        ScreenTools.defaultFontPixelHeight / 2

                Row {
                    spacing: ScreenTools.defaultFontPixelWidth

                    ExclusiveGroup { id: modeGroup }

                    QGCLabel {
                        text: "TX Mode:"
                    }

                    QGCRadioButton {
                        exclusiveGroup: modeGroup
                        text:           "1"
                        checked:        controller.transmitterMode == 1
739
                        enabled:        !controller.calibrating
740 741 742 743 744 745 746 747

                        onClicked: controller.transmitterMode = 1
                    }

                    QGCRadioButton {
                        exclusiveGroup: modeGroup
                        text:           "2"
                        checked:        controller.transmitterMode == 2
748
                        enabled:        !controller.calibrating
749 750 751 752 753 754 755 756

                        onClicked: controller.transmitterMode = 2
                    }

                    QGCRadioButton {
                        exclusiveGroup: modeGroup
                        text:           "3"
                        checked:        controller.transmitterMode == 3
757
                        enabled:        !controller.calibrating
758 759 760 761 762 763 764 765

                        onClicked: controller.transmitterMode = 3
                    }

                    QGCRadioButton {
                        exclusiveGroup: modeGroup
                        text:           "4"
                        checked:        controller.transmitterMode == 4
766
                        enabled:        !controller.calibrating
767 768 769 770

                        onClicked: controller.transmitterMode = 4
                    }
                }
Don Gagne's avatar
Don Gagne committed
771 772

                Image {
773
                    width:      parent.width
Don Gagne's avatar
Don Gagne committed
774 775 776 777
                    fillMode:   Image.PreserveAspectFit
                    smooth:     true
                    source:     controller.imageHelp
                }
778

Don Gagne's avatar
Don Gagne committed
779 780 781 782
                // Axis monitor
                Column {
                    width:      parent.width
                    spacing:    5
783

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

Don Gagne's avatar
Don Gagne committed
786 787 788 789 790 791 792
                    Connections {
                        target: controller

                        onAxisValueChanged: {
                            if (axisMonitorRepeater.itemAt(axis)) {
                                axisMonitorRepeater.itemAt(axis).loader.item.axisValue = value
                            }
793
                        }
794 795 796 797 798 799

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

Don Gagne's avatar
Don Gagne committed
802 803
                    Repeater {
                        id:     axisMonitorRepeater
804
                        model:  _activeJoystick ? _activeJoystick.axisCount : 0
Don Gagne's avatar
Don Gagne committed
805
                        width:  parent.width
806

Don Gagne's avatar
Don Gagne committed
807 808
                        Row {
                            spacing:    5
809

Don Gagne's avatar
Don Gagne committed
810 811
                            // Need this to get to loader from Connections above
                            property Item loader: theLoader
812

Don Gagne's avatar
Don Gagne committed
813 814 815 816
                            QGCLabel {
                                id:     axisLabel
                                text:   modelData
                            }
817

Don Gagne's avatar
Don Gagne committed
818 819 820 821 822 823
                            Loader {
                                id:                     theLoader
                                anchors.verticalCenter: axisLabel.verticalCenter
                                height:                 ScreenTools.defaultFontPixelHeight
                                width:                  200
                                sourceComponent:        axisMonitorDisplayComponent
824
                                Component.onCompleted:  item.narrowIndicator = true
Don Gagne's avatar
Don Gagne committed
825 826 827

                                property bool mapped:               true
                                readonly property bool reversed:    false
828 829 830 831 832


                                MouseArea {
                                    id:             deadbandMouseArea
                                    anchors.fill:   parent.item
833
                                    enabled:        controller.deadbandToggle
834 835 836 837 838

                                    property real startY

                                    onPressed: {
                                        startY = mouseY
839
                                        parent.item.deadbandColor = "#3C6315"
840 841 842 843 844 845 846 847
                                    }
                                    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)
848
                                        parent.item.deadbandColor = "#8c161a"
849 850
                                    }
                                }
Don Gagne's avatar
Don Gagne committed
851
                            }
852

853 854
                        }
                    }
Don Gagne's avatar
Don Gagne committed
855
                } // Column - Axis Monitor
856

Don Gagne's avatar
Don Gagne committed
857 858 859 860
                // Button monitor
                Column {
                    width:      parent.width
                    spacing:    ScreenTools.defaultFontPixelHeight
861

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

Don Gagne's avatar
Don Gagne committed
864 865
                    Connections {
                        target: _activeJoystick
866

Don Gagne's avatar
Don Gagne committed
867 868 869 870
                        onRawButtonPressedChanged: {
                            if (buttonMonitorRepeater.itemAt(index)) {
                                buttonMonitorRepeater.itemAt(index).pressed = pressed
                            }
871 872 873
                        }
                    }

Don Gagne's avatar
Don Gagne committed
874 875 876
                    Flow {
                        width:      parent.width
                        spacing:    -1
877

Don Gagne's avatar
Don Gagne committed
878 879
                        Repeater {
                            id:     buttonMonitorRepeater
880
                            model:  _activeJoystick ? _activeJoystick.totalButtonCount : 0
881

Don Gagne's avatar
Don Gagne committed
882 883 884 885 886 887
                            Rectangle {
                                width:          ScreenTools.defaultFontPixelHeight * 1.2
                                height:         width
                                border.width:   1
                                border.color:   qgcPal.text
                                color:          pressed ? qgcPal.buttonHighlight : qgcPal.button
888

Don Gagne's avatar
Don Gagne committed
889
                                property bool pressed
890

Don Gagne's avatar
Don Gagne committed
891 892 893 894 895 896 897
                                QGCLabel {
                                    anchors.fill:           parent
                                    color:                  pressed ? qgcPal.buttonHighlightText : qgcPal.buttonText
                                    horizontalAlignment:    Text.AlignHCenter
                                    verticalAlignment:      Text.AlignVCenter
                                    text:                   modelData
                                }
898
                            }
Don Gagne's avatar
Don Gagne committed
899 900 901 902 903 904 905
                        } // Repeater
                    } // Row
                } // Column - Axis Monitor
            } // Column - Right Column
        } // Item
    } // Component - pageComponent
} // SetupPage
Gregory Dymarek's avatar
Gregory Dymarek committed
906 907