#ifndef BUTTON_h #define BUTTON_h class Button { private: int _pin; int _id; bool _state; volatile bool _inputFlag = false; bool _changeFlag = false; bool _pressedFlag = false; bool _holdFlag = false; unsigned long _previousTimer; int _clickInterval = 1000; int _holdInterval = 1000; int _repeatInterval = 1000; void (*_cb)(Button*, uint8_t, bool); // Callback function bool _read(); void _setClickInterval(int x); void _setHoldInterval(int x); void _setRepeatInterval(int x); public: // Public members: static const uint8_t kEventPressed = 0; // Button was pressed static const uint8_t kEventReleased = 1; // Button was released static const uint8_t kEventClicked = 2; // Button was clicked (pressed and released within _clickInterval) static const uint8_t kEventHeld = 3; // Button was held down for longer than _holdInterval static const uint8_t kEventTick = 4; // Event released every _repeatInterval when button held // Public functions: Button(int pin, int id = 99); void initInterrupts(void(*function)()); void setEventHandler(void(*function)(Button*, uint8_t, bool)); bool getState(); int getId(); int getClickInterval(); int getHoldInterval(); int getRepeatInterval(); void check(); void ICACHE_RAM_ATTR tick(); }; #endif