All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
io_input.c
Go to the documentation of this file.
#define _GNU_SOURCE 1
#include "stdio.h"
#include <termios.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/time.h>
#include "../c_wrapper/pruio.h"
int
isleep(unsigned int mseconds)
{
fd_set set;
struct timeval timeout;
/* Initialize the file descriptor set. */
FD_ZERO(&set);
FD_SET(STDIN_FILENO, &set);
/* Initialize the timeout data structure. */
timeout.tv_sec = 0;
timeout.tv_usec = mseconds * 1000;
return TEMP_FAILURE_RETRY(select(FD_SETSIZE,
&set, NULL, NULL,
&timeout));
}
int main(int argc, char **argv)
{
pruIo *io = pruio_new(PRUIO_DEF_ACTIVE, 0x98, 0, 1);
do { // pseudo loop to avoid goto
if (io->Errr) {
printf("initialisation failed (%s)\n", io->Errr); break;}
if (pruio_config(io, 1, 0x1FE, 0, 4)) {
printf("config failed (%s)\n", io->Errr); break;}
struct termios oldt, newt; // make terminal non-blocking
tcgetattr( STDIN_FILENO, &oldt );
newt = oldt;
newt.c_lflag &= ~( ICANON | ECHO );
newt.c_cc[VMIN] = 0;
newt.c_cc[VTIME] = 0;
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
while(!isleep(1)) { // run loop until keystroke
printf("\r%8X %8X %8X %8X %4X %4X %4X %4X %4X %4X %4X %4X"
, io->Gpio->Raw[0]->Mix, io->Gpio->Raw[1]->Mix, io->Gpio->Raw[2]->Mix, io->Gpio->Raw[3]->Mix
, io->Adc->Value[1], io->Adc->Value[2], io->Adc->Value[3], io->Adc->Value[4]
, io->Adc->Value[5], io->Adc->Value[6], io->Adc->Value[7], io->Adc->Value[8]);
fflush(STDIN_FILENO);
}
tcsetattr(STDIN_FILENO, TCSANOW, &oldt); // reset terminal
printf("\n");
} while (0);
pruio_destroy(io); /* destroy driver structure */
return 0;
}
isleep
int isleep(unsigned int mseconds)
Wait for keystroke or timeout.
Definition: io_input.c:36
gpioUdt::Raw
gpioArr * Raw[PRUIO_AZ_GPIO+1]
pointer to current raw device data (IO), all 32 bits
Definition: pruio.h:200
main
int main(int argc, char **argv)
The main function.
Definition: io_input.c:55
io
VAR io
create new driver UDT
Definition: 1.bas:21
pruIo::Adc
adcUdt * Adc
pointer to ADC device structure
Definition: pruio.h:404
pruIo
Wrapper structure for PruIo.
Definition: pruio.h:403
pruio_new
pruIo * pruio_new(uint16 Act, uint8 Av, uint32 OpD, uint8 SaD)
Wrapper function for the constructor PruIo::PruIo().
pruIo::Errr
char * Errr
pointer for error messages
Definition: pruio.h:411
pruio_destroy
void pruio_destroy(pruIo *Io)
Wrapper function for the destructor PruIo::~PruIo.
PRUIO_DEF_ACTIVE
activate all devices
Definition: pruio.h:385
adcUdt::Value
uint16 * Value
fetched ADC samples
Definition: pruio.h:133
gpioArr::Mix
uint32 Mix
current state of pins (IN&OUT mixed)
Definition: pruio.h:184
pruIo::Gpio
gpioUdt * Gpio
pointer to GPIO device structure
Definition: pruio.h:405
pruio_config
char * pruio_config(pruIo *Io, uint32 Samp, uint32 Mask, uint32 Tmr, uint16 Mds)
Wrapper function for PruIo::config().