/firmware/src/shared/ButtonArray.hh

http://github.com/makerbot/G3Firmware · C++ Header · 48 lines · 25 code · 9 blank · 14 comment · 0 complexity · 76711a354fe2e4897a4a2f13ea158626 MD5 · raw file

  1. #ifndef BUTTONARRAY_HH
  2. #define BUTTONARRAY_HH
  3. #include <util/atomic.h>
  4. #include "Types.hh"
  5. // TODO: Make this an interface?
  6. /// The button array modules manages an array of buttons, and maintains
  7. /// a buffer of the last pressed button. It has two entry points: a fast
  8. /// #scanButtons, which is a fast button scanning routine that should be
  9. /// called from an interrupt, and #getButton, which should be called by a
  10. /// slow loop that has time to respond to the button.
  11. ///
  12. /// Porting Notes:
  13. /// This modules uses low-level port registers, and must be re-written for
  14. /// each board archetecture. This should be done by adding a ButtonArray.cc
  15. /// definition in the board directory.
  16. /// \ingroup HardwareLibraries
  17. class ButtonArray {
  18. private:
  19. uint8_t buttonPress;
  20. bool buttonPressWaiting;
  21. public:
  22. /// Representation of the different buttons available on the keypad
  23. enum ButtonName {
  24. ZERO = 1,
  25. ZMINUS = 2,
  26. ZPLUS = 3,
  27. YMINUS = 4,
  28. YPLUS = 5,
  29. XMINUS = 6,
  30. XPLUS = 7,
  31. CANCEL = 11,
  32. OK = 12
  33. };
  34. void init();
  35. // Returns true if any of the button states have changed.
  36. void scanButtons();
  37. bool getButton(ButtonName& button);
  38. };
  39. #endif // BUTTONARRAY_HH