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.

funcs.c 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "serial.h"
  4. extern int verbosity;
  5. /* ---------------------------------------------------------------- */
  6. /*
  7. * compute the integer mean value of a four values
  8. * tagged lines.
  9. */
  10. int parseXvalue(char *line, char cflag)
  11. {
  12. int value, foo;
  13. int vrd[4];
  14. value=0;
  15. if ( cflag != *line ) {
  16. if (verbosity) {
  17. fprintf(stderr, "%s : line[0] 0x%x bad\n",
  18. __func__, *line);
  19. }
  20. return -777;
  21. }
  22. foo = sscanf(line+1, "%d %d %d %d", vrd, vrd+1, vrd+2, vrd+3);
  23. #if DEBUG_LEVEL
  24. fprintf(stderr, "%s : sscanf -> %d\n", __func__, foo);
  25. #endif
  26. if (4 != foo) {
  27. return -666;
  28. }
  29. for (foo=0; foo<4; foo++) {
  30. value += vrd[foo];
  31. }
  32. value /= 4;
  33. return value;
  34. }
  35. /* ---------------------------------------------------------------- */
  36. /*
  37. * this fonction is specific to the LM35 thermo-sensor
  38. * connected to a ADC pin of an Arduino Mega
  39. *
  40. * WARNING !
  41. * this function _must_ be modofied if you change the
  42. * Vref of the Analog to Digital converter on the
  43. * Arduino !
  44. *
  45. */
  46. int values2temperature(int raw[4], float array[4])
  47. {
  48. int foo;
  49. for (foo=0; foo<4; foo++) {
  50. array[foo] = (float)raw[foo] * (1.1 / 1023.0 * 100.0);
  51. }
  52. return 0;
  53. }
  54. /* ---------------------------------------------------------------- */
  55. int parse4_Ivalues(char *line, char cflag, int array[4])
  56. {
  57. int foo, raw[4];
  58. if ( cflag != *line ) {
  59. if (verbosity) {
  60. fprintf(stderr, "%s : line[0] 0x%x bad\n",
  61. __func__, *line);
  62. }
  63. return -776;
  64. }
  65. foo = sscanf(line+1, "%d %d %d %d", raw, raw+1, raw+2, raw+3);
  66. if (4 != foo) {
  67. fprintf(stderr, "%s : sscanf -> %d\n", __func__, foo);
  68. return -665;
  69. }
  70. memcpy(array, raw, 4*sizeof(int));
  71. return 4;
  72. }
  73. /* ---------------------------------------------------------------- */
  74. int parse4_Fvalues(char *line, char cflag, float array[4])
  75. {
  76. float ftmp[4];
  77. int foo;
  78. if ( cflag != *line ) {
  79. if (verbosity) {
  80. fprintf(stderr, "%s : line[0] 0x%x bad\n",
  81. __func__, *line);
  82. }
  83. return -777;
  84. }
  85. foo = sscanf(line+1, "%f %f %f %f", ftmp, ftmp+1, ftmp+2, ftmp+3);
  86. if (4 != foo) {
  87. fprintf(stderr, "%s : sscanf -> %d\n", __func__, foo);
  88. return -666;
  89. }
  90. // fprintf(stderr, "\tV %f\n", ftmp[0]);
  91. memcpy(array, ftmp, 4*sizeof(float));
  92. return 4;
  93. }
  94. /* ---------------------------------------------------------------- */