-
Notifications
You must be signed in to change notification settings - Fork 11
/
spc.py
43 lines (34 loc) · 973 Bytes
/
spc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#AUDIOPHONICS SPC POWER CONTROLLER
#Python RPI-GPIO Script
#In case WiringPi do not work
#Python, PIP and RPI.GPIO must be installed
#(pip install RPi.GPIO)
#Must be run as root to be able to send shutdown order
try:
import RPi.GPIO as GPIO
except RuntimeError:
print("Error importing RPi.GPIO!")
GPIO.setmode(GPIO.BCM)
import time
import os
#Set GPIO used here :
bootok = 22
shutdown = 17
print 'Audiophonics Shutdown script starting...'
print "Asserting pins : "
print "BootOK : GPIO"+str(bootok)+"=out, High"
print "ShutDown : GPIO"+str(shutdown)+"=in, Low"
#When script Launched, send BOOT OK signal
GPIO.setup(bootok, GPIO.OUT)
GPIO.output(bootok, GPIO.HIGH)
# Initialise GPIO 17 for shutdown order
GPIO.setup(shutdown, GPIO.IN)
while True :
sdstate = GPIO.input(shutdown)
#print sdstate
time.sleep(0.5)
if sdstate == 1 :
print "ShutDown order received, RaspBerry pi will now shutdown..."
time.sleep(0.5)
os.system('shutdown -h -P now')
break