DD2-monitor/viz/curses/7segments.c

109 lines
2.1 KiB
C
Raw Normal View History

2019-01-10 11:44:47 +11:00
/*
* DD2 Monitoring
*
* ncurses seven segment display
*/
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
2019-01-27 02:10:12 +11:00
#include <ctype.h>
2019-01-10 11:44:47 +11:00
#include <getopt.h>
#include <ncurses.h>
#include "ecran.h"
int verbosity;
/* ---------------------------------------------------------------- */
2019-01-27 02:10:12 +11:00
int aff7segs_base(WINDOW * win, int lig, int col, int bits, int k)
{
int numbit, mask;
2019-01-27 02:10:12 +11:00
int foo;
2019-01-10 11:44:47 +11:00
2019-01-27 02:10:12 +11:00
for (foo=0; foo<9; foo++) {
mvwhline(win, lig+foo, col, '~', 6);
}
wstandout(win);
for (numbit=0; numbit<8; numbit++) {
mask = 1 << numbit;
2019-01-27 02:10:12 +11:00
switch(mask & bits) {
case 0x01:
2019-01-27 02:10:12 +11:00
mvwaddstr(win, lig, col+1, " ");
break;
case 0x02:
2019-01-27 02:10:12 +11:00
mvwaddch(win, lig+1, col+5, ' ');
mvwaddch(win, lig+2, col+5, ' ');
mvwaddch(win, lig+3, col+5, ' ');
break;
case 0x04:
2019-01-27 02:10:12 +11:00
mvwaddch(win, lig+5, col+5, ' ');
mvwaddch(win, lig+6, col+5, ' ');
mvwaddch(win, lig+7, col+5, ' ');
break;
case 0x08:
2019-01-27 02:10:12 +11:00
mvwaddstr(win, lig+8, col+1, " ");
break;
case 0x10:
2019-01-27 02:10:12 +11:00
mvwaddch(win, lig+5, col, ' ');
mvwaddch(win, lig+6, col, ' ');
mvwaddch(win, lig+7, col, ' ');
break;
case 0x20:
2019-01-27 02:10:12 +11:00
mvwaddch(win, lig+1, col , ' ');
mvwaddch(win, lig+2, col , ' ');
mvwaddch(win, lig+3, col , ' ');
break;
case 0x40:
2019-01-27 02:10:12 +11:00
mvwaddstr(win, lig+4, col+1, " ");
break;
case 0x80:
/* decimal point */
break;
}
}
2019-01-27 02:10:12 +11:00
wstandend(win);
2019-01-27 02:10:12 +11:00
return 0;
}
2019-01-10 11:44:47 +11:00
/* ---------------------------------------------------------------- */
2019-01-27 02:10:12 +11:00
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;
}
2019-01-23 00:25:26 +11:00
/* ---------------------------------------------------------------- */
2019-01-10 11:44:47 +11:00