RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login
    Please do not post a support request without first reading and following the advice in https://retropie.org.uk/forum/topic/3/read-this-first

    Launching Emulationstation with a gamepad (Logitech F310) button and through SSH... to screen!

    Scheduled Pinned Locked Moved Help and Support
    sshlogitech f310bashautostart
    7 Posts 1 Posters 700 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      k3001993
      last edited by k3001993

      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 to chmod +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 we grep 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.

      1 Reply Last reply Reply Quote 0
      • K
        k3001993
        last edited by

        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:
        
        1 Reply Last reply Reply Quote 0
        • K
          k3001993
          last edited by

          This might be the solution, I'll try tomorrow.

          1 Reply Last reply Reply Quote 0
          • K
            k3001993
            last edited by

            Yes! I made it!
            That was what I wanted.

            I moved my script to /usr/bin/ for easy path execution and renamed it to just retropie.

            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 starts emulationstation. 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 all emulationstation 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 real retropie script locally.
            1 Reply Last reply Reply Quote 0
            • K
              k3001993
              last edited by k3001993

              This post is deleted!
              1 Reply Last reply Reply Quote 0
              • K
                k3001993
                last edited by

                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.
                The retropie script is just used to call to the real script, which is now called gamepad.

                1. nano /usr/bin/retropie
                #!/bin/bash
                killall gamepad >> /dev/null 2>&1
                killall emulationstation >> /dev/null 2>&1
                bash -c "gamepad"
                
                1. nano /etc/xdg/lxsession/LXDE-pi/autostart
                @lxterminal --command="retropie"
                
                1. 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 runs gamepad but locally. I didn't manage to hide the terminal. Maybe tomorrow?

                1 Reply Last reply Reply Quote 0
                • K
                  k3001993
                  last edited by

                  If you don't want to use the line ssh pi@raspberrypi.local 'DISPLAY=:0 retropie' and still want to run my retropie script through SSH but NOT inside your established connection, then:

                  Do nano /usr/bin/retropie or nano /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.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post

                  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.