forked from openenergymonitor/avrdude-rpi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoreset
executable file
·46 lines (40 loc) · 999 Bytes
/
autoreset
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
44
45
46
#!/usr/bin/python
import RPi.GPIO as GPIO
import sys, os, re, time, fcntl
import errno
fd = sys.stdin.fileno()
fl = fcntl.fcntl(fd, fcntl.F_GETFL)
fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
dtr = re.compile('.+TIOCM_DTR.+')
start = time.time()
pin = 4
def reset():
GPIO.setmode(GPIO.BCM)
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, GPIO.HIGH)
time.sleep(0.12)
GPIO.output(pin, GPIO.LOW)
def process():
while True:
try:
duration = time.time() - start
input = sys.stdin.readline().strip()
if input is None: # == "":
input = sys.stdin.readline().strip()
if dtr.match(input):
reset()
return
elif duration > 5000:
return
except Exception as e:
if hasattr(e, 'errno'):
if e.errno != 11: # Ignore resource unavailable
raise
else:
raise
process()
print "avrdude-original: Using autoreset DTR on GPIO " +str(pin)
GPIO.cleanup()
exit