Forum Discussion

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I'm not sure if i understand you correctly but take a look at the "Board Diagnostics"-Template in Nios II IDE. There is a function called getchar() used for this.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi cece,

    Thx for your answere. But getchart don't solve my problem, because its a blocking function. This means, if no key is pressed, the function getchar blocks until a key is pressed. With kbhit it is possible just to test, if an key was pressed(without blocking).

    -> with the help of <termios.h> it should be possible to programm a kbhit function, but the functions :

    - tcgetatt

    - tcsetattr

    from termios.h doesnt&#39;t work ??? Any other solutions are welcome

    Here the code :

    int getch()

    {

    static int ch = -1, fd = 0;

    struct termios neu, alt;

    fd = fileno(stdin);

    tcgetattr(fd, &alt);

    neu = alt;

    neu.c_lflag &= ~(ICANON|ECHO);

    tcsetattr(fd, TCSANOW, &neu);

    ch = getchar();

    tcsetattr(fd, TCSANOW, &alt);

    return ch;

    }

    int kbhit(void)

    {

    struct termios term, oterm;

    int fd = 0;

    int c = 0;

    tcgetattr(fd, &oterm);

    memcpy(&term, &oterm, sizeof(term));

    }