summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--i/serialplot/serialplot.c61
-rw-r--r--i/serialplot/serialplot_sdl.c57
-rw-r--r--i/serialplot/serialplot_sdl.h2
3 files changed, 89 insertions, 31 deletions
diff --git a/i/serialplot/serialplot.c b/i/serialplot/serialplot.c
index 532f128..ec412e2 100644
--- a/i/serialplot/serialplot.c
+++ b/i/serialplot/serialplot.c
@@ -1,5 +1,5 @@
/*TODO : refaire un calcul de moyenne : OK
- * faire un système d'échelle plus lisible
+ * 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 :
*/
@@ -133,7 +133,17 @@ main (int argc, char **argv)
else
fd_input = 0 ;
int melt = 0;
- int vals[8];
+
+ 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 */
@@ -161,6 +171,7 @@ main (int argc, char **argv)
{
if(event.type == SDL_KEYDOWN)
{
+ Uint8 *keystate;
switch (event.key.keysym.sym)
{
case SDLK_ESCAPE:
@@ -170,20 +181,40 @@ main (int argc, char **argv)
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");
+ case SDLK_KP_MINUS:
+ keystate = SDL_GetKeyState(NULL);
+ if ( keystate[SDLK_F1])
+ scale[0] /=2 ;
+ if ( keystate[SDLK_F2])
+ scale[1] /=2 ;
break;
- default : printf("touche sans fonction\n");
+ 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;
}
}
- else if (event.type == SDL_QUIT)
+ if (event.type == SDL_QUIT)
{
quit++;
}
@@ -192,8 +223,8 @@ main (int argc, char **argv)
if (FD_ISSET(fd_input,&fsdcR))
{
if (fgets (input,
- sizeof (input) / sizeof (input[0]),
- FILE_input ))
+ sizeof (input) / sizeof (input[0]),
+ FILE_input ))
{
if (input[0] == '!')
{
@@ -208,7 +239,7 @@ main (int argc, char **argv)
{
int i;
i =conv_Rd_type(etat_lect);
- draw(melt,i,vals);
+ draw(melt,i,vals,scale,position);
draw_inf(i,vals);
nextFrame();
etat_c = E1;
diff --git a/i/serialplot/serialplot_sdl.c b/i/serialplot/serialplot_sdl.c
index 22013f8..958736e 100644
--- a/i/serialplot/serialplot_sdl.c
+++ b/i/serialplot/serialplot_sdl.c
@@ -1,38 +1,65 @@
#include "serialplot_sdl.h"
void
-draw (int melt, int n, int vals[])
+draw (int melt, int n, int vals[], double scale[],int position[])
{
int i;
Uint32 color;
static const Uint8 colors[][3] =
{
- { 0, 255, 0 },
- { 255, 0, 255 },
- { 255, 255, 0 },
- { 255, 0, 0 },
- { 0, 255, 255 },
- { 255, 255, 255 },
+ { 0, 0, 255 }, // bleu
+ { 0, 255, 0 }, // vert
+ { 255, 0, 0 }, // rouge
+ { 255, 0, 255 }, // mauve
+ { 255, 255, 0 }, // jaune
+ { 0, 255, 255 }, // cyan
+ { 255, 255, 255 }, // blanc
};
int c = 0;
static int x = 0;
int y;
- int ymin = 0;
- int ystep = screen->h / (melt ? 1 : n);
+ //int ymin = 0;
+ /* ystep = la hauteur de la surface / soit par le nb de courbe à
+ * affiché ou par 1 */
+ //int ystep = screen->h / (melt ? 1 : n);
x = (x + 1) % screen->w;
/* Vérouille la surface pour y ecrire directement. */
if (SDL_MUSTLOCK (screen)) SDL_LockSurface (screen);
clearcol (x);
for (i = 0; i < n; i++)
{
- double v = vals[i];
- y = ymin + ystep / 2 - v * ystep / 2;
- y = y < 0 ? ymin : (y >= ymin + ystep ? ymin + ystep - 1 : y);
- color = SDL_MapRGB (screen->format, colors[c][0], colors[c][1], colors[c][2]);
+
+ int v = vals[i];
+ y = screen->h / 2 - v * scale[i] + position[i];
+ /* saturation des extremes */
+ if (y<0)
+ y=0;
+ else
+ if(y > screen->h)
+ y = screen->h;
+ color = SDL_MapRGB (screen->format,
+ colors[c][0],
+ colors[c][1],
+ colors[c][2]);
+ putpixel(x,y,color);
+ y = screen->h / 2 + position[i];
+ color = SDL_MapRGB (screen->format,
+ colors[6][0],
+ colors[6][1],
+ colors[6][2]);
putpixel(x,y,color);
- if (!melt)
- ymin += ystep;
c = (c + 1) % (sizeof (colors) / sizeof (colors[0]));
+ // double v = vals[i];
+// y = ymin + ystep / 2 - v * ystep / 2;
+// y = y < 0 ? ymin : (y >= ymin + ystep ? ymin + ystep - 1 : y);
+// color = SDL_MapRGB (screen->format, colors[c][0], colors[c][1], colors[c][2]);
+// putpixel(x,y,color);
+// if (!melt)
+// {
+// ymin += ystep;
+// }
+//
+// c = (c + 1) % (sizeof (colors) / sizeof (colors[0]));
}
if (SDL_MUSTLOCK (screen)) SDL_UnlockSurface (screen);
}
diff --git a/i/serialplot/serialplot_sdl.h b/i/serialplot/serialplot_sdl.h
index 2152c8a..b612ac3 100644
--- a/i/serialplot/serialplot_sdl.h
+++ b/i/serialplot/serialplot_sdl.h
@@ -10,7 +10,7 @@
void erreur (void);
void nextFrame (void);
-void draw (int melt, int n, int vals[]);
+void draw (int melt, int n, int vals[], double scale[], int position [] );
void putpixel(int x, int y, Uint32 pixel);
void clearcol (int x);
void draw_inf(int n, int vals[]);