Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added 3 seconds delay to shutdown button ( long press delay ) #30

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# pi-power-button
# pi-power-button - 3 seconds delay

Scripts used in our official [Raspberry Pi power button guide](https://howchoo.com/g/mwnlytk3zmm/how-to-add-a-power-button-to-your-raspberry-pi).
## Details

This software allows to turn on and off your raspberry. For turning off the raspberry you will need to hold the button for 3seconds. This makes unintentional turn offs or static current not turn off the raspberry randomly.

## Installation

1. [Connect to your Raspberry Pi via SSH](https://howchoo.com/g/mgi3mdnlnjq/how-to-log-in-to-a-raspberry-pi-via-ssh)
1. Clone this repo: `git clone https://github.com/Howchoo/pi-power-button.git`
1. Clone this repo: `git clone https://github.com/ImpressiveTaste/pi-power-button`
1. Optional: Edit line 9/10 in listen-for-shutdown.py to your preferred pin (Please see "Is it possible to use another pin other than Pin 5 (GPIO 3/SCL)?" below!)
1. Run the setup script: `./pi-power-button/script/install`

Expand Down
15 changes: 13 additions & 2 deletions listen-for-shutdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,21 @@

import RPi.GPIO as GPIO
import subprocess

import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(3, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.wait_for_edge(3, GPIO.FALLING)

stay=1 #incidcates if shutdown hasbeen sent correctly

while stay:
GPIO.wait_for_edge(3, GPIO.FALLING) #button is pressed
for i in range(30): #wait for a second
time.sleep(0.1)
if GPIO.input(3) == 1: #if button not pressed
stay=1
break
else:
stay=0

subprocess.call(['shutdown', '-h', 'now'], shell=False)