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
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,
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
Code: Select all
pressed leftshoulder with type button, index 7, hatdir nil on gamepad 050000005e040000fd02000003090000
pressed 5 on joystick 050000005e040000fd02000003090000
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>