[+] GLFWAPI const char *glfwGetGamepadName(int jid)

[+] GLFWAPI uint32_t glfwGetGamepadVendorID(int jid)
[+] GLFWAPI uint32_t glfwGetGamepadProductID(int jid)
[+] GLFWAPI uint32_t glfwGetGamepadProductRev(int jid)
This commit is contained in:
Reece Wilson 2023-11-05 00:02:27 +00:00
parent 6b2a2675ee
commit 15a7f24fb8
2 changed files with 107 additions and 3 deletions

View File

@ -6052,7 +6052,28 @@ GLFWAPI int glfwUpdateGamepadMappings(const char* string);
*
* @ingroup input
*/
GLFWAPI const char* glfwGetGamepadName(int jid);
GLFWAPI const char *glfwGetGamepadName(int jid);
/**
* @brief
* @param jid
* @return USB vendor-id
*/
GLFWAPI uint16_t glfwGetGamepadVendorID(int jid);
/**
* @brief
* @param jid
* @return USB product-id
*/
GLFWAPI uint16_t glfwGetGamepadProductID(int jid);
/**
* @brief
* @param jid
* @return USB product-version
*/
GLFWAPI uint16_t glfwGetGamepadProductRev(int jid);
/*! @brief Retrieves the state of the specified joystick remapped as a gamepad.
*

View File

@ -1543,6 +1543,90 @@ GLFWAPI const char* glfwGetGamepadName(int jid)
return js->mapping->name;
}
GLFWAPI uint16_t glfwGetGamepadVendorID(int jid)
{
_GLFWjoystick* js;
assert(jid >= GLFW_JOYSTICK_1);
assert(jid <= GLFW_JOYSTICK_LAST);
_GLFW_REQUIRE_INIT_OR_RETURN(0);
if (jid < 0 || jid > GLFW_JOYSTICK_LAST)
{
_glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick ID %i", jid);
return 0;
}
if (!initJoysticks())
return 0;
js = _glfw.joysticks + jid;
if (!js->connected)
return 0;
if (!_glfw.platform.pollJoystick(js, _GLFW_POLL_PRESENCE))
return 0;
return js->usbInfo.vendor;
}
GLFWAPI uint16_t glfwGetGamepadProductID(int jid)
{
_GLFWjoystick* js;
assert(jid >= GLFW_JOYSTICK_1);
assert(jid <= GLFW_JOYSTICK_LAST);
_GLFW_REQUIRE_INIT_OR_RETURN(0);
if (jid < 0 || jid > GLFW_JOYSTICK_LAST)
{
_glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick ID %i", jid);
return 0;
}
if (!initJoysticks())
return 0;
js = _glfw.joysticks + jid;
if (!js->connected)
return 0;
if (!_glfw.platform.pollJoystick(js, _GLFW_POLL_PRESENCE))
return 0;
return js->usbInfo.product;
}
GLFWAPI uint16_t glfwGetGamepadProductRev(int jid)
{
_GLFWjoystick* js;
assert(jid >= GLFW_JOYSTICK_1);
assert(jid <= GLFW_JOYSTICK_LAST);
_GLFW_REQUIRE_INIT_OR_RETURN(0);
if (jid < 0 || jid > GLFW_JOYSTICK_LAST)
{
_glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick ID %i", jid);
return 0;
}
if (!initJoysticks())
return 0;
js = _glfw.joysticks + jid;
if (!js->connected)
return 0;
if (!_glfw.platform.pollJoystick(js, _GLFW_POLL_PRESENCE))
return 0;
return js->usbInfo.version;
}
GLFWAPI int glfwGetGamepadState(int jid, GLFWgamepadstate* state)
{
int i;
@ -1674,5 +1758,4 @@ GLFWAPI uint64_t glfwGetTimerFrequency(void)
{
_GLFW_REQUIRE_INIT_OR_RETURN(0);
return _glfwPlatformGetTimerFrequency();
}
}