Browse Source

more improvment on seven segments

tth 1 year ago
parent
commit
c52b1659b5
4 changed files with 69 additions and 5 deletions
  1. 33
    2
      viz/curses/7segments.c
  2. 3
    0
      viz/curses/ecran.c
  3. 2
    0
      viz/curses/ecran.h
  4. 31
    3
      viz/curses/t.c

+ 33
- 2
viz/curses/7segments.c View File

@@ -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 120
 return 0;
120 121
 }
121 122
 /* ---------------------------------------------------------------- */
123
+int aff7segs_short(WINDOW * win, int lig, int col, short value)
124
+{
125
+char	buff[10];
126
+int	idx;
127
+
128
+sprintf(buff, "%6d", value);
129
+mvwaddstr(win, lig-1, col, buff);
130
+for (idx=0; idx<strlen(buff); idx++) {
131
+	aff7segs_digit(win, lig, col+(idx*9), buff[idx]);
132
+	}
133
+wrefresh(win);
134
+
135
+return 0;
136
+}
137
+/* ---------------------------------------------------------------- */
138
+int aff7segs_float(WINDOW * win, int lig, int col, float value)
139
+{
140
+char	buff[10];
141
+int	idx;
142
+
143
+sprintf(buff, "%6.2f", value);
144
+mvwaddstr(win, lig-1, col, buff);
145
+for (idx=0; idx<strlen(buff); idx++) {
146
+	aff7segs_digit(win, lig, col+(idx*9), buff[idx]);
147
+	}
148
+wrefresh(win);
122 149
 
150
+return 0;
151
+}
152
+
153
+/* ---------------------------------------------------------------- */

+ 3
- 0
viz/curses/ecran.c View File

@@ -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();

+ 2
- 0
viz/curses/ecran.h View File

@@ -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);

+ 31
- 3
viz/curses/t.c View File

@@ -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 57
 
33 58
 	if (verbosity && (loop%2)) {
34 59
 		temps = time(NULL);
35
-		sprintf(ligne, "%12ld | %s", temps, ctime(&temps));
60
+		p_tms = localtime(&temps);
61
+		foo = strftime(ligne, 100, "%F %H:%M", p_tms);
62
+		// sprintf(ligne, "%12ld | %s", temps, ctime(&temps));
36 63
 		message(ligne);
37 64
 		}
38 65
 
@@ -160,6 +187,7 @@ switch (demonum) {
160 187
 	case 0:		demo_vumetres(nb_loops, 0);		break;
161 188
 	case 1:		demo_waterfall(nb_loops, 0);		break;
162 189
 	case 2:		demo_7segments(nb_loops, 0);		break;
190
+	case 3:		demo_composite(nb_loops, 0);		break;
163 191
 	default:
164 192
 		fprintf(stderr, "eyecandy #%d don't exist\n", demonum);
165 193
 		break;

Loading…
Cancel
Save