DD2-monitor/viz/curses/t.c

131 lines
2.3 KiB
C
Raw Normal View History

2019-01-10 01:44:47 +01:00
#include <stdio.h>
2019-01-10 20:35:03 +01:00
#include <unistd.h>
2019-01-10 01:44:47 +01:00
#include <stdlib.h>
#include <strings.h>
2019-01-22 15:24:49 +01:00
#include <time.h>
2019-01-10 01:44:47 +01:00
#include <getopt.h>
#include <ncurses.h>
#include "ecran.h"
int verbosity;
/* ---------------------------------------------------------------- */
void demo_vumetres(int nbl, int notused)
{
int loop, idx;
int hpos;
char ligne[100];
float value;
for (loop=0; loop<nbl; loop++) {
value = (float)loop / (float)nbl;
2019-01-24 13:06:26 +01:00
for (idx=0; idx<8; idx++) {
2019-01-24 13:06:26 +01:00
hpos = 4 * (idx+1);
2019-01-24 01:41:08 +01:00
value = drand48();
2019-01-24 13:06:26 +01:00
if (idx<4) vumetre_0(stdscr, hpos, 12, value, 60);
else vumetre_1(stdscr, hpos, 12, value, 60);
}
refresh();
usleep(200*1000);
}
}
2019-01-10 01:44:47 +01:00
/* ---------------------------------------------------------------- */
void demo_waterfall(int nbl, int k)
2019-01-10 01:44:47 +01:00
{
2019-01-10 14:07:56 +01:00
int loop, foo;
char line[100];
WINDOW *water;
static float rvals[4];
2019-01-22 15:24:49 +01:00
struct timespec ts;
2019-01-10 14:07:56 +01:00
2019-01-22 15:24:49 +01:00
ts.tv_sec = 0;
ts.tv_nsec = 200 * 1000 * 1000;
2019-01-10 01:44:47 +01:00
water = open_waterfall("premier essai", 0);
for (loop=0; loop<nbl; loop++) {
2019-01-24 01:20:39 +01:00
sprintf(line, " %06X %04X ", loop, rand()&0xffff);
message(line);
2019-01-10 14:07:56 +01:00
wrefresh(stdscr);
2019-01-10 01:44:47 +01:00
2019-01-10 14:07:56 +01:00
for (foo=0; foo<4; foo++) {
if (rand()%100<42) {
2019-01-22 15:24:49 +01:00
rvals[foo] += 4.04 * (foo + 1);
2019-01-10 14:07:56 +01:00
}
if (rvals[foo] > 1023.0) {
rvals[foo] = (float)(rand() % 25);
2019-01-10 14:07:56 +01:00
}
2019-01-10 01:44:47 +01:00
}
2019-01-10 14:07:56 +01:00
plot_waterfall(water, 1, rvals);
2019-01-22 15:24:49 +01:00
/* if (rand()%10 < 1) sleep(1); */
foo = nanosleep(&ts, NULL);
if (foo) {
/* got a signal ? */
message("err on nanosleep");
}
2019-01-10 14:07:56 +01:00
}
close_waterfall(water, 0);
2019-01-10 01:44:47 +01:00
}
/* ---------------------------------------------------------------- */
static void finish(int signal)
{
endwin(); exit(0);
}
/* ---------------------------------------------------------------- */
int main (int argc, char *argv[])
{
int opt;
int demonum = 0;
2019-01-10 01:44:47 +01:00
/* set some default values */
verbosity = 0;
while ((opt = getopt(argc, argv, "vy:")) != -1) {
2019-01-10 01:44:47 +01:00
switch (opt) {
case 'v': verbosity++; break;
case 'y': demonum = atoi(optarg); break;
2019-01-10 01:44:47 +01:00
default:
fprintf(stderr, "%s : uh ?", argv[0]);
exit(1);
break;
}
}
initscr();
nonl(); cbreak(); noecho();
keypad(stdscr, TRUE); /* acces aux touches 'curseur' */
2019-01-10 14:07:56 +01:00
fond_ecran(" Demonstrator ");
2019-01-10 01:44:47 +01:00
switch (demonum) {
case 0: demo_vumetres(666, 0); break;
case 1: demo_waterfall(666, 0); break;
}
2019-01-10 01:44:47 +01:00
/*
* plop, on a fini, restaurer la console
*/
finish(0);
return 0;
}
/* ---------------------------------------------------------------- */