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.

essai.c 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * essai.c
  3. */
  4. #include <stdio.h>
  5. #include <unistd.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <curses.h>
  9. #include <time.h>
  10. #include "core/utils.h"
  11. #include "core/sysmetrics.h"
  12. #include "serial/serial.h"
  13. #include "viz/curses/ecran.h"
  14. int verbosity;
  15. /* --------------------------------------------------------------- */
  16. int affiche_valeurs(int sfd, int nbloops)
  17. {
  18. int idx, foo;
  19. char ligne[200];
  20. int Idatas[4];
  21. float Fdatas[4];
  22. for (idx=0; idx<nbloops; idx++) {
  23. foo = getline_to(sfd, ligne, 100, 0);
  24. if (verbosity) message(ligne);
  25. #if DEBUG_LEVEL
  26. if (foo) fprintf(stderr, "get values -> %d\n", foo);
  27. #endif
  28. foo = parse4_Ivalues(ligne, 'T', Idatas);
  29. #if DEBUG_LEVEL
  30. if (foo) fprintf(stderr, "parse I val -> %d\n", foo);
  31. #endif
  32. values2temperature(Idatas, Fdatas);
  33. for (foo=0; foo<3; foo++) {
  34. sprintf(ligne, "%4d", Idatas[foo]);
  35. minidigit_affstr(stdscr, 3+(12*foo), 4, ligne);
  36. aff7segs_float(stdscr, 3+(12*foo), 55, Fdatas[foo]);
  37. }
  38. }
  39. return 0;
  40. }
  41. /* --------------------------------------------------------------- */
  42. static void finish(int signal)
  43. {
  44. endwin();
  45. fprintf(stderr, "end of pid %d\n", getpid());
  46. exit(0);
  47. }
  48. /* --------------------------------------------------------------- */
  49. void help(int k)
  50. {
  51. puts("options : ");
  52. puts("\t-d\tserial device to read.");
  53. puts("\t-v\tincrease verbosity.");
  54. exit(0);
  55. }
  56. /* --------------------------------------------------------------- */
  57. int main(int argc, char *argv[])
  58. {
  59. int opt, foo;
  60. int serial_in;
  61. char *device = "/dev/ttyACM0";
  62. while ((opt = getopt(argc, argv, "d:hv")) != -1) {
  63. switch (opt) {
  64. case 'd': device = optarg; break;
  65. case 'h': help(0); break;
  66. case 'v': verbosity++; break;
  67. default: break;
  68. }
  69. }
  70. serial_in = prepare_UART(device, 9600);
  71. if (serial_in < 0) {
  72. fprintf(stderr, "%s : open device : error %d on %s\n",
  73. argv[0], serial_in, device);
  74. exit(1);
  75. }
  76. initscr();
  77. nonl(); cbreak(); noecho();
  78. keypad(stdscr, TRUE); /* acces aux touches 'curseur' */
  79. fond_ecran(" Demonstrator ");
  80. affiche_valeurs(serial_in, 10000);
  81. /*
  82. * plop, on a fini, il faut restaurer la console
  83. */
  84. finish(0);
  85. return 0;
  86. }
  87. /* --------------------------------------------------------------- */