Skip to content

Commit

Permalink
Merge pull request #3592 from nicktiberi/master
Browse files Browse the repository at this point in the history
Normalize and check upper/lower bounds of hats input on OS X
  • Loading branch information
lioncash committed Feb 5, 2016
2 parents 2282651 + e7ad0fd commit bd71364
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.mm
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,21 @@
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)
{
Expand Down

0 comments on commit bd71364

Please sign in to comment.