summaryrefslogtreecommitdiff
path: root/i/serialplot/serialplot.c
diff options
context:
space:
mode:
Diffstat (limited to 'i/serialplot/serialplot.c')
-rw-r--r--i/serialplot/serialplot.c243
1 files changed, 243 insertions, 0 deletions
diff --git a/i/serialplot/serialplot.c b/i/serialplot/serialplot.c
new file mode 100644
index 0000000..532f128
--- /dev/null
+++ b/i/serialplot/serialplot.c
@@ -0,0 +1,243 @@
+/*TODO : refaire un calcul de moyenne : OK
+ * faire un système d'échelle plus lisible
+ * intégrer la lecture serie dans le programme : OK
+ * plus de protection sur l'option t :
+*/
+
+#include <SDL.h>
+#include <SDL_syswm.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#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*/
+ | SDL_DOUBLEBUF);
+ 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];
+ 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)
+ {
+ switch (event.key.keysym.sym)
+ {
+ case SDLK_ESCAPE:
+ case SDLK_q:
+ quit=1;
+ break;
+ case SDLK_m:
+ melt = !melt;
+ break;
+ case SDLK_a:
+ case SDLK_b:
+ case SDLK_c:
+ case SDLK_d:
+ case SDLK_e:
+ case SDLK_f:
+ case SDLK_g:
+ case SDLK_h: printf("abcdefgh\n");
+ break;
+ default : printf("touche sans fonction\n");
+ break;
+ }
+ }
+ else 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);
+ 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;
+}
+