Recalbox Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • recalbox.com
    • Gitlab repository
    • Documentation
    • Discord

    Exit emulator with one button press vía gpio

    GamePad/GPIO/USB encoder
    button press vía gpio
    9
    41
    16686
    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.
    • supernature2k
      supernature2k @Substring last edited by supernature2k

      @Substring try this:

      import RPi.GPIO as GPIO
      import time
      import os
      import thread
      import datetime
      import socket
      import sys
      from datetime import datetime
      from configgen import recalboxFiles
      # this last one retrieves emulators bin names
      
      IPADDR = "127.0.0.1"
      PORTNUM = 55355
      # IP and port for retroarch network commands
      
      QUIT = 3
      
      
      GPIO.setwarnings(False)		# no warnings
      GPIO.setmode(GPIO.BCM)		# set up BCM GPIO numbering 
       
      GPIO.setup(QUIT, GPIO.IN, pull_up_down=GPIO.PUD_UP)
      # GPIO on pin 3 is the GPIO 2 in BCM mode
      #to Reset+
      
        
      # Define a threaded callback function to run in another thread when events are detected  
      def button_pressed(channel):
      	
      	nwcommand="QUIT"
      	retroarch(nwcommand)
      	killthats**t(channel)
      		
      	
      #	on quit press, trying to kill all listed emus 
      def killthats**t(channel):
      	if channel == QUIT:
      		for bin in recalboxFiles.recalboxBins:
      				print bin
      				proc = os.path.basename(bin)
      				print proc
      				os.system("killall -9 "+proc)
      
      
      # 	sending network command to retroarch (only exit and reset atm)		
      def retroarch(nwcommand):
      	try:
      		s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
      	except socket.error:
      		print 'Failed to create socket'
      		sys.exit()
      	s.sendto(nwcommand, (IPADDR, PORTNUM))
      		
      
      GPIO.add_event_detect(QUIT, GPIO.BOTH, callback=button_pressed, bouncetime=2)
      while True:
      	time.sleep(0.2)
      

      Pi powered NES | Gameboy HD | RecalStation | RecalDrive
      Upvote messages if it has been useful ;)

      sevenx 1 Reply Last reply Reply Quote 0
      • sevenx
        sevenx @supernature2k last edited by

        @supernature2k
        Does this automaticly start ES again after killing the Emulator?

        supernature2k 1 Reply Last reply Reply Quote 0
        • supernature2k
          supernature2k @sevenx last edited by

          @sevenx no as ES is not killed when you launch an emu

          Pi powered NES | Gameboy HD | RecalStation | RecalDrive
          Upvote messages if it has been useful ;)

          sevenx 1 Reply Last reply Reply Quote 0
          • sevenx
            sevenx @supernature2k last edited by

            @supernature2k
            Do you have some time, to talk about a new project from me? Over PM?

            supernature2k 1 Reply Last reply Reply Quote 0
            • supernature2k
              supernature2k @sevenx last edited by

              @sevenx ok

              Pi powered NES | Gameboy HD | RecalStation | RecalDrive
              Upvote messages if it has been useful ;)

              1 Reply Last reply Reply Quote 0
              • lackyluuk
                lackyluuk Translator last edited by

                @8bit_astronaut maybe this article I wrote some time ago can help. I use the script to reset the emulator. But with replacing the RESET with QUIT you should be able to quit it and return to ES.

                https://github.com/recalbox/recalbox-os/wiki/Emulator-interactions-via-GPIO-mapping-(EN)

                NintendoRS | Nintendo Adapter Box | Cardboard Recalbox

                8bit_astronaut 2 Replies Last reply Reply Quote 0
                • 8bit_astronaut
                  8bit_astronaut @lackyluuk last edited by

                  @lackyluuk that looks great! Ill check it in a moment, thank you so much!

                  1 Reply Last reply Reply Quote 0
                  • 8bit_astronaut
                    8bit_astronaut @lackyluuk last edited by

                    @lackyluuk its necesary to have an internet conection for recalbox???

                    DjLeChuck 1 Reply Last reply Reply Quote 0
                    • lackyluuk
                      lackyluuk Translator last edited by

                      @8bit_astronaut No, I think it should also work without. But it is highly recommended 🙂

                      NintendoRS | Nintendo Adapter Box | Cardboard Recalbox

                      1 Reply Last reply Reply Quote 0
                      • DjLeChuck
                        DjLeChuck @8bit_astronaut last edited by

                        @8bit_astronaut Not at all. The internet connection is only useful for scraping directly with your recalbox or for accessing you share folder through your network.

                        1 Reply Last reply Reply Quote 0
                        • sevenx
                          sevenx last edited by sevenx

                          maybe?

                          exit-emu-1b-installer:
                          http://webcache.googleusercontent.com/search?q=cache:https://gist.github.com/Phantiss/3e0cab70f7084431e1c389d633e53662

                          rpi-exit-emu-1b .py
                          http://webcache.googleusercontent.com/search?q=cache:https://gist.github.com/Phantiss/b9248718a208e293d332feed0a9cbc27

                          S98exit-emu-1b
                          http://webcache.googleusercontent.com/search?q=cache:https://gist.github.com/Phantiss/813037bfd7c9d22a3cd2887714463eda

                          DjLeChuck 1 Reply Last reply Reply Quote 0
                          • DjLeChuck
                            DjLeChuck @sevenx last edited by

                            @sevenx Haha nice! I update the wiki page and links.

                            DjLeChuck 1 Reply Last reply Reply Quote 0
                            • DjLeChuck
                              DjLeChuck @DjLeChuck last edited by DjLeChuck

                              Wiki updated! https://github.com/recalbox/recalbox-os/wiki/Enable-Gpio-button-to-close-emulator-with-only-one-button-press

                              1 Reply Last reply Reply Quote 0
                              • supernature2k
                                supernature2k last edited by

                                I think my script is betta (btw, I corrected this RESET instead of QUIT):

                                • sending network command to retroarch is better
                                • using sub's list of emulator bins is better (no need to modify script if new emus implemented)

                                Pi powered NES | Gameboy HD | RecalStation | RecalDrive
                                Upvote messages if it has been useful ;)

                                DjLeChuck 1 Reply Last reply Reply Quote 0
                                • DjLeChuck
                                  DjLeChuck @supernature2k last edited by

                                  @supernature2k Can you update the wiki this way? 🙂

                                  1 Reply Last reply Reply Quote 0
                                  • lackyluuk
                                    lackyluuk Translator last edited by lackyluuk

                                    @DjLeChuck We could include @supernature2k s script into the article i posted above. This article is in general about interacting with emulators through the retroarch network commands. Instead of having multiple articles spreaded around we could have all in the same place. What do you think?

                                    NintendoRS | Nintendo Adapter Box | Cardboard Recalbox

                                    DjLeChuck 1 Reply Last reply Reply Quote 0
                                    • DjLeChuck
                                      DjLeChuck @lackyluuk last edited by

                                      @lackyluuk Obviously you're right! My intention was only to restore the deleted page, but if we can removed it and say "Go on this page it's better!" I'm OK. 🙂

                                      1 Reply Last reply Reply Quote 0
                                      • lackyluuk
                                        lackyluuk Translator last edited by

                                        @DjLeChuck I only try to keep the articles in a clean way to prevent confiusion so that many question can be answered 🙂 ( I also want to write / change an article for the right image installation, because lot of people have problems with it 😞 )

                                        If someone can confirm that @supernature2k s script is working like this above, then I can try to implement this in a proper way 🙂

                                        NintendoRS | Nintendo Adapter Box | Cardboard Recalbox

                                        1 Reply Last reply Reply Quote 0
                                        • Substring
                                          Substring last edited by

                                          @supernature2k's script still requires a "better integration" to work in recalbox (he knows what i expect from him). The idea i'd love is to have a confg file saying :

                                          [GPIO26]
                                          action=stopEmulators
                                          [GPIO25]
                                          action=shutdownSystem
                                          

                                          such a thing
                                          I find it pointless to cumulate python scripts to handle GPIO when all should be gathered into 1 single place

                                          Former dev - Please reply with @substring so that i am notified when you answer me
                                          Ex dev - Merci de me répondre en utilisant @substring pour que je sois notifé

                                          8bit_astronaut 1 Reply Last reply Reply Quote 0
                                          • 8bit_astronaut
                                            8bit_astronaut last edited by

                                            Thank you everyone for all your help!
                                            Well, to be fair i dont have internet in my house, just internet in my phone (bring independiente sucks....)
                                            So...i want to know...is there a way to use The script without internet?

                                            Some says that The script doesnt use WiFi, and others says that it uses....

                                            So...maybe is there an option?

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

                                            Want to support us ?

                                            82
                                            Online

                                            99.6k
                                            Users

                                            28.1k
                                            Topics

                                            187.1k
                                            Posts

                                            Copyright © 2021 recalbox.com