pit_keyboard.cpp

Go to the documentation of this file.
00001 #include <stdio.h> /* permet d'aller chercher les infos du STDIN en non-blocking */
00002 #include <poll.h>  /* permet de modifier l'affichage au moment de getc() */
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 /* Cette fonction permet de ne pas afficher les caracteres  entres au clavier */
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 /* Cette fonction permet de remettre l'affichage a son etat  normal. */
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 /* Permet de faire la lecture d'une touche a la fois du clavier */
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     /* Disable canonical mode, and set buffer size to 1 byte */
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     /* Disable canonical mode, and set buffer size to 1 byte */
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 /* Remets le clavier a son etat normal. */
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 /* Determine si une lecture du STDIN doit etre effectuee.*/
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 }

Generated on Sat Mar 29 22:55:55 2008 for pixelTrigger by  doxygen 1.5.0