This is the mail archive of the
ecos-discuss@sourceware.org
mailing list for the eCos project.
Termios and waiting for character input
- From: Andre-John Mas <ajmas at sympatico dot ca>
- To: ec at sympatico dot ca,<ecos-discuss at ecos dot sourceware dot org>
- Date: Wed, 23 Aug 2006 19:13:58 -0400
- Subject: [ECOS] Termios and waiting for character input
Hi,
I have the code below. I want to be able to block until something
is inputted and then continue. The only problem is am finding that
it continues even without anything being inputed. What should I be
doing differently:
struct termios term;
struct termios termsave;
int fd = STDIN_FILENO;
// INFO: make sure this is a tty
if (!isatty(fd)) {
fprintf(stderr,"isatty: STDIN_FILENO not a tty\n");
exit(1);
}
// INFO: get term i/o flags for this tty
if (tcgetattr(fd, &termsave) < 0) {
perror("tcgetattr");
exit(1);
}
term = termsave; /* termsave contains old termios */
term.c_lflag &= ~ECHO; /* turn off echo if it's set */
term.c_lflag &= ~ECHOE; /* turn off echoe if it's set */
term.c_lflag &= ~ICANON; /* turn off echoe if it's set */
// INFO: propagate changes
if (tcsetattr(fd, TCSAFLUSH, &term) < 0) {
perror("tcsetattr");
exit(1);
}
char c;
cin >> c;
// INFO: restore old state
if (tcsetattr(fd, TCSAFLUSH, &termsave) < 0) {
perror("tcsetattr");
exit(1);
}
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss