RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login

    Is there a "best practice" for safe shutdown with a phy.button? And ...

    Scheduled Pinned Locked Moved General Discussion and Gaming
    shutdownbutton
    5 Posts 3 Posters 339 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.
    • top-specciT
      top-specci
      last edited by

      Hi,
      I google a lot and found lot of discussions and "solutions" (Threads, youtube-videos, scripts at Github, ...),
      but often they are older or not "good" (not stopping emulatorstation and possible data lose (gamelist.xml ...).

      Is there an actuall "best practice" what is prefered and "working" ?

      I plan to use a physical button to shutdown the Retropie.

      When the button is pressed for longer than 3 seconds:

      • Emulatorstation should be stopped correctly
      • A short Shutdown-sound should be played
      • Shutdown-picture should be displayed for 2 seconds
      • RetroPie should be going down

      Thats all ;-)

      Thanks for usefull hints and tipps,
      Martin

      mituM WeirdHW 2 Replies Last reply Reply Quote 0
      • mituM
        mitu Global Moderator @top-specci
        last edited by

        @top-specci said in Is there a "best practice" for safe shutdown with a phy.button? And ...:

        Is there an actuall "best practice" what is prefered and "working" ?

        Make sure that any emulators are stopped first, then EmulationStation is stopped and then you can order the shutdown of the system.

        1 Reply Last reply Reply Quote 0
        • WeirdHW
          WeirdH @top-specci
          last edited by

          @top-specci I use this one. It is super versatile and does all the proper quitting that Emulationstation needs to not lose metadata and such.

          Granted, there is a bit of reading up and fiddling around involved, but I now have a dedicated button (hooked up to some GPIO pins) that does a beautiful and clean shutdown.

          1 Reply Last reply Reply Quote 0
          • top-specciT
            top-specci
            last edited by top-specci

            Issue solved, see my next post

            Hi,
            I had now create a "mix" from several ideas from the web, seems to work ... but ...

            On one Pi it's working fine,
            On the other Pi (for me totally unclear), the restart from the "emulatorstation" will not be executed when the script was started from cron. When start the script on shell, everything is working.
            I check also the rights from folder and files.

            Also when started from cron: If I replace the line were the emulatortastation should be started again with a test line (showing an background-image), the image is shown! So the script is running fine, but why will emulatorstation not started?
            Any ideas?
            ( I also add the full path to: os.system("/usr/bin/emulatorstation"), did not help )

            Hint: Short push (0.8s) will restart the emulatorstation, longer pushing the button will shutdown the Pi.

             #!/usr/bin/env python
            import time
            import os
            import RPi.GPIO as GPIO
            
            switch = 5   #  GPIO-Pin Number!
            delay = 0.8
            debounce = 0.2
            
            GPIO.setwarnings(False)
            GPIO.setmode (GPIO.BOARD)
            GPIO.setup(switch,GPIO.IN,pull_up_down = GPIO.PUD_UP)
            
            while True:
               if GPIO.input(switch) == 0 :
                  time.sleep(debounce)
                  start_time = time.time()
                  while GPIO.input(switch) == 0 :
                     if time.time() - start_time > delay - debounce:
                        time.sleep(0.5)
                        os.system ("sudo fbi -T 1 -noverbose /home/pi/shutdown.png")
                        time.sleep(1.2)
                        if GPIO.input(switch) == 0 :
                           os.system ("sudo fbi -T 1 -noverbose /home/pi/shutdown-now.png")
                           time.sleep(2.0)
                           os.system ("sudo shutdown -h 0")
                        else:
                           time.sleep(1)
                           os.system("emulationstation")
                           # os.system ("sudo fbi -T 1 -noverbose /home/pi/restart.png") # Testline!
                           time.sleep(1)
               else:
                  time.sleep(debounce)
            
            1 Reply Last reply Reply Quote 0
            • top-specciT
              top-specci
              last edited by top-specci

              Argggh,
              found the reason for the problem written before:
              I add the cron for user "root", this is incorrect! Must be for user pi !
              root user is not allowed to start "emulatorstation".

              @reboot /usr/bin/python /home/pi/mshutdown.py 
              
              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.