summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerInterface
diff options
context:
space:
mode:
authorArthur Carlsson <arthur@kiron.net>2017-06-30 23:56:42 +0200
committerLéo Lam <leo@innovatetechnologi.es>2017-09-15 19:19:46 +0200
commit79a646a67de7faa3826ffe480226fc25b4a900d5 (patch)
tree25d405a214189976aa829e1b7e641b0235e52d0c /Source/Core/InputCommon/ControllerInterface
parent2b4bf8662a18b8b3a49e67133f3e2e2fa45322b6 (diff)
Prevent multiple HID elements of same usage type on OSX
On OSX, iterate the HID device's elements and only store the last of each type to accommodate for flaky hardware
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface')
-rw-r--r--Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.mm17
1 files changed, 17 insertions, 0 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.mm b/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.mm
index 9bbd953a4b..ecbef721a5 100644
--- a/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.mm
+++ b/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.mm
@@ -2,6 +2,7 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.
+#include <algorithm>
#include <sstream>
#include <Foundation/Foundation.h>
@@ -49,11 +50,26 @@ Joystick::Joystick(IOHIDDeviceRef device, std::string name)
if (axes)
{
+ std::vector<IOHIDElementRef> elems;
for (int i = 0; i < CFArrayGetCount(axes); i++)
{
IOHIDElementRef e = (IOHIDElementRef)CFArrayGetValueAtIndex(axes, i);
// DeviceElementDebugPrint(e, nullptr);
+ uint32_t usage = IOHIDElementGetUsage(e);
+ // Check for any existing elements with the same usage
+ auto it = std::find_if(elems.begin(), elems.end(), [usage](const auto& ref) {
+ return usage == IOHIDElementGetUsage(ref);
+ });
+
+ if (it == elems.end())
+ elems.push_back(e);
+ else
+ *it = e;
+ }
+
+ for (auto e : elems)
+ {
if (IOHIDElementGetUsage(e) == kHIDUsage_GD_Hatswitch)
{
AddInput(new Hat(e, m_device, Hat::up));
@@ -67,6 +83,7 @@ Joystick::Joystick(IOHIDDeviceRef device, std::string name)
new Axis(e, m_device, Axis::positive));
}
}
+
CFRelease(axes);
}