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

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