Volumio Pi Switch korekta błędu – GPIO.wait_for_edge

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
#!/usr/bin/env python3
 
from subprocess import call
import RPi.GPIO as GPIO
from time import sleep
 
PinSeven = 7   # GPIO 4 (Pin Seven)
PinEight = 11  # GPIO 17 (Pin Eight)
 
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.cleanup()
 
GPIO.setup(PinSeven, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(PinEight, GPIO.OUT, initial=1)
 
try:
    while True:
        if GPIO.input(PinSeven) == GPIO.HIGH:
            sleep(0.1)
            sleep(2)
            if GPIO.input(PinSeven) == False:
                sleep(1)
                GPIO.output(PinEight, 0)
                call('poweroff', shell=False)
            else:
                call('reboot', shell=False)
            break
except Exception as e:
    #print("Error occurred: {}".format(e))
    GPIO.cleanup()
finally:
    GPIO.cleanup()