Button State Query
There is a push-button on the LinuxBox which can be user-specifically evaluated.
To determine the button state use the following command:
readbits -p a -b 1
Pressing the push-button prompts the program to yield a "0" signal.
Subsequent resetting yields "1".
The button is connected with GPIO Port A and Bit 1.
In -C- the button can be querried as follows:
#include "stdio.h"
#include "stdlib.h"
#include "unistd.h"
#include "sys/ioctl.h"
#include "fcntl.h"
#include "asm/etraxgpio.h"
int main(void)
{
int fd;
int value;
int iomask;
if ((fd = open("/dev/gpioa", O_RDWR))<0)
{
printf("Open error on /dev/gpiog\n");
exit(0);
}
iomask=1<<1;
printf("Press the button...\n");
while (1)
{
value=ioctl(fd, _IO(ETRAXGPIO_IOCTYPE, IO_READBITS));
if ((value&iomask)==0) {
printf("Button pressed\n");
}
sleep(1);
}
}
|