-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathguide_out_gpio
executable file
·49 lines (38 loc) · 981 Bytes
/
guide_out_gpio
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
#!/usr/bin/python
import sys
import time
import select
import os
from pyA20.gpio import gpio
from pyA20.gpio import port
from pyA20.gpio import connector
def set_pin(d):
if d > 0:
gpio.output(st4pins[3], 1)
else:
gpio.output(st4pins[3], 0)
if d < 0:
gpio.output(st4pins[0], 1)
else:
gpio.output(st4pins[0], 0)
gpio.init()
st4pins = [ port.PD14, port.PC4, port.PC7, port.PA7 ]
for p in st4pins:
gpio.setcfg(p, gpio.OUTPUT)
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
while True:
line = sys.stdin.readline()
(v, usec) = [int(s) for s in line.split()]
t1 = time.time()
print "%d %d %d" % (v, int(t1), (t1 - int(t1)) * 1000000)
set_pin(v)
if usec > 0:
if usec > 100000:
ready_to_read, ready_to_write, in_error = select.select([sys.stdin], [], [], usec / 1000000.0)
if len(ready_to_read) > 0:
continue
else:
time.sleep(usec / 1000000.0)
t2 = time.time()
set_pin(0)
print "%d %d %d" % (0, int(t2), (t2 - int(t2)) * 1000000)