2019-01-10 11:44:47 +11:00
|
|
|
#include <stdio.h>
|
2019-01-11 06:35:03 +11:00
|
|
|
#include <unistd.h>
|
2019-01-10 11:44:47 +11:00
|
|
|
#include <stdlib.h>
|
2019-01-27 02:10:12 +11:00
|
|
|
#include <string.h>
|
2019-01-23 01:24:49 +11:00
|
|
|
#include <time.h>
|
2019-01-10 11:44:47 +11:00
|
|
|
#include <getopt.h>
|
|
|
|
#include <ncurses.h>
|
|
|
|
|
|
|
|
#include "ecran.h"
|
|
|
|
|
|
|
|
int verbosity;
|
|
|
|
|
2019-01-30 09:25:59 +11:00
|
|
|
/* ---------------------------------------------------------------- */
|
|
|
|
int demo_composite(int nbl, int k)
|
|
|
|
{
|
|
|
|
int loop, foo;
|
|
|
|
short sval;
|
|
|
|
char ligne[120];
|
|
|
|
float fval;
|
|
|
|
|
|
|
|
for (loop=0; loop<nbl; loop++) {
|
|
|
|
sval = (short)((loop % 1024)-512);
|
|
|
|
|
|
|
|
foo = aff7segs_short(stdscr, 5, 5, sval);
|
|
|
|
if (foo) message("KRKRK");
|
|
|
|
fval = (float)sval / 1024.0;
|
|
|
|
foo = aff7segs_float(stdscr, 16, 5, fval);
|
|
|
|
if (foo) message("KRKRK");
|
|
|
|
|
|
|
|
sprintf(ligne, "%04x", loop);
|
|
|
|
mvaddstr(2, 1, ligne);
|
|
|
|
refresh();
|
|
|
|
usleep(400*1000);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2019-01-27 02:10:12 +11:00
|
|
|
/* ---------------------------------------------------------------- */
|
|
|
|
void demo_7segments(int nbl, int notused)
|
|
|
|
{
|
2019-01-30 09:25:59 +11:00
|
|
|
int loop, idx, foo;
|
2019-01-29 02:38:06 +11:00
|
|
|
char ligne[120];
|
|
|
|
time_t temps;
|
2019-01-30 09:25:59 +11:00
|
|
|
struct tm *p_tms;
|
2019-01-27 02:10:12 +11:00
|
|
|
|
|
|
|
for (loop=0; loop<nbl; loop++) {
|
2019-01-30 09:25:59 +11:00
|
|
|
sprintf(ligne, "%04x", loop);
|
2019-01-27 22:23:35 +11:00
|
|
|
mvaddstr(2, 1, ligne);
|
2019-01-27 02:10:12 +11:00
|
|
|
for (idx=0; idx<strlen(ligne); idx++) {
|
2019-01-27 22:23:35 +11:00
|
|
|
aff7segs_digit(stdscr, 3, 10+(idx*9), ligne[idx]);
|
2019-01-27 02:10:12 +11:00
|
|
|
}
|
|
|
|
|
2019-01-27 22:12:49 +11:00
|
|
|
sprintf(ligne, "%.3f", drand48());
|
2019-01-29 02:38:06 +11:00
|
|
|
mvaddstr(13, 1, ligne);
|
2019-01-27 22:12:49 +11:00
|
|
|
for (idx=0; idx<strlen(ligne); idx++) {
|
2019-01-29 02:38:06 +11:00
|
|
|
aff7segs_digit(stdscr, 14, 10+(idx*9), ligne[idx]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (verbosity && (loop%2)) {
|
|
|
|
temps = time(NULL);
|
2019-01-30 09:25:59 +11:00
|
|
|
p_tms = localtime(&temps);
|
|
|
|
foo = strftime(ligne, 100, "%F %H:%M", p_tms);
|
|
|
|
// sprintf(ligne, "%12ld | %s", temps, ctime(&temps));
|
2019-01-29 02:38:06 +11:00
|
|
|
message(ligne);
|
2019-01-27 22:12:49 +11:00
|
|
|
}
|
2019-01-27 02:10:12 +11:00
|
|
|
|
2019-01-27 22:12:49 +11:00
|
|
|
refresh();
|
|
|
|
usleep(400*1000);
|
2019-01-27 02:10:12 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-01-24 11:00:18 +11:00
|
|
|
/* ---------------------------------------------------------------- */
|
|
|
|
void demo_vumetres(int nbl, int notused)
|
|
|
|
{
|
|
|
|
int loop, idx;
|
|
|
|
int hpos;
|
2019-01-29 02:38:06 +11:00
|
|
|
char ligne[100];
|
2019-01-24 11:00:18 +11:00
|
|
|
float value;
|
2019-01-29 02:38:06 +11:00
|
|
|
time_t temps;
|
2019-01-24 11:00:18 +11:00
|
|
|
|
|
|
|
for (loop=0; loop<nbl; loop++) {
|
|
|
|
|
|
|
|
value = (float)loop / (float)nbl;
|
|
|
|
|
2019-01-24 23:06:26 +11:00
|
|
|
for (idx=0; idx<8; idx++) {
|
2019-01-24 11:00:18 +11:00
|
|
|
|
2019-01-24 23:06:26 +11:00
|
|
|
hpos = 4 * (idx+1);
|
2019-01-24 11:41:08 +11:00
|
|
|
value = drand48();
|
2019-01-24 11:00:18 +11:00
|
|
|
|
2019-01-24 23:06:26 +11:00
|
|
|
if (idx<4) vumetre_0(stdscr, hpos, 12, value, 60);
|
|
|
|
else vumetre_1(stdscr, hpos, 12, value, 60);
|
2019-01-24 11:00:18 +11:00
|
|
|
|
|
|
|
}
|
2019-01-29 02:38:06 +11:00
|
|
|
|
|
|
|
if (verbosity && (loop%2)) {
|
|
|
|
temps = time(NULL);
|
|
|
|
sprintf(ligne, "%12ld | %s", temps, ctime(&temps));
|
|
|
|
message(ligne);
|
|
|
|
}
|
2019-01-24 11:00:18 +11:00
|
|
|
|
|
|
|
refresh();
|
|
|
|
usleep(200*1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-01-10 11:44:47 +11:00
|
|
|
/* ---------------------------------------------------------------- */
|
2019-01-24 08:39:03 +11:00
|
|
|
void demo_waterfall(int nbl, int k)
|
2019-01-10 11:44:47 +11:00
|
|
|
{
|
2019-01-11 00:07:56 +11:00
|
|
|
int loop, foo;
|
|
|
|
char line[100];
|
|
|
|
WINDOW *water;
|
|
|
|
static float rvals[4];
|
2019-01-23 01:24:49 +11:00
|
|
|
struct timespec ts;
|
2019-01-11 00:07:56 +11:00
|
|
|
|
2019-01-23 01:24:49 +11:00
|
|
|
ts.tv_sec = 0;
|
2019-01-24 08:39:03 +11:00
|
|
|
ts.tv_nsec = 200 * 1000 * 1000;
|
2019-01-10 11:44:47 +11:00
|
|
|
|
|
|
|
water = open_waterfall("premier essai", 0);
|
|
|
|
|
|
|
|
for (loop=0; loop<nbl; loop++) {
|
|
|
|
|
2019-01-24 11:20:39 +11:00
|
|
|
sprintf(line, " %06X %04X ", loop, rand()&0xffff);
|
|
|
|
message(line);
|
|
|
|
|
2019-01-11 00:07:56 +11:00
|
|
|
wrefresh(stdscr);
|
2019-01-10 11:44:47 +11:00
|
|
|
|
2019-01-11 00:07:56 +11:00
|
|
|
for (foo=0; foo<4; foo++) {
|
|
|
|
if (rand()%100<42) {
|
2019-01-23 01:24:49 +11:00
|
|
|
rvals[foo] += 4.04 * (foo + 1);
|
2019-01-11 00:07:56 +11:00
|
|
|
}
|
|
|
|
if (rvals[foo] > 1023.0) {
|
2019-01-13 02:26:15 +11:00
|
|
|
rvals[foo] = (float)(rand() % 25);
|
2019-01-11 00:07:56 +11:00
|
|
|
}
|
2019-01-10 11:44:47 +11:00
|
|
|
}
|
2019-01-11 00:07:56 +11:00
|
|
|
|
|
|
|
plot_waterfall(water, 1, rvals);
|
|
|
|
|
2019-01-23 01:24:49 +11:00
|
|
|
/* if (rand()%10 < 1) sleep(1); */
|
|
|
|
foo = nanosleep(&ts, NULL);
|
|
|
|
if (foo) {
|
|
|
|
/* got a signal ? */
|
|
|
|
message("err on nanosleep");
|
|
|
|
}
|
2019-01-11 00:07:56 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
close_waterfall(water, 0);
|
|
|
|
|
2019-01-10 11:44:47 +11:00
|
|
|
}
|
|
|
|
/* ---------------------------------------------------------------- */
|
|
|
|
static void finish(int signal)
|
|
|
|
{
|
|
|
|
endwin(); exit(0);
|
|
|
|
}
|
|
|
|
/* ---------------------------------------------------------------- */
|
|
|
|
int main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int opt;
|
2019-01-24 11:00:18 +11:00
|
|
|
int demonum = 0;
|
2019-01-27 21:01:33 +11:00
|
|
|
int nb_loops = 200;
|
2019-01-10 11:44:47 +11:00
|
|
|
|
|
|
|
/* set some default values */
|
|
|
|
verbosity = 0;
|
|
|
|
|
2019-01-27 21:01:33 +11:00
|
|
|
while ((opt = getopt(argc, argv, "n:vy:")) != -1) {
|
2019-01-10 11:44:47 +11:00
|
|
|
switch (opt) {
|
2019-01-27 21:01:33 +11:00
|
|
|
case 'n': nb_loops = atoi(optarg); break;
|
2019-01-10 11:44:47 +11:00
|
|
|
|
2019-01-27 21:01:33 +11:00
|
|
|
case 'v': verbosity++; break;
|
|
|
|
|
|
|
|
case 'y': demonum = atoi(optarg); break;
|
2019-01-24 11:00:18 +11:00
|
|
|
|
2019-01-10 11:44:47 +11:00
|
|
|
default:
|
|
|
|
fprintf(stderr, "%s : uh ?", argv[0]);
|
|
|
|
exit(1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
initscr();
|
|
|
|
nonl(); cbreak(); noecho();
|
|
|
|
|
|
|
|
keypad(stdscr, TRUE); /* acces aux touches 'curseur' */
|
|
|
|
|
2019-01-11 00:07:56 +11:00
|
|
|
fond_ecran(" Demonstrator ");
|
2019-01-10 11:44:47 +11:00
|
|
|
|
2019-01-24 11:00:18 +11:00
|
|
|
switch (demonum) {
|
2019-01-27 21:01:33 +11:00
|
|
|
case 0: demo_vumetres(nb_loops, 0); break;
|
|
|
|
case 1: demo_waterfall(nb_loops, 0); break;
|
|
|
|
case 2: demo_7segments(nb_loops, 0); break;
|
2019-01-30 09:25:59 +11:00
|
|
|
case 3: demo_composite(nb_loops, 0); break;
|
2019-01-29 02:38:06 +11:00
|
|
|
default:
|
|
|
|
fprintf(stderr, "eyecandy #%d don't exist\n", demonum);
|
|
|
|
break;
|
2019-01-24 11:00:18 +11:00
|
|
|
}
|
2019-01-10 11:44:47 +11:00
|
|
|
|
|
|
|
/*
|
|
|
|
* plop, on a fini, restaurer la console
|
|
|
|
*/
|
|
|
|
finish(0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* ---------------------------------------------------------------- */
|