Latest build (dev) - dolphin - not receiving exit input

Hey, Im using the latest dev build and I’ve noticed when I disconnect my PS3 controller from the plug and use it wirelessly all buttons work but the exit dolphin function does not work?
It does work when I connect it to the controller plug.

I’ve noticed in emu-station the controller when plugged in registers as SHANWAN PS3 gamepad, but when unplugged and connects wirelessly becomes Sony Playstation(R)3 Controller.

The hotkey value I think is different between these 2 controller profiles, which is maybe causing the conflict.

Do you know where the controller code for exiting dolphin is? I think it should be 9 or 16 but not sure need to test.

edit: I think 4.2 EmuElec release doesn’t suffer from this bug as I remember being able to press the Hotkey+Start to exit fine.

I cannot reproduce this, but I do not use a PS3 controller, so maybe the issue is there.

It occurs in my 4.2 Release version too. Before I could exit out of dolphin using Hotkey+Start just fine. Off the top of ur head does emuelecRunEmu.sh launch a controller process that listens for the hotkey and exit being pressed. In the dev version it exits if I press hotkey+start just after dolphin has loaded the game.

Not sure I totally understand what you mean… but global exit hotkey is handled by gptokeyb and it is invoked from emuelecRunEmu.sh

Hey man, how would I go about testing if gotokeyb works or not?

gptokeyb 1 dolphin (or whatever the dolphin binary is called)
and use your quit combination, if it does not end, then your gamepad is probably not configured correctly

Hey I tried running:

gptokeyb 1 >$

so the output shows in the terminal and found that the first time the controller is paired it works as expected, however running it a second time it does not work, I have to re-plug the controller in and it works. So to re-cap, when it’s plugged in it works, when it’s connected via bluetooth it works only the first time it’s paired.
Hopefully this helps diagnose the issue.

It seems that the presses are not calling the handleEvent in main. Strange gonna diagnose a bit more.

I cannot reproduce this, with all of my gamepads. So it just points to either your gamepad not working correctly with SDL2, or it is not in the gamecontrollerdb.txt file which means is not properly configured. I will suggest you first try with another gamepad just to make sure.

Hmm its not even calling the gamepad events to add the controller when connected wirelessly. Hence why no events are working. I made a more complete gamecontrollerdb.txt. How do I include it into the image?

Running sdljoytest I got the following, so you are right its not included in gamecontrollerdb.txt:

Sys_InitInput: Compiled with SDL version 2.0.9
Sys_InitInput: Linked   with SDL version 2.0.9
Sys_InitInput: SDL2 joystick subsystem init
Sys_InitInput: Loading /storage/.config/SDL-GameControllerDB/gamecontrollerdb.txt
Sys_InitInput: SDL_GameControllerAddMappingsFromFile() added 170 controller maps
Sys_InitInput: Joystick subsytem - Found 1 joysticks at startup
Joystick 0 name 'Sony PLAYSTATION(R)3 Controller'
Joystick 0 is not a game controller
Joystick 0 Axes 04 / Buttons 19 / Hats 00 / Balls 00
Joystick 0 Instance id 0
Joystick 0 Guid 050000004c0500006802000000000000
SDL_GameControllerOpen failed: Couldn't find mapping for device (0)
Opening joystick with old SDL joystick API
Opened joystick device index 0 (Sony PLAYSTATION(R)3 Controller)
        axes: 4
     buttons: 19
        hats: 0
       balls: 0
 instance id: 0
        guid: 050000004c0500006802000000000000
Sys_InitInput: 1 haptic devices detected.
Sys_InitInput: Rumble initialization OK
SDL2: Joytick hotplug supported
Waiting for joystick events. Press CTRL+C to exit.
SDL_JOYDEVICEADDED jdevice.which 00 (Sony PLAYSTATION(R)3 Controller) [DEVICE INDEX]
 Joystick 00 (Sony PLAYSTATION(R)3 Controller) in use
 Ignoring plugged-in joystick device number 00 (Sony PLAYSTATION(R)3 Controller)
Sys_InitInput: 1 haptic devices detected.
Sys_InitInput: Rumble initialization OK
Joystick   00 button 16 state 1
Joystick   00 button 16 state 0

