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

    {SOLVED} How to make a momentary push button that exit games and take me back to game menu ?

    Scheduled Pinned Locked Moved Help and Support
    push buttonretropiepsxscriptnewbie
    56 Posts 3 Posters 6.9k 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.
    • O
      O.M.A.A
      last edited by O.M.A.A

      Hi guys,
      I have been trying to build my ultimate ps classic using raspberry pi 3b+, the reset button, and power button all works fine, but I had difficulties in making the open button(that exit games and takes me directly to the games menu) works with many attempts.
      @mitu guided me to script created by @cyperghost (https://github.com/crcerror/ES-generic-shutdown), but I didn't understand a thing xD.
      so, is there an easy explanation for how to make that script to work ?
      Thanks ;)

      mituM 1 Reply Last reply Reply Quote 0
      • mituM
        mitu Global Moderator @O.M.A.A
        last edited by

        @O-M-A-A said in How to make a momentary push button that exit games and take me back to game menu ?:

        so, is there an easy explanation for how to make that script to work ?

        What exactly doesn't work and why do you think you need to understand the script ? Read again my reply - you just need to map the button action to execute the script with the --es-closeemu option. You don't need to use the script itself to interpret the buttons press, for that you can use the same method you used for the other buttons.
        How did you configure the power and reset buttons - did you use a script ?

        1 Reply Last reply Reply Quote 1
        • O
          O.M.A.A
          last edited by O.M.A.A

          @mitu
          I just watched ETA Prime videos on how to setup shutdown and reset button, so basically, just copying what he did.

          I tried the scripts that both of u did, and a file name: multi_switch.sh was installed, I opened it with notepad++, searching for the --es-closeemu, but no idea where can I map my gpio which is in my case GPIO 7 (pins 25 and 26).

          mituM 1 Reply Last reply Reply Quote 0
          • mituM
            mitu Global Moderator @O.M.A.A
            last edited by

            @O-M-A-A I'm not familiar with those videos, so I can't advise about that. Do you have a link to the script you used for the power and reset button actions ?

            1 Reply Last reply Reply Quote 1
            • O
              O.M.A.A
              last edited by O.M.A.A

              @mitu
              thanks for ur reply,
              here is for the shutdown button:

              #!/usr/bin/python
              import RPi.GPIO as GPIO
              import time
              import subprocess
              
              GPIO.setmode(GPIO.BOARD)
              
              # we will use the pin numbering to match the pins on the Pi, instead of the
              # GPIO pin outs (makes it easier to keep track of things)
              # use the same pin that is used for the reset button (one button to rule them all!)
              GPIO.setup(5, GPIO.IN)
              
              oldButtonState1 = True
              
              while True:
                  #grab the current button state
                  buttonState1 = GPIO.input(5)
              
                  # check to see if button has been pushed
                  if buttonState1 != oldButtonState1 and buttonState1 == False:
                      # shutdown
                      subprocess.call("shutdown -h now", shell=True,
                        stdout=subprocess.PIPE, stderr=subprocess.PIPE)
                      oldButtonState1 = buttonState1
              
                  time.sleep(.5)
              
              1 Reply Last reply Reply Quote 0
              • O
                O.M.A.A
                last edited by

                @mitu
                is it possible to just send me a file were it is already mapped and rdy to exit game on gpio 7, so I just need to drop it ?

                mituM 1 Reply Last reply Reply Quote 0
                • mituM
                  mitu Global Moderator @O.M.A.A
                  last edited by mitu

                  @O-M-A-A You'll need to add another test for GPIO7 in the while loop, check if GPIO7 is pressed and then call the multi_switch.sh script to reset the current emulator. You'll need to copy the script to /home/pi/scripts first.

                  #!/usr/bin/python
                  import RPi.GPIO as GPIO
                  import time
                  import subprocess
                  
                  GPIO.setmode(GPIO.BOARD)
                  
                  # we will use the pin numbering to match the pins on the Pi, instead of the
                  # GPIO pin outs (makes it easier to keep track of things)
                  # use the same pin that is used for the reset button (one button to rule them all!)
                  GPIO.setup(5, GPIO.IN)
                  GPIO.setup(7, GPIO.IN)
                  
                  oldButtonState1 = True
                  oldButtonState2 = True
                  
                  while True:
                      #grab the current button state
                      buttonState1 = GPIO.input(5)
                      buttonState2 = GPIO.input(7)
                  
                      # check to see if button has been pushed
                      if buttonState1 != oldButtonState1 and buttonState1 == False:
                          # shutdown
                          subprocess.call("shutdown -h now", shell=True,
                            stdout=subprocess.PIPE, stderr=subprocess.PIPE)
                          oldButtonState1 = buttonState1
                      
                      if buttonState2 != oldButtonState2 and buttonState2 == False:
                          # Reset emulator
                          subprocess.call("/home/pi/scripts/multi_switch.sh --es-closeemu", shell=True,
                            stdout=subprocess.PIPE, stderr=subprocess.PIPE)
                          oldButtonState2 = buttonState2
                    
                      time.sleep(.5)
                  
                  cyperghostC 1 Reply Last reply Reply Quote 2
                  • cyperghostC
                    cyperghost @mitu
                    last edited by cyperghost

                    @mitu Yes that's right ... but you can further utilize the script. If you use the parameters --es-pid and --rc-pid you can determine in which state the Raspberry currently is. So is ES ready booted? Is there an emulator currently running.... and then set actions for each state.

                    @O-M-A-A
                    You should get in touch with some coding

                    O 1 Reply Last reply Reply Quote 1
                    • O
                      O.M.A.A @cyperghost
                      last edited by O.M.A.A

                      @cyperghost I'm too bad with coding xD but I hope one day I get used to some of it.
                      @mitu I copied the script u posted to /home/pi/scripts,
                      so, now I have this script in this destination: /home/pi/scripts, which contains the script u posted, and another script is in this destination: /home/pi/RetroPie/scripts which is called multi_switch.sh and it contains a very long script.

                      the power on/off button still working, but I didn't understand this part (You'll need to add another test for GPIO7 in the while loop, check if GPIO7 is pressed and then call the multi_switch.sh script to reset the current emulator), which is why still exit emulator button not working yet.

                      cyperghostC 1 Reply Last reply Reply Quote 0
                      • cyperghostC
                        cyperghost @O.M.A.A
                        last edited by

                        @O-M-A-A Please perform following command
                        chmod +x /home/pi/scripts/multi_switch.sh to make it executable

                        1 Reply Last reply Reply Quote 1
                        • mituM
                          mitu Global Moderator
                          last edited by

                          In addition to what @cyperghost said, copy the multi_switch.sh script also in /home/pi/scripts - that's the script I meant to copy there, not the one you posted (and I modified).

                          O 1 Reply Last reply Reply Quote 0
                          • O
                            O.M.A.A @mitu
                            last edited by

                            @mitu @cyperghost
                            ok I will try it now

                            1 Reply Last reply Reply Quote 0
                            • O
                              O.M.A.A
                              last edited by

                              @mitu @cyperghost

                              I renamed the file in /home/pi/scripts, to multi_switch.sh as in this picture

                              1.png

                              and it contains only the script u posted:

                              2.png

                              then I executed this command : chmod +x /home/pi/scripts/multi_switch.sh

                              but still didn't work, even the power button doesn't work now.
                              not sure what's the mistake I'm doing here.

                              mituM cyperghostC 2 Replies Last reply Reply Quote 0
                              • mituM
                                mitu Global Moderator @O.M.A.A
                                last edited by mitu

                                @O-M-A-A You misunderstood the instructions - maybe I wasn't so clear.
                                You already have a script - the one your posted. Modify it and add the code I posted. In addition to the new script you have, download and put the multi_switch.sh script, which you can get from https://raw.githubusercontent.com/crcerror/ES-generic-shutdown/master/multi_switch.sh, into the /home/pi/scripts folder, then make it executable (chmod +x /home/pi/scripts/multi_switch.sh).
                                Run your original script (now modified) and see if you get the desired behavior.

                                1 Reply Last reply Reply Quote 0
                                • cyperghostC
                                  cyperghost @O.M.A.A
                                  last edited by cyperghost

                                  @O-M-A-A This does not make sense

                                  Please use command wget https://raw.githubusercontent.com/crcerror/ES-generic-shutdown/master/multi_switch.sh -O /home/pi/scripts/multi_switch.sh

                                  and then again chmod +x /home/pi/scripts/multi_switch.sh

                                  1 Reply Last reply Reply Quote 0
                                  • O
                                    O.M.A.A
                                    last edited by

                                    @mitu thank you very much for your response,
                                    I will try it now, and I hope I get it now

                                    1 Reply Last reply Reply Quote 0
                                    • O
                                      O.M.A.A
                                      last edited by

                                      @cyperghost @mitu

                                      Is this what u guys meant ?

                                      1.png

                                      shutdown.py contains the modified script, while I downloaded the multi_switch.sh and drop it this destination, then I executed this command (chmod +x /home/pi/scripts/multi_switch.sh)., the power button is working but not the exit emu button.
                                      I hope this is what u guys meant !!

                                      mituM 1 Reply Last reply Reply Quote 0
                                      • mituM
                                        mitu Global Moderator @O.M.A.A
                                        last edited by mitu

                                        @O-M-A-A said in How to make a momentary push button that exit games and take me back to game menu ?:

                                        I hope this is what u guys meant !!

                                        Not really:

                                        Run your original script (now modified) and see if you get the desired behavior.

                                        You need to run shutdown.py, not the other way around.

                                        1 Reply Last reply Reply Quote 0
                                        • O
                                          O.M.A.A
                                          last edited by

                                          @mitu
                                          the original script's name is shutdown.py, I did modified it, or what did u mean ?

                                          cyperghostC 1 Reply Last reply Reply Quote 0
                                          • cyperghostC
                                            cyperghost @O.M.A.A
                                            last edited by cyperghost

                                            @O-M-A-A How do you startup this python script? (It should be the one @mitu presented you in this posting)

                                            O 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.