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.9KB

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