From 5daccba235814bdf3f61ebf5e76813330aa66b69 Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Tue, 7 Jun 2016 15:14:08 -0700 Subject: [PATCH] xbox controller works on restart --- libraries/controllers/src/controllers/UserInputMapper.cpp | 6 +++++- libraries/controllers/src/controllers/UserInputMapper.h | 2 +- plugins/hifiSdl2/src/Joystick.cpp | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/libraries/controllers/src/controllers/UserInputMapper.cpp b/libraries/controllers/src/controllers/UserInputMapper.cpp index e3a520e6c4..9132b9d3a5 100755 --- a/libraries/controllers/src/controllers/UserInputMapper.cpp +++ b/libraries/controllers/src/controllers/UserInputMapper.cpp @@ -77,7 +77,7 @@ void UserInputMapper::registerDevice(InputDevice::Pointer device) { } const auto& deviceID = device->_deviceID; - //recordDeviceOfType(device->getName()); + recordDeviceOfType(device->getName()); qCDebug(controllers) << "Registered input device <" << device->getName() << "> deviceID = " << deviceID; @@ -126,6 +126,10 @@ void UserInputMapper::removeDevice(int deviceID) { auto device = proxyEntry->second; qCDebug(controllers) << "Unregistering input device <" << device->getName() << "> deviceID = " << deviceID; + if (!_deviceCounts.contains(device->getName())) { + _deviceCounts[device->getName()] -= 1; + } + unloadMappings(device->getDefaultMappingConfigs()); auto mappingsEntry = _mappingsByDevice.find(deviceID); diff --git a/libraries/controllers/src/controllers/UserInputMapper.h b/libraries/controllers/src/controllers/UserInputMapper.h index 9c79415b6e..2c8aabc099 100644 --- a/libraries/controllers/src/controllers/UserInputMapper.h +++ b/libraries/controllers/src/controllers/UserInputMapper.h @@ -142,7 +142,7 @@ namespace controller { std::vector _lastStandardStates = std::vector(); int recordDeviceOfType(const QString& deviceName); - QHash _deviceCounts; + QHash _deviceCounts; static float getValue(const EndpointPointer& endpoint, bool peek = false); static Pose getPose(const EndpointPointer& endpoint, bool peek = false); diff --git a/plugins/hifiSdl2/src/Joystick.cpp b/plugins/hifiSdl2/src/Joystick.cpp index a109656489..614adff7d6 100644 --- a/plugins/hifiSdl2/src/Joystick.cpp +++ b/plugins/hifiSdl2/src/Joystick.cpp @@ -64,7 +64,7 @@ void Joystick::handleButtonEvent(const SDL_ControllerButtonEvent& event) { controller::Input::NamedVector Joystick::getAvailableInputs() const { using namespace controller; - static const Input::NamedVector availableInputs{ + const Input::NamedVector availableInputs{ makePair(A, "A"), makePair(B, "B"), makePair(X, "X"),