Cocoa: Fix range handling for hats and buttons

Fixes #888.
This commit is contained in:
Camilla Löwy 2017-03-23 15:54:34 +01:00
parent 1982543cd2
commit 55d0560746
2 changed files with 13 additions and 17 deletions

View File

@ -187,6 +187,7 @@ information on what to include when reporting a bug.
- [Cocoa] Bugfix: Leaving video mode with `glfwSetWindowMonitor` would set
incorrect position and size (#748)
- [Cocoa] Bugfix: Iconified full screen windows could not be restored (#848)
- [Cocoa] Bugfix: Value range was ignored for joystick hats and buttons (#888)
- [X11] Moved to XI2 `XI_RawMotion` for disable cursor mode motion input (#125)
- [EGL] Added support for `EGL_KHR_get_all_proc_addresses` (#871)
- [EGL] Added support for `EGL_KHR_context_flush_control`

View File

@ -53,29 +53,19 @@ typedef struct _GLFWjoyelementNS
//
static long getElementValue(_GLFWjoystick* js, _GLFWjoyelementNS* element)
{
IOReturn result = kIOReturnSuccess;
IOHIDValueRef valueRef;
long value = 0;
if (js && element && js->ns.device)
if (js->ns.device)
{
result = IOHIDDeviceGetValue(js->ns.device,
if (IOHIDDeviceGetValue(js->ns.device,
element->native,
&valueRef);
if (kIOReturnSuccess == result)
&valueRef) == kIOReturnSuccess)
{
value = IOHIDValueGetIntegerValue(valueRef);
// Record min and max for auto calibration
if (value < element->minimum)
element->minimum = value;
if (value > element->maximum)
element->maximum = value;
}
}
// Auto user scale
return value;
}
@ -349,8 +339,13 @@ int _glfwPlatformPollJoystick(int jid, int mode)
CFArrayGetValueAtIndex(js->ns.axes, i);
const long value = getElementValue(js, axis);
const long delta = axis->maximum - axis->minimum;
// Perform auto calibration
if (value < axis->minimum)
axis->minimum = value;
if (value > axis->maximum)
axis->maximum = value;
const long delta = axis->maximum - axis->minimum;
if (delta == 0)
_glfwInputJoystickAxis(jid, i, value);
else
@ -365,7 +360,7 @@ int _glfwPlatformPollJoystick(int jid, int mode)
{
_GLFWjoyelementNS* button = (_GLFWjoyelementNS*)
CFArrayGetValueAtIndex(js->ns.buttons, i);
const char value = getElementValue(js, button) ? 1 : 0;
const char value = getElementValue(js, button) - button->minimum;
_glfwInputJoystickButton(jid, i, value);
}
@ -386,7 +381,7 @@ int _glfwPlatformPollJoystick(int jid, int mode)
_GLFWjoyelementNS* hat = (_GLFWjoyelementNS*)
CFArrayGetValueAtIndex(js->ns.hats, i);
long state = getElementValue(js, hat);
long state = getElementValue(js, hat) - hat->minimum;
if (state < 0 || state > 8)
state = 8;