forked from deanmao/avrdude-rpi
/
autoreset
executable file
·53 lines (43 loc) · 1.04 KB
/
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
47
48
49
50
51
52
53
#!/usr/bin/python2.7
import RPi.GPIO as GPIO
import sys, os, re, time, fcntl
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)
pin = 11
GPIO.setup(pin, GPIO.OUT)
dtr = re.compile('.*TIOCM_DTR.*')
isDone = re.compile('^$')
start = time.time()
def reset():
GPIO.output(pin, GPIO.HIGH)
time.sleep(0.12)
GPIO.output(pin, GPIO.LOW)
print "Leaving reset()"
def process():
while True:
try:
duration = time.time() - start
input = sys.stdin.readline().strip()
# Debugging the strace pipe
#print "text: ["+input+"]"
if duration > 60:
print "autoreset: Timeout reached, exiting!"
return
if isDone.match(input):
return
if dtr.match(input):
print "Calling reset()!"
reset()
print "Done toggling pin."
except IOError:
# print "Exception!"
# break
continue
# pass
process()
print "Cleaning up gpio."
GPIO.cleanup()
print "autoreset: done!"
sys.exit(0)