Merge pull request #3592 from nicktiberi/master
Normalize and check upper/lower bounds of hats input on OS X
This commit is contained in:
commit
bd713643d1
|
@ -227,11 +227,21 @@ Joystick::Hat::Hat(IOHIDElementRef element, IOHIDDeviceRef device, direction dir
|
||||||
ControlState Joystick::Hat::GetState() const
|
ControlState Joystick::Hat::GetState() const
|
||||||
{
|
{
|
||||||
IOHIDValueRef value;
|
IOHIDValueRef value;
|
||||||
int position;
|
|
||||||
|
|
||||||
if (IOHIDDeviceGetValue(m_device, m_element, &value) == kIOReturnSuccess)
|
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)
|
switch (position)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue