Rev Author Line No. Line
4686 kaklik 1 #!/usr/bin/python
2 import wiringpi2 as gpio
3 import time
4 import subprocess
5  
4745 kaklik 6 power_sense_pin = 83
7  
4686 kaklik 8 gpio.wiringPiSetupGpio()
4745 kaklik 9 gpio.pinMode(power_sense_pin, 0)
10 gpio.pullUpDnControl(power_sense_pin, 0)
4686 kaklik 11  
4745 kaklik 12 time.sleep(2)
4686 kaklik 13  
4745 kaklik 14 oldstav = gpio.digitalRead(power_sense_pin)
4686 kaklik 15  
16 while True:
4745 kaklik 17 stav = gpio.digitalRead(power_sense_pin)
4686 kaklik 18  
4687 kaklik 19 if oldstav == 0 and stav == 0:
4690 kaklik 20 subprocess.call("shutdown -P 0", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
4688 kaklik 21 else:
22 print "power is OK."
4745 kaklik 23  
4688 kaklik 24 oldstav = stav
4686 kaklik 25  
4687 kaklik 26 time.sleep(2)
4686 kaklik 27  
28