From 55d0560746632deb2df0807f4ba190383a353ad2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Thu, 23 Mar 2017 15:54:34 +0100 Subject: [PATCH] Cocoa: Fix range handling for hats and buttons Fixes #888. --- README.md | 1 + src/cocoa_joystick.m | 29 ++++++++++++----------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 76b384a3..9baa86bf 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/src/cocoa_joystick.m b/src/cocoa_joystick.m index e828002b..61d85a9f 100644 --- a/src/cocoa_joystick.m +++ b/src/cocoa_joystick.m @@ -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, - element->native, - &valueRef); - - if (kIOReturnSuccess == result) + if (IOHIDDeviceGetValue(js->ns.device, + element->native, + &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;