libpruio  0.6.8
Fast and easy Digital/Analog Input/Output for Beaglebones
sos.c
Go to the documentation of this file.
1 
18 #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 "libpruio/pruio.h" /* include header */
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  /* select returns 0 if timeout, 1 if input available, -1 if error. */
50  return TEMP_FAILURE_RETRY(select(FD_SETSIZE,
51  &set, NULL, NULL,
52  &timeout));
53 }
54 
56 #define PIN 24
58 #define OUT_K pruio_gpio_setValue(io, PIN, 128 + pinmode) ; isleep(150) ; pruio_gpio_setValue(io, PIN, pinmode) ; isleep(100) ;
60 #define OUT_L pruio_gpio_setValue(io, PIN, 128 + pinmode) ; isleep(350) ; pruio_gpio_setValue(io, PIN, pinmode) ; isleep(100) ;
62 #define OUT_S OUT_K ; OUT_K ; OUT_K ; isleep(150)
64 #define OUT_O OUT_L ; OUT_L ; OUT_L ; isleep(150)
65 
67 int main(int argc, char **argv)
68 {
69  pruIo *io = pruio_new(PRUIO_DEF_ACTIVE, 4, 0x98, 0);
70  do { // pseudo loop to avoid goto
71  if (io->Errr) {
72  printf("initialisation failed (%s)\n", io->Errr); break;}
73 
74  uint8 pinmode = io->BallConf[PIN];
75 
76  if (pruio_config(io, 1, 0x1FE, 0, 4)) {
77  printf("config failed (%s)\n", io->Errr); break;}
78 
79  printf("watch SOS code on user LED 3 (near ethernet connector)\n\n");
80  printf("execute the following command to get rid of mmc1 triggers\n");
81  printf(" sudo su && echo none > /sys/class/leds/beaglebone:green:usr3/trigger && echo 0 > /sys/class/leds/beaglebone:green:usr3/brightness && exit\n\n");
82  printf("press any key to quit");
83 
84  struct termios oldt, newt; /* make terminal non-blocking */
85  tcgetattr( STDIN_FILENO, &oldt );
86  newt = oldt;
87  newt.c_lflag &= ~( ICANON | ECHO );
88  newt.c_cc[VMIN] = 0;
89  newt.c_cc[VTIME] = 1;
90  tcsetattr( STDIN_FILENO, TCSANOW, &newt );
91 
92  while(0 >= getchar()) { /* run loop until keystroke */
93  OUT_S;
94  OUT_O;
95  OUT_S;
96  isleep(1500);
97  }
98 
99  tcsetattr( STDIN_FILENO, TCSANOW, &oldt ); /* reset terminal */
100 
101  pruio_gpio_setValue(io, PIN, pinmode); /* reset LED (cosmetic) */
102  } while (0);
103  printf("\n");
104 
105  pruio_destroy(io); /* destroy driver structure */
106  return 0;
107 }
VAR io
create new driver UDT
Definition: 1.bas:18
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().
unsigned char uint8
8 bit unsigned integer data type.
Definition: pruio.h:39
@ PRUIO_DEF_ACTIVE
Activate all subsystems.
Definition: pruio.h:531
char * pruio_gpio_setValue(pruIo *Io, uint8 Ball, uint8 Modus)
Wrapper function for GpioUdt::setValue().
const ANY_PTR NULL
The NULL pointer.
VAR pinmode
The current pinmode.
Definition: sos.bas:42
#define OUT_O
Output an 'O' (long - long - long).
Definition: sos.c:64
int isleep(unsigned int mseconds)
Wait for keystroke or timeout.
Definition: sos.c:36
int main(int argc, char **argv)
The main function.
Definition: sos.c:67
#define OUT_S
Output a 'S' (short - short - short).
Definition: sos.c:62
#define PIN
The CPU ball to control (user LED 3).
Definition: sos.c:56
Wrapper structure for PruIo.
Definition: pruio.h:550