DIY fertilizer mixer and plant watering machine https://www.xythobuz.de/giessomat.html
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Statemachine.h 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. menu_a, // manual, auto
  29. menu_b, // pumps, valves
  30. auto_mode_a, // select mode 1
  31. auto_mode_b, // select mode 2
  32. auto_fert, // select fertilizer
  33. auto_fert_run,
  34. auto_tank_run,
  35. auto_plant, // select plant
  36. auto_plant_run,
  37. auto_done,
  38. fillnwater_plant, // select plants
  39. fillnwater_tank_run,
  40. fillnwater_plant_run,
  41. automation_mode,
  42. menu_pumps, // selet pump
  43. menu_pumps_time, // set runtime
  44. menu_pumps_go, // running
  45. menu_pumps_run,
  46. menu_pumps_done,
  47. menu_valves, // select valve
  48. menu_valves_time, // set runtime
  49. menu_valves_go, // running
  50. menu_valves_run,
  51. menu_valves_done,
  52. error
  53. };
  54. class DigitBuffer {
  55. public:
  56. DigitBuffer(int _size);
  57. ~DigitBuffer();
  58. bool spaceLeft(void);
  59. bool hasDigits(void);
  60. int countDigits(void);
  61. void addDigit(int d);
  62. void removeDigit(void);
  63. void clear(void);
  64. uint32_t getNumber(void);
  65. private:
  66. int size;
  67. int pos;
  68. int *digits;
  69. };
  70. typedef void (*print_fn)(const char *, const char *, const char *, const char *, int);
  71. typedef void (*backspace_fn)(void);
  72. Statemachine(print_fn _print, backspace_fn _backspace);
  73. void begin(void);
  74. void input(int n);
  75. void act(void);
  76. const char *getStateName(void);
  77. bool isIdle(void);
  78. private:
  79. void switch_to(States s);
  80. uint32_t number_input(void);
  81. DigitBuffer db;
  82. States state, old_state;
  83. print_fn print;
  84. backspace_fn backspace;
  85. BoolField selected_plants;
  86. uint32_t selected_id; // pump or valve id
  87. uint32_t selected_time; // runtime
  88. unsigned long start_time, stop_time, last_animation_time;
  89. String error_condition;
  90. unsigned long into_state_time;
  91. // used for calibrating, in fill'n'water mode
  92. bool filling_started_empty;
  93. bool watering_started_full;
  94. };
  95. #endif // _STATEMACHINE_H_