normalize and check upper/lower bounds of hats input on OS X

This commit is contained in:
Nick Tiberi 2016-02-04 15:40:00 -05:00
parent 2282651fdb
commit e7ad0fd600
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)
{