more improvment on seven segments

This commit is contained in:
Tonton Th 2019-01-29 23:25:59 +01:00
parent 65e9d58486
commit c52b1659b5
4 changed files with 71 additions and 7 deletions

View File

@ -6,7 +6,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <string.h>
#include <ctype.h>
#include <getopt.h>
#include <ncurses.h>
@ -110,8 +110,9 @@ switch (digit) {
case ' ': bits = 0; break;
case '.': bits = 0x80; break;
case '-': bits = 0x40; break;
default: bits = 0x09; break;
default: bits = 0x49; break;
}
aff7segs_base(win, lig, col, bits, 0);
@ -119,4 +120,34 @@ aff7segs_base(win, lig, col, bits, 0);
return 0;
}
/* ---------------------------------------------------------------- */
int aff7segs_short(WINDOW * win, int lig, int col, short value)
{
char buff[10];
int idx;
sprintf(buff, "%6d", value);
mvwaddstr(win, lig-1, col, buff);
for (idx=0; idx<strlen(buff); idx++) {
aff7segs_digit(win, lig, col+(idx*9), buff[idx]);
}
wrefresh(win);
return 0;
}
/* ---------------------------------------------------------------- */
int aff7segs_float(WINDOW * win, int lig, int col, float value)
{
char buff[10];
int idx;
sprintf(buff, "%6.2f", value);
mvwaddstr(win, lig-1, col, buff);
for (idx=0; idx<strlen(buff); idx++) {
aff7segs_digit(win, lig, col+(idx*9), buff[idx]);
}
wrefresh(win);
return 0;
}
/* ---------------------------------------------------------------- */

View File

@ -16,7 +16,10 @@ int message(char *txt)
{
static int pass = 0;
fprintf(stderr, "%s [%s]\n", __func__, txt);
standout();
mvhline(LINES-1, 0, '~', COLS);
mvaddch(LINES-1, 0, "\\|/-"[(pass++)%4]);
mvaddstr(LINES-1, 2, txt);
standend();

View File

@ -7,6 +7,8 @@ int message(char *);
int aff7segs_base(WINDOW * win, int lig, int col, int bits, int k);
int aff7segs_digit(WINDOW * win, int lig, int col, char digit);
int aff7segs_short(WINDOW * win, int lig, int col, short value);
int aff7segs_float(WINDOW * win, int lig, int col, float value);
WINDOW * open_waterfall(char *title, int flags);

View File

@ -11,14 +11,39 @@
int verbosity;
/* ---------------------------------------------------------------- */
void demo_7segments(int nbl, int notused)
int demo_composite(int nbl, int k)
{
int loop, idx, c, p;
int loop, foo;
short sval;
char ligne[120];
time_t temps;
float fval;
for (loop=0; loop<nbl; loop++) {
sprintf(ligne, "$%04x", 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;
}
/* ---------------------------------------------------------------- */
void demo_7segments(int nbl, int notused)
{
int loop, idx, foo;
char ligne[120];
time_t temps;
struct tm *p_tms;
for (loop=0; loop<nbl; loop++) {
sprintf(ligne, "%04x", loop);
mvaddstr(2, 1, ligne);
for (idx=0; idx<strlen(ligne); idx++) {
aff7segs_digit(stdscr, 3, 10+(idx*9), ligne[idx]);
@ -32,7 +57,9 @@ for (loop=0; loop<nbl; loop++) {
if (verbosity && (loop%2)) {
temps = time(NULL);
sprintf(ligne, "%12ld | %s", temps, ctime(&temps));
p_tms = localtime(&temps);
foo = strftime(ligne, 100, "%F %H:%M", p_tms);
// sprintf(ligne, "%12ld | %s", temps, ctime(&temps));
message(ligne);
}
@ -160,6 +187,7 @@ 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;
case 3: demo_composite(nb_loops, 0); break;
default:
fprintf(stderr, "eyecandy #%d don't exist\n", demonum);
break;