Browse code

more improvment on seven segments

tth authored on 29/01/2019 22:25:59
Showing 4 changed files
... ...
@@ -6,7 +6,7 @@
6 6
 
7 7
 #include  <stdio.h>
8 8
 #include  <stdlib.h>
9
-#include  <strings.h>
9
+#include  <string.h>
10 10
 #include  <ctype.h>
11 11
 #include  <getopt.h>
12 12
 #include  <ncurses.h>
... ...
@@ -110,8 +110,9 @@ switch (digit) {
110 110
 
111 111
 	case ' ':	bits = 0;		break;
112 112
 	case '.':	bits = 0x80;		break;
113
+	case '-':	bits = 0x40;		break;
113 114
 
114
-	default:	bits = 0x09;		break;
115
+	default:	bits = 0x49;		break;
115 116
 	}
116 117
 
117 118
 aff7segs_base(win, lig, col, bits, 0);
... ...
@@ -119,4 +120,34 @@ aff7segs_base(win, lig, col, bits, 0);
119 119
 return 0;
120 120
 }
121 121
 /* ---------------------------------------------------------------- */
122
+int aff7segs_short(WINDOW * win, int lig, int col, short value)
123
+{
124
+char	buff[10];
125
+int	idx;
126
+
127
+sprintf(buff, "%6d", value);
128
+mvwaddstr(win, lig-1, col, buff);
129
+for (idx=0; idx<strlen(buff); idx++) {
130
+	aff7segs_digit(win, lig, col+(idx*9), buff[idx]);
131
+	}
132
+wrefresh(win);
133
+
134
+return 0;
135
+}
136
+/* ---------------------------------------------------------------- */
137
+int aff7segs_float(WINDOW * win, int lig, int col, float value)
138
+{
139
+char	buff[10];
140
+int	idx;
141
+
142
+sprintf(buff, "%6.2f", value);
143
+mvwaddstr(win, lig-1, col, buff);
144
+for (idx=0; idx<strlen(buff); idx++) {
145
+	aff7segs_digit(win, lig, col+(idx*9), buff[idx]);
146
+	}
147
+wrefresh(win);
122 148
 
149
+return 0;
150
+}
151
+
152
+/* ---------------------------------------------------------------- */
... ...
@@ -16,7 +16,10 @@ int message(char *txt)
16 16
 {
17 17
 static	int	pass = 0;
18 18
 
19
+fprintf(stderr, "%s [%s]\n", __func__, txt);
20
+
19 21
 standout();
22
+mvhline(LINES-1, 0, '~', COLS);
20 23
 mvaddch(LINES-1, 0, "\\|/-"[(pass++)%4]);
21 24
 mvaddstr(LINES-1, 2, txt);
22 25
 standend();
... ...
@@ -7,6 +7,8 @@ int message(char *);
7 7
 
8 8
 int aff7segs_base(WINDOW * win, int lig, int col, int bits, int k);
9 9
 int aff7segs_digit(WINDOW * win, int lig, int col, char digit);
10
+int aff7segs_short(WINDOW * win, int lig, int col, short value);
11
+int aff7segs_float(WINDOW * win, int lig, int col, float value);
10 12
 
11 13
 
12 14
 WINDOW * open_waterfall(char *title, int flags);
... ...
@@ -10,15 +10,40 @@
10 10
 
11 11
 int	verbosity;
12 12
 
13
+/* ---------------------------------------------------------------- */
14
+int demo_composite(int nbl, int k)
15
+{
16
+int		loop, foo;
17
+short		sval;
18
+char		ligne[120];
19
+float		fval;
20
+
21
+for (loop=0; loop<nbl; loop++) {
22
+	sval = (short)((loop % 1024)-512);
23
+
24
+	foo = aff7segs_short(stdscr, 5, 5, sval);
25
+	if (foo) message("KRKRK");
26
+	fval = (float)sval / 1024.0;
27
+	foo = aff7segs_float(stdscr, 16, 5, fval);
28
+	if (foo) message("KRKRK");
29
+
30
+	sprintf(ligne, "%04x", loop);
31
+	mvaddstr(2, 1, ligne);
32
+	refresh();
33
+	usleep(400*1000);
34
+	}
35
+return 0;
36
+}
13 37
 /* ---------------------------------------------------------------- */
14 38
 void demo_7segments(int nbl, int notused)
15 39
 {
16
-int		loop, idx, c, p;
40
+int		loop, idx, foo;
17 41
 char		ligne[120];
18 42
 time_t		temps;
43
+struct tm       *p_tms;
19 44
 
20 45
 for (loop=0; loop<nbl; loop++) {
21
-	sprintf(ligne, "$%04x", loop);
46
+	sprintf(ligne, "%04x", loop);
22 47
 	mvaddstr(2, 1, ligne);
23 48
 	for (idx=0; idx<strlen(ligne); idx++) {
24 49
 		aff7segs_digit(stdscr, 3, 10+(idx*9), ligne[idx]);
... ...
@@ -32,7 +57,9 @@ for (loop=0; loop<nbl; loop++) {
32 32
 
33 33
 	if (verbosity && (loop%2)) {
34 34
 		temps = time(NULL);
35
-		sprintf(ligne, "%12ld | %s", temps, ctime(&temps));
35
+		p_tms = localtime(&temps);
36
+		foo = strftime(ligne, 100, "%F %H:%M", p_tms);
37
+		// sprintf(ligne, "%12ld | %s", temps, ctime(&temps));
36 38
 		message(ligne);
37 39
 		}
38 40
 
... ...
@@ -160,6 +187,7 @@ switch (demonum) {
160 160
 	case 0:		demo_vumetres(nb_loops, 0);		break;
161 161
 	case 1:		demo_waterfall(nb_loops, 0);		break;
162 162
 	case 2:		demo_7segments(nb_loops, 0);		break;
163
+	case 3:		demo_composite(nb_loops, 0);		break;
163 164
 	default:
164 165
 		fprintf(stderr, "eyecandy #%d don't exist\n", demonum);
165 166
 		break;