2019-01-10 11:44:47 +11:00
|
|
|
/*
|
|
|
|
* DD2 Monitoring
|
|
|
|
*
|
|
|
|
* ncurses seven segment display
|
|
|
|
*/
|
|
|
|
|
2019-07-31 06:20:33 +11:00
|
|
|
/**********************************************************************
|
|
|
|
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
|
|
|
Version 2, December 2004
|
|
|
|
|
|
|
|
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
|
|
|
|
|
|
|
Everyone is permitted to copy and distribute verbatim or modified
|
|
|
|
copies of this license document, and changing it is allowed as long
|
|
|
|
as the name is changed.
|
|
|
|
|
|
|
|
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
|
|
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
|
|
|
|
|
|
|
0. You just DO WHAT THE FUCK YOU WANT TO.
|
|
|
|
**********************************************************************/
|
|
|
|
|
2019-01-10 11:44:47 +11:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2019-01-30 09:25:59 +11:00
|
|
|
#include <string.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"
|
|
|
|
|
2019-02-03 03:40:56 +11:00
|
|
|
extern int verbosity;
|
2019-01-10 11:44:47 +11:00
|
|
|
|
|
|
|
/* ---------------------------------------------------------------- */
|
2019-01-27 02:10:12 +11:00
|
|
|
int aff7segs_base(WINDOW * win, int lig, int col, int bits, int k)
|
2019-01-13 02:26:15 +11:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-01-27 21:36:51 +11:00
|
|
|
#define KC '+'
|
|
|
|
#define KS "++++"
|
|
|
|
|
2019-01-27 02:10:12 +11:00
|
|
|
wstandout(win);
|
2019-01-13 02:26:15 +11:00
|
|
|
for (numbit=0; numbit<8; numbit++) {
|
|
|
|
mask = 1 << numbit;
|
2019-01-27 02:10:12 +11:00
|
|
|
switch(mask & bits) {
|
2019-01-13 02:26:15 +11:00
|
|
|
case 0x01:
|
2019-01-27 21:36:51 +11:00
|
|
|
mvwaddstr(win, lig, col+1, KS);
|
2019-01-27 02:10:12 +11:00
|
|
|
break;
|
2019-01-13 02:26:15 +11:00
|
|
|
case 0x02:
|
2019-01-27 21:36:51 +11:00
|
|
|
mvwaddch(win, lig+1, col+5, KC);
|
|
|
|
mvwaddch(win, lig+2, col+5, KC);
|
|
|
|
mvwaddch(win, lig+3, col+5, KC);
|
2019-01-27 02:10:12 +11:00
|
|
|
break;
|
2019-01-13 02:26:15 +11:00
|
|
|
case 0x04:
|
2019-01-27 21:36:51 +11:00
|
|
|
mvwaddch(win, lig+5, col+5, KC);
|
|
|
|
mvwaddch(win, lig+6, col+5, KC);
|
|
|
|
mvwaddch(win, lig+7, col+5, KC);
|
2019-01-27 02:10:12 +11:00
|
|
|
break;
|
2019-01-13 02:26:15 +11:00
|
|
|
case 0x08:
|
2019-01-27 21:36:51 +11:00
|
|
|
mvwaddstr(win, lig+8, col+1, KS);
|
2019-01-27 02:10:12 +11:00
|
|
|
break;
|
2019-01-13 02:26:15 +11:00
|
|
|
case 0x10:
|
2019-01-27 21:36:51 +11:00
|
|
|
mvwaddch(win, lig+5, col, KC);
|
|
|
|
mvwaddch(win, lig+6, col, KC);
|
|
|
|
mvwaddch(win, lig+7, col, KC);
|
2019-01-27 02:10:12 +11:00
|
|
|
break;
|
2019-01-13 02:26:15 +11:00
|
|
|
case 0x20:
|
2019-01-27 21:36:51 +11:00
|
|
|
mvwaddch(win, lig+1, col , KC);
|
|
|
|
mvwaddch(win, lig+2, col , KC);
|
|
|
|
mvwaddch(win, lig+3, col , KC);
|
2019-01-27 02:10:12 +11:00
|
|
|
break;
|
2019-01-13 02:26:15 +11:00
|
|
|
case 0x40:
|
2019-01-27 21:36:51 +11:00
|
|
|
mvwaddstr(win, lig+4, col+1, KS);
|
2019-01-27 02:10:12 +11:00
|
|
|
break;
|
2019-01-13 02:26:15 +11:00
|
|
|
case 0x80:
|
|
|
|
/* decimal point */
|
2019-01-27 21:36:51 +11:00
|
|
|
mvwaddch(win, lig+7, col+2 , KC);
|
|
|
|
mvwaddch(win, lig+7, col+3 , KC);
|
|
|
|
mvwaddch(win, lig+8, col+2 , KC);
|
|
|
|
mvwaddch(win, lig+8, col+3 , KC);
|
2019-01-13 02:26:15 +11:00
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-01-27 02:10:12 +11:00
|
|
|
wstandend(win);
|
2019-01-13 02:26:15 +11:00
|
|
|
|
2019-01-27 02:10:12 +11:00
|
|
|
return 0;
|
2019-01-13 02:26:15 +11:00
|
|
|
}
|
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;
|
|
|
|
|
2019-01-31 02:44:43 +11:00
|
|
|
#if TRACE > 1
|
2019-01-27 02:10:12 +11:00
|
|
|
fprintf(stderr, ">>> %s ( %p %d %d '%c' )\n", __func__,
|
|
|
|
win, lig, col, digit);
|
|
|
|
#endif
|
|
|
|
|
2019-01-29 02:07:48 +11:00
|
|
|
if (isxdigit(digit)) digit = toupper(digit);
|
|
|
|
|
2019-01-27 02:10:12 +11:00
|
|
|
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;
|
|
|
|
|
2019-01-29 02:07:48 +11:00
|
|
|
/* hexadecimal letters */
|
|
|
|
case 'A': bits = 0x77; break;
|
|
|
|
case 'B': bits = 0x7c; break;
|
|
|
|
case 'C': bits = 0x39; break;
|
|
|
|
case 'D': bits = 0x5e; break;
|
|
|
|
case 'E': bits = 0x79; break;
|
|
|
|
case 'F': bits = 0x71; break;
|
|
|
|
|
2019-01-27 21:36:51 +11:00
|
|
|
case ' ': bits = 0; break;
|
|
|
|
case '.': bits = 0x80; break;
|
2019-01-30 09:25:59 +11:00
|
|
|
case '-': bits = 0x40; break;
|
2019-01-27 21:36:51 +11:00
|
|
|
|
2019-01-30 09:25:59 +11:00
|
|
|
default: bits = 0x49; break;
|
2019-01-27 02:10:12 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
aff7segs_base(win, lig, col, bits, 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2019-01-23 00:25:26 +11:00
|
|
|
/* ---------------------------------------------------------------- */
|
2019-01-30 09:25:59 +11:00
|
|
|
int aff7segs_short(WINDOW * win, int lig, int col, short value)
|
|
|
|
{
|
|
|
|
char buff[10];
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
sprintf(buff, "%6d", value);
|
2019-01-31 02:44:43 +11:00
|
|
|
// mvwaddstr(win, lig-1, col, buff);
|
2019-01-30 09:25:59 +11:00
|
|
|
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);
|
2019-01-31 02:44:43 +11:00
|
|
|
// mvwaddstr(win, lig-1, col, buff);
|
2019-01-30 09:25:59 +11:00
|
|
|
for (idx=0; idx<strlen(buff); idx++) {
|
|
|
|
aff7segs_digit(win, lig, col+(idx*9), buff[idx]);
|
|
|
|
}
|
|
|
|
wrefresh(win);
|
2019-01-10 11:44:47 +11:00
|
|
|
|
2019-01-30 09:25:59 +11:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------- */
|