DIY fertilizer mixer and plant watering machine https://www.xythobuz.de/giessomat.html
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Statemachine.h 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright (c) 2021 Thomas Buck <thomas@xythobuz.de>
  3. *
  4. * This file is part of Giess-o-mat.
  5. *
  6. * Giess-o-mat is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Giess-o-mat is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Giess-o-mat. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. #ifndef _STATEMACHINE_H_
  20. #define _STATEMACHINE_H_
  21. #include <Arduino.h>
  22. #include "BoolField.h"
  23. #define stringify( name ) # name
  24. class Statemachine {
  25. public:
  26. enum States {
  27. init = 0,
  28. door_select,
  29. menu_a, // manual, auto
  30. menu_b, // pumps, valves
  31. menu_c, // aux
  32. auto_mode_a, // select mode 1
  33. auto_mode_b, // select mode 2
  34. auto_fert_a, // select fertilizer 1
  35. auto_fert_b, // select fertilizer 2
  36. auto_fert_run,
  37. auto_tank_run,
  38. auto_stirr_run,
  39. auto_plant, // select plant
  40. auto_plant_kickstart_run,
  41. auto_plant_run,
  42. auto_done,
  43. fillnwater_plant, // select plants
  44. fillnwater_tank_run,
  45. fillnwater_kickstart_run,
  46. fillnwater_plant_run,
  47. automation_mode,
  48. menu_pumps, // selet pump
  49. menu_pumps_time, // set runtime
  50. menu_pumps_go, // running
  51. menu_pumps_run,
  52. menu_pumps_done,
  53. menu_valves, // select valve
  54. menu_valves_time, // set runtime
  55. menu_valves_go, // running
  56. menu_valves_run,
  57. menu_valves_done,
  58. menu_aux, // select aux channel
  59. menu_aux_time, // set runtime
  60. menu_aux_go, // running
  61. menu_aux_run,
  62. menu_aux_done,
  63. error
  64. };
  65. class DigitBuffer {
  66. public:
  67. DigitBuffer(int _size);
  68. ~DigitBuffer();
  69. bool spaceLeft(void);
  70. bool hasDigits(void);
  71. int countDigits(void);
  72. void addDigit(int d);
  73. void removeDigit(void);
  74. void clear(void);
  75. uint32_t getNumber(void);
  76. private:
  77. int size;
  78. int pos;
  79. int *digits;
  80. };
  81. typedef void (*print_fn)(const char *, const char *, const char *, const char *, int);
  82. typedef void (*backspace_fn)(void);
  83. Statemachine(print_fn _print, backspace_fn _backspace);
  84. void begin(void);
  85. void input(int n);
  86. void act(void);
  87. const char *getStateName(void);
  88. bool isIdle(void);
  89. private:
  90. void switch_to(States s);
  91. uint32_t number_input(void);
  92. DigitBuffer db;
  93. States state, old_state;
  94. print_fn print;
  95. backspace_fn backspace;
  96. BoolField selected_plants;
  97. uint32_t selected_id; // pump or valve id
  98. uint32_t selected_time; // runtime
  99. unsigned long start_time, stop_time, last_animation_time;
  100. String error_condition;
  101. unsigned long into_state_time;
  102. // used for calibrating, in fill'n'water mode
  103. bool filling_started_empty;
  104. bool watering_started_full;
  105. String menu_entered_digits;
  106. };
  107. #endif // _STATEMACHINE_H_