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

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