In this app there is code to read keyboard input from a user in a realtime that goes something like this:
while (1)
{
if (keyPress()) // Look for a keyboard press
{
key = getKeyPress(); // Get the keystroke
break;
}
delay(50);
}
So the code basically loops forever checking for a keyboard press from the user every 50 ms.
Can this be done under from a QNX console somehow? I scanned the help files but I only seem to see code under photon that can do something similar to the above code.
I think the devi-* drivers can be started with -rP on the text console, and then a path /dev/devi/keyboard0, /dev/devi/mouse0 appears, from which you can read(). The structures are defined in dcmd_hid.h or io-hid.h or something. I would definitly get the Input Driver DDK since this contains source code for several input drivers that should help.
In a separate thread you would then use select() to wait for input, rather than polling.
Without photon running I started io-hid as follows:
io-hid &
Then I started devi-hid as follows:
devi-hid -rP kbd
At this point I get a /dev/devi/keyboard0
So I quickly did a ‘cat /dev/devi/keyboard0’ and typed some characters on my keyboard. I expected them to be outputting from cat similar to when I do a ‘cat /dev/ser1’ and when I move my serial mouse I see stuff outputted.
So either using ‘cat’ doesn’t work in that way with /dev/devi/keyboard0 or something else is wrong.
Note that whatever keyboard driver starts when the system launches in console mode is still running because I launch io-hid by hand. Could this be interfering with io-hid and devi-hid getting the keyboard input?
I was expecting my code could do something as simple as spawning off a thread that did something like:
char buffer[255];
fd = open ("/dev/devi/keyboard0", O_RDONLY);
while (1)
{
read(fd, buffer, sizeof(buffer));
// parse the keystroke and do with it what I want
}
Will this not work since read does a blocking wait for keystrokes to arrive (I do this with reading from my serial ports and it works very nicely)
If what I want to do is not this simple I will re-write that part of the code that waits for input to simply do a scanf() on keyboard input. Much more clumsy but will work if that code is also spun off into it’s own thread.
I think you have to provide an input driver for io-hid, either USB (for USB Keyboards) or PS2. I tried io-hid -dusb and then the cat command worked fine with a USB keyboard. Similarly it should work with the PS2 input driver for io-hid but I never tried.