From 501c0fe301f51269913c20766646b11ede6b22a4 Mon Sep 17 00:00:00 2001 From: Jacob Walser Date: Fri, 27 Jan 2017 18:18:21 -0500 Subject: [PATCH] Close SDL joystick threads after joystick is unplugged --- src/Joystick/JoystickManager.cc | 12 +++++------ src/VehicleSetup/JoystickConfig.qml | 32 ++++++++++++++--------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/Joystick/JoystickManager.cc b/src/Joystick/JoystickManager.cc index 9b55ccea4..97a0b10cc 100644 --- a/src/Joystick/JoystickManager.cc +++ b/src/Joystick/JoystickManager.cc @@ -92,11 +92,10 @@ void JoystickManager::_setActiveJoystickFromSettings(void) qCDebug(JoystickManagerLog) << "Releasing joystick:" << i.key(); if (_activeJoystick && !newMap.contains(_activeJoystick->name())) { qCDebug(JoystickManagerLog) << "\twas active"; - _activeJoystick->stopPolling(); - _activeJoystick = NULL; + setActiveJoystick(NULL); } - // FIXME: Don't leave this hanging! We need to free the object. - //i.value()->deleteLater(); + i.value()->wait(1000); + i.value()->deleteLater(); } } @@ -150,9 +149,10 @@ void JoystickManager::setActiveJoystick(Joystick* joystick) settings.beginGroup(_settingsGroup); settings.setValue(_settingsKeyActiveJoystick, _activeJoystick->name()); - emit activeJoystickChanged(_activeJoystick); - emit activeJoystickNameChanged(_activeJoystick->name()); } + + emit activeJoystickChanged(_activeJoystick); + emit activeJoystickNameChanged(_activeJoystick?_activeJoystick->name():""); } QVariantList JoystickManager::joysticks(void) diff --git a/src/VehicleSetup/JoystickConfig.qml b/src/VehicleSetup/JoystickConfig.qml index 58069ffa7..0b5c3f459 100644 --- a/src/VehicleSetup/JoystickConfig.qml +++ b/src/VehicleSetup/JoystickConfig.qml @@ -369,8 +369,8 @@ SetupPage { QGCCheckBox { id: enabledCheckBox - enabled: _activeJoystick.calibrated - text: _activeJoystick.calibrated ? qsTr("Enable joystick input") : qsTr("Enable not allowed (Calibrate First)") + enabled: _activeJoystick ? _activeJoystick.calibrated : false + text: _activeJoystick ? _activeJoystick.calibrated ? qsTr("Enable joystick input") : qsTr("Enable not allowed (Calibrate First)") : "" checked: _activeVehicle.joystickEnabled onClicked: _activeVehicle.joystickEnabled = checked @@ -379,7 +379,9 @@ SetupPage { target: joystickManager onActiveJoystickChanged: { + if(_activeJoystick) { enabledCheckBox.checked = Qt.binding(function() { return _activeJoystick.calibrated && _activeVehicle.joystickEnabled }) + } } } } @@ -414,9 +416,7 @@ SetupPage { target: joystickManager onAvailableJoysticksChanged: { var index = joystickCombo.find(joystickManager.activeJoystickName) - if (index == -1) { - console.warn(qsTr("Active joystick name not in combo"), joystickManager.activeJoystickName) - } else { + if (index >= 0) { joystickCombo.currentIndex = index } } @@ -433,7 +433,7 @@ SetupPage { QGCRadioButton { exclusiveGroup: throttleModeExclusiveGroup text: qsTr("Center stick is zero throttle") - checked: _activeJoystick.throttleMode == 0 + checked: _activeJoystick ? _activeJoystick.throttleMode == 0 : false onClicked: _activeJoystick.throttleMode = 0 } @@ -442,11 +442,11 @@ SetupPage { x: 20 width: parent.width spacing: ScreenTools.defaultFontPixelWidth - visible: _activeJoystick.throttleMode == 0 + visible: _activeJoystick ? _activeJoystick.throttleMode == 0 : false QGCCheckBox { id: accumulator - checked: _activeJoystick.accumulator + checked: _activeJoystick ? _activeJoystick.accumulator : false text: qsTr("Spring loaded throttle smoothing") onClicked: _activeJoystick.accumulator = checked @@ -456,7 +456,7 @@ SetupPage { QGCRadioButton { exclusiveGroup: throttleModeExclusiveGroup text: qsTr("Full down stick is zero throttle") - checked: _activeJoystick.throttleMode == 1 + checked: _activeJoystick ? _activeJoystick.throttleMode == 1 : false onClicked: _activeJoystick.throttleMode = 1 } @@ -467,7 +467,7 @@ SetupPage { QGCCheckBox { id: exponential - checked: _activeJoystick.exponential + checked: _activeJoystick ? _activeJoystick.exponential : false text: qsTr("Use exponential curve on roll, pitch, yaw") onClicked: _activeJoystick.exponential = checked @@ -556,7 +556,7 @@ SetupPage { Repeater { id: buttonActionRepeater - model: _activeJoystick.totalButtonCount + model: _activeJoystick ? _activeJoystick.totalButtonCount : 0 Row { spacing: ScreenTools.defaultFontPixelWidth @@ -566,7 +566,7 @@ SetupPage { QGCCheckBox { anchors.verticalCenter: parent.verticalCenter - checked: _activeJoystick.buttonActions[modelData] != "" + checked: _activeJoystick ? _activeJoystick.buttonActions[modelData] != "" : false onClicked: _activeJoystick.setButtonAction(modelData, checked ? buttonActionCombo.textAt(buttonActionCombo.currentIndex) : "") } @@ -592,7 +592,7 @@ SetupPage { QGCComboBox { id: buttonActionCombo width: ScreenTools.defaultFontPixelWidth * 20 - model: _activeJoystick.actions + model: _activeJoystick ? _activeJoystick.actions : 0 onActivated: _activeJoystick.setButtonAction(modelData, textAt(index)) Component.onCompleted: currentIndex = find(_activeJoystick.buttonActions[modelData]) @@ -623,7 +623,7 @@ SetupPage { Repeater { id: jsButtonActionRepeater - model: _activeJoystick.totalButtonCount + model: _activeJoystick ? _activeJoystick.totalButtonCount : 0 Row { spacing: ScreenTools.defaultFontPixelWidth @@ -704,7 +704,7 @@ SetupPage { Repeater { id: axisMonitorRepeater - model: _activeJoystick.axisCount + model: _activeJoystick ? _activeJoystick.axisCount : 0 width: parent.width Row { @@ -756,7 +756,7 @@ SetupPage { Repeater { id: buttonMonitorRepeater - model: _activeJoystick.totalButtonCount + model: _activeJoystick ? _activeJoystick.totalButtonCount : 0 Rectangle { width: ScreenTools.defaultFontPixelHeight * 1.2 -- 2.22.0