Browse code

des minidigits pour afficher l'heure

tth authored on 05/02/2019 15:50:09
Showing 3 changed files
... ...
@@ -11,6 +11,7 @@ int aff7segs_short(WINDOW * win, int lig, int col, short value);
11 11
 int aff7segs_float(WINDOW * win, int lig, int col, float value);
12 12
 
13 13
 int minidigit_0(WINDOW *win, int lig, int col, char digit, int k);
14
+int minidigit_HMS(WINDOW *win, int lig, int col, int k);
14 15
 
15 16
 
16 17
 WINDOW * open_waterfall(char *title, int flags);
... ...
@@ -7,6 +7,7 @@
7 7
 #include  <stdio.h>
8 8
 #include  <stdlib.h>
9 9
 #include  <string.h>
10
+#include	<time.h>
10 11
 #include  <ctype.h>
11 12
 #include  <getopt.h>
12 13
 #include  <ncurses.h>
... ...
@@ -88,3 +89,19 @@ wrefresh(win);
88 88
 return 0;
89 89
 }
90 90
 /* ---------------------------------------------------------------- */
91
+int minidigit_HMS(WINDOW *win, int lig, int col, int k)
92
+{
93
+int		foo;
94
+char		chaine[20];
95
+struct tm       *p_tms;
96
+time_t		temps;
97
+
98
+temps = time(NULL);
99
+p_tms = localtime(&temps);
100
+(void)strftime(chaine, 19, "%H:%M:%S", p_tms);
101
+for (foo=0; foo<strlen(chaine); foo++) {
102
+	minidigit_0(stdscr, lig, col+foo*8, chaine[foo], 0);
103
+	}
104
+return 0;
105
+}
106
+/* ---------------------------------------------------------------- */
... ...
@@ -16,16 +16,16 @@ int demo_minidigits(int nbl, int k)
16 16
 {
17 17
 int		loop, foo;
18 18
 char		chaine[100];
19
-struct tm       *p_tms;
20
-time_t		temps;
21 19
 
22 20
 for (loop=0; loop<nbl; loop++) {
23 21
 
24 22
 	sprintf(chaine, "== %06X ==", loop);
25 23
 	message(chaine);
26 24
 
25
+	sprintf(chaine, ".%08d.", rand()%1000000);
26
+
27 27
 	for (foo=0; foo<10; foo++) {
28
-		minidigit_0(stdscr, 5, 2+foo*8, '0'+foo, 0);
28
+		minidigit_0(stdscr, 5, 2+foo*8, chaine[foo], 0);
29 29
 		}
30 30
 	wrefresh(stdscr);
31 31
 	usleep(350*1000);
... ...
@@ -33,15 +33,11 @@ for (loop=0; loop<nbl; loop++) {
33 33
 	for (foo=0; foo<10; foo++) {
34 34
 		minidigit_0(stdscr, 5, 2+foo*8, ' ', 0);
35 35
 		}
36
+
37
+	minidigit_HMS(stdscr, 15, 9, 0);
38
+
36 39
 	wrefresh(stdscr);
37 40
 	usleep(250*1000);
38
-
39
-	temps = time(NULL);
40
-	p_tms = localtime(&temps);
41
-	(void)strftime(chaine, 100, "%H.%M", p_tms);
42
-	for (foo=0; foo<strlen(chaine); foo++) {
43
-		minidigit_0(stdscr, 15, 8+foo*8, chaine[foo], 0);
44
-		}
45 41
 	}
46 42
 return -1;
47 43
 }