|
|
@ -8,25 +8,28 @@ import QGroundControl.ScreenTools 1.0 |
|
|
|
Item { |
|
|
|
Item { |
|
|
|
id: _joyRoot |
|
|
|
id: _joyRoot |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
property alias lightColors: mapPal.lightColors ///< true: use light colors from QGCMapPalette for drawing |
|
|
|
property real xAxis: 0 ///< Value range [-1,1], negative values left stick, positive values right stick |
|
|
|
property real xAxis: 0 ///< Value range [-1,1], negative values left stick, positive values right stick |
|
|
|
property real yAxis: 0 ///< Value range [-1,1], negative values up stick, positive values down stick |
|
|
|
property real yAxis: 0 ///< Value range [-1,1], negative values down stick, positive values up stick |
|
|
|
property bool yAxisThrottle: false ///< true: yAxis used for throttle, range [1,0], positive value are stick up |
|
|
|
property bool yAxisPositiveRangeOnly: false ///< true: value range [0,1], false: value range [-1,1] |
|
|
|
property bool yAxisThrottleCentered: false ///< false: center yAxis in throttle for reverser and forward |
|
|
|
property bool yAxisReCenter: true ///< true: snaps back to center on release, false: stays at current position on release |
|
|
|
property real xPositionDelta: 0 ///< Amount to move the control on x axis |
|
|
|
property real xPositionDelta: 0 ///< Amount to move the control on x axis |
|
|
|
property real yPositionDelta: 0 ///< Amount to move the control on y axis |
|
|
|
property real yPositionDelta: 0 ///< Amount to move the control on y axis |
|
|
|
property bool springYToCenter:true ///< true: Spring Y to center on release |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
property real _centerXY: width / 2 |
|
|
|
property real _centerXY: width / 2 |
|
|
|
property bool _processTouchPoints: false |
|
|
|
property bool _processTouchPoints: false |
|
|
|
property real stickPositionX: _centerXY |
|
|
|
|
|
|
|
property real stickPositionY: yAxisThrottleCentered ? _centerXY : height |
|
|
|
|
|
|
|
property color _fgColor: QGroundControl.globalPalette.text |
|
|
|
property color _fgColor: QGroundControl.globalPalette.text |
|
|
|
property color _bgColor: QGroundControl.globalPalette.window |
|
|
|
property color _bgColor: QGroundControl.globalPalette.window |
|
|
|
|
|
|
|
property real stickPositionX: _centerXY |
|
|
|
|
|
|
|
property real stickPositionY: yAxisReCenter ? _centerXY : height |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QGCMapPalette { id: mapPal } |
|
|
|
|
|
|
|
|
|
|
|
onWidthChanged: calculateXAxis() |
|
|
|
onWidthChanged: calculateXAxis() |
|
|
|
onStickPositionXChanged: calculateXAxis() |
|
|
|
onStickPositionXChanged: calculateXAxis() |
|
|
|
onHeightChanged: calculateYAxis() |
|
|
|
onHeightChanged: calculateYAxis() |
|
|
|
onStickPositionYChanged: calculateYAxis() |
|
|
|
onStickPositionYChanged: calculateYAxis() |
|
|
|
|
|
|
|
onYAxisPositiveRangeOnlyChanged: calculateYAxis() |
|
|
|
|
|
|
|
|
|
|
|
function calculateXAxis() { |
|
|
|
function calculateXAxis() { |
|
|
|
if(!_joyRoot.visible) { |
|
|
|
if(!_joyRoot.visible) { |
|
|
@ -42,13 +45,13 @@ Item { |
|
|
|
if(!_joyRoot.visible) { |
|
|
|
if(!_joyRoot.visible) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
var yAxisTemp = stickPositionY / height |
|
|
|
var fullRange = yAxisPositiveRangeOnly ? 1 : 2 |
|
|
|
yAxisTemp *= 2.0 |
|
|
|
var pctUp = 1.0 - (stickPositionY / height) |
|
|
|
yAxisTemp -= 1.0 |
|
|
|
var rangeUp = pctUp * fullRange |
|
|
|
if (yAxisThrottle) { |
|
|
|
if (!yAxisPositiveRangeOnly) { |
|
|
|
yAxisTemp = ((yAxisTemp * -1.0) / 2.0) + 0.5 |
|
|
|
rangeUp -= 1 |
|
|
|
} |
|
|
|
} |
|
|
|
yAxis = yAxisTemp |
|
|
|
yAxis = rangeUp |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function reCenter() { |
|
|
|
function reCenter() { |
|
|
@ -58,9 +61,9 @@ Item { |
|
|
|
xPositionDelta = 0 |
|
|
|
xPositionDelta = 0 |
|
|
|
yPositionDelta = 0 |
|
|
|
yPositionDelta = 0 |
|
|
|
|
|
|
|
|
|
|
|
// Center sticks |
|
|
|
// Re-Center sticks as needed |
|
|
|
stickPositionX = _centerXY |
|
|
|
stickPositionX = _centerXY |
|
|
|
if (yAxisThrottleCentered) { |
|
|
|
if (yAxisReCenter) { |
|
|
|
stickPositionY = _centerXY |
|
|
|
stickPositionY = _centerXY |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -68,7 +71,7 @@ Item { |
|
|
|
function thumbDown(touchPoints) { |
|
|
|
function thumbDown(touchPoints) { |
|
|
|
// Position the control around the initial thumb position |
|
|
|
// Position the control around the initial thumb position |
|
|
|
xPositionDelta = touchPoints[0].x - _centerXY |
|
|
|
xPositionDelta = touchPoints[0].x - _centerXY |
|
|
|
if (yAxisThrottle) { |
|
|
|
if (yAxisPositiveRangeOnly) { |
|
|
|
yPositionDelta = touchPoints[0].y - stickPositionY |
|
|
|
yPositionDelta = touchPoints[0].y - stickPositionY |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
yPositionDelta = touchPoints[0].y - _centerXY |
|
|
|
yPositionDelta = touchPoints[0].y - _centerXY |
|
|
@ -118,7 +121,7 @@ Item { |
|
|
|
|
|
|
|
|
|
|
|
QGCColoredImage { |
|
|
|
QGCColoredImage { |
|
|
|
color: _fgColor |
|
|
|
color: _fgColor |
|
|
|
visible: yAxisThrottle |
|
|
|
visible: yAxisPositiveRangeOnly |
|
|
|
height: ScreenTools.defaultFontPixelHeight |
|
|
|
height: ScreenTools.defaultFontPixelHeight |
|
|
|
width: height |
|
|
|
width: height |
|
|
|
sourceSize.height: height |
|
|
|
sourceSize.height: height |
|
|
@ -132,7 +135,7 @@ Item { |
|
|
|
|
|
|
|
|
|
|
|
QGCColoredImage { |
|
|
|
QGCColoredImage { |
|
|
|
color: _fgColor |
|
|
|
color: _fgColor |
|
|
|
visible: yAxisThrottle |
|
|
|
visible: yAxisPositiveRangeOnly |
|
|
|
height: ScreenTools.defaultFontPixelHeight |
|
|
|
height: ScreenTools.defaultFontPixelHeight |
|
|
|
width: height |
|
|
|
width: height |
|
|
|
sourceSize.height: height |
|
|
|
sourceSize.height: height |
|
|
@ -146,7 +149,7 @@ Item { |
|
|
|
|
|
|
|
|
|
|
|
QGCColoredImage { |
|
|
|
QGCColoredImage { |
|
|
|
color: _fgColor |
|
|
|
color: _fgColor |
|
|
|
visible: yAxisThrottle |
|
|
|
visible: yAxisPositiveRangeOnly |
|
|
|
height: ScreenTools.defaultFontPixelHeight |
|
|
|
height: ScreenTools.defaultFontPixelHeight |
|
|
|
width: height |
|
|
|
width: height |
|
|
|
sourceSize.height: height |
|
|
|
sourceSize.height: height |
|
|
@ -160,7 +163,7 @@ Item { |
|
|
|
|
|
|
|
|
|
|
|
QGCColoredImage { |
|
|
|
QGCColoredImage { |
|
|
|
color: _fgColor |
|
|
|
color: _fgColor |
|
|
|
visible: yAxisThrottle |
|
|
|
visible: yAxisPositiveRangeOnly |
|
|
|
height: ScreenTools.defaultFontPixelHeight |
|
|
|
height: ScreenTools.defaultFontPixelHeight |
|
|
|
width: height |
|
|
|
width: height |
|
|
|
sourceSize.height: height |
|
|
|
sourceSize.height: height |
|
|
@ -207,9 +210,6 @@ Item { |
|
|
|
maximumTouchPoints: 1 |
|
|
|
maximumTouchPoints: 1 |
|
|
|
touchPoints: [ TouchPoint { id: touchPoint } ] |
|
|
|
touchPoints: [ TouchPoint { id: touchPoint } ] |
|
|
|
onPressed: _joyRoot.thumbDown(touchPoints) |
|
|
|
onPressed: _joyRoot.thumbDown(touchPoints) |
|
|
|
onReleased: { |
|
|
|
onReleased: _joyRoot.reCenter() |
|
|
|
if(springYToCenter) |
|
|
|
|
|
|
|
_joyRoot.reCenter() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|