DD2-monitor/viz/curses/t.c
2019-01-27 11:01:33 +01:00

162 lines
2.9 KiB
C

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <getopt.h>
#include <ncurses.h>
#include "ecran.h"
int verbosity;
/* ---------------------------------------------------------------- */
void demo_7segments(int nbl, int notused)
{
int loop, idx, c, p;
char ligne[100];
for (idx=0; idx<10; idx++) {
c = '0'+idx;
p = 1+(idx*9);
aff7segs_digit(stdscr, 17, p, c);
mvaddch(16, p, c);
}
for (loop=0; loop<nbl; loop++) {
sprintf(ligne, "%5d", loop);
for (idx=0; idx<strlen(ligne); idx++) {
aff7segs_digit(stdscr, 5, 1+(idx*9), ligne[idx]);
}
mvaddstr(3, 2, ligne);
refresh();
usleep(200*1000);
}
}
/* ---------------------------------------------------------------- */
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;
for (idx=0; idx<8; idx++) {
hpos = 4 * (idx+1);
value = drand48();
if (idx<4) vumetre_0(stdscr, hpos, 12, value, 60);
else vumetre_1(stdscr, hpos, 12, value, 60);
}
refresh();
usleep(200*1000);
}
}
/* ---------------------------------------------------------------- */
void demo_waterfall(int nbl, int k)
{
int loop, foo;
char line[100];
WINDOW *water;
static float rvals[4];
struct timespec ts;
ts.tv_sec = 0;
ts.tv_nsec = 200 * 1000 * 1000;
water = open_waterfall("premier essai", 0);
for (loop=0; loop<nbl; loop++) {
sprintf(line, " %06X %04X ", loop, rand()&0xffff);
message(line);
wrefresh(stdscr);
for (foo=0; foo<4; foo++) {
if (rand()%100<42) {
rvals[foo] += 4.04 * (foo + 1);
}
if (rvals[foo] > 1023.0) {
rvals[foo] = (float)(rand() % 25);
}
}
plot_waterfall(water, 1, rvals);
/* if (rand()%10 < 1) sleep(1); */
foo = nanosleep(&ts, NULL);
if (foo) {
/* got a signal ? */
message("err on nanosleep");
}
}
close_waterfall(water, 0);
}
/* ---------------------------------------------------------------- */
static void finish(int signal)
{
endwin(); exit(0);
}
/* ---------------------------------------------------------------- */
int main (int argc, char *argv[])
{
int opt;
int demonum = 0;
int nb_loops = 200;
/* set some default values */
verbosity = 0;
while ((opt = getopt(argc, argv, "n:vy:")) != -1) {
switch (opt) {
case 'n': nb_loops = atoi(optarg); break;
case 'v': verbosity++; break;
case 'y': demonum = atoi(optarg); break;
default:
fprintf(stderr, "%s : uh ?", argv[0]);
exit(1);
break;
}
}
initscr();
nonl(); cbreak(); noecho();
keypad(stdscr, TRUE); /* acces aux touches 'curseur' */
fond_ecran(" Demonstrator ");
switch (demonum) {
case 0: demo_vumetres(nb_loops, 0); break;
case 1: demo_waterfall(nb_loops, 0); break;
case 2: demo_7segments(nb_loops, 0); break;
}
/*
* plop, on a fini, restaurer la console
*/
finish(0);
return 0;
}
/* ---------------------------------------------------------------- */