VizBlocks
Button.hpp
Go to the documentation of this file.
1 #ifndef BUTTON_h
2 #define BUTTON_h
3 
4 class Button
5 {
6 
7 private:
8 
9  int _pin;
10  int _id;
11 
12  bool _state;
13 
14  volatile bool _inputFlag = false;
15  bool _changeFlag = false;
16 
17  bool _pressedFlag = false;
18  bool _holdFlag = false;
19 
20  unsigned long _previousTimer;
21 
22  int _clickInterval = 1000;
23  int _holdInterval = 1000;
24  int _repeatInterval = 1000;
25 
26  void (*_cb)(Button*, uint8_t, bool); // Callback function
27 
31  bool _read();
32 
36  void _setClickInterval(int x);
37 
41  void _setHoldInterval(int x);
42 
46  void _setRepeatInterval(int x);
47 
48 public:
49 
50  // Public members:
51 
52  static const uint8_t kEventPressed = 0; // Button was pressed
53  static const uint8_t kEventReleased = 1; // Button was released
54  static const uint8_t kEventClicked = 2; // Button was clicked (pressed and released within _clickInterval)
55  static const uint8_t kEventHeld = 3; // Button was held down for longer than _holdInterval
56  static const uint8_t kEventTick = 4; // Event released every _repeatInterval when button held
57 
58  // Public functions:
59 
60  Button(int pin, int id = 99);
64  void initInterrupts(void (*function)());
68  void setEventHandler(void (*function)(Button*, uint8_t, bool));
72  bool getState();
76  int getId();
92  void check();
93  void
96  ICACHE_RAM_ATTR tick();
97 
98 };
99 
100 #endif
Button::kEventHeld
static const uint8_t kEventHeld
Definition: Button.hpp:55
Button::getRepeatInterval
int getRepeatInterval()
What does this do?
Button::Button
Button(int pin, int id=99)
Button::kEventClicked
static const uint8_t kEventClicked
Definition: Button.hpp:54
Button::check
void check()
What does this do?
Button::getClickInterval
int getClickInterval()
What does this do?
Button::setEventHandler
void setEventHandler(void(*function)(Button *, uint8_t, bool))
What does this do?
Button::tick
void ICACHE_RAM_ATTR tick()
What does this do?
Button
Definition: Button.hpp:5
Button::kEventPressed
static const uint8_t kEventPressed
Definition: Button.hpp:52
Button::getState
bool getState()
What does this do?
Button::getHoldInterval
int getHoldInterval()
What does this do?
Button::kEventReleased
static const uint8_t kEventReleased
Definition: Button.hpp:53
Button::getId
int getId()
What does this do?
Button::kEventTick
static const uint8_t kEventTick
Definition: Button.hpp:56
Button::initInterrupts
void initInterrupts(void(*function)())
What does this do?