hi all:
i have read this post:
http://www.at91.com/samphpbb/viewtop...st=0&sk=t&sd=a
now my driver works fine, in the interrupt routine i report the key:
IN KERNEL:
input_report_key(keyboard, kbd_t.lastkey, KEY_IS_DOWN);
input_report_key(keyboard, kbd_t.lastkey, KEY_IS_UP);
input_sync(keyboard);
when i printk it ,the value is correct (only support press one gpio at a time);
Now,i want to detect it in my application,i use these code:
Code:
int main(int argc, char **argv)
{
int keyboard;
int ret,i;
char c;
fd_set readfd;
struct timeval timeout;
keyboard = open("/dev/event0",O_RDONLY | O_NONBLOCK);
assert(keyboard>0);
while(1)
{
timeout.tv_sec=2;
timeout.tv_usec=0;
FD_ZERO(&readfd);
FD_SET(keyboard,&readfd);
ret=select(keyboard+1,&readfd,NULL,NULL,&timeout);//NULL
if(ret < 0) perror("select");
else if(ret == 0) printf("time out\n");
else
{
printf("ret=%d\n", ret); //always enter here!!!
if(FD_ISSET(keyboard,&readfd))
{
i=read(keyboard,&c,1);
if('\n'==c)
continue;
printf("input is %c,%d\n",c,c);
if ('q'==c)
break;
}
}
}
close(keyboard);
return 0;
}
i run this code,when i donot press the gpio,it seems to work OK,that's say:
the terminal will print "time out" every 2 second.
HOWEVER,when i press the gpio (and release),it always runs to last "else":
ret=1
input is ,0
ret=1
input is ,0
ret=1
input is ,0
ret=1
input is ,0
and do not STOP again.Why these happen?
BY THE WAY,can i use the gpio button to emulate a tty keyboard? I mean i can use "getchar()" through my application :)
your quick reply is appreciated!