gpio_status.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import time
4 import curses
5 import atexit
6 import sys
7 
8 import pigpio
9 
10 GPIOS=32
11 
12 MODES=["INPUT", "OUTPUT", "ALT5", "ALT4", "ALT0", "ALT1", "ALT2", "ALT3"]
13 
14 def cleanup():
15  curses.nocbreak()
16  curses.echo()
17  curses.endwin()
18  pi.stop()
19 
20 pi = pigpio.pi()
21 if not pi.connected:
22  sys.exit(1)
23 
24 stdscr = curses.initscr()
25 curses.noecho()
26 curses.cbreak()
27 
28 atexit.register(cleanup)
29 
30 cb = []
31 
32 for g in range(GPIOS):
33  cb.append(pi.callback(g, pigpio.EITHER_EDGE))
34 
35 # disable gpio 28 as the PCM clock is swamping the system
36 
37 cb[28].cancel()
38 
39 stdscr.nodelay(1)
40 
41 stdscr.addstr(0, 23, "Status of gpios 0-31", curses.A_REVERSE)
42 
43 while True:
44 
45  for g in range(GPIOS):
46  tally = cb[g].tally()
47  mode = pi.get_mode(g)
48 
49  col = (g // 11) * 25
50  row = (g % 11) + 2
51 
52  stdscr.addstr(row, col, "{:2}".format(g), curses.A_BOLD)
53 
54  stdscr.addstr(
55  "={} {:>6}: {:<10}".format(pi.read(g), MODES[mode], tally))
56 
57  stdscr.refresh()
58 
59  time.sleep(0.1)
60 
61  c = stdscr.getch()
62 
63  if c != curses.ERR:
64  break
65 
def cleanup()
Definition: gpio_status.py:14


cob_hand_bridge
Author(s): Mathias Lüdtke
autogenerated on Tue Oct 20 2020 03:35:57