@emuele I got it semi working. The only issue is when I execute gptokey it does not auto detect the controller when wireless. I have to connect it via the cable and disconnect it for it to get the SDL_CONTROLLERDEVICEADDED event to fire and add the controller. What if the event was manually called on startup of gptokeyb? That may fix the issue.

I also need the following added to gamecontrollerdb.txt see below:

050000004c0500006802000000000000,PS3 Controller,a:b14,b:b13,back:b0,dpdown:b6,dpleft:b7,dpright:b5,dpup:b4,guide:b16,leftshoulder:b10,leftstick:b1,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b11,rightstick:b2,righttrigger:b9,rightx:a2,righty:a3,start:b3,x:b15,y:b12,platform:Linux,

Ok I figured out the fix. In gptokey.cpp the function calls have to swapped around so the gamecontrollerdb.txt in the config gets called.

So the fix would be:

  if (const char* db_file = SDL_getenv("SDL_GAMECONTROLLERCONFIG_FILE")) {
    SDL_GameControllerAddMappingsFromFile(db_file);
  }

  // SDL initialization and main loop
  if (SDL_Init(SDL_INIT_GAMECONTROLLER) != 0) {
    printf("SDL_Init() failed: %s\n", SDL_GetError());
    return -1;
  }

Still gotta test it with a game but it should be correct.

UPDATE: Tested and working fine.

Also I got a gamecontrollerdb.txt which has a bunch of missing controller configs. Do you want me to organise it and send? Let me know.

So wait… you mean to tell me that you did not set up your controller while it was wireless? here is how it works:

1.- Connect controller (either by wire or wireless)
2.- Configure your controller on EmulationStation, this is very important You NEED to set up your controller in ES.
3.- Automatically it will get added to the gamecontrollerdb.txt as well as other configurations

Wired controllers and BT controllers usually have different GUID which is why for you it only works wired, since I assume you never configure the controller while wireless, which is why it is not in the gamecontrollerdb.txt

The gamecontrollerdb.txt gets auto populated. But if you wish to add your controller to it, is better to do it upstream on the sdlGameControllerDB Github.

As for the gptokeyb changes I have asked lethal_guitar to review it as he knows a lot more about the code than me.

Oh, well setting up the controller was no issue, as emulationstation auto detects it wirelessly just fine. I did not know you had to re-configure by unplugging the configuring again when it connects via BT.

However when launching gptokeyb it was not auto-detecting as it is pointing to the wrong gamecontrollerbd.txt be default (since it was called after the SDL initialization ). It should point too:
/storage/.config/SDL-GameControllerDB/gamecontrollerdb.txt
AND NOT
/usr/config/SDL-GameControllerDB/gamecontrollerdb.txt

I think the error output window in emulationstation when you get a launch game crash also might have this SDL function call ordering bug too.

I’ve tested the SDL function calls swapped and it makes it work correctly. The reason why the bug has not been picked up before, is most likely not many have used it for dolphin with controllers that werent present in the default gamecontrollerbd.txt that is in /usr/config/SDL-GameControllerDB/gamecontrollerdb.txt which is read-only.

It does not point to the second one you mentioned, at least not here, all the gamepads get added to the first path and they work fine. It even says so in your logs

Sys_InitInput: Loading /storage/.config/SDL-GameControllerDB/gamecontrollerdb.txt

SDL gets the file from the ENV variable, and unless you changed it, it ALWAYS points to the .config path, as you can see here: https://github.com/EmuELEC/EmuELEC/blob/dev/packages/sx05re/emuelec/profile.d/99-emuelec.conf#L7 not sure were you got the other path from.

EDIT: I accepted your PR either way :slight_smile: so hopefully that fixes the issue for you

The SDL initialization gets called before the path is set, thereby breaking the code. Trust me it doesnt look for the users config gamecontrollerdb.txt file by default. Hence why it never worked with my controller even though it was added to the user game controller file.

lethal_guitar mentioned the text viewer also being broken due to ordering which I noted in an earlier post.

I believe you, I guess, altho I cannot reproduce this at all, maybe because I do not have that controller. But if that PR fixes it for you, then its all set :slight_smile: