Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some buttons in USB controllers won't emit signal #80

Open
protoman opened this issue Nov 19, 2017 · 20 comments
Open

Some buttons in USB controllers won't emit signal #80

protoman opened this issue Nov 19, 2017 · 20 comments

Comments

@protoman
Copy link

In SDL configuration menu, I can map all the buttons fine, they are all detected.
But when I start my game, some buttons won't emit event and I can't use them.

Relevant configuration:

AppUsesSecondJoystick=n

RedefinedKeys="NO_REMAP NO_REMAP NO_REMAP NO_REMAP NO_REMAP ESCAPE NO_REMAP"

AppTouchscreenKeyboardKeysAmount=5

RedefinedKeysScreenKb="X A Z C RETURN W"

RedefinedKeysScreenKbNames="JUMP FIRE SHIELD DASH START R"

# Redefine gamepad keys to SDL keysyms, button order is:
# A B X Y L1 R1 L2 R2 LThumb RThumb Start Select Up Down Left Right
RedefinedKeysGamepad="X A Z C Q W E R T Y RETURN HOME UP DOWN LEFT RIGHT"
FloatingScreenJoystick=n

When I plug my PS4 Controller, buttons CIRCLE and R1 won't give any events. The code that reads input is like:
while (true) { // keep reading until a key is found while (SDL_PollEvent(&event)) { __android_log_print(ANDROID_LOG_INFO, "###ROCKBOT###", "### INPUT::pick_key_or_button - event.type[%d] ###", (int)event.type);

This not never executes for those keys. I've also tested with a PS2 controller and got same problem, and a user reported that by using one of those "clip" controllers on his tablet, he also can't use a few buttons.

@protoman
Copy link
Author

I am trying to debug this and I think I've found the cause, even if I still don't know exactly how to fix.
So, first the code for the buttons that didn't work in TranslateKeyGamepad are 98 and 101. So I've looked upon SDL_android_gamepad_keymap variable and added logs into SDL_ANDROID_SetIndividualGamepadKeymap, and the parameter values are (in same order as the method signature): [120][97][118][98][113][119][101][114][116][121][13][278][273][274][276][275]

So, we have in the values both 98 and 101 (Y and L2), that is great but....
The map actually don't use those values, but rather KEYCODE_BUTTON_Y that is 100, KEYCODE_BUTTON_1 that is 188 and KEYCODE_BUTTON_L2 that is 104, KEYCODE_BUTTON_7 that is 194.

So, the problem is that TranslateKeyGamepad is trying to get from the array using the key value and not the index for the equivalent key... yeah, I got lost here :-(

@protoman
Copy link
Author

protoman commented Nov 21, 2017

OH, I found it :)
C and Z do not exist, they also do not exist on any gamepad I've seen (PS3/XBox/SHIELD)

KEYCODE_BUTTON_Z = 101,
KEYCODE_BUTTON_C = 98,

I tried to fix that and add the two buttons, but I was unable without spending a lot of time to change the defines for the keys, and when I got into that part I was aware of breaking things for not knowing what I was doing.

@pelya
Copy link
Owner

pelya commented Nov 21, 2017 via email

@protoman
Copy link
Author

protoman commented Nov 21, 2017 via email

@pelya
Copy link
Owner

pelya commented Nov 21, 2017 via email

@protoman
Copy link
Author

protoman commented Nov 21, 2017 via email

@pelya
Copy link
Owner

pelya commented Nov 21, 2017 via email

@protoman
Copy link
Author

protoman commented Nov 21, 2017 via email

@pelya
Copy link
Owner

pelya commented Nov 22, 2017 via email

@protoman
Copy link
Author

protoman commented Nov 22, 2017 via email

@protoman
Copy link
Author

protoman commented Nov 22, 2017 via email

@pelya
Copy link
Owner

pelya commented Nov 22, 2017 via email

@tbaker4802
Copy link

tbaker4802 commented Nov 22, 2017 via email

@protoman
Copy link
Author

protoman commented Nov 22, 2017 via email

@pelya
Copy link
Owner

pelya commented Nov 22, 2017 via email

@protoman
Copy link
Author

I will give a try later today.
Yesterday I made a very similar change that didn't solve the issue, but I noticed you made further changes before this, to add more keys, so lets see; I'll let you know.

BTW, I made a few methods to add achievements into the game. Once I have the time to separate it into its own class, I'll make a push. I hadn't submited before because it had a freeze problem, but it seems I solved by using runOnUiThread on the calls in the Java code.

@protoman
Copy link
Author

protoman commented Nov 22, 2017

The fix "works" in the sense that buttons work, but it actually makes two buttons as one. So, in dualshock4, Circle ans X are not the same thing (A in the case of my configuration).
I will give a try and implement a full-fledged fix, it just will take time, as I'm not familiar with all your code (mostly the #define key stuff is hard as one define uses another one in some point) and I don't have much free time, but it will be better just add two more buttons.

@protoman
Copy link
Author

protoman commented Nov 23, 2017

Got the buttons working, but something strange happened. I don't know if was my change or yours, because I made my changes after executing a git pull, but now the digital d-pad won't work anymore and the dualshock4 LED is turned off after I plug it in. I can get the analog working, but it is not really the best for playing this kind of game. Tomorrow I try to figure out what made the d-pad stop working by looking at your commits and my changes.

My config is:
RedefinedKeysGamepad="X A Z C 4 5 Q R 8 9 j k RETURN HOME UP DOWN LEFT RIGHT PAGEUP PAGEDOWN HOME END PLUS MINUS LEFTBRACKET RIGHTBRACKET"

Diff of my changes (sorry about not being cleaned, it is late of the night here in Brazil right now):
http://rockbot.upperland.net/files/diff_changes_joystick.txt

@protoman
Copy link
Author

I got the d-pad working by adding back the dpadx checkm that you removed when adding thumbs, into the code.
But one thing I noticed is that both touch buttons as gamepad sends key.which as zero. Ideally, it would be better to use distinct values, so the programmer can know from where the input is coming. The reason is that my game have an option to map custom buttons, but this makes the on-screen joystick not work anymore if I map the buttons to something else. The easiest fix for that would be to use default keys when the input comes from on-screen keyboard, and custom ones when it comes from anything else. But, as it seems a good bunch of work to add this into your code, as I would have to add an extra parameter to all SDL_ANDROID_MainThreadPushKeyboardKey() calls, the other option would be to just change, from my game, the key-mapping for the touch-joystick also.

I will see what I can do about that...

@pelya
Copy link
Owner

pelya commented Nov 25, 2017 via email

@protoman
Copy link
Author

I made the whole fix, including sending key.witch as 0 for touch and 1 for gamepad/other inputs, so the developer can deal with those differently if he wants. In my case, I use default keys for input 0 and use custom ones for input 1.

As soon as I can, I will clean-up the code and make a pull-request; I am very busy this week with some real-life stuff :)
I also will create pull-requests to add achievements and another to fix volume with Amiga-MOD files in SDL_mixer - see here: https://discourse.libsdl.org/t/sdl-mixer-playing-a-mod-file-changes-music-volume/18252/3 - once I test it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants