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

    Modify Power Button Behaviour to 'Hold for three seconds'??

    Scheduled Pinned Locked Moved ControlBlock, PowerBlock & Co.
    retropieshutdownpythonscriptdelay
    3 Posts 2 Posters 739 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.
    • C
      Chillimonster
      last edited by

      Im using the following shutdown script, but its susceptible to false triggers (Or shutdown if you catch the button etc)

      Is there a way to make it wait until the button has been pressed for a period of time (Say three seconds)

      I'm running Retropi 4.4 on a Pi3B+

      **#!/bin/python
      
      import RPi.GPIO as GPIO
      import time
      import os
      
      #gpio_pin_number=YOUR_CHOSEN_GPIO_NUMBER_HERE
      #Replace YOUR_CHOSEN_GPIO_NUMBER_HERE with the GPIO pin number you wish to use
      #Make sure you know which rapsberry pi revision you are using first
      #The line should look something like this e.g. "gpio_pin_number=7"
      
      GPIO.setmode(GPIO.BCM)
      
      GPIO.setup(3, GPIO.IN, pull_up_down = GPIO.PUD_UP)
      
      def Shutdown(channel):
      	os.system("sudo systemctl poweroff")
      	
      GPIO.add_event_detect(3, GPIO.FALLING, callback = Shutdown, bouncetime = 2000)
      while 1:
      	time.sleep(5)
      	
      GPIO.cleanup()
      #Revert all GPIO pins to their normal states (i.e. input = safe)**
      
      1 Reply Last reply Reply Quote 0
      • mituM
        mitu Global Moderator
        last edited by

        You can increase the bouncetime from 2sec to something larger.

        C 1 Reply Last reply Reply Quote 0
        • C
          Chillimonster @mitu
          last edited by

          @mitu said in Modify Power Button Behaviour to 'Hold for three seconds'??:

          You can increase the bouncetime from 2sec to something larger.

          Even as it is now, just a single quick push will shut the software down - i dont have to hold the button at all.

          Perhaps I need to use a different script that relies on the button being held.

          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.