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

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



  • 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)**
    


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



  • @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.


 

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.