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

    Can someone modify this script and add a system restart script with it ;)

    Scheduled Pinned Locked Moved Help and Support
    push buttonretropiescript requestrestart
    2 Posts 2 Posters 401 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

      Hi guys,

      I'm trying to make 3 buttons on my retropie console, I have already made 2 buttons: these are shutdown button, and reset button that exit emulator.

      Here is the script that was used for these 2 buttons ( Thanks to @mitu and @cyperghost ) :

      #!/usr/bin/python
      import RPi.GPIO as GPIO
      import time
      import subprocess
      
      GPIO.setmode(GPIO.BOARD)
      
      shutdownPin=5
      resetPin=3
      
      GPIO.setup(shutdownPin, GPIO.IN)
      GPIO.setup(resetPin, GPIO.IN)
      
      oldButtonState1 = True
      
      while True:
          #grab the current button state
          buttonState1 = GPIO.input(shutdownPin)
          buttonState2 = GPIO.input(resetPin)
      
          # 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 not buttonState2:
              # Reset emulator
              print "Reset pressed"
              subprocess.call("/home/pi/scripts/multi_switch.sh --es-closeemu", shell=True,
                stdout=subprocess.PIPE, stderr=subprocess.PIPE)
      
          time.sleep(.3)
      

      I want to add to it a restart button that restart the system. Thanks in advance ;)

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

        Seems like you know just enough to be dangerous 😜
        You can copy and modify your Button1 code, just use "shutdown -r now" instead.

        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.