Browse Source

Merge pull request #7375 from patrickelectric/joystick_virtual

Improve virtual joystick functionality
QGC4.4
Don Gagne 6 years ago committed by GitHub
parent
commit
5cc3f3dcc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      src/FlightDisplay/FlightDisplayView.qml
  2. 4
      src/FlightDisplay/FlightDisplayViewWidgets.qml
  3. 4
      src/FlightDisplay/VirtualJoystick.qml
  4. 32
      src/QmlControls/JoystickThumbPad.qml
  5. 7
      src/Settings/App.SettingsGroup.json
  6. 1
      src/Settings/AppSettings.cc
  7. 1
      src/Settings/AppSettings.h
  8. 11
      src/ui/preferences/GeneralSettings.qml

3
src/FlightDisplay/FlightDisplayView.qml

@ -550,8 +550,11 @@ QGCView { @@ -550,8 +550,11 @@ QGCView {
active: (_virtualJoystick ? _virtualJoystick.value : false) && !(_activeVehicle ? _activeVehicle.highLatencyLink : false)
property bool useLightColors: isBackgroundDark
// The default behaviour is not centralized throttle
property bool centralizeThrottle: _virtualJoystickCentralized ? _virtualJoystickCentralized.value : false
property Fact _virtualJoystick: QGroundControl.settingsManager.appSettings.virtualJoystick
property Fact _virtualJoystickCentralized: QGroundControl.settingsManager.appSettings.virtualJoystickCentralized
}
ToolStrip {

4
src/FlightDisplay/FlightDisplayViewWidgets.qml

@ -86,6 +86,10 @@ Item { @@ -86,6 +86,10 @@ Item {
target: QGroundControl.settingsManager.appSettings.virtualJoystick
onValueChanged: _setInstrumentWidget()
}
Connections {
target: QGroundControl.settingsManager.appSettings.virtualJoystickCentralized
onValueChanged: _setInstrumentWidget()
}
Connections {
target: QGroundControl.settingsManager.appSettings.showLargeCompass

4
src/FlightDisplay/VirtualJoystick.qml

@ -18,7 +18,7 @@ import QGroundControl.Vehicle 1.0 @@ -18,7 +18,7 @@ import QGroundControl.Vehicle 1.0
Item {
//property bool useLightColors - Must be passed in from loaded
//property bool centralizeThrottle - Must be passed in from loaded
Timer {
interval: 40 // 25Hz, same as real joystick rate
running: QGroundControl.settingsManager.appSettings.virtualJoystick.value && _activeVehicle
@ -39,8 +39,8 @@ Item { @@ -39,8 +39,8 @@ Item {
width: parent.height
height: parent.height
yAxisThrottle: true
yAxisThrottleCentered: centralizeThrottle
lightColors: useLightColors
throttle: true
}
JoystickThumbPad {

32
src/QmlControls/JoystickThumbPad.qml

@ -11,26 +11,38 @@ Item { @@ -11,26 +11,38 @@ Item {
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 bool yAxisThrottle: false ///< true: yAxis used for throttle, range [1,0], positive value are stick up
property bool yAxisThrottleCentered: false ///< false: center yAxis in throttle for reverser and forward
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 bool throttle: false
property real _centerXY: width / 2
property bool _processTouchPoints: false
property bool _stickCenteredOnce: false
property real stickPositionX: _centerXY
property real stickPositionY: yAxisThrottle ? height : _centerXY
property real stickPositionY: yAxisThrottleCentered ? _centerXY : height
QGCMapPalette { id: mapPal }
onStickPositionXChanged: {
onWidthChanged: calculateXAxis()
onStickPositionXChanged: calculateXAxis()
onHeightChanged: calculateYAxis()
onStickPositionYChanged: calculateYAxis()
function calculateXAxis()
{
if(!visible()) {
return;
}
var xAxisTemp = stickPositionX / width
xAxisTemp *= 2.0
xAxisTemp -= 1.0
xAxis = xAxisTemp
}
onStickPositionYChanged: {
function calculateYAxis()
{
if(!visible()) {
return;
}
var yAxisTemp = stickPositionY / height
yAxisTemp *= 2.0
yAxisTemp -= 1.0
@ -50,7 +62,7 @@ Item { @@ -50,7 +62,7 @@ Item {
// Center sticks
stickPositionX = _centerXY
if (!yAxisThrottle) {
if (yAxisThrottleCentered) {
stickPositionY = _centerXY
}
}
@ -86,7 +98,7 @@ Item { @@ -86,7 +98,7 @@ Item {
QGCColoredImage {
color: lightColors ? "white" : "black"
visible: throttle
visible: yAxisThrottle
height: ScreenTools.defaultFontPixelHeight
width: height
sourceSize.height: height
@ -100,7 +112,7 @@ Item { @@ -100,7 +112,7 @@ Item {
QGCColoredImage {
color: lightColors ? "white" : "black"
visible: throttle
visible: yAxisThrottle
height: ScreenTools.defaultFontPixelHeight
width: height
sourceSize.height: height
@ -114,7 +126,7 @@ Item { @@ -114,7 +126,7 @@ Item {
QGCColoredImage {
color: lightColors ? "white" : "black"
visible: throttle
visible: yAxisThrottle
height: ScreenTools.defaultFontPixelHeight
width: height
sourceSize.height: height
@ -128,7 +140,7 @@ Item { @@ -128,7 +140,7 @@ Item {
QGCColoredImage {
color: lightColors ? "white" : "black"
visible: throttle
visible: yAxisThrottle
height: ScreenTools.defaultFontPixelHeight
width: height
sourceSize.height: height

7
src/Settings/App.SettingsGroup.json

@ -104,6 +104,13 @@ @@ -104,6 +104,13 @@
"defaultValue": false
},
{
"name": "virtualJoystickCentralized",
"shortDescription": "Set virtual joystick to be centralize throttle (spring-loaded).",
"longDescription": "If this option is enabled the virtual joystick throttle stick will be centralized.",
"type": "bool",
"defaultValue": false
},
{
"name": "gstDebugLevel",
"shortDescription": "Video streaming debug",
"longDescription": "Sets the environment variable GST_DEBUG for all pipeline elements on boot.",

1
src/Settings/AppSettings.cc

@ -78,6 +78,7 @@ DECLARE_SETTINGSFACT(AppSettings, telemetrySave) @@ -78,6 +78,7 @@ DECLARE_SETTINGSFACT(AppSettings, telemetrySave)
DECLARE_SETTINGSFACT(AppSettings, telemetrySaveNotArmed)
DECLARE_SETTINGSFACT(AppSettings, audioMuted)
DECLARE_SETTINGSFACT(AppSettings, virtualJoystick)
DECLARE_SETTINGSFACT(AppSettings, virtualJoystickCentralized)
DECLARE_SETTINGSFACT(AppSettings, appFontPointSize)
DECLARE_SETTINGSFACT(AppSettings, showLargeCompass)
DECLARE_SETTINGSFACT(AppSettings, savePath)

1
src/Settings/AppSettings.h

@ -33,6 +33,7 @@ public: @@ -33,6 +33,7 @@ public:
DEFINE_SETTINGFACT(telemetrySaveNotArmed)
DEFINE_SETTINGFACT(audioMuted)
DEFINE_SETTINGFACT(virtualJoystick)
DEFINE_SETTINGFACT(virtualJoystickCentralized)
DEFINE_SETTINGFACT(appFontPointSize)
DEFINE_SETTINGFACT(indoorPalette)
DEFINE_SETTINGFACT(showLargeCompass)

11
src/ui/preferences/GeneralSettings.qml

@ -455,6 +455,17 @@ QGCView { @@ -455,6 +455,17 @@ QGCView {
property Fact _virtualJoystick: QGroundControl.settingsManager.appSettings.virtualJoystick
}
FactCheckBox {
text: qsTr("Auto-Center throttle")
visible: _virtualJoystickCentralized.visible && (
QGroundControl.multiVehicleManager.activeVehicle.sub || QGroundControl.multiVehicleManager.activeVehicle.rover
)
fact: _virtualJoystickCentralized
Layout.leftMargin: _margins
property Fact _virtualJoystickCentralized: QGroundControl.settingsManager.appSettings.virtualJoystickCentralized
}
GridLayout {
columns: 2

Loading…
Cancel
Save