Skip to main content
Ron Koch
Associate II
September 13, 2017
Question

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

  • September 13, 2017
  • 3 replies
  • 1829 views
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?

    This topic has been closed for replies.

    3 replies

    Tesla DeLorean
    Guru
    September 13, 2017
    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Ron Koch
    Ron KochAuthor
    Associate II
    September 13, 2017
    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. 

    Tesla DeLorean
    Guru
    September 13, 2017
    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..