From 0c181dcf74d486fb3b0b9fd56640a7d3a354ad74 Mon Sep 17 00:00:00 2001 From: Locria Cyber <74560659+iacore@users.noreply.github.com> Date: Wed, 14 Jun 2023 18:53:01 +0000 Subject: [PATCH] Fix to Pass tests --- src/input.c | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/input.c b/src/input.c index 5f107d41..3e2a4b39 100644 --- a/src/input.c +++ b/src/input.c @@ -67,6 +67,8 @@ static GLFWbool initJoysticks(void) return _glfw.joysticksInitialized = GLFW_TRUE; } +#if defined(GLFW_BUILD_LINUX_JOYSTICK) + uint16_t parseHexDigit(char c) { if (c >= '0' && c <= '9') return c - '0'; @@ -89,21 +91,10 @@ static struct vendor_product parseGUID(const char* guid) return result; } -// Finds a mapping based on joystick GUID -// -static _GLFWmapping* findMapping(const char* guid) +static _GLFWmapping* findMappingUSBVendorProduct(const char* guid) { + struct vendor_product this; - - // exact match - for (int i = 0; i < _glfw.mappingCount; i++) - { - if (strncmp(_glfw.mappings[i].guid, guid, 32) == 0) - return _glfw.mappings + i; - } - -#if defined(GLFW_BUILD_LINUX_JOYSTICK) - // only match vendor product this = parseGUID(guid); for (int i = 0; i < _glfw.mappingCount; i++) @@ -113,11 +104,31 @@ static _GLFWmapping* findMapping(const char* guid) if (memcmp(&this, &that, sizeof(struct vendor_product)) == 0) return _glfw.mappings + i; } -#endif return NULL; } +#endif + +// Finds a mapping based on joystick GUID +// +static _GLFWmapping* findMapping(const char* guid) +{ + // exact match + for (int i = 0; i < _glfw.mappingCount; i++) + { + if (strncmp(_glfw.mappings[i].guid, guid, 32) == 0) + return _glfw.mappings + i; + } + +#if defined(GLFW_BUILD_LINUX_JOYSTICK) + // only match vendor id, product id + return findMappingUSBVendorProduct(guid); +#else + return NULL; +#endif +} + // Checks whether a gamepad mapping element is present in the hardware // static GLFWbool isValidElementForJoystick(const _GLFWmapelement* e,