My USB-connected DualSense gamepad's name is reported as "Wireless Controller", but the GamepadMappingString is "PS5 Controller".
Here's a simple demonstration main.lua (requires you download https://raw.githubusercontent.com/gabom ... llerdb.txt as gamecontrollerdb.txt for it to detect a DualSense gamepad):
Code: Select all
love.joystick.loadGamepadMappings("gamecontrollerdb.txt")
function love.gamepadpressed(joystick, button)
print("getGamepadMappingString", joystick:getGamepadMappingString())
print("getName", joystick:getName())
print()
end
getGamepadMappingString 030000004c050000e60c000000000000,PS5 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,misc1:b13,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Windows
getName Wireless Controller
getGamepadMappingString 030000004c050000c405000000016800,*,a:b0,b:b1,back:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b5,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,platform:Windows
getName PS4 Controller
getGamepadMappingString 030000005e0400008e02000000007801,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Windows
getName XInput Controller #1
I'll cut through the noise for you and show getGamepadMappingString vs. getName:
- * "PS5 Controller" vs. "Wireless Controller"
* "*" vs. "PS4 Controller"
* "XInput Controller" vs. "XInput Controller #1"
Xbox makes sense since getName is distinguishing which index it's using which
is displayed on the gamepad.
But why does getName use a generic name instead of the one from the
GamepadMapping? Does it not trust GamepadMappings to have valid names (several
of them from gamecontrollerdb.txt are "*" and I guess you could provide any
mappings you wanted)? I guess "Wireless Controller" is the name Windows gives
to the device (but it's also the name given to the PS4 gamepad and the Xbox
gamepad's name has XBOX in it)? Maybe love2d has special support for some gamepads?
For now, my workaround is to try both:
Code: Select all
function love.gamepadpressed(joystick, button)
local parts = lume.split(joystick:getGamepadMappingString(), ',')
local name = parts[2]
if not name or name:len() < 3 then
name = joystick:getName()
end
local index = joystick:getConnectedIndex()
print(string.format("Changing primary gamepad to #%d '%s'.", index, name))
-- handle using joystick as the new primary input here
-- ...
end