I need a kbhit() equivalent

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

I am using the WICED SDK 3.3.1.

I need to be able to poll the serial input at stdin and not stop if nothing is present.  I can't use getchar() because it hangs waiting for the next character.  There is no kbhit() function that I can find like Windows has.  I also tried incorporating POSIX-compliant code for implementing the equivalent of kbhit():

  FD_ZERO(&rdset);

  FD_SET(0, &rdset);  // 0 is the file descriptor for stdin

  timeout.tv_sec  = 0;

  timeout.tv_usec = 0;

  return select(1, &rdset, NULL, NULL, &timeout);  // 1 is one more than highest descriptor to check (0)

but I need a select() function which I also cannot find in the library.

Has anyone implemented this on this platform yet.

Roger

0 Likes
1 Solution
Anonymous
Not applicable

You need to build your own low level routine using the basic uart functions. Stdio support in the sdk is for basic debugging use only. Refer to the console app for similar usage. But for generic support using the low level read and write uart is necessary. 

View solution in original post

0 Likes
1 Reply
Anonymous
Not applicable

You need to build your own low level routine using the basic uart functions. Stdio support in the sdk is for basic debugging use only. Refer to the console app for similar usage. But for generic support using the low level read and write uart is necessary. 

0 Likes