DIY fertilizer mixer and plant watering machine https://www.xythobuz.de/giessomat.html
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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #ifndef _STATEMACHINE_H_
  2. #define _STATEMACHINE_H_
  3. #include <Arduino.h>
  4. class Statemachine {
  5. public:
  6. enum States {
  7. init,
  8. menu, // auto, pumps, valves
  9. menu_auto, // select mode
  10. menu_auto_fertilizer, // select fertilizer
  11. menu_auto_fertilizer_running,
  12. menu_auto_reservoir_running,
  13. menu_auto_plant, // select plant
  14. menu_auto_plant_running,
  15. menu_auto_done,
  16. menu_pumps, // selet pump
  17. menu_pumps_time, // set runtime
  18. menu_pumps_go, // running
  19. menu_pumps_running,
  20. menu_pumps_done,
  21. menu_valves, // select valve
  22. menu_valves_time, // set runtime
  23. menu_valves_go, // running
  24. menu_valves_running,
  25. menu_valves_done,
  26. error
  27. };
  28. class DigitBuffer {
  29. public:
  30. DigitBuffer(int _size);
  31. ~DigitBuffer();
  32. bool spaceLeft(void);
  33. bool hasDigits(void);
  34. int countDigits(void);
  35. void addDigit(int d);
  36. void removeDigit(void);
  37. void clear(void);
  38. uint32_t getNumber(void);
  39. private:
  40. int size;
  41. int pos;
  42. int *digits;
  43. };
  44. typedef void (*print_fn)(const char *, const char *, const char *, const char *, int);
  45. typedef void (*backspace_fn)(void);
  46. Statemachine(print_fn _print, backspace_fn _backspace);
  47. void begin(void);
  48. void input(int n);
  49. void act(void);
  50. private:
  51. void switch_to(States s);
  52. uint32_t number_input(void);
  53. DigitBuffer db;
  54. States state, old_state;
  55. print_fn print;
  56. backspace_fn backspace;
  57. uint32_t selected_id; // pump or valve id
  58. uint32_t selected_time; // runtime
  59. unsigned long start_time, stop_time, last_animation_time;
  60. String error_condition;
  61. };
  62. #endif // _STATEMACHINE_H_