#include <stdio.h>
#include <unistd.h>
#include <termios.h>
#include <ctype.h>
#define QUIT_CHAR 0x04 // Ctrl+D --> quit
struct termios CookedTermIos; // for cooked mode
struct termios RawTermIos; // for raw mode
int main(void)
{
char c;
// save present terminal setting
tcgetattr(STDIN_FILENO, &CookedTermIos);
// Create raw mode terminal setting
RawTermIos = CookedTermIos;
cfmakeraw(&RawTermIos);
// Set
tcsetattr(STDIN_FILENO, 0, &RawTermIos);
while((c = getchar()) != QUIT_CHAR )
{
if(isprint(c)){
printf("you push key: ");
putchar(c);
putchar('\n');
}else{
printf("control key <%02X> \n" , c);
if(c == '\n') fputs("\r\n", stdout);
}
}
tcsetattr(STDIN_FILENO, 0, &CookedTermIos);
putchar('\n');
return 0;
}
Tuesday, March 31, 2009
Rawmode Serial port programming
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment