View difference between Paste ID: AAFHwFLr and dczbWQ0T
SHOW: | | - or go back to the newest paste.
1
# Pi Supply Soft Shutdown Script
2-
# Version 1.1
2+
# Version 1.2
3
# Nathan Bookham 2013
4
# Stephen Longhurst 2013
5
6
# Import the modules to send commands to the system and access GPIO pins
7
from subprocess import call
8
import RPi.GPIO as gpio
9-
# Define a variable to store the pin number
9+
10-
soft_shutdown_pin = 7 # Default pin for Pi Supply is 7
10+
# Define variables to store the pin numbers
11
soft_shutdown_pin = 16 # Default pin for Pi Supply is 7
12
keep_powered_pin = 18 # Default pin for Pi Supply is 8
13
14-
    call('halt', shell=False)
14+
15
def shutdown():
16-
gpio.setmode(gpio.BOARD) # Set pin numbering to board numbering
16+
    # Cleanup GPIO
17-
gpio.setup(soft_shutdown_pin, gpio.IN) # Set up pin 7 as an input
17+
    gpio.cleanup()
18
19-
gpio.wait_for_edge(soft_shutdown_pin, gpio.RISING) # Wait for input from button
19+
    # Shutdown with halt and power off in 1 minute
20
    call(['shutdown', '-hP','+1'], shell=False)
21-
shutdown() # Run the shutdown function
21+
22
# Set pin numbering to board numbering
23
gpio.setmode(gpio.BOARD)
24
25
# Setup the input Pin to wait on
26
gpio.setup(soft_shutdown_pin, gpio.IN)
27
28
# Pin to pull high to keep the Pi Supply giving us power
29
gpio.setup(keep_powered_pin, gpio.OUT, initial=gpio.HIGH)
30
31
# Run the shutdown function
32
shutdown()