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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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], buff[200];
  20. float datas[4];
  21. for (idx=0; idx<nbloops; idx++) {
  22. foo = getline_to(sfd, ligne, 100, 0);
  23. #if DEBUG_LEVEL
  24. if (foo) fprintf(stderr, "get values -> %d\n", foo);
  25. #endif
  26. foo = parse4values(ligne, 'T', datas);
  27. #if DEBUG_LEVEL
  28. if (foo) fprintf(stderr, "parse -> %d\n", foo);
  29. #endif
  30. values2temperature(datas);
  31. foo = aff7segs_float(stdscr, 3, 5, datas[0]);
  32. foo = aff7segs_float(stdscr, 14, 5, datas[1]);
  33. foo = aff7segs_float(stdscr, 25, 5, datas[2]);
  34. }
  35. return 0;
  36. }
  37. /* --------------------------------------------------------------- */
  38. static void finish(int signal)
  39. {
  40. endwin();
  41. fprintf(stderr, "end of pid %d\n", getpid());
  42. exit(0);
  43. }
  44. /* --------------------------------------------------------------- */
  45. void help(int k)
  46. {
  47. puts("options : ");
  48. puts("\t-d\tserial device to read.");
  49. puts("\t-v\tincrease verbosity.");
  50. exit(0);
  51. }
  52. /* --------------------------------------------------------------- */
  53. int main(int argc, char *argv[])
  54. {
  55. int opt, foo;
  56. int serial_in;
  57. char *device = "/dev/ttyACM0";
  58. while ((opt = getopt(argc, argv, "d:hv")) != -1) {
  59. switch (opt) {
  60. case 'd': device = optarg; break;
  61. case 'h': help(0); break;
  62. case 'v': verbosity++; break;
  63. default: break;
  64. }
  65. }
  66. serial_in = prepare_UART(device, 9600);
  67. if (serial_in < 0) {
  68. fprintf(stderr, "%s : open device : error %d on %s\n",
  69. argv[0], serial_in, device);
  70. exit(1);
  71. }
  72. initscr();
  73. nonl(); cbreak(); noecho();
  74. keypad(stdscr, TRUE); /* acces aux touches 'curseur' */
  75. fond_ecran(" Demonstrator ");
  76. affiche_valeurs(serial_in, 10000);
  77. /*
  78. * plop, on a fini, il faut restaurer la console
  79. */
  80. finish(0);
  81. return 0;
  82. }
  83. /* --------------------------------------------------------------- */