Browse Source

first version of ncurses waterfall

master
tth 2 years ago
parent
commit
ba9b0d993f
5 changed files with 97 additions and 32 deletions
  1. +6
    -4
      viz/curses/Makefile
  2. +8
    -9
      viz/curses/ecran.c
  3. +3
    -1
      viz/curses/ecran.h
  4. +25
    -9
      viz/curses/t.c
  5. +55
    -9
      viz/curses/waterfall.c

+ 6
- 4
viz/curses/Makefile View File

@ -1,21 +1,23 @@
# --------------- ***
COPT = -Wall -g -DTRACE=0
# --------------- ***
ecran.o: ecran.c Makefile ecran.h
gcc -Wall -c $<
gcc $(COPT) -c $<
7segments.o: 7segments.c Makefile
gcc -Wall -c $<
gcc $(COPT) -c $<
waterfall.o: waterfall.c Makefile
gcc -Wall -c $<
gcc $(COPT) -c $<
# --------------- ***
OBJ = ecran.o waterfall.o 7segments.o
t: t.c Makefile $(OBJ) ecran.h
gcc -Wall $< $(OBJ) -lncurses -o $@
gcc $(COPT) $< $(OBJ) -lncurses -o $@
# --------------- ***

+ 8
- 9
viz/curses/ecran.c View File

@ -1,6 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <string.h>
#include <getopt.h>
#include <ncurses.h>
@ -21,16 +21,21 @@ standend();
/* refresh(); */
}
/* ---------------------------------------------------------------- */
int fond_ecran(void)
int fond_ecran(char *title)
{
char *tp;
#if TRACE
int foo;
char buffer[200];
#endif
tp = " DD2 MONITORING by tTh 2019 ";
if (NULL != title) tp = title;
barre_inverse('+', 0);
standout();
mvaddstr(0, 2, " DD2 MONITORING by tTh 2019 ");
mvaddstr(0, 2, tp);
#if TRACE
sprintf(buffer, " ecran %dx%d ", COLS, LINES);
foo = strlen(buffer);
@ -39,12 +44,6 @@ mvaddstr(0, COLS-2-foo, buffer);
standend();
refresh();
#if TRACE
fprintf(stderr, "HAUT %3d\n", HAUT);
fprintf(stderr, "HAUT_1 %3d BARRE_1 %3d\n", HAUT_1, BARRE_1);
fprintf(stderr, "HAUT_2 %3d BARRE_2 %3d\n", HAUT_2, BARRE_2);
#endif
return 0;
}
/* ---------------------------------------------------------------- */

+ 3
- 1
viz/curses/ecran.h View File

@ -1,6 +1,8 @@
int fond_ecran(void);
int fond_ecran(char *titre);
WINDOW * open_waterfall(char *title, int flags);
int plot_waterfall(WINDOW *wf, int flags, float values[4]);
int close_waterfall(WINDOW *wf, int notused);

+ 25
- 9
viz/curses/t.c View File

@ -12,20 +12,36 @@ int verbosity;
/* ---------------------------------------------------------------- */
void demo(int nbl, int k)
{
int loop;
char line[100];
WINDOW *water;
int loop, foo;
char line[100];
WINDOW *water;
static float rvals[4];
water = open_waterfall("premier essai", 0);
for (loop=0; loop<nbl; loop++) {
sprintf(line, "%04X %04X", loop, rand()&0xffff);
mvaddstr(5, 5, line);
sprintf(line, "%04X %04X", loop, rand()&0xffff);
mvwaddstr(stdscr, LINES-1, 1, line);
wrefresh(stdscr);
sleep(1);
refresh();
for (foo=0; foo<4; foo++) {
if (rand()%100<42) {
rvals[foo] += 3.8*(foo + 1);
}
if (rvals[foo] > 1023.0) {
rvals[foo] = (float)(rand() % 15);
}
}
plot_waterfall(water, 1, rvals);
if (rand()%10 < 1) sleep(1);
}
close_waterfall(water, 0);
}
/* ---------------------------------------------------------------- */
static void finish(int signal)
@ -59,9 +75,9 @@ nonl(); cbreak(); noecho();
keypad(stdscr, TRUE); /* acces aux touches 'curseur' */
fond_ecran();
fond_ecran(" Demonstrator ");
demo(1024, 0);
demo(9000, 0);
/*
* plop, on a fini, restaurer la console


+ 55
- 9
viz/curses/waterfall.c View File

@ -22,27 +22,73 @@ WINDOW *open_waterfall(char *title, int flags)
WINDOW *win;
int l, c, w, h;
l = 2; c = 1;
w = COLS - 2; h = LINES -3;
l = 1; c = 1;
w = COLS - 2; h = LINES - 3;
win = newwin(h, w, l, c);
scrollok(win, 1);
waddstr(win, title); waddch(win, '\n');
wrefresh(win);
return win;
}
/* ---------------------------------------------------------------- */
int plot_waterfall(WINDOW *wf, float values[4])
int plot_waterfall(WINDOW *wf, int mode, float values[4])
{
#define TL 1000
int foo;
char tag, ligne[TL+1];
int foo, idx;
char tag, ligne[TL+1];
float coef_w;
static long iter;
for(foo=0; foo<TL; foo++) *(ligne+foo) = '-';
if (0 == (iter%10)) {
memset(ligne, '-', TL);
}
else {
memset(ligne, ' ', TL);
}
for (foo=0; foo<500; foo+=10) {
ligne[foo] = '|';
}
ligne[COLS-4] = '\0';
iter++;
coef_w = (float)(COLS-2) / 1024.0;
#if TRACE
sprintf(ligne, "coef_w = %f\n", coef_w);
waddstr(wf, ligne); waddch(wf, '\n');
#endif
switch (mode) {
case 0: default:
sprintf(ligne, "%11.3f %11.3f %11.3f %11.3f",
values[0], values[1], values[2], values[3]);
#if TRACE
fprintf(stderr, "%s [%s]\n", __func__, ligne);
#endif
break;
case 1:
for(foo=0; foo<4; foo++) {
tag = "ATOX"[foo];
idx = (int)(values[foo]*coef_w);
ligne[idx] = tag;
}
ligne[COLS-4] = '\0';
break;
for(foo=0; foo<4; foo++) {
tag = "ATOX"[foo];
}
/* poke the text in the curses window */
// scroll(wf);
waddstr(wf, ligne); waddch(wf, '\n');
wrefresh(wf);
return -1;
}
/* ---------------------------------------------------------------- */


Loading…
Cancel
Save