Gamepad mappings not applying

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
enra64
Prole
Posts: 3
Joined: Wed Jul 26, 2017 5:41 pm

Gamepad mappings not applying

Post by enra64 »

Hello (and sorry for the large post),
I am currently trying to add support for gamepads to my game.

Specifically, I am trying to get the new XBOX Wireless controller ("Standard 2016") to work, with the GUID 050000005e040000fd02000003090000, connected via bluetooth to my linux system. The gamepad gets the name 'Xbox Wireless Controller', even though i could not find that name or my GUID anywhere (I searched in the SDL codebase, here (v2.0.5) and here (v2.0.4)

Because the built-in mappings are wrong, I want to create and apply a new mapping. To do this, it seems, I could either create a SDL mapping and load it with loadGamepadMappings or set it manually with setGamepadMapping. However, I cannot get the mapping to stick: no matter which of the functions I use, love does not seem to update the mapping. I wrote a small example to verify I was not doing something dumb:

Code: Select all

function love.gamepadpressed(joystick, button)
        local inputtype, inputindex, hatdirection = joystick:getGamepadMapping(button)
        inputtype = inputtype or "nil"
        inputindex = inputindex or "nil"
        hatdirection = hatdirection or "nil"

        print("pressed "..button.." with type "..inputtype..", index "..inputindex..", hatdir "..hatdirection.." on gamepad "..joystick:getGUID())
end

function love.joystickpressed(joystick, button)
        print("pressed "..button.." on joystick "..joystick:getGUID())
end

function love.load(arg)
    -- find the first connected joystick
    local joystick_list = love.joystick.getJoysticks()
    local joystick = joystick_list[1]

    if joystick:isGamepad() then
        print("new gamepad '"..joystick:getName().."' with GUID "..joystick:getGUID())
    else
        print("new joystick '"..joystick:getName().."' with GUID "..joystick:getGUID())
    end
    
    -- try to remap the button that *should* be leftshoulder; if console argument is given, use that
    local leftshoulder_button_number = tonumber(arg[2]) or 7
    local success = love.joystick.setGamepadMapping("050000005e040000fd02000003090000", "leftshoulder", "button", leftshoulder_button_number, nil)
    print("success mapping button "..leftshoulder_button_number.." to leftshoulder? "..tostring(success))

    --- load gamepad mapping (commented out to test one of the two mapping functions)
    --love.joystick.loadGamepadMappings("custom_gamecontroller_db.txt")
end
If I understand the documentation correctly, after executing the mapping functions, the "button" argument to "love.gamepadpressed" should return leftshoulder for the button with index 7. Now comes the part that confuses me: No matter what inputindex I use, the "Y" button on my controller triggers the leftshoulder button, with getGamepadMapping returning the inputindex that was given to setGamepadMapping. Am I not understanding how the function is supposed to be used? Loading the gamepad mapping does not help me either, but maybe it is wrong:

Code: Select all

050000005e040000fd02000003090000,Xbox one 2016 wireless bluetooth linux,a:b0,b:b1,x:b3,y:b4,start:b11,leftstick:b13,rightstick:b14,leftshoulder:b7,rightshoulder:b8,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a5,righttrigger:a4,platform:Linux,
A couple of sample outputs:
inputindex set to 7 (the button number joystickpressed gives when pressing the actual leftshoulder button), when pressing leftshoulder:

Code: Select all

pressed back with type nil, index nil, hatdir nil on gamepad 050000005e040000fd02000003090000
pressed 7 on joystick 050000005e040000fd02000003090000
inputindex set to 7, when pressing Y:

Code: Select all

pressed leftshoulder with type button, index 7, hatdir nil on gamepad 050000005e040000fd02000003090000
pressed 5 on joystick 050000005e040000fd02000003090000
So, I guess my question is: am I not using the functions correctly (or is my mapping bad?), or are they buggy?

I would greatly appreciate any help you can give me, since I have been tinkering with this problem for days, and I don't really want to write a parser for the SDL mappings and do my own mapping, nor use a library and rewrite my input system to fit it. A .love is attached so you can test my code easily, different inputindex values can be tested via

Code: Select all

love gamepad_test.love <inputindex>
. If you are interested, the complete source code is available at https://github.com/enra64/spacy3.
Attachments
gamepad_test.love
(1.02 KiB) Downloaded 144 times
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Gamepad mappings not applying

Post by raidho36 »

Yeah I had the same problem except for my gamepad the mapping was correct.
enra64
Prole
Posts: 3
Joined: Wed Jul 26, 2017 5:41 pm

Re: Gamepad mappings not applying

Post by enra64 »

First of all, thank you for answering. At least i have not gone mad over this, as you seem to have experienced the same problem.

I have now tested the loadGamepadMappings with a cheap USB NES gamepad that love did not immediately recognize as a gamepad. However, after loading the SDL file it got recognized as a gamepad with the correct mapping! So to me it seems that you cannot re-map buttons. Is that desired behaviour? I would really like to be able to remap my gamepad :/

My Mapping:

Code: Select all

03000000790000001100000010010000,USB NES Controller,a:b1,b:b0,start:b9,back:b8,leftx:a0,lefty:a1
enra64
Prole
Posts: 3
Joined: Wed Jul 26, 2017 5:41 pm

Re: Gamepad mappings not applying

Post by enra64 »

So, after sifting through the love2d code for gamepads, it seems to me that while it is intended that buttons can be remapped even with an already available mapping, there are two problems at hand:

a) the code for replacing a mapping in setGamepadMapping is buggy, see the issue I created: https://bitbucket.org/rude/love/issues/ ... -correctly

b) even with the correction, SDL does not work with updated mappings. I think here and here it is expected that SDL sends buttons which have been already converted using the mapping, which does not seem to be the case. I will investigate further at a later point in time.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 6 guests