From 6085767ff373cb6ded89a46c8d86855b923cb7a1 Mon Sep 17 00:00:00 2001 From: burg Date: Sat, 22 Jan 2005 23:52:59 +0000 Subject: Optimisation de l'affichage et correction de bogues. --- i/serialplot/serialplot.c | 284 +++++++++++++++++++++++----------------------- 1 file changed, 142 insertions(+), 142 deletions(-) (limited to 'i/serialplot/serialplot.c') diff --git a/i/serialplot/serialplot.c b/i/serialplot/serialplot.c index 2e59e71..aae9541 100644 --- a/i/serialplot/serialplot.c +++ b/i/serialplot/serialplot.c @@ -11,6 +11,9 @@ #include #include #include + +#include + #include #include #include @@ -24,7 +27,6 @@ int old_value[256]; unsigned long cpt[8]; struct termios oldconf; - int main (int argc, char **argv) { @@ -40,47 +42,47 @@ main (int argc, char **argv) while((rep= getopt (argc, argv,"hvs:t:")) != -1) switch (rep) { - case 'h': - printf("serialplot -h cet aide\n\n"); - printf("serialplot -s /dev/ttyS0 permet de choisir\n"); - printf(" entre le port serie /dev/ttyS0 \n"); - printf(" au lieu de l'entre standard\n"); - printf(" -t un nombre dans cet intervalle\n"); - printf(" [1-255], le nb de bit à 1\n"); - printf(" correspond au nombre de valeur\n"); - printf(" a afficher"); - printf("\nserialplot -v affiche les credits\n\n"); - exit(0); - case 'v': - printf("\n%s by __--''\\_TB_/''--__\n\n",argv[0]); - exit(0); - case 's': - cvalue = optarg; - input_flag = 1; - break; - case 't': - cvalue2 = optarg; - if ((etat_lect = read_std_param(cvalue2)) == EPRINT) - { - fprintf(stderr, - "\n %s est un mauvais parametre\n\n", - cvalue2); - exit(-1); - } - printf("decode type: %d\n",conv_Rd_type(etat_lect)); - break; - case '?': - if (isprint(optopt)) - fprintf(stderr, - "Option inconnu `-%c'.\n", - optopt); - else - fprintf(stderr, - "\ncaractere d'option inconnu '\\x%x'.\n", - optopt); - exit(-1); - default: - abort(); + case 'h': + printf("serialplot -h cet aide\n\n"); + printf("serialplot -s /dev/ttyS0 permet de choisir\n"); + printf(" entre le port serie /dev/ttyS0 \n"); + printf(" au lieu de l'entre standard\n"); + printf(" -t un nombre dans cet intervalle\n"); + printf(" [1-255], le nb de bit à 1\n"); + printf(" correspond au nombre de valeur\n"); + printf(" a afficher"); + printf("\nserialplot -v affiche les credits\n\n"); + exit(0); + case 'v': + printf("\n%s by __--''\\_TB_/''--__\n\n",argv[0]); + exit(0); + case 's': + cvalue = optarg; + input_flag = 1; + break; + case 't': + cvalue2 = optarg; + if ((etat_lect = read_std_param(cvalue2)) == EPRINT) + { + fprintf(stderr, + "\n %s est un mauvais parametre\n\n", + cvalue2); + exit(-1); + } + printf("decode type: %d\n",conv_Rd_type(etat_lect)); + break; + case '?': + if (isprint(optopt)) + fprintf(stderr, + "Option inconnu `-%c'.\n", + optopt); + else + fprintf(stderr, + "\ncaractere d'option inconnu '\\x%x'.\n", + optopt); + exit(-1); + default: + abort(); } static int fd_x11; int quit=0; @@ -88,28 +90,27 @@ main (int argc, char **argv) /* Initialise SDL. */ if (SDL_Init (SDL_INIT_TIMER | SDL_INIT_VIDEO) == -1) erreur (); atexit (SDL_Quit); - + /* Selectionne un mode video. */ - screen = SDL_SetVideoMode (640, 480, 0, SDL_HWSURFACE /*| SDL_FULLSCREEN*/ - | SDL_DOUBLEBUF); + screen = SDL_SetVideoMode (640, 480, 0, SDL_HWSURFACE /*| SDL_FULLSCREEN*/); if (!screen) erreur (); printf("init SDL : done\n"); SDL_SysWMinfo info; SDL_VERSION(&info.version); if ( SDL_GetWMInfo(&info) <0 ) - { - exit(-1); - } + { + exit(-1); + } fd_x11 = ConnectionNumber(info.info.x11.display); printf("fd X11 defined\n"); - + int fd_input; char input[8]; if (input_flag == 1) - { - /*ouvre le port serie*/ - fd_input = init_serial(cvalue); - printf("init serial port : done\n"); + { + /*ouvre le port serie*/ + fd_input = init_serial(cvalue); + printf("init serial port : done\n"); //commande specifique a l'appli char command[10]; @@ -155,84 +156,83 @@ main (int argc, char **argv) FILE * FILE_input = ( input_flag == 1) ? fdopen(fd_input,"r+") : stdin; while(!quit) - { - FD_SET(fd_input,&fsdcR); - FD_SET(fd_x11,&fsdcR); - retval = select ( (fd_input > fd_x11) ? fd_input + 1 : fd_x11 + 1, - &fsdcR, - NULL, - NULL, - NULL - ); - if (retval) - { - if (FD_ISSET(fd_x11,&fsdcR)) - { - while(SDL_PollEvent(&event)) - { - if(event.type == SDL_KEYDOWN) - { - Uint8 *keystate; - switch (event.key.keysym.sym) - { - case SDLK_ESCAPE: - case SDLK_q: - quit=1; - break; - case SDLK_m: - melt = !melt; - break; - case SDLK_KP_MINUS: - keystate = SDL_GetKeyState(NULL); - if ( keystate[SDLK_F1]) - scale[0] /=2 ; - if ( keystate[SDLK_F2]) - scale[1] /=2 ; - break; - case SDLK_KP_PLUS: - keystate = SDL_GetKeyState(NULL); - if ( keystate[SDLK_F1]) - scale[0] *=2; - if ( keystate[SDLK_F2]) - scale[1] *=2; - break; - case SDLK_PAGEUP: - keystate = SDL_GetKeyState(NULL); - if ( keystate[SDLK_F1]) - position[0] -=5; - if ( keystate[SDLK_F2]) - position[1] -=5; - break; - case SDLK_PAGEDOWN: - keystate = SDL_GetKeyState(NULL); - if ( keystate[SDLK_F1]) - position[0] +=5; - if ( keystate[SDLK_F2]) - position[1] +=5; - break; - - default : //printf("touche sans fonction\n"); - break; - } - } - if (event.type == SDL_QUIT) - { - quit++; - } - } - } - if (FD_ISSET(fd_input,&fsdcR)) - { - if (fgets (input, - sizeof (input) / sizeof (input[0]), - FILE_input )) - { - if (input[0] == '!') - { - read_line(vals,&etat_c,etat_lect,input); - } - } - } + { + FD_SET(fd_input,&fsdcR); + FD_SET(fd_x11,&fsdcR); + retval = select ( (fd_input > fd_x11) ? fd_input + 1 : fd_x11 + 1, + &fsdcR, + NULL, + NULL, + NULL + ); + if (retval) + { + if (FD_ISSET(fd_x11,&fsdcR)) + { + while(SDL_PollEvent(&event)) + { + if(event.type == SDL_KEYDOWN) + { + Uint8 *keystate; + switch (event.key.keysym.sym) + { + case SDLK_ESCAPE: + case SDLK_q: + quit=1; + break; + case SDLK_m: + melt = !melt; + break; + case SDLK_KP_MINUS: + keystate = SDL_GetKeyState(NULL); + if ( keystate[SDLK_F1]) + scale[0] /=2 ; + if ( keystate[SDLK_F2]) + scale[1] /=2 ; + break; + case SDLK_KP_PLUS: + keystate = SDL_GetKeyState(NULL); + if ( keystate[SDLK_F1]) + scale[0] *=2; + if ( keystate[SDLK_F2]) + scale[1] *=2; + break; + case SDLK_PAGEUP: + keystate = SDL_GetKeyState(NULL); + if ( keystate[SDLK_F1]) + position[0] -=5; + if ( keystate[SDLK_F2]) + position[1] -=5; + break; + case SDLK_PAGEDOWN: + keystate = SDL_GetKeyState(NULL); + if ( keystate[SDLK_F1]) + position[0] +=5; + if ( keystate[SDLK_F2]) + position[1] +=5; + break; + default : //printf("touche sans fonction\n"); + break; + } + } + if (event.type == SDL_QUIT) + { + quit++; + } + } + } + if (FD_ISSET(fd_input,&fsdcR)) + { + if (fgets (input, + sizeof (input) / sizeof (input[0]), + FILE_input )) + { + if (input[0] == '!') + { + read_line(vals,&etat_c,etat_lect,input); + } + } + } } // Etat d'affichage @@ -247,17 +247,17 @@ main (int argc, char **argv) } -/* - if (fgets (input, sizeof (input) / sizeof (input[0]), stdin)) - { - s = input; - for (i = 0; i < sizeof (vals) / sizeof (vals[0]); i++) - { - vals[i] = strtod (s, &es); - if (es == s) - break; - s = es; - } + /* + if (fgets (input, sizeof (input) / sizeof (input[0]), stdin)) + { + s = input; + for (i = 0; i < sizeof (vals) / sizeof (vals[0]); i++) + { + vals[i] = strtod (s, &es); + if (es == s) + break; + s = es; + } draw(melt, i, vals); -- cgit v1.2.3