source: multiio/pcmmio/original/kbhit.c @ 32eca41

Last change on this file since 32eca41 was 32eca41, checked in by Joel Sherrill <joel.sherrill@…>, on 06/08/09 at 18:21:56

2009-06-08 Joel Sherrill <joel.sherrill@…>

  • Makefile, kbhit.c, mio_io.c, mio_io.h: First successful compilation under RTEMS. Added some Linux ifdef's.
  • rtems_config.c: New file.
  • Property mode set to 100644
File size: 1.6 KB
Line 
1/* $Header$
2*
3*
4*   Filename : $RCSfile$
5*
6*   $Id$
7*
8*   $Log$
9*   Revision 1.1.1.1  2009/06/08 14:52:43  joel
10*   Initial import.
11*
12*   Revision 1.1  2005/04/19 20:39:11  steve
13*   Initial revision
14*
15*
16*
17*/
18
19
20/* These functions are from the Wrox Press Book "Beginning Linux
21   Programming - Second Edition" by Richard Stones and Neil Matthew.
22   (C) 1996 & 1999 and are included here in compliance with the GNU
23   Public license.
24
25*/
26
27#include <stdio.h>
28#include <termios.h>
29#if defined(__linux__)
30#include <term.h>
31#include <curses.h>
32#endif
33#include <unistd.h>
34
35static struct termios initial_settings, new_settings;
36static int peek_character = -1;
37
38void init_keyboard(void);
39void close_keyboard(void);
40int kbhit(void);
41int readch(void);
42
43void init_keyboard(void)
44{
45    tcgetattr(0,&initial_settings);
46    new_settings = initial_settings;
47    new_settings.c_lflag &= ~ICANON;
48    new_settings.c_lflag &= ~ECHO;
49    new_settings.c_lflag &= ~ISIG;
50    new_settings.c_cc[VMIN] = 1;
51    new_settings.c_cc[VTIME] = 0;
52    tcsetattr(0, TCSANOW, &new_settings);
53}
54
55void close_keyboard(void)
56{
57    tcsetattr(0, TCSANOW, &initial_settings);
58}
59
60
61int kbhit(void)
62{
63char ch;
64int nread;
65
66    if(peek_character != -1)
67        return 1;
68
69    new_settings.c_cc[VMIN] = 0;
70    tcsetattr(0, TCSANOW, &new_settings);
71    nread = read(0, &ch, 1);
72    new_settings.c_cc[VMIN] = 1;
73    tcsetattr(0, TCSANOW, &new_settings);
74
75    if(nread == 1)
76    {
77        peek_character = ch;
78        return 1;
79    }
80
81    return 0;
82}
83
84int readch(void)
85{
86char ch;
87
88    if(peek_character != -1)
89    {
90        ch = peek_character;
91        peek_character = -1;
92        return ch;
93    }
94    read(0,&ch,1);
95    return ch;
96}
97
Note: See TracBrowser for help on using the repository browser.