Joystick:getName vs GamepadMappingString?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
idbrii
Prole
Posts: 34
Joined: Sat Jun 12, 2021 5:07 am

Joystick:getName vs GamepadMappingString?

Post by idbrii »

Why doesn't Joystick:getName return the name of the gamepad from loadGamepadMappings?

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
When I press a button on a DualSense (USB), DualShock4 (USB), and then Xbox 360 wired, I get this output:
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"
The return value for getName on the PS4 gamepad is clearly a better name. The
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
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: Joystick:getName vs GamepadMappingString?

Post by ReFreezed »

idbrii wrote: Thu Dec 30, 2021 9:00 pm I guess "Wireless Controller" is the name Windows gives to the device
This. getName() just returns what the OS reports, while getGamepadMappingString() just returns what the loaded .txt file happen to contain. They are simply different things. Also, joysticks always have a name but may not have any "gamepad mappings".
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 7 guests