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-31 02:44:43 +11:00
|
|
|
#include <math.h>
|
2019-01-10 11:44:47 +11:00
|
|
|
#include <getopt.h>
|
|
|
|
#include <ncurses.h>
|
|
|
|
|
|
|
|
#include "ecran.h"
|
|
|
|
|
|
|
|
int verbosity;
|
|
|
|
|
2019-02-05 22:16:27 +11:00
|
|
|
/* ---------------------------------------------------------------- */
|
|
|
|
int demo_minidigits(int nbl, int k)
|
|
|
|
{
|
|
|
|
int loop, foo;
|
|
|
|
char chaine[100];
|
|
|
|
|
|
|
|
for (loop=0; loop<nbl; loop++) {
|
|
|
|
|
|
|
|
sprintf(chaine, "== %06X ==", loop);
|
2019-05-15 00:18:03 +11:00
|
|
|
aff_message(chaine);
|
2019-02-05 22:16:27 +11:00
|
|
|
|
2019-02-06 02:50:09 +11:00
|
|
|
sprintf(chaine, ".%08d.", rand()%1000000);
|
|
|
|
|
2019-04-04 01:25:38 +11:00
|
|
|
/***
|
2019-02-05 22:16:27 +11:00
|
|
|
for (foo=0; foo<10; foo++) {
|
2019-02-06 02:50:09 +11:00
|
|
|
minidigit_0(stdscr, 5, 2+foo*8, chaine[foo], 0);
|
2019-02-05 22:16:27 +11:00
|
|
|
}
|
2019-04-04 01:25:38 +11:00
|
|
|
***/
|
|
|
|
minidigit_affstr(stdscr, 5, 2, chaine);
|
2019-02-05 22:16:27 +11:00
|
|
|
wrefresh(stdscr);
|
|
|
|
usleep(350*1000);
|
|
|
|
|
2019-04-04 01:25:38 +11:00
|
|
|
/***
|
2019-02-05 22:16:27 +11:00
|
|
|
for (foo=0; foo<10; foo++) {
|
|
|
|
minidigit_0(stdscr, 5, 2+foo*8, ' ', 0);
|
|
|
|
}
|
2019-04-04 01:25:38 +11:00
|
|
|
***/
|
2019-02-06 02:50:09 +11:00
|
|
|
|
|
|
|
minidigit_HMS(stdscr, 15, 9, 0);
|
|
|
|
|
2019-02-05 22:16:27 +11:00
|
|
|
wrefresh(stdscr);
|
|
|
|
usleep(250*1000);
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
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);
|
|
|
|
|
2019-01-31 02:44:43 +11:00
|
|
|
foo = aff7segs_short(stdscr, 5, 3, sval);
|
2019-05-15 00:18:03 +11:00
|
|
|
if (foo) aff_message("KRKRK aff7 short");
|
2019-01-31 02:44:43 +11:00
|
|
|
|
2019-01-30 09:25:59 +11:00
|
|
|
fval = (float)sval / 1024.0;
|
2019-01-31 02:44:43 +11:00
|
|
|
foo = aff7segs_float(stdscr, 16, 3, fval);
|
2019-05-15 00:18:03 +11:00
|
|
|
if (foo) aff_message("KRKRK aff7 float");
|
2019-01-31 02:44:43 +11:00
|
|
|
|
|
|
|
fval = fabs(fval);
|
|
|
|
foo = vumetre_0(stdscr, 29, 5, fval, COLS-10);
|
|
|
|
|
2019-01-30 09:25:59 +11:00
|
|
|
sprintf(ligne, "%04x", loop);
|
|
|
|
mvaddstr(2, 1, ligne);
|
|
|
|
refresh();
|
2019-01-31 02:44:43 +11:00
|
|
|
usleep(200*1000);
|
2019-01-30 09:25:59 +11:00
|
|
|
}
|
|
|
|
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-05-15 00:18:03 +11:00
|
|
|
aff_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));
|
2019-05-15 00:18:03 +11:00
|
|
|
aff_message(ligne);
|
2019-01-29 02:38:06 +11:00
|
|
|
}
|
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);
|
2019-05-15 00:18:03 +11:00
|
|
|
aff_message(line);
|
2019-01-24 11:20:39 +11:00
|
|
|
|
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 ? */
|
2019-05-15 00:18:03 +11:00
|
|
|
aff_message("err on nanosleep");
|
2019-01-23 01:24:49 +11:00
|
|
|
}
|
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-04-04 01:25:38 +11:00
|
|
|
fond_ecran(" Ncurses Eyecandy ");
|
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-02-05 22:16:27 +11:00
|
|
|
case 4: demo_minidigits(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;
|
|
|
|
}
|
|
|
|
/* ---------------------------------------------------------------- */
|