normalize and check upper/lower bounds of hats input on OS X
This commit is contained in:
parent
2282651fdb
commit
e7ad0fd600
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue