DIY fertilizer mixer and plant watering machine https://www.xythobuz.de/giessomat.html
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Statemachine.h 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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_mode_c, // select mode 3
  35. auto_fert_a, // select fertilizer 1
  36. auto_fert_b, // select fertilizer 2
  37. auto_fert_run,
  38. auto_tank_run,
  39. auto_stirr_run,
  40. auto_plant, // select plant
  41. auto_plant_kickstart_run,
  42. auto_plant_run,
  43. auto_done,
  44. fillnwater_plant, // select plants
  45. fillnwater_tank_run,
  46. fillnwater_kickstart_run,
  47. fillnwater_plant_run,
  48. fullauto_fert, // d i a
  49. fullauto_plant, // d i a
  50. fullauto_stirr_run, // d i a
  51. fullauto_fert_run, // d i a
  52. fullauto_tank_run, // d i a
  53. fullauto_kickstart_run, // d i a
  54. fullauto_plant_run, // d i a
  55. fullauto_plant_overrun, // d i a
  56. fullauto_tank_purge_run, // d i a
  57. fullauto_kickstart_purge_run, // d i a
  58. fullauto_plant_purge_run, // d i a
  59. fullauto_plant_purge_overrun, // d i a
  60. fullauto_done, // d i a
  61. automation_mode,
  62. menu_pumps, // selet pump
  63. menu_pumps_time, // set runtime
  64. menu_pumps_go, // running
  65. menu_pumps_run,
  66. menu_pumps_done,
  67. menu_valves, // select valve
  68. menu_valves_time, // set runtime
  69. menu_valves_go, // running
  70. menu_valves_run,
  71. menu_valves_done,
  72. menu_aux, // select aux channel
  73. menu_aux_time, // set runtime
  74. menu_aux_go, // running
  75. menu_aux_run,
  76. menu_aux_done,
  77. error
  78. };
  79. class DigitBuffer {
  80. public:
  81. DigitBuffer(int _size);
  82. ~DigitBuffer();
  83. bool spaceLeft(void);
  84. bool hasDigits(void);
  85. int countDigits(void);
  86. void addDigit(int d);
  87. void removeDigit(void);
  88. void clear(void);
  89. uint32_t getNumber(void);
  90. private:
  91. int size;
  92. int pos;
  93. int *digits;
  94. };
  95. typedef void (*print_fn)(const char *, const char *, const char *, const char *, int);
  96. typedef void (*backspace_fn)(void);
  97. Statemachine(print_fn _print, backspace_fn _backspace);
  98. void begin(void);
  99. void input(int n);
  100. void act(void);
  101. const char *getStateName(void);
  102. bool isIdle(void);
  103. private:
  104. void switch_to(States s);
  105. uint32_t number_input(void);
  106. DigitBuffer db;
  107. States state, old_state;
  108. print_fn print;
  109. backspace_fn backspace;
  110. BoolField selected_plants;
  111. BoolField selected_ferts;
  112. uint32_t selected_id; // pump or valve id
  113. uint32_t selected_time; // runtime
  114. unsigned long start_time, stop_time, last_animation_time;
  115. String error_condition;
  116. unsigned long into_state_time;
  117. // used for calibrating, in fill'n'water mode
  118. bool filling_started_empty;
  119. bool watering_started_full;
  120. String menu_entered_digits;
  121. };
  122. #endif // _STATEMACHINE_H_