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
joy2key: new version using PySDL2 #3356
Conversation
Thanks very much for this. Will test. Much appreciated! |
It's started from scriptdir from RetroPie-Setup as it needs to work when nothing is installed. So runcommand should use the installed version, but RetroPie-Setup should use the local copy. But the installed version should always be in sync as it's installed after every update. |
scriptmodules/helpers.sh
Outdated
fi | ||
|
||
local joy2key="$(_joy2key_runcommand)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although joy2key is included as part of runcommand, and maybe this should be changed
A core helper function shouldn't rely on the runcommand module.
So this function would be better integrated into the core imho
Might be more logical if the code was handled like inifuncs.sh and archivefuncs.sh and shared between runcommand and RetroPie (but different copies). But we can do that later if needed. But it's useful to be able to run it on a start of RetroPie-Setup even if runcommand isn't installed. |
Please disregard the function location moving. Only need it to be standalone so it works without install. I will rework it later as I want to move some of our existing libraries/scripts we install such as inifuncs.sh and archivefuncs.sh and it would be logical to reorganize this at the same time. |
98f4a81
to
68b8139
Compare
OK, I added a few changes:
|
Thanks for this. Will give it a test. |
The SDL python code fails on Raspberry Pi OS buster due to the python library lacking SDL_HINT_JOYSTICK_HIDAPI and SDL_HINT_NO_SIGNAL_HANDLERS commenting the related code out makes it work. I guess it shouldn't be a big workaround if this is missing in the older module. |
Those can be guarded with a SDL version check - I assume this is with the default EDIT: actually we'd have to guard it behind the Python wrapper library check, though checking the |
This was with our RetroPie SDL 2.0.10. I like the changes. Works well so far. I think I'd prefer a longer delay when holding before repeating and faster repeat speed if that's doable. I've not really looked at the code yet. Basically so it better matches how keyboard input works. I will have a look at the code when I have more time but thanks again for all your work on this. It's definitely a big improvement. |
This can be tweaked at the top of the script by modifying |
Thanks. I'll have a play. |
This should be fixed now. I've opted for using env variables, since the SDL library might support the hint, but the wrapper might not:
|
The poll_delay setting to use JS_POLL_DELAY_DEBOUNCE is missing for SDL_JOYAXISMOTION - I added it to the PR but please rebase or adjust as needed. I think I prefer DEBOUNCE set to 250 btw. |
c0a0298
to
1cec970
Compare
Sorry I rebased my change as had the wrong wording in comment but then included the 250 increase change by accident. I'll leave it as it will be squashed but adjust the code as needed |
I wonder if the |
Also could avoid the |
I added a couple of modifications, based on the comments and testing performed
|
Looks good to me. I'm going to merge if you're happy? Thanks for this. |
I will do a test with a new install just to check the configuration is ok. |
Added a new `joy2key` implementation, using PySDL2 for joystick event handling. PySDL2 is a python module that wraps SDL2 (and other SDL libraries) using the built-in `ctypes` module. Pros: * event handling is simplified a bit, using SDL's event loop. * (subjective) the code is a bit more structured and easy to follow. * joystick handling is rewritten based on EmulationStation code, movement is smoother and scrolling is improved. * support for input repeat to improve scrolling, just keep the input pressed and scrolling continues Cons: * module is a bit larger (296 LOC vs 224 in current joy2key.py) * needs PySDL2 (which might not be packaged, see the notes below) and SDL2 * arguably, device config to keyboard event mapping is more complex (abstracted as InputDev) Notes: * availability of PySDL2 as a system package is good, but it's not standard in Debian 10 (stable) at the moment. The module is present though (as a backport) in Ubuntu 18.04 (and later) and Raspberry Pi OS (Buster). When it will be universally available, we should probably revisit the code that checks for the version and make it a hard requirement in `get_retropie_depends`, similar to `python3-pyudev`. * added PgUp/PgDown to the default parameters for `joy2key`, they are mapped in a similar fashion to EmulationStation to the shoulder buttons. This doesn't apply to Runcommand's invocation, since it uses a different set of parameters. * added a configuration option in `runcommand` for selecting the joy2key version used. Default is the SDL version (when PySDL2 is installed), with the ability to fallback to the previous version (udev based).
Looks ok on a new installation (tested on a Pi4 RPI OS Lite). |
Awesome work. Thanks. |
Added a new
joy2key
implementation, using PySDL2 for joystick event handling.PySDL2 is a python module that wraps SDL2 (and other SDL libraries) using the built-in
ctypes
module.Pros:
Cons:
Notes:
The module is present though (as a backport) in Ubuntu 18.04 (and later) and Raspberry Pi OS (Buster).
If not found at runtime, then the current
joy2key.py
is used instead and for this thejoy2keyStart
helper was modified.* in the current version ofjoy2keyStart
,joy2key
is started from$scriptdir
, the changes will make it run fromruncommand
's installation folder. Not sure if this was an oversight or on purpose.joy2key
, they are mapped in a similar fashion to EmulationStation to the shoulder buttons.