DD2-monitor/viz/curses/waterfall.c

118 lines
2.0 KiB
C
Raw Normal View History

2019-01-10 11:44:47 +11:00
/*
* DD2 Monitoring
*
* ncurses waterfall interface
*/
#include <stdio.h>
#include <stdlib.h>
2019-01-11 06:35:03 +11:00
#include <string.h>
2019-01-10 11:44:47 +11:00
#include <getopt.h>
#include <ncurses.h>
#include "ecran.h"
extern int verbosity;
/* ---------------------------------------------------------------- */
WINDOW *open_waterfall(char *title, int flags)
{
WINDOW *win;
int l, c, w, h;
2019-01-11 00:07:56 +11:00
l = 1; c = 1;
w = COLS; h = LINES - 3;
2019-01-10 11:44:47 +11:00
win = newwin(h, w, l, c);
2019-01-11 00:07:56 +11:00
scrollok(win, 1);
waddstr(win, title); waddch(win, '\n');
wrefresh(win);
2019-01-10 11:44:47 +11:00
return win;
}
/* ---------------------------------------------------------------- */
2019-01-11 00:07:56 +11:00
int plot_waterfall(WINDOW *wf, int mode, float values[4])
2019-01-10 11:44:47 +11:00
{
#define TL 1000
2019-01-11 00:07:56 +11:00
int foo, idx;
char tag, ligne[TL+1];
float coef_w;
static long iter;
2019-01-10 11:44:47 +11:00
2019-01-11 00:07:56 +11:00
if (0 == (iter%10)) {
2019-01-11 06:35:03 +11:00
memset(ligne, '.', TL);
2019-01-11 00:07:56 +11:00
}
else {
memset(ligne, ' ', TL);
}
2019-01-11 06:35:03 +11:00
for (foo=0; foo<500; foo+=20) {
ligne[foo] = '.';
2019-01-11 00:07:56 +11:00
}
ligne[COLS-1] = '\0';
2019-01-11 00:07:56 +11:00
iter++;
coef_w = (float)(COLS-1) / 1024.0;
2019-01-11 00:07:56 +11:00
2019-01-11 06:35:03 +11:00
#if TRACE > 1
fprintf(stderr, "COLS = %d, coef_w = %f\n", COLS, coef_w);
2019-01-11 00:07:56 +11:00
#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;
2019-01-11 06:35:03 +11:00
#if TRACE
fprintf(stderr, "%c %3d ", tag, idx);
#endif
2019-01-11 00:07:56 +11:00
}
ligne[COLS-1] = '\0';
2019-01-11 06:35:03 +11:00
#if TRACE
fprintf(stderr, "\n"); fflush(stderr);
#endif
2019-01-11 00:07:56 +11:00
break;
2019-01-10 11:44:47 +11:00
}
2019-01-11 00:07:56 +11:00
/* poke the text in the curses window */
// scroll(wf);
waddstr(wf, ligne); waddch(wf, '\n');
wrefresh(wf);
2019-01-10 11:44:47 +11:00
return -1;
}
/* ---------------------------------------------------------------- */
int close_waterfall(WINDOW *wf, int notused)
{
2019-01-27 21:55:25 +11:00
int foo;
2019-01-10 11:44:47 +11:00
if (NULL == wf) {
fprintf(stderr, "%s wf is null\n", __func__);
return -1;
}
2019-01-27 21:55:25 +11:00
foo = delwin(wf);
if (ERR==foo) {
fprintf(stderr, "%s : err on delwin\n", __func__);
return -1;
}
2019-01-10 11:44:47 +11:00
return 0;
}
/* ---------------------------------------------------------------- */