summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--i/serialplot/Makefile2
-rw-r--r--i/serialplot/serialplot.c284
-rw-r--r--i/serialplot/serialplot_sdl.c29
3 files changed, 162 insertions, 153 deletions
diff --git a/i/serialplot/Makefile b/i/serialplot/Makefile
index a31ac4b..1f88001 100644
--- a/i/serialplot/Makefile
+++ b/i/serialplot/Makefile
@@ -1,5 +1,5 @@
CFLAGS = $(shell sdl-config --cflags) -g -Wall
-LDLIBS = $(shell sdl-config --libs) -lSDL_image
+LDLIBS = $(shell sdl-config --libs) -g -Wall -lSDL_image
OBJECTS = BFont.o serialplot_sdl.o serialplot_io.o serialplot_RdMch.o
all: serialplot
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 <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
+
+#include <sys/ioctl.h>
+
#include <stdio.h>
#include <string.h>
#include <ctype.h>
@@ -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);
diff --git a/i/serialplot/serialplot_sdl.c b/i/serialplot/serialplot_sdl.c
index 8dbbb8b..2c4fb32 100644
--- a/i/serialplot/serialplot_sdl.c
+++ b/i/serialplot/serialplot_sdl.c
@@ -35,8 +35,8 @@ draw (int melt, int n, int vals[], double scale[],int position[])
if (y<0)
y=0;
else
- if(y > screen->h)
- y = screen->h;
+ if(y >= screen->h)
+ y = screen->h - 1;
color = SDL_MapRGB (screen->format,
colors[c][0],
colors[c][1],
@@ -67,19 +67,28 @@ draw (int melt, int n, int vals[], double scale[],int position[])
void
nextFrame (void)
{
-// static int lastFrame = 0;
-// static const int minFrame = 1000 / 50;
-// int curFrame;
+ static int lastUpdate = 0;
+ int curFrame;
+ curFrame = SDL_GetTicks ();
+ if (!lastUpdate || lastUpdate < curFrame - 1000 / 10)
+ {
+ lastUpdate = curFrame;
+ SDL_Flip (screen);
+ }
+#if 0
+ static int lastFrame = 0;
+ static const int minFrame = 1000 / 50;
+ int curFrame;
/* Echange les deux tampons. */
SDL_Flip (screen);
/* Freine le programme s'il est trops rapide. */
-// curFrame = SDL_GetTicks ();
-// if (lastFrame && lastFrame + minFrame > curFrame)
-// SDL_Delay (lastFrame + minFrame - curFrame);
+ curFrame = SDL_GetTicks ();
+ if (lastFrame && lastFrame + minFrame > curFrame)
+ SDL_Delay (lastFrame + minFrame - curFrame);
/* Enregistre l'heure de dernier rafraichisement. */
-// lastFrame = curFrame;
-
+ lastFrame = curFrame;
+#endif
}
void