mdqinc / SDL_GameControllerDB

A community sourced database of game controller mappings to be used with SDL2 Game Controller functionality
http://libsdl.org
zlib License
1.38k stars 520 forks source link

Wrong DPad entries for Android #760

Closed darksylinc closed 5 months ago

darksylinc commented 6 months ago

Hi!

I'm adapting SDL2's gamepad code to our own code so that we can use SDL_GameControllerDB directly (i.e. for various technical reasons we're not using SDL2).

We bought a XBox controller and noticed the DPad wasn't working. After some debugging, I nailed it to wrong mapping. I thought "Ok, perhaps my implementation is wrong and I missed something".

So then I proceed to compare with vanilla SDL2 (2.30.0) demo. And lo and behold, the gamepad's dpad button wasn't working on SDL2 either.

The entry in question is this one:

050000005e040000130b0000ffff3f00,Xbox Series Controller,a:b0,b:b1,back:b15,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,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:Android,

However I already know what the problem is and how to fix it.

On Android, SDL2 hardcodes all hats (dpad) to emit buttons b11, b12, b13, b14. I don't know SDL2's rationale behind this decision, but it is what it is.

It seems like originally SDL2 would actually map hats correctly, but this was changed in March 2018.

Thus any Android entry of the type "hX.Y" (i.e. like h0.4) is simply wrong for any modern SDL2 build.

Fortunately the fix appears to be simple:

But before doing anything; I'd like to create a ticket with SDL2. This looks like a bug on their part.

The problem is that even if SDL2 would fix it, this project would still have tainted entries. Because the reverse would happen. i.e. all entries of dpdown:b12 would have to be replaced with dpdown:h0.4 and so on.

offalynne commented 6 months ago

For your software, you can presumably find this case and apply the correction ?

I'd like to create a ticket with SDL2

If SDL2 would fix it, this project would still have tainted entries [...] all entries of dpdown:b12 would have to be replaced with dpdown:h0.4 and so on.

This is preferable, and we can make that change

darksylinc commented 6 months ago

For your software, you can presumably find this case and apply the correction ? Yes.

This is preferable, and we can make that change

Yep. I already opened a ticket. The more I think about this, the more this looks like an SDL bug.

darksylinc commented 5 months ago

Hi!

SDL project replied back.

The bug is in this project. The Android mappings must not contain hat entries as they won't work.

They even quoted the official DB mapping for this same gamepad, and it doesn't match that of this project's:

     "050000005e040000130b0000ffff3f00,Xbox Series X Controller,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,", 
offalynne commented 5 months ago

@darksylinc feel free to make the corections and open a PR

offalynne commented 5 months ago

655f8c14eed964d3d64a4ffc1cc2870c9622d9b8