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.

Keymatrix.h 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #ifndef _KEYMATRIX_H_
  2. #define _KEYMATRIX_H_
  3. #ifdef FUNCTION_UI
  4. #include <CircularBuffer.h>
  5. class Keymatrix {
  6. public:
  7. class Event {
  8. public:
  9. enum EventType {
  10. button_down,
  11. button_up,
  12. no_event
  13. };
  14. Event(EventType _type, int _row, int _col);
  15. EventType getType(void);
  16. int getRow(void);
  17. int getCol(void);
  18. // helper for 4x3 telephone keypad
  19. // -1 is *, -2 is #, or digits 0-9
  20. int getNum(void);
  21. private:
  22. EventType type;
  23. int row, col;
  24. };
  25. Keymatrix(int _rows, int _cols);
  26. ~Keymatrix(void);
  27. // first rows, then cols
  28. void setPins(int _pins[]);
  29. void setDebounce(unsigned long ms);
  30. void scan(void);
  31. bool hasEvent(void);
  32. Event getEvent(void);
  33. private:
  34. unsigned long debounce;
  35. const static unsigned long default_debounce = 5;
  36. unsigned long last_scan_time;
  37. int rows, cols;
  38. int *pins;
  39. bool *lastPressed;
  40. bool *lastState;
  41. CircularBuffer<Event *, 32> events;
  42. };
  43. #endif // FUNCTION_UI
  44. #endif // _KEYMATRIX_H_