[How-To] Browse the bash history with a game controller
-
Hi folks,
edit: Dirty hack deleted that broke controller support in other menus. Read the next post from @meleu for a clean and working solution. π
Cheers
Clyde -
@clyde I may be wrong, but I think the way you're doing can possibly bring some problems like not launching
joy2key.py
properly in later instances ofretropie_setup.sh
(or any otherjoy2key
client).My untested suggestion
Add this to your
.bashrc
(not your.profile
):export scriptdir="$HOME/RetroPie-Setup" source "$HOME/RetroPie-Setup/scriptmodules/helpers.sh" joy2keyStart
And add this to your
.bash_logout
(create the file if it doesn't exist):joy2keyStop
Explaining
No parameters to
joy2keyStart
will use the default ones:
/dev/input/jsX kcub1 kcuf1 kcuu1 kcud1 0x0a 0x20
.Advantage/difference from your approach:
jsX
: means every connected controller (not onlyjs0
orjs4
, for example)0x20
(the last argument) means<space>
, and your approach is using0x9
, meaning<tab>
. I think it's not an issue for your goal, right?
Also, adding
joy2keyStop
to your.bash_logout
will stopjoy2key.py
when you log out from a subshell, making it "sensible" to new joysticks [dis]connections on later instancesjoy2key.py
. -
@clyde It is a real cool idea but this one has it's pitfalls. There are wonderfull commands. like
history | tail -n50
This hinders direct access to .bash_rc file ;) -
First and foremost, thank you very much for your help.
@meleu said in [How-To] Browse the bash history with a game controller:
@clyde I may be wrong, but I think the way you're doing can possibly bring some problems like not launching
joy2key.py
properly in later instances ofretropie_setup.sh
(or any otherjoy2key
client).Why is that? Just curious and willing to learn.
Add this to your
.bashrc
(not your.profile
):source "$HOME/RetroPie-Setup/scriptmodules/helpers.sh" joy2keyStart
Alas, this doesn't work and gives me the error
-bash: /scriptmodules/supplementary/runcommand/joy2key.py: no such file or directory
.Advantage/difference from your approach:
jsX
: means every connected controller (not onlyjs0
orjs4
, for example)
Ah, I wondered about the
jsX
and I thought this would only work from within a script.0x20
(the last argument) means<space>
, and your approach is using0x9
, meaning<tab>
. I think it's not an issue for your goal, right?
Right, I just copied the line from
runcommand.sh
. π -
@clyde said in [How-To] Browse the bash history with a game controller:
Why is that? Just curious and willing to learn.
Try it yourself. Just start the command
/opt/retropie/supplementary/runcommand/joy2key.py /dev/input/js0 kcub1 kcuf1 kcuu1 kcud1 0x0a 0x09 &
twice and you see you will do two inputs at once.Start it three times, you will make three hops... and so on.
-
@clyde said in [How-To] Browse the bash history with a game controller:
@meleu said in [How-To] Browse the bash history with a game controller:
@clyde I may be wrong, but I think the way you're doing can possibly bring some problems like not launching
joy2key.py
properly in later instances ofretropie_setup.sh
(or any otherjoy2key
client).Why is that? Just curious and willing to learn.
A test confirmed your concerns. With my approach, my controller doesn't work in
retropie_setup.sh
anymore. I watched the instances ofjoy2key
in htop: One instance is created at boot, another one when I exit ES to the shell. Both remain even when I exit the shell back to ES. Subsequent visits to the shell don't increase the number ofjoy2key
instances any further. Startingretropie_setup.sh
from ES Retropie menu kills the second instance (judging by its pid), but the remaining instance don't work in the setup's menu. Just mentioned for your information.I still would like to know the why behind it, though. π
edit:
@cyperghost: My post collided with yours. I still wonder why multiple instances ofjoy2key
can't coexist together, especially if they are mapped to the same keys. I just lack the knowledge about the internals of the Linux input system. -
@clyde They can coexists together but not if they use the same joystick number js{0...9}. But it is in general not a good programming style if you let called processes be in the wild. So you catch it's PID via
$!
routine -
@Clyde So see your attempt as first try we can to some evolution on the hop ;)
1. Try to call joy2key
call background processes and forget to terminate them
You see the results it can cause in your script
2. Try to call joy2key
call background process, and terminate it's process by nane - after there i no need of it. So you make your call with joy2key, and just use
pkill -f joy2key
That's a shotgun, all processes which are called joy2key are terminated. Easy and works in most situations ;)
3. Try to call joy2key
call background process, catch it's process ID and terminate it - after there i no need of it. Catch it's PID with
$!
command and then kill this one PIDMuch better isn't it? So you can avoid answer people do like .... your script causes this and that...
4. Try to call joy2key
function start_joy(){ "$ROOTDIR/supplementary/runcommand/joy2key.py" js0 kcub1 kcuf1 kcuu1 kcud1 0x0a 0x09 & JOY2KEY_PID=$! } function end_joy(){ if [[ -n "$JOY2KEY_PID" ]]; then kill -INT JOY2KEY_PID fi }
So we have funtion calls, and catch PID but still have only one joystick in action... We can do that better?
5. Try to call joy2key
function start_joy(){ local joy_find; local i joy_find=$(find /dev/input/js?) for i in ${joy_find[@]}; do "$ROOTDIR/supplementary/runcommand/joy2key.py" "$i" kcub1 kcuf1 kcuu1 kcud1 0x0a 0x09 & JOY2KEY_PID+=("$!") done } function end_joy(){ if [[ -n "$JOY2KEY_PID" ]]; then kill -INT "${JOY2KEY_PID[@]}" fi }
Much better all instances of js{...} are called but we have multiple instances of joy2script running (but each sessions is assigned to only one joypad) but this works very good but is waste of resources .... but we are 80% done and understood how to call functions and how to create arrays in bash ;)
BTW: the use of
find
here is very unprofessional. You must take care of word splitting. So the answer if someone asks why you did you do that this way, the only smart anwer is: I know what I'm doing ;)6. Try to get joy2key running
readonly JOY2KEY_SCRIPTLOC="$HOME/RetroPie-Setup/scriptmodules/helpers.sh" readonly CONFIG=(kcub1 kcuf1 kcuu1 kcud1 0x0a kf10 0x20 kf9) source "$JOY2KEY_SCRIPTLOC" scriptdir="$HOME/RetroPie-Setup" # We call the script with connected Joypads only, you can leave array CONFIG empty then you will use default... joy2keyStart ${CONFIG[@]} # Do here your actions # ...... joy2keyStop # Terminate joy2key python script
That's the professional way and it's much easier to use in your code ;)
Enjoy ;)
-
@clyde said in [How-To] Browse the bash history with a game controller:
First and foremost, thank you very much for your help.
@meleu said in [How-To] Browse the bash history with a game controller:
@clyde I may be wrong, but I think the way you're doing can possibly bring some problems like not launching
joy2key.py
properly in later instances ofretropie_setup.sh
(or any otherjoy2key
client).Why is that? Just curious and willing to learn.
because
runcommand.sh
andretropie_setup.sh
always check if there's an instance ofjoy2key.py
running before launching it.Add this to your
.bashrc
(not your.profile
):source "$HOME/RetroPie-Setup/scriptmodules/helpers.sh" joy2keyStart
Alas, this doesn't work and gives me the error
-bash: /scriptmodules/supplementary/runcommand/joy2key.py: no such file or directory
.whoops! I missed a detail, the first line below.
export scriptdir="$HOME/RetroPie-Setup" source "$HOME/RetroPie-Setup/scriptmodules/helpers.sh" joy2keyStart
Edited my previous post accordingly.
-
@meleu Yes the litte export ;)
-
@meleu @cyperghost The export did the trick. It works now and doesn't break the other menu controls. π Thank you for all the effort and explanations. I learned a lot today, as may others who stumble upon this thread, too.
I edited my opening post to a mere reference to @meleu's solution. π
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.