summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerInterface/OSX
diff options
context:
space:
mode:
authorMathew Maidment <mathew1800@gmail.com>2016-02-05 16:51:21 -0500
committerMathew Maidment <mathew1800@gmail.com>2016-02-05 16:51:21 -0500
commitbd713643d197f75dedc79c9dd087070c9d413202 (patch)
tree0418ece2f73df230a26fe3a0bd4509a5dff6636d /Source/Core/InputCommon/ControllerInterface/OSX
parent2282651fdb7bee30694f03cac74c379335655fad (diff)
parente7ad0fd600e56d4779dc1ad5549762f5978be043 (diff)
Merge pull request #3592 from nicktiberi/master
Normalize and check upper/lower bounds of hats input on OS X
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface/OSX')
-rw-r--r--Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.mm14
1 files 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)
{