Launching Emulationstation with a gamepad (Logitech F310) button and through SSH... to screen!
-
This is gonna be an epic journey, guys. ANY help is welcome. If you can't help, then I hope you learn something. If that's the case, nice!
TL;DR I want to be able to launch RetroPie when pressing a gamepad button and bring that process to on-screen automatically through SSH.
So my Raspberry has a 7 inch touchscreen directly attached through the DSI connection.
Things I have achieved building my ultimate gaming station:- Launch a web browser on startup on full screen.
- Get the cursor to disappear after 1 second of idling.
- Map correctly a Logitech F310, including the analog sticks (only tested with lr-pcsx-rearmed aka Playstation). This one was hard AF.
- Open emulationstation directly on screen when pressing the central button of my gamepad.
Things I have not achieved yet:
- Establish the hotkey+X combination to open RetroArch config.
- Unpause a game that has been paused (I know the default keyboard button is P, but still doesn't work).
- Open emulationstation directly on screen when pressing the central button of my gamepad through SSH.
Ok, so, to make this possible we need a script to listen to gamepad events such as, pressing the button.
This script will be mentioned as
./script.sh
from now on. Don't forget tochmod +x ./script.sh
if you want to follow along.#!/bin/bash while true; do jstest --event /dev/input/js0 | grep -m 1 "type 1, time .*, number 8, value 1" killall emulationstation emulationstation done
What this script does is really simple. It uses
jstest
to listen for gamepad events, then wegrep
the type 1 (aka button has been pressed) and the number 8 (central button of my gamepad). This makes the script only go forward when the button 8 is pressed. Then it kills all emulationstation processes just because we don't want any duplicates, then starts a new one.The script sends our emulator to our connected screen, but it should not matter how or from where we execute the script, right?
Also, running the listener script in the background at startup is not our problem either. Just use /etc/xdg/lxsession/LXDE-pi/autostart.
@lxterminal --command [COMMAND]
or@lxterminal -e [PROGRAM]
work like a charm.But ultimately, we want to be able to lauch the
./script.sh
through SSH. This is where the pain starts. If we launch the script, it will launch in our SSH shell (a black screen is all you'll get). How can we launch this explicitly on a new terminal in front of whatever we have on-screen if we launch it through SSH?Thanks.
-
I have found a possible way, using
lxterminal
. But this is what I get when using it through SSH:Unable to init server: Could not connect: Connection refused (lxterminal:1445): Gtk-WARNING **: 01:29:40.705: cannot open display:
-
This might be the solution, I'll try tomorrow.
-
Yes! I made it!
That was what I wanted.I moved my script to
/usr/bin/
for easy path execution and renamed it to justretropie
.So if I do
ssh pi@raspberrypi.local 'DISPLAY=:0 retropie'
, my script opens and waits for me to press the central button of my gamepad, then it startsemulationstation
. Success!I'm already thinking about how to make it even better because I found this particular issue:
- This
retropie
script keeps open in our SSH shell so if you press the button again, it kills allemulationstation
processes and starts one again (aka restart). We might want to make a simple script to be executed once, only for SSH execution, that executes the realretropie
script locally.
- This
-
This post is deleted! -
I'm ending it here for now. Posting here all commands and configs I made in order to make it work:
Moved
Downloads/gamepad.sh
to/usr/bin/gamepad
for even more easy path execution.
Theretropie
script is just used to call to the real script, which is now calledgamepad
.nano /usr/bin/retropie
#!/bin/bash killall gamepad >> /dev/null 2>&1 killall emulationstation >> /dev/null 2>&1 bash -c "gamepad"
nano /etc/xdg/lxsession/LXDE-pi/autostart
@lxterminal --command="retropie"
nano /usr/bin/gamepad
#!/bin/bash export TERM="xterm-256color" while true; do jstest --event /dev/input/js0 | grep -m 1 "type 1, time .*, number 8, value 1" >> /dev/null 2>&1 killall emulationstation >> /dev/null 2>&1 emulationstation done
Wrapping up: Running
ssh pi@raspberrypi.local 'DISPLAY=:0 retropie'
actually runsgamepad
but locally. I didn't manage to hide the terminal. Maybe tomorrow? -
If you don't want to use the line
ssh pi@raspberrypi.local 'DISPLAY=:0 retropie'
and still want to run myretropie
script through SSH but NOT inside your established connection, then:Do
nano /usr/bin/retropie
ornano /usr/bin/gamepad
And add this line below #!/bin/bash or wherever it works for you.
export DISPLAY=:0
Sometimes
emulationstation
crashes but I don't want to go that deep.My job is completely done here. Have fun and stay safe.
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.