Linux MIPS Architecture development
 help / color / mirror / Atom feed
* questions about keyboard
@ 2004-04-14 20:18 Xu, Jiang
  2004-04-14 20:25 ` Jan-Benedict Glaw
  0 siblings, 1 reply; 9+ messages in thread
From: Xu, Jiang @ 2004-04-14 20:18 UTC (permalink / raw)
  To: linux-mips

[-- Attachment #1: Type: text/plain, Size: 950 bytes --]

Hi,  All,
 
I tried couple places and hope can get some help here.
 
I try to connect a USB keyboard device to a mips embedded system.
There is no console or X Window or any type of the graphic system
configured.
All I want to do is to:
The user can dynamically connect the USB keyboard to the device. The device
will listen to the key event from the keyboard and response by doing certain
things.
 
I believe I successfully configured the USB keyboard.  I verified this by
put "printk" at the first line of the function handle_scancode in
keyboard.c.  Everytime when I push the key on the keyboard, I see that
printk.
 
However, what I don't get is how can I get the key event from the kernel?  I
tried to listen to all the ttyN, but none of them connect to the keyboard.  
I wonder how I can write a user space application that can get the key
event?  Could somebody help me out?  Because it is an embedded device, there
is no X.
 
Thanks
 
John
 

[-- Attachment #2: Type: text/html, Size: 2938 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: questions about keyboard
  2004-04-14 20:18 Xu, Jiang
@ 2004-04-14 20:25 ` Jan-Benedict Glaw
  0 siblings, 0 replies; 9+ messages in thread
From: Jan-Benedict Glaw @ 2004-04-14 20:25 UTC (permalink / raw)
  To: linux-mips

