/*TODO : refaire un calcul de moyenne : OK * faire un système d'échelle plus lisible : partiellement fait * intégrer la lecture serie dans le programme : OK * plus de protection sur l'option t : * Faudrait rajouté: une fonction de sauvegarde */ #include #include #include #include #include #include #include #include #include #include #include "serialplot_sdl.h" #include "serialplot_io.h" #include "serialplot_RdMch.h" SDL_Surface *screen; int old_value[256]; unsigned long cpt[8]; struct termios oldconf; int main (int argc, char **argv) { int rep; char *cvalue = NULL; char *cvalue2 = NULL; enum R_stat etat_lect; opterr = 0; int input_flag =0; // flag de choix de l'entre 0 = stdin // decodeage de la ligne de commande 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(); } static int fd_x11; int quit=0; SDL_Event event; /* 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*/); if (!screen) erreur (); printf("init SDL : done\n"); SDL_SysWMinfo info; SDL_VERSION(&info.version); if ( SDL_GetWMInfo(&info) <0 ) { 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"); //commande specifique a l'appli char command[10]; // Not yet implemented //command = "!z"; //write_serial(fd_input,&command); //fgets(input,sizeof (input) / sizeof (input[0]),fdopen(fd_input,"r+")) strcpy(command,"!c"); write_serial(fd_input,command); // lecture blocante donc marche pas // fgets(input,sizeof (input) / sizeof (input[0]),fdopen(fd_input,"r+")); // if((input[0]=='!') && (input[1]=='C')) // fprintf(stdout,"Calibration: OK\n"); // else // { // fprintf(stderr,"Erreur à la calibration\n"); // quit ++; // } } else fd_input = 0 ; int melt = 0; int vals[8]; // valeur à afficher par voies double scale[8]; // facteur d'echelle par voies int position[8]; // position sur la voie int i; for (i=0; i<8;i++) { scale[i] = 1; position[i] = 0; } enum R_stat etat_c = E1; /* initialisation du select */ fd_set fsdcR; int retval; FD_ZERO(&fsdcR); 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); } } } } // Etat d'affichage if (etat_c == EPRINT) { int i; i =conv_Rd_type(etat_lect); draw(melt,i,vals,scale,position); draw_inf(i,vals); nextFrame(); etat_c = E1; } /* 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); draw_inf(i, vals); nextFrame(); } */ } /* ferme le port serie */ if (input_flag ==1) close_serial(fd_input); printf("close\n"); return 0; }