From e7ad0fd600e56d4779dc1ad5549762f5978be043 Mon Sep 17 00:00:00 2001 From: Nick Tiberi Date: Thu, 4 Feb 2016 15:40:00 -0500 Subject: [PATCH] normalize and check upper/lower bounds of hats input on OS X --- .../ControllerInterface/OSX/OSXJoystick.mm | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.mm b/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.mm index 0c8a199d5d..bc503ec398 100644 --- a/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.mm +++ b/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.mm @@ -227,11 +227,21 @@ Joystick::Hat::Hat(IOHIDElementRef element, IOHIDDeviceRef device, direction dir ControlState Joystick::Hat::GetState() const { IOHIDValueRef value; - int position; if (IOHIDDeviceGetValue(m_device, m_element, &value) == kIOReturnSuccess) { - position = IOHIDValueGetIntegerValue(value); + int position = IOHIDValueGetIntegerValue(value); + int min = IOHIDElementGetLogicalMin(m_element); + int max = IOHIDElementGetLogicalMax(m_element); + + // if the position is outside the min or max, don't register it as a valid button press + if (position < min || position > max) + { + return 0; + } + + // normalize the position so that its lowest value is 0 + position -= min; switch (position) {