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