Merge pull request #3592 from nicktiberi/master

Normalize and check upper/lower bounds of hats input on OS X
This commit is contained in:
Mathew Maidment 2016-02-05 16:51:21 -05:00
commit bd713643d1
1 changed files with 12 additions and 2 deletions

View File

@ -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)
{