summaryrefslogtreecommitdiff
path: root/6515/libsensors_iio/software/simple_apps/common/console_helper.c
blob: 288862768c95d5904eb48931a49b5db1f867b6b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
 $License:
    Copyright (C) 2012 InvenSense Corporation, All Rights Reserved.
 $
 */

/******************************************************************************
 *
 * $Id:$
 *
 *****************************************************************************/

#include <stdio.h>
#ifdef _WIN32
#include <windows.h>
#include <conio.h>
#endif
#ifdef LINUX
#include <sys/select.h>
#endif
#include <time.h>
#include <string.h>

int ConsoleKbhit(void)
{
#ifdef _WIN32
    return _kbhit();
#else
    struct timeval tv;
    fd_set read_fd;

    tv.tv_sec=0;
    tv.tv_usec=0;
    FD_ZERO(&read_fd);
    FD_SET(0, &read_fd);

    if(select(1, &read_fd, NULL, NULL, &tv) == -1)
        return 0;

    if(FD_ISSET(0, &read_fd))
        return 1;

    return 0;
#endif
}

char ConsoleGetChar(void)
{
#ifdef _WIN32
    return _getch();
#else
    return getchar();
#endif
}