libpruio  0.6.8
Fast and easy Digital/Analog Input/Output for Beaglebones
io_input.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 
14 
15 import curses
16 from libpruio import *
17 
18 
19 def io_input(stdscr):
20  # Clear and refresh the screen for a blank canvas
21  stdscr.clear()
22  stdscr.nodelay(1)
23 
24 
25  io = pruio_new(PRUIO_DEF_ACTIVE, 4, 0x98, 0)
26  try:
27 
28  IO = io.contents
29  if IO.Errr: raise AssertionError("pruio_new failed (%s)" % IO.Errr)
30  if pruio_config(io, 1, 0x1FE, 0, 4): # upload config, start IO mode
31  raise AssertionError("config failed (%s)" % IO.Errr)
32  # IO mode is running, you can control digital output, read digital or analog input
33 
34  AdcV = IO.Adc.contents.Value
35 
36  GpiV = IO.Gpio.contents.Raw
37 
38  c = -1
39  stdscr.addstr(5,0, "Press any key to quit")
40  while c == -1:
41  for i in range(0, 4): # all GpioSS
42  stdscr.addstr(i,0, "{:032b}".format(GpiV[i].contents.Mix))
43  for i in range(1, 9): # all ADC steps
44  stdscr.addstr(4,(i-1)*5, "{:04X}".format(AdcV[i])) # AIN in hex
45  c = stdscr.getch()
46  finally:
47  pruio_destroy(io) # we're done
48 
49 if __name__ == "__main__":
50  curses.wrapper(io_input)
char * pruio_config(pruIo *Io, uint32 Samp, uint32 Mask, uint32 Tmr, uint16 Mds)
Wrapper function for PruIo::config().
pruIo * pruio_new(uint16 Act, uint8 Av, uint32 OpD, uint8 SaD)
Wrapper function for the constructor PruIo::PruIo().
void pruio_destroy(pruIo *Io)
Wrapper function for the destructor PruIo::~PruIo().