[-- Attachment #1: Type: text/plain, Size: 935 bytes --]

On Wed, 2004-04-14 14:18:18 -0600, Xu, Jiang <Jiang.Xu@echostar.com>
wrote in message <F71A246055866844B66AFEB10654E7860F1B0B@riv-exchb6.echostar.com>:
> However, what I don't get is how can I get the key event from the kernel?  I
> tried to listen to all the ttyN, but none of them connect to the keyboard.  
> I wonder how I can write a user space application that can get the key
> event?  Could somebody help me out?  Because it is an embedded device, there
> is no X.

Well, one of /dev/tty, /dev/tty0 or /dev/console should work. If you'd
likt to use the new'n'fancy style, use /dev/input/eventX .

MfG, JBG

-- 
   Jan-Benedict Glaw       jbglaw@lug-owl.de    . +49-172-7608481
   "Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg
    fuer einen Freien Staat voll Freier Bürger" | im Internet! |   im Irak!
   ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: questions about keyboard
@ 2004-04-14 20:31 Xu, Jiang
  2004-04-14 20:36 ` Geert Uytterhoeven
  0 siblings, 1 reply; 9+ messages in thread
From: Xu, Jiang @ 2004-04-14 20:31 UTC (permalink / raw)
  To: linux-mips

Well, this is the problem.
For some reasons, none of the /dev/tty /dev/tty0... /dev/console is
connected to the keyboard, I have tried listening all of them.  Did I
configured something wrong? But kernel seems to be getting the key event
from the keyboard.
Another question is if it should connect to one of those device nodes, is
there anyway I can hack the kernel to see where the key event sent to?

Thanks

John


-----Original Message-----
From: Jan-Benedict Glaw [mailto:jbglaw@lug-owl.de] 
Sent: Wednesday, April 14, 2004 2:26 PM
To: linux-mips@linux-mips.org
Subject: Re: questions about keyboard


On Wed, 2004-04-14 14:18:18 -0600, Xu, Jiang <Jiang.Xu@echostar.com> wrote
in message <F71A246055866844B66AFEB10654E7860F1B0B@riv-exchb6.echostar.com>:
> However, what I don't get is how can I get the key event from the 
> kernel?  I tried to listen to all the ttyN, but none of them connect to
the keyboard.
> I wonder how I can write a user space application that can get the key
> event?  Could somebody help me out?  Because it is an embedded device,
there
> is no X.

Well, one of /dev/tty, /dev/tty0 or /dev/console should work. If you'd likt
to use the new'n'fancy style, use /dev/input/eventX .

MfG, JBG

-- 
   Jan-Benedict Glaw       jbglaw@lug-owl.de    . +49-172-7608481
   "Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg
    fuer einen Freien Staat voll Freier Bürger" | im Internet! |   im Irak!
   ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM |
TCPA));

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: questions about keyboard
  2004-04-14 20:31 Xu, Jiang
@ 2004-04-14 20:36 ` Geert Uytterhoeven
  0 siblings, 0 replies; 9+ messages in thread
From: Geert Uytterhoeven @ 2004-04-14 20:36 UTC (permalink / raw)
  To: Xu, Jiang; +Cc: Linux/MIPS Development

On Wed, 14 Apr 2004, Xu, Jiang wrote:
> Well, this is the problem.
> For some reasons, none of the /dev/tty /dev/tty0... /dev/console is
> connected to the keyboard, I have tried listening all of them.  Did I
> configured something wrong? But kernel seems to be getting the key event
> from the keyboard.
> Another question is if it should connect to one of those device nodes, is
> there anyway I can hack the kernel to see where the key event sent to?

Do you have CONFIG_VT=y? I guess not.

Do you receive anything on /dev/input/eventX?

> -----Original Message-----
> From: Jan-Benedict Glaw [mailto:jbglaw@lug-owl.de]
> Sent: Wednesday, April 14, 2004 2:26 PM
> To: linux-mips@linux-mips.org
> Subject: Re: questions about keyboard
>
>
> On Wed, 2004-04-14 14:18:18 -0600, Xu, Jiang <Jiang.Xu@echostar.com> wrote
> in message <F71A246055866844B66AFEB10654E7860F1B0B@riv-exchb6.echostar.com>:
> > However, what I don't get is how can I get the key event from the
> > kernel?  I tried to listen to all the ttyN, but none of them connect to
> the keyboard.
> > I wonder how I can write a user space application that can get the key
> > event?  Could somebody help me out?  Because it is an embedded device,
> there
> > is no X.
>
> Well, one of /dev/tty, /dev/tty0 or /dev/console should work. If you'd likt
> to use the new'n'fancy style, use /dev/input/eventX .

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: questions about keyboard
@ 2004-04-14 20:56 Xu, Jiang
  2004-04-15  8:36 ` Jan-Benedict Glaw
  0 siblings, 1 reply; 9+ messages in thread
From: Xu, Jiang @ 2004-04-14 20:56 UTC (permalink / raw)
  To: 'Geert Uytterhoeven'; +Cc: Linux/MIPS Development

I do turn on CONFIG_VT, if I don't I will not be able to pass compiling the
keyboard.c and some other stuffs.
Because I did not turn on INPUT_EVDEV, so I did not create the device node
before. 

However, I just gave it a quick try by turning on INPUT_EVDEV and create the
device nodes; and actually I saw response on input/event0!! Thanks!

Now I have some questions:
1.  I have CONFIG_VT on, so why ttyN is not connected to the device? I saw
console.o and tty_io.o, etc.
What may be wrong or did I miss doing some things that I should do?
2.  In the application, how can I know which input/event# the usb keyboard
connects to?
3.  Is there some reference documents about how to read things from
input/event# ? I mean such as how to read key event?

Thanks

John




-----Original Message-----
From: Geert Uytterhoeven [mailto:geert@linux-m68k.org] 
Sent: Wednesday, April 14, 2004 2:37 PM
To: Xu, Jiang
Cc: Linux/MIPS Development
Subject: RE: questions about keyboard


On Wed, 14 Apr 2004, Xu, Jiang wrote:
> Well, this is the problem.
> For some reasons, none of the /dev/tty /dev/tty0... /dev/console is 
> connected to the keyboard, I have tried listening all of them.  Did I 
> configured something wrong? But kernel seems to be getting the key 
> event from the keyboard. Another question is if it should connect to 
> one of those device nodes, is there anyway I can hack the kernel to 
> see where the key event sent to?

Do you have CONFIG_VT=y? I guess not.

Do you receive anything on /dev/input/eventX?

> -----Original Message-----
> From: Jan-Benedict Glaw [mailto:jbglaw@lug-owl.de]
> Sent: Wednesday, April 14, 2004 2:26 PM
> To: linux-mips@linux-mips.org
> Subject: Re: questions about keyboard
>
>
> On Wed, 2004-04-14 14:18:18 -0600, Xu, Jiang <Jiang.Xu@echostar.com> 
> wrote in message 
> <F71A246055866844B66AFEB10654E7860F1B0B@riv-exchb6.echostar.com>:
> > However, what I don't get is how can I get the key event from the 
> > kernel?  I tried to listen to all the ttyN, but none of them connect 
> > to
> the keyboard.
> > I wonder how I can write a user space application that can get the 
> > key event?  Could somebody help me out?  Because it is an embedded 
> > device,
> there
> > is no X.
>
> Well, one of /dev/tty, /dev/tty0 or /dev/console should work. If you'd 
> likt to use the new'n'fancy style, use /dev/input/eventX .

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 --
geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like
that.
							    -- Linus
Torvalds

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: questions about keyboard
  2004-04-14 20:56 questions about keyboard Xu, Jiang
@ 2004-04-15  8:36 ` Jan-Benedict Glaw
  0 siblings, 0 replies; 9+ messages in thread
From: Jan-Benedict Glaw @ 2004-04-15  8:36 UTC (permalink / raw)
  To: Linux/MIPS Development

[-- Attachment #1: Type: text/plain, Size: 1700 bytes --]

On Wed, 2004-04-14 14:56:20 -0600, Xu, Jiang <Jiang.Xu@echostar.com>
wrote in message <F71A246055866844B66AFEB10654E7860F1B0D@riv-exchb6.echostar.com>:
> 2.  In the application, how can I know which input/event# the usb keyboard
> connects to?

You don't. You can

	- Hope that your keyboard is the one and only device...
	- Read /proc/bus/input/devices - there should be a "kbd" handler
	  in the "H: " section
	- select() on all event* devices and just only process
	  keypresses generated from "normal" keys.

> 3.  Is there some reference documents about how to read things from
> input/event# ? I mean such as how to read key event?

I don't think there's really good docu available, but it's really
simple. Just open all devices, select() until there's data available (or
just call a blocking read() on it). Something like this should work, but
you'd better add error checking to the open() call...

#include <linux/input.h>

ssize_t ret;
struct input_event my_input;
int fd;

fd = open ("/dev/input/event0", O_RDONLY);
for (;;) {
	ret = read (fd, &my_input, sizeof (my_input));
	if (ret != sizeof (my_input)
		break;

	if (my_input.type != EV_KEY)
		continue;
	/* my_input.code and my_input.type now contain the key and
	   press/release state; refer to the #defines in linux/input.h
	   for the mapping .code -> ASCII value */
}
close (fd);


-- 
   Jan-Benedict Glaw       jbglaw@lug-owl.de    . +49-172-7608481
   "Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg
    fuer einen Freien Staat voll Freier Bürger" | im Internet! |   im Irak!
   ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: questions about keyboard
@ 2004-04-15 20:08 Xu, Jiang
  2004-04-15 20:22 ` Jan-Benedict Glaw
  0 siblings, 1 reply; 9+ messages in thread
From: Xu, Jiang @ 2004-04-15 20:08 UTC (permalink / raw)
  To: 'Jan-Benedict Glaw', Linux/MIPS Development

Thanks for the reply, I did some testing and found some interesting things:

1.  Everytime I push the key on the keyboard, I can see something out from
/dev/input/event0 by "cat /dev/input/event0".
However, I don't see a directory named "proc/input", did I miss configure
something in the kernel?
2.  read() does work and is a blocking read.  However, if I use select, then
it does not work.
Select() never detects the state change.
Here is the sample code I am using:
{
   int test_fd = -1;
   fd_set rfds;
   struct timeval tv;
  
   tv.tv_sec = 1;
   tv.tv_usec = 0;
   test_fd = open("/dev/input/event0", O_RDONLY); 
   if( test_fd < 0 )
     exit(0);
   
   while( 1 )
   {	
	FD_ZERO(&rfds);
	FD_SET(test_fd, &rfds);
      retval = select( 1, &rfds, NULL, NULL, &tv );
      if( retval )
         printf("\nDetects something....");
   }
}

What could be wrong?

Thanks

John

-----Original Message-----
From: Jan-Benedict Glaw [mailto:jbglaw@lug-owl.de] 
Sent: Thursday, April 15, 2004 2:36 AM
To: Linux/MIPS Development
Subject: Re: questions about keyboard


On Wed, 2004-04-14 14:56:20 -0600, Xu, Jiang <Jiang.Xu@echostar.com> wrote
in message <F71A246055866844B66AFEB10654E7860F1B0D@riv-exchb6.echostar.com>:
> 2.  In the application, how can I know which input/event# the usb 
> keyboard connects to?

You don't. You can

	- Hope that your keyboard is the one and only device...
	- Read /proc/bus/input/devices - there should be a "kbd" handler
	  in the "H: " section
	- select() on all event* devices and just only process
	  keypresses generated from "normal" keys.

> 3.  Is there some reference documents about how to read things from 
> input/event# ? I mean such as how to read key event?

I don't think there's really good docu available, but it's really simple.
Just open all devices, select() until there's data available (or just call a
blocking read() on it). Something like this should work, but you'd better
add error checking to the open() call...

#include <linux/input.h>

ssize_t ret;
struct input_event my_input;
int fd;

fd = open ("/dev/input/event0", O_RDONLY);
for (;;) {
	ret = read (fd, &my_input, sizeof (my_input));
	if (ret != sizeof (my_input)
		break;

	if (my_input.type != EV_KEY)
		continue;
	/* my_input.code and my_input.type now contain the key and
	   press/release state; refer to the #defines in linux/input.h
	   for the mapping .code -> ASCII value */
}
close (fd);


-- 
   Jan-Benedict Glaw       jbglaw@lug-owl.de    . +49-172-7608481
   "Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg
    fuer einen Freien Staat voll Freier Bürger" | im Internet! |   im Irak!
   ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM |
TCPA));

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: questions about keyboard
  2004-04-15 20:08 Xu, Jiang
@ 2004-04-15 20:22 ` Jan-Benedict Glaw
  0 siblings, 0 replies; 9+ messages in thread
From: Jan-Benedict Glaw @ 2004-04-15 20:22 UTC (permalink / raw)
  To: Linux/MIPS Development

[-- Attachment #1: Type: text/plain, Size: 1964 bytes --]

On Thu, 2004-04-15 14:08:54 -0600, Xu, Jiang <Jiang.Xu@echostar.com>
wrote in message <F71A246055866844B66AFEB10654E7860F1B10@riv-exchb6.echostar.com>:
> Thanks for the reply, I did some testing and found some interesting things:
> 
> 1.  Everytime I push the key on the keyboard, I can see something out from
> /dev/input/event0 by "cat /dev/input/event0".
> However, I don't see a directory named "proc/input", did I miss configure
> something in the kernel?

Maybe your kernel isn't configured with CONFIG_PROC_FS=y ?
Maybe it's not mounted?

> 2.  read() does work and is a blocking read.  However, if I use select, then
> it does not work.
> Select() never detects the state change.
> Here is the sample code I am using:
> {
>    int test_fd = -1;

No need to initialize - you're assigning a value before accessing it.

>    fd_set rfds;
>    struct timeval tv;
>   
>    tv.tv_sec = 1;
>    tv.tv_usec = 0;

tv_* need to be set before *every* select () invocation, not only once.

>    test_fd = open("/dev/input/event0", O_RDONLY); 
>    if( test_fd < 0 )
>      exit(0);
>    
>    while( 1 )
>    {	
> 	FD_ZERO(&rfds);
> 	FD_SET(test_fd, &rfds);
>       retval = select( 1, &rfds, NULL, NULL, &tv );

That's wrong. The "1" should be "fd + 1".

>       if( retval )
>          printf("\nDetects something....");

A negative retval would also be != 0 ...

>    }
> }
> 
> What could be wrong?

Most probably it's the hardcoded "1" with the select. That is, select
only looks at all fd's which are smaller than one, so only fd=0 would be
testes, but this one isn't in the set, so...

MfG, JBG

-- 
   Jan-Benedict Glaw       jbglaw@lug-owl.de    . +49-172-7608481
   "Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg
    fuer einen Freien Staat voll Freier Bürger" | im Internet! |   im Irak!
   ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: questions about keyboard
@ 2004-04-15 20:44 Xu, Jiang
  0 siblings, 0 replies; 9+ messages in thread
From: Xu, Jiang @ 2004-04-15 20:44 UTC (permalink / raw)
  To: 'Jan-Benedict Glaw', Linux/MIPS Development

I really really appreciate your help.  
That is a very stupid bug, I should review my code more carefully before I
sent out for help.  Sorry about that, I guess somehow my brain just messed
up.  

Anyway, I did turn on the CONFIG_PROC_FS.  
I also mount the usb by "mount -t usbdevfs none /proc/bus/usb"; and if I
"cat /proc/filesystems" it does show "usbdevfs".  
However, is there a "inputdevfs" and is there a similar command line such as
"mount -t inputdevfs none /proc/bus/input"?
I don't see anything like "CONFIG_INPUT_DEVICEFS"?
I am using 2.4.18 kernel.

Thanks

John


-----Original Message-----
From: Jan-Benedict Glaw [mailto:jbglaw@lug-owl.de] 
Sent: Thursday, April 15, 2004 2:22 PM
To: Linux/MIPS Development
Subject: Re: questions about keyboard


On Thu, 2004-04-15 14:08:54 -0600, Xu, Jiang <Jiang.Xu@echostar.com> wrote
in message <F71A246055866844B66AFEB10654E7860F1B10@riv-exchb6.echostar.com>:
> Thanks for the reply, I did some testing and found some interesting 
> things:
> 
> 1.  Everytime I push the key on the keyboard, I can see something out 
> from /dev/input/event0 by "cat /dev/input/event0". However, I don't 
> see a directory named "proc/input", did I miss configure something in 
> the kernel?

Maybe your kernel isn't configured with CONFIG_PROC_FS=y ? Maybe it's not
mounted?

> 2.  read() does work and is a blocking read.  However, if I use 
> select, then it does not work.
> Select() never detects the state change.
> Here is the sample code I am using:
> {
>    int test_fd = -1;

No need to initialize - you're assigning a value before accessing it.

>    fd_set rfds;
>    struct timeval tv;
>   
>    tv.tv_sec = 1;
>    tv.tv_usec = 0;

tv_* need to be set before *every* select () invocation, not only once.

>    test_fd = open("/dev/input/event0", O_RDONLY); 
>    if( test_fd < 0 )
>      exit(0);
>    
>    while( 1 )
>    {	
> 	FD_ZERO(&rfds);
> 	FD_SET(test_fd, &rfds);
>       retval = select( 1, &rfds, NULL, NULL, &tv );

That's wrong. The "1" should be "fd + 1".

>       if( retval )
>          printf("\nDetects something....");

A negative retval would also be != 0 ...

>    }
> }
> 
> What could be wrong?

Most probably it's the hardcoded "1" with the select. That is, select only
looks at all fd's which are smaller than one, so only fd=0 would be testes,
but this one isn't in the set, so...

MfG, JBG

-- 
   Jan-Benedict Glaw       jbglaw@lug-owl.de    . +49-172-7608481
   "Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg
    fuer einen Freien Staat voll Freier Bürger" | im Internet! |   im Irak!
   ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM |
TCPA));

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2004-04-15 20:44 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-04-14 20:56 questions about keyboard Xu, Jiang
2004-04-15  8:36 ` Jan-Benedict Glaw
  -- strict thread matches above, loose matches on Subject: below --
2004-04-15 20:44 Xu, Jiang
2004-04-15 20:08 Xu, Jiang
2004-04-15 20:22 ` Jan-Benedict Glaw
2004-04-14 20:31 Xu, Jiang
2004-04-14 20:36 ` Geert Uytterhoeven
2004-04-14 20:18 Xu, Jiang
2004-04-14 20:25 ` Jan-Benedict Glaw

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox