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

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