Go to the documentation of this file.00001
00002
00003 #ifdef _WIN32
00004 #else
00005
00006
00007 #include "hrl_lib/kbhit.h"
00008
00009 static struct termios termattr, save_termattr;
00010 static int ttysavefd = -1;
00011 static enum
00012 {
00013 RESET, RAW, CBREAK
00014 } ttystate = RESET;
00015
00016
00017
00018
00019
00020
00021
00022 int
00023 set_tty_raw(void)
00024 {
00025 int i;
00026
00027 i = tcgetattr (STDIN_FILENO, &termattr);
00028 if (i < 0)
00029 {
00030 printf("tcgetattr() returned %d for fildes=%d\n",i,STDIN_FILENO);
00031 perror ("");
00032 return -1;
00033 }
00034 save_termattr = termattr;
00035
00036 termattr.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
00037 termattr.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
00038 termattr.c_cflag &= ~(CSIZE | PARENB);
00039 termattr.c_cflag |= CS8;
00040 termattr.c_oflag &= ~(OPOST);
00041
00042 termattr.c_cc[VMIN] = 1;
00043 termattr.c_cc[VTIME] = 0;
00044
00045 i = tcsetattr (STDIN_FILENO, TCSANOW, &termattr);
00046 if (i < 0)
00047 {
00048 printf("tcsetattr() returned %d for fildes=%d\n",i,STDIN_FILENO);
00049 perror("");
00050 return -1;
00051 }
00052
00053 ttystate = RAW;
00054 ttysavefd = STDIN_FILENO;
00055
00056 return 0;
00057 }
00058
00059
00060
00061
00062
00063
00064
00065 int
00066 set_tty_cbreak()
00067 {
00068 int i;
00069
00070 i = tcgetattr (STDIN_FILENO, &termattr);
00071 if (i < 0)
00072 {
00073 printf("tcgetattr() returned %d for fildes=%d\n",i,STDIN_FILENO);
00074 perror ("");
00075 return -1;
00076 }
00077
00078 save_termattr = termattr;
00079
00080 termattr.c_lflag &= ~(ECHO | ICANON);
00081 termattr.c_cc[VMIN] = 1;
00082 termattr.c_cc[VTIME] = 0;
00083
00084 i = tcsetattr (STDIN_FILENO, TCSANOW, &termattr);
00085 if (i < 0)
00086 {
00087 printf("tcsetattr() returned %d for fildes=%d\n",i,STDIN_FILENO);
00088 perror ("");
00089 return -1;
00090 }
00091 ttystate = CBREAK;
00092 ttysavefd = STDIN_FILENO;
00093
00094 return 0;
00095 }
00096
00097
00098
00099
00100
00101
00102
00103
00104 int
00105 set_tty_cooked()
00106 {
00107 int i;
00108 if (ttystate != CBREAK && ttystate != RAW)
00109 {
00110 return 0;
00111 }
00112 i = tcsetattr (STDIN_FILENO, TCSAFLUSH, &save_termattr);
00113 if (i < 0)
00114 {
00115 return -1;
00116 }
00117 ttystate = RESET;
00118 return 0;
00119 }
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130 unsigned char
00131 kb_getc(void)
00132 {
00133 int i;
00134 unsigned char ch;
00135 ssize_t size;
00136 termattr.c_cc[VMIN] = 0;
00137 i = tcsetattr (STDIN_FILENO, TCSANOW, &termattr);
00138 size = read (STDIN_FILENO, &ch, 1);
00139 termattr.c_cc[VMIN] = 1;
00140 i = tcsetattr (STDIN_FILENO, TCSANOW, &termattr);
00141 if (size == 0)
00142 {
00143 return 0;
00144 }
00145 else
00146 {
00147 return ch;
00148 }
00149 }
00150
00151
00152
00153
00154
00155
00156 unsigned char
00157 kb_getc_w(void)
00158 {
00159 unsigned char ch;
00160 size_t size;
00161
00162 while (1)
00163 {
00164
00165 usleep(20000);
00166
00167 size = read (STDIN_FILENO, &ch, 1);
00168 if (size > 0)
00169 {
00170 break;
00171 }
00172 }
00173 return ch;
00174 }
00175
00176
00177 #endif // _WIN32
00178
hrl_lib
Author(s): Cressel Anderson, Travis Deyle, Advait Jain, Hai Nguyen, Advisor: Prof. Charlie Kemp, Lab: Healthcare Robotics Lab at Georgia Tech
autogenerated on Wed Nov 27 2013 11:34:06