4import QGroundControl.Controls
7 // The following properties must be passed in from the Loader
8 // property bool autoCenterThrottle - true: throttle will snap back to center when released
9 // property bool leftHandedMode - true: virtual joystick layout will be reversed
13 property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
14 property bool _initialConnectComplete: _activeVehicle ? _activeVehicle.initialConnectComplete : false
15 property real leftYAxisValue: autoCenterThrottle ? height / 2 : height
16 property var calibration: false
17 property real uiTotalWidth: 0
18 property real uiRealX: 0
21 interval: 40 // 25Hz, same as real joystick rate
22 running: QGroundControl.settingsManager.appSettings.virtualJoystick.value
25 if (_activeVehicle && _initialConnectComplete) {
26 leftHandedMode ? _activeVehicle.virtualTabletJoystickValue(leftStick.xAxis, leftStick.yAxis, rightStick.xAxis, rightStick.yAxis) : _activeVehicle.virtualTabletJoystickValue(rightStick.xAxis, rightStick.yAxis, leftStick.xAxis, leftStick.yAxis)
28 leftYAxisValue = leftStick.yAxis // We keep Y axis value from the throttle stick for using it while there is a resize
32 onHeightChanged: { keepYAxisWhileChanged() }
33 onWidthChanged: { keepXAxisWhileChanged() }
34 onCalibrationChanged: { calibration ? calibrateJoysticks() : undefined }
36 function calibrateJoysticks() {
37 if( virtualJoysticks.visible ) {
38 keepXAxisWhileChanged()
39 leftYAxisValue = leftStick.yAxisReCentered() // Keep track of the correct leftYAxisValue while the width is adjusted at first start up
43 function keepYAxisWhileChanged () {
44 if( virtualJoysticks.visible ) {
45 leftStick.resize( leftYAxisValue )
50 function keepXAxisWhileChanged () {
51 if( virtualJoysticks.visible ) {
59 anchors.leftMargin: xPositionDelta
60 anchors.bottomMargin: -yPositionDelta
61 anchors.left: parent.left
62 anchors.bottom: parent.bottom
65 yAxisPositiveRangeOnly: _activeVehicle && !_activeVehicle.rover && !leftHandedMode
66 yAxisReCenter: autoCenterThrottle
71 anchors.rightMargin: -xPositionDelta
72 anchors.bottomMargin: -yPositionDelta
73 anchors.right: parent.right
74 anchors.bottom: parent.bottom
77 yAxisPositiveRangeOnly: _activeVehicle && !_activeVehicle.rover && leftHandedMode