premier afficheir 7 segments

This commit is contained in:
tth 2019-01-26 16:10:12 +01:00
parent b43e3b0a1c
commit cb0a2b5732
3 changed files with 100 additions and 17 deletions

View File

@ -7,6 +7,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <ctype.h>
#include <getopt.h>
#include <ncurses.h>
@ -15,42 +16,93 @@
int verbosity;
/* ---------------------------------------------------------------- */
int afficheur_7segs(WINDOW * win, int lig, int col, int bits, int k)
int aff7segs_base(WINDOW * win, int lig, int col, int bits, int k)
{
int numbit, mask;
int foo;
for (foo=0; foo<9; foo++) {
mvwhline(win, lig+foo, col, '~', 6);
}
wstandout(win);
for (numbit=0; numbit<8; numbit++) {
mask = 1 << numbit;
switch(mask) {
switch(mask & bits) {
case 0x01:
mvwaddstr(win, lig, col+1, " ");
break;
case 0x02:
mvwaddch(win, lig+1, col+5, ' ');
mvwaddch(win, lig+2, col+5, ' ');
mvwaddch(win, lig+3, col+5, ' ');
break;
case 0x04:
mvwaddch(win, lig+5, col+5, ' ');
mvwaddch(win, lig+6, col+5, ' ');
mvwaddch(win, lig+7, col+5, ' ');
break;
case 0x08:
mvwaddstr(win, lig+8, col+1, " ");
break;
case 0x10:
mvwaddch(win, lig+5, col, ' ');
mvwaddch(win, lig+6, col, ' ');
mvwaddch(win, lig+7, col, ' ');
break;
case 0x20:
mvwaddch(win, lig+1, col , ' ');
mvwaddch(win, lig+2, col , ' ');
mvwaddch(win, lig+3, col , ' ');
break;
case 0x40:
mvwaddstr(win, lig+4, col+1, " ");
break;
case 0x80:
/* decimal point */
break;
default:
fprintf(stderr, "%s mask is wrong\n", __func__);
break;
}
}
wstandend(win);
return -1;
return 0;
}
/* ---------------------------------------------------------------- */
int aff7segs_digit(WINDOW * win, int lig, int col, char digit)
{
int bits;
#if TRACE
fprintf(stderr, ">>> %s ( %p %d %d '%c' )\n", __func__,
win, lig, col, digit);
#endif
if (!isdigit(digit)) {
return -1;
}
switch (digit) {
case '0': bits = 0x3f; break;
case '1': bits = 0x06; break;
case '2': bits = 0x5b; break;
case '3': bits = 0x4f; break;
case '4': bits = 0x66; break;
case '5': bits = 0x6d; break;
case '6': bits = 0x7d; break;
case '7': bits = 0x07; break;
case '8': bits = 0x7f; break;
case '9': bits = 0x6f; break;
default:
bits = 0x40;
break;
}
aff7segs_base(win, lig, col, bits, 0);
return 0;
}
/* ---------------------------------------------------------------- */

View File

@ -5,6 +5,9 @@
int fond_ecran(char *titre);
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);
WINDOW * open_waterfall(char *title, int flags);
int plot_waterfall(WINDOW *wf, int flags, float values[4]);

View File

@ -1,7 +1,7 @@
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <strings.h>
#include <string.h>
#include <time.h>
#include <getopt.h>
#include <ncurses.h>
@ -10,12 +10,39 @@
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*8);
aff7segs_digit(stdscr, 17, p, c);
mvaddch(16, p, c);
}
for (loop=0; loop<nbl; loop++) {
sprintf(ligne, "%4d", loop);
for (idx=0; idx<strlen(ligne); idx++) {
aff7segs_digit(stdscr, 5, 1+(idx*8), ligne[idx]);
}
mvaddstr(3, 2, ligne);
refresh();
usleep(300*1000);
}
}
/* ---------------------------------------------------------------- */
void demo_vumetres(int nbl, int notused)
{
int loop, idx;
int hpos;
char ligne[100];
// char ligne[100];
float value;
for (loop=0; loop<nbl; loop++) {
@ -118,6 +145,7 @@ fond_ecran(" Demonstrator ");
switch (demonum) {
case 0: demo_vumetres(666, 0); break;
case 1: demo_waterfall(666, 0); break;
case 2: demo_7segments(450, 0); break;
}
/*