Monitoring du Phytotron
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

t.c 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <time.h>
  6. #include <math.h>
  7. #include <getopt.h>
  8. #include <ncurses.h>
  9. #include "ecran.h"
  10. int verbosity;
  11. /* ---------------------------------------------------------------- */
  12. int demo_minidigits(int nbl, int k)
  13. {
  14. int loop, foo;
  15. char chaine[100];
  16. for (loop=0; loop<nbl; loop++) {
  17. sprintf(chaine, "== %06X ==", loop);
  18. message(chaine);
  19. sprintf(chaine, ".%08d.", rand()%1000000);
  20. /***
  21. for (foo=0; foo<10; foo++) {
  22. minidigit_0(stdscr, 5, 2+foo*8, chaine[foo], 0);
  23. }
  24. ***/
  25. minidigit_affstr(stdscr, 5, 2, chaine);
  26. wrefresh(stdscr);
  27. usleep(350*1000);
  28. /***
  29. for (foo=0; foo<10; foo++) {
  30. minidigit_0(stdscr, 5, 2+foo*8, ' ', 0);
  31. }
  32. ***/
  33. minidigit_HMS(stdscr, 15, 9, 0);
  34. wrefresh(stdscr);
  35. usleep(250*1000);
  36. }
  37. return -1;
  38. }
  39. /* ---------------------------------------------------------------- */
  40. int demo_composite(int nbl, int k)
  41. {
  42. int loop, foo;
  43. short sval;
  44. char ligne[120];
  45. float fval;
  46. for (loop=0; loop<nbl; loop++) {
  47. sval = (short)((loop % 1024)-512);
  48. foo = aff7segs_short(stdscr, 5, 3, sval);
  49. if (foo) message("KRKRK aff7 short");
  50. fval = (float)sval / 1024.0;
  51. foo = aff7segs_float(stdscr, 16, 3, fval);
  52. if (foo) message("KRKRK aff7 float");
  53. fval = fabs(fval);
  54. foo = vumetre_0(stdscr, 29, 5, fval, COLS-10);
  55. sprintf(ligne, "%04x", loop);
  56. mvaddstr(2, 1, ligne);
  57. refresh();
  58. usleep(200*1000);
  59. }
  60. return 0;
  61. }
  62. /* ---------------------------------------------------------------- */
  63. void demo_7segments(int nbl, int notused)
  64. {
  65. int loop, idx, foo;
  66. char ligne[120];
  67. time_t temps;
  68. struct tm *p_tms;
  69. for (loop=0; loop<nbl; loop++) {
  70. sprintf(ligne, "%04x", loop);
  71. mvaddstr(2, 1, ligne);
  72. for (idx=0; idx<strlen(ligne); idx++) {
  73. aff7segs_digit(stdscr, 3, 10+(idx*9), ligne[idx]);
  74. }
  75. sprintf(ligne, "%.3f", drand48());
  76. mvaddstr(13, 1, ligne);
  77. for (idx=0; idx<strlen(ligne); idx++) {
  78. aff7segs_digit(stdscr, 14, 10+(idx*9), ligne[idx]);
  79. }
  80. if (verbosity && (loop%2)) {
  81. temps = time(NULL);
  82. p_tms = localtime(&temps);
  83. foo = strftime(ligne, 100, "%F %H:%M", p_tms);
  84. // sprintf(ligne, "%12ld | %s", temps, ctime(&temps));
  85. message(ligne);
  86. }
  87. refresh();
  88. usleep(400*1000);
  89. }
  90. }
  91. /* ---------------------------------------------------------------- */
  92. void demo_vumetres(int nbl, int notused)
  93. {
  94. int loop, idx;
  95. int hpos;
  96. char ligne[100];
  97. float value;
  98. time_t temps;
  99. for (loop=0; loop<nbl; loop++) {
  100. value = (float)loop / (float)nbl;
  101. for (idx=0; idx<8; idx++) {
  102. hpos = 4 * (idx+1);
  103. value = drand48();
  104. if (idx<4) vumetre_0(stdscr, hpos, 12, value, 60);
  105. else vumetre_1(stdscr, hpos, 12, value, 60);
  106. }
  107. if (verbosity && (loop%2)) {
  108. temps = time(NULL);
  109. sprintf(ligne, "%12ld | %s", temps, ctime(&temps));
  110. message(ligne);
  111. }
  112. refresh();
  113. usleep(200*1000);
  114. }
  115. }
  116. /* ---------------------------------------------------------------- */
  117. void demo_waterfall(int nbl, int k)
  118. {
  119. int loop, foo;
  120. char line[100];
  121. WINDOW *water;
  122. static float rvals[4];
  123. struct timespec ts;
  124. ts.tv_sec = 0;
  125. ts.tv_nsec = 200 * 1000 * 1000;
  126. water = open_waterfall("premier essai", 0);
  127. for (loop=0; loop<nbl; loop++) {
  128. sprintf(line, " %06X %04X ", loop, rand()&0xffff);
  129. message(line);
  130. wrefresh(stdscr);
  131. for (foo=0; foo<4; foo++) {
  132. if (rand()%100<42) {
  133. rvals[foo] += 4.04 * (foo + 1);
  134. }
  135. if (rvals[foo] > 1023.0) {
  136. rvals[foo] = (float)(rand() % 25);
  137. }
  138. }
  139. plot_waterfall(water, 1, rvals);
  140. /* if (rand()%10 < 1) sleep(1); */
  141. foo = nanosleep(&ts, NULL);
  142. if (foo) {
  143. /* got a signal ? */
  144. message("err on nanosleep");
  145. }
  146. }
  147. close_waterfall(water, 0);
  148. }
  149. /* ---------------------------------------------------------------- */
  150. static void finish(int signal)
  151. {
  152. endwin(); exit(0);
  153. }
  154. /* ---------------------------------------------------------------- */
  155. int main (int argc, char *argv[])
  156. {
  157. int opt;
  158. int demonum = 0;
  159. int nb_loops = 200;
  160. /* set some default values */
  161. verbosity = 0;
  162. while ((opt = getopt(argc, argv, "n:vy:")) != -1) {
  163. switch (opt) {
  164. case 'n': nb_loops = atoi(optarg); break;
  165. case 'v': verbosity++; break;
  166. case 'y': demonum = atoi(optarg); break;
  167. default:
  168. fprintf(stderr, "%s : uh ?", argv[0]);
  169. exit(1);
  170. break;
  171. }
  172. }
  173. initscr();
  174. nonl(); cbreak(); noecho();
  175. keypad(stdscr, TRUE); /* acces aux touches 'curseur' */
  176. fond_ecran(" Ncurses Eyecandy ");
  177. switch (demonum) {
  178. case 0: demo_vumetres(nb_loops, 0); break;
  179. case 1: demo_waterfall(nb_loops, 0); break;
  180. case 2: demo_7segments(nb_loops, 0); break;
  181. case 3: demo_composite(nb_loops, 0); break;
  182. case 4: demo_minidigits(nb_loops, 0); break;
  183. default:
  184. fprintf(stderr, "eyecandy #%d don't exist\n", demonum);
  185. break;
  186. }
  187. /*
  188. * plop, on a fini, restaurer la console
  189. */
  190. finish(0);
  191. return 0;
  192. }
  193. /* ---------------------------------------------------------------- */