libpruio  0.2
Input/Output driver for digital/analog lines on Beagleboard hardware
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
io_input.c
Go to the documentation of this file.
1 
17 #define _GNU_SOURCE 1
19 #include "stdio.h"
20 #include <termios.h>
21 #include <unistd.h>
22 #include <errno.h>
23 #include <sys/types.h>
24 #include <sys/time.h>
25 #include "../c_wrapper/pruio.h"
26 
27 
35 int
36 isleep(unsigned int mseconds)
37 {
38  fd_set set;
39  struct timeval timeout;
40 
41  /* Initialize the file descriptor set. */
42  FD_ZERO(&set);
43  FD_SET(STDIN_FILENO, &set);
44 
45  /* Initialize the timeout data structure. */
46  timeout.tv_sec = 0;
47  timeout.tv_usec = mseconds * 1000;
48 
49  return TEMP_FAILURE_RETRY(select(FD_SETSIZE,
50  &set, NULL, NULL,
51  &timeout));
52 }
53 
55 int main(int argc, char **argv)
56 {
57  pruIo *io = pruio_new(PRUIO_DEF_ACTIVE, 0x98, 0, 1);
58  do { // pseudo loop to avoid goto
59  if (io->Errr) {
60  printf("initialisation failed (%s)\n", io->Errr); break;}
61 
62  if (pruio_config(io, 1, 0x1FE, 0, 4)) {
63  printf("config failed (%s)\n", io->Errr); break;}
64 
65  struct termios oldt, newt; // make terminal non-blocking
66  tcgetattr( STDIN_FILENO, &oldt );
67  newt = oldt;
68  newt.c_lflag &= ~( ICANON | ECHO );
69  newt.c_cc[VMIN] = 0;
70  newt.c_cc[VTIME] = 0;
71  tcsetattr(STDIN_FILENO, TCSANOW, &newt);
72 
73  while(!isleep(1)) { // run loop until keystroke
74  printf("\r%8X %8X %8X %8X %4X %4X %4X %4X %4X %4X %4X %4X"
75  , io->Gpio->Raw[0]->Mix, io->Gpio->Raw[1]->Mix, io->Gpio->Raw[2]->Mix, io->Gpio->Raw[3]->Mix
76  , io->Adc->Value[1], io->Adc->Value[2], io->Adc->Value[3], io->Adc->Value[4]
77  , io->Adc->Value[5], io->Adc->Value[6], io->Adc->Value[7], io->Adc->Value[8]);
78  fflush(STDIN_FILENO);
79  }
80  tcsetattr(STDIN_FILENO, TCSANOW, &oldt); // reset terminal
81 
82  printf("\n");
83  } while (0);
84 
85  pruio_destroy(io); /* destroy driver structure */
86  return 0;
87 }
int isleep(unsigned int mseconds)
Wait for keystroke or timeout.
Definition: io_input.c:36
gpioArr * Raw[PRUIO_AZ_GPIO+1]
pointer to current raw device data (IO), all 32 bits
Definition: pruio.h:200
int main(int argc, char **argv)
The main function.
Definition: io_input.c:55
VAR io
create new driver UDT
Definition: 1.bas:21
adcUdt * Adc
pointer to ADC device structure
Definition: pruio.h:404
Wrapper structure for PruIo.
Definition: pruio.h:403
pruIo * pruio_new(uint16 Act, uint8 Av, uint32 OpD, uint8 SaD)
Wrapper function for the constructor PruIo::PruIo().
char * Errr
pointer for error messages
Definition: pruio.h:411
void pruio_destroy(pruIo *Io)
Wrapper function for the destructor PruIo::~PruIo.
activate all devices
Definition: pruio.h:385
uint16 * Value
fetched ADC samples
Definition: pruio.h:133
uint32 Mix
current state of pins (IN&OUT mixed)
Definition: pruio.h:184
gpioUdt * Gpio
pointer to GPIO device structure
Definition: pruio.h:405
char * pruio_config(pruIo *Io, uint32 Samp, uint32 Mask, uint32 Tmr, uint16 Mds)
Wrapper function for PruIo::config().