LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-17-2009, 02:39 AM   #1
lanmanck
LQ Newbie
 
Registered: Apr 2008
Posts: 2

Rep: Reputation: 0
Question how to detect my gpio keyboard?


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!
 
Old 09-20-2009, 09:45 PM   #2
lanmanck
LQ Newbie
 
Registered: Apr 2008
Posts: 2

Original Poster
Rep: Reputation: 0
hello?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using GPIO (from kernel GPIO support) in MY application DannyGilbert Linux - Kernel 2 03-16-2009 07:52 AM
Can't detect PS/2 Keyboard, only USB one. nemea_lion Linux - Hardware 3 02-28-2007 06:35 PM
detect keyboard - no way ninguem_vj Linux - Hardware 3 09-25-2006 12:08 PM
Need help to detect keyboard sugreer Linux - Hardware 1 07-11-2003 07:51 AM
Slackware 8.0 doesn't detect keyboard mrned Linux - Software 2 10-26-2001 09:07 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration