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.7KB

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