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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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(float array[4])
  47. {
  48. int foo;
  49. for (foo=0; foo<4; foo++) {
  50. array[foo] *= (1.1 / 1023.0 * 100.0);
  51. }
  52. return 0;
  53. }
  54. /* ---------------------------------------------------------------- */
  55. int parse4values(char *line, char cflag, float array[4])
  56. {
  57. float ftmp[4];
  58. int foo;
  59. if ( cflag != *line ) {
  60. if (verbosity) {
  61. fprintf(stderr, "%s : line[0] 0x%x bad\n",
  62. __func__, *line);
  63. }
  64. return -777;
  65. }
  66. foo = sscanf(line+1, "%f %f %f %f", ftmp, ftmp+1, ftmp+2, ftmp+3);
  67. if (4 != foo) {
  68. fprintf(stderr, "%s : sscanf -> %d\n", __func__, foo);
  69. return -666;
  70. }
  71. // fprintf(stderr, "\tV %f\n", ftmp[0]);
  72. memcpy(array, ftmp, 4*sizeof(float));
  73. return 4;
  74. }
  75. /* ---------------------------------------------------------------- */