-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpio.py
executable file
·82 lines (57 loc) · 1.57 KB
/
gpio.py
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
# http://abyz.me.uk/rpi/pigpio/
# sudo gpiod
import time
import curses
import atexit
import pigpio
GPIOS=32
MODES=["INPUT", "OUTPUT", "ALT5", "ALT4", "ALT0", "ALT1", "ALT2", "ALT3"]
def cleanup():
curses.nocbreak()
curses.echo()
curses.endwin()
pi.stop()
pi = pigpio.pi()
stdscr = curses.initscr()
curses.noecho()
curses.cbreak()
atexit.register(cleanup)
cb = []
for g in range(GPIOS):
cb.append(pi.callback(g, pigpio.EITHER_EDGE))
# disable gpio 28 as the PCM clock is swamping the system
cb[28].cancel()
stdscr.nodelay(1)
stdscr.addstr(0, 23, "Status of gpios 0-31", curses.A_REVERSE)
# pi.set_pull_up_down(17, pigpio.PUD_OFF)
time.sleep(1)
pi.write(2, 0) # turn on relay at startup
time.sleep(1)
pi.write(3, 0) # turn on relay at startup
time.sleep(1)
pi.write(4, 0) # turn on relay at startup
time.sleep(1)
pi.write(14, 0) # turn on relay at startup
time.sleep(1)
while True:
for g in range(GPIOS):
tally = cb[g].tally()
mode = pi.get_mode(g)
col = (g / 11) * 25
row = (g % 11) + 2
stdscr.addstr(row, col, "{:2}".format(g), curses.A_BOLD)
stdscr.addstr(
"={} {:>6}: {:<10}".format(pi.read(g), MODES[mode], tally))
stdscr.refresh()
time.sleep(0.1)
c = stdscr.getch()
if c != curses.ERR:
pi.write(2, 1) # turn off relay at any keypress
time.sleep(1)
pi.write(3, 1) # turn off relay at any keypress
time.sleep(1)
pi.write(4, 1) # turn off relay at any keypress
time.sleep(1)
pi.write(14, 1) # turn off relay at any keypress
break