cancel
Showing results for 
Search instead for 
Did you mean: 

Non-blocking function to detect Console stdin input? conio.h? kbhit()?

Ron Koch
Associate II
Posted on September 13, 2017 at 18:41

I'm looking for a way to input data on stdin, but with a non-blocking function. Everything I've tried in stdio.h blocks program execution while waiting for a keypress. I want to input a keypress if one has occurred, but continue program execution if one has not. 

I understand the function kbhit() is usually in conio.h, but that library isn't present in my AC6 install. Is it available?

Is there another way?

3 REPLIES 3
Posted on September 13, 2017 at 19:09

It is going to depend on how you've implemented __io_getchar()

http://www.openstm32.org/tiki-view_forum_thread.php?comments_parentId=1065&display=print_all

 

You'd have to implement you're own equivalent to kbhit() based on your input source.

ie

    if (USART2->SR & USART_SR_RXNE) return(1); else return(0);

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Ron Koch
Associate II
Posted on September 13, 2017 at 21:18

Please pardon my not communicating that I'm using semihosting to redirect the stdio to the AC6 console through the debugger. So there is no physical USART to query. 

I'm using the ST-Link debugger integrated on the NucleoF4 board. 

Posted on September 13, 2017 at 22:37

Something you'd want to probe with your tool vendor.

Presuming it is using the SWV channel rather than the VCP/USART, you could perhaps looks at the ITM registers, or look at the __io_getchar() or equivalent.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..