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.

Statemachine.h 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 plant
  10. menu_auto_mode, // select mode
  11. menu_auto_go, // running
  12. menu_auto_done,
  13. menu_pumps, // selet pump
  14. menu_pumps_time, // set runtime
  15. menu_pumps_go, // running
  16. menu_pumps_running,
  17. menu_pumps_done,
  18. menu_valves, // select valve
  19. menu_valves_time, // set runtime
  20. menu_valves_go, // running
  21. menu_valves_running,
  22. menu_valves_done,
  23. error
  24. };
  25. class DigitBuffer {
  26. public:
  27. DigitBuffer(int _size);
  28. ~DigitBuffer();
  29. bool spaceLeft(void);
  30. bool hasDigits(void);
  31. int countDigits(void);
  32. void addDigit(int d);
  33. void removeDigit(void);
  34. void clear(void);
  35. uint32_t getNumber(void);
  36. private:
  37. int size;
  38. int pos;
  39. int *digits;
  40. };
  41. typedef void (*print_fn)(const char *, const char *, const char *, const char *, int);
  42. typedef void (*backspace_fn)(void);
  43. Statemachine(print_fn _print, backspace_fn _backspace);
  44. void begin(void);
  45. void input(int n);
  46. void act(void);
  47. private:
  48. void switch_to(States s);
  49. uint32_t number_input(void);
  50. DigitBuffer db;
  51. States state, old_state;
  52. print_fn print;
  53. backspace_fn backspace;
  54. uint32_t selected_id; // pump or valve id
  55. uint32_t selected_time; // runtime
  56. unsigned long start_time, stop_time, last_animation_time;
  57. String error_condition;
  58. };
  59. #endif // _STATEMACHINE_H_