00001 #include <stdio.h>
00002 #include <poll.h>
00003 #include <termios.h>
00004 #include <string.h>
00005 #include <sstream>
00006
00007 #include "pit_keyboard.h"
00008
00009 using namespace std;
00010
00011 pit_keyboard::pit_keyboard()
00012 {
00013 }
00014
00015 pit_keyboard::~pit_keyboard()
00016 {
00017 }
00018
00019
00020
00021
00022 void pit_keyboard::EchoOff(void)
00023 {
00024 struct termios new1;
00025 struct termios stored;
00026
00027 tcgetattr(0,&stored);
00028 memcpy(&new1, &stored, sizeof(struct termios));
00029 new1.c_lflag &= (~ECHO);
00030 tcsetattr(0,TCSANOW,&new1);
00031 return;
00032 }
00033
00034
00035 void pit_keyboard::EchoOn(void)
00036 {
00037 struct termios stored,new1;
00038
00039 tcgetattr(0,&stored);
00040 memcpy(&new1, &stored, sizeof(struct termios));
00041 new1.c_lflag |= (ECHO);
00042 tcsetattr(0,TCSANOW,&new1);
00043 return;
00044 }
00045
00046
00047
00048 void pit_keyboard::SetKeyboard(void)
00049 {
00050 struct termios stored;
00051 struct termios new1;
00052
00053 tcgetattr(fileno(stdin),&stored);
00054 memcpy(&new1,&stored,sizeof(struct termios));
00055
00056 new1.c_lflag &= (~ICANON);
00057 new1.c_cc[VTIME] = 0;
00058 new1.c_cc[VMIN] = 1;
00059 tcsetattr(fileno(stdin),TCSANOW,&new1);
00060
00061 tcgetattr(fileno(stdout),&stored);
00062 memcpy(&new1,&stored,sizeof(struct termios));
00063
00064 new1.c_lflag &= (~ICANON);
00065 new1.c_cc[VTIME] = 0;
00066 new1.c_cc[VMIN] = 1;
00067 tcsetattr(fileno(stdout),TCSANOW,&new1);
00068 return;
00069 }
00070
00071
00072 void pit_keyboard::ResetKeyboard(void)
00073 {
00074 struct termios stored;
00075 struct termios new1;
00076
00077 tcgetattr(fileno(stdin),&stored);
00078 memcpy(&new1,&stored,sizeof(struct termios));
00079 new1.c_lflag |= (ICANON);
00080 tcsetattr(fileno(stdin),TCSANOW,&new1);
00081
00082 tcgetattr(fileno(stdout),&stored);
00083 memcpy(&new1,&stored,sizeof(struct termios));
00084 new1.c_lflag |= (ICANON);
00085 tcsetattr(fileno(stdout),TCSANOW,&new1);
00086
00087 return;
00088 }
00089
00090
00091 bool pit_keyboard::kbhit(void){
00092 struct pollfd fds[1];
00093
00094 fds[0].fd = fileno(stdin);
00095 fds[0].events = POLLIN;
00096 poll(fds, 1L, 0);
00097 if (fds[0].revents == POLLIN) {
00098 return true;
00099 }
00100 return false;
00101 }
00102
00103
00104
00105 void pit_keyboard::cmdHandler(std::string command){
00106
00107 }