Public Member Functions | Static Public Attributes | List of all members
Button Class Reference

Event-driven button class. More...

#include <Button.h>

Public Member Functions

 Button (int pin, int id=99)
 Class constructor. More...
 
void check ()
 Polls the button's _inputFlag and detects events. This should be called in the sketch's loop() function. More...
 
int getClickInterval ()
 Returns button's click interval. More...
 
int getHoldInterval ()
 Returns button's hold interval. More...
 
int getId ()
 Returns the button ID. More...
 
int getRepeatInterval ()
 Returns button's tick interval. More...
 
bool getState ()
 Returns the current button state. More...
 
void initInterrupts (void(*function)())
 Set the function to be called when a pin interrupt occurs. Ideally this wouldn't be needed and the pin interrupt would just call Button::tick(), but only static member functions can be used as callbacks for pin interrupts, so a wrapper function has to be written in the global scope and passed back into the button object. More...
 
void setEventHandler (void(*function)(Button *, uint8_t, bool))
 Set the function that is called any time a button event is detected. Some example callback functions can be found in the InputNode example. More...
 
void ICACHE_RAM_ATTR tick ()
 Raises the button's _inputFlag. This should be wrapped in a function in the global scope and fed into Button::initInterrupts() More...
 

Static Public Attributes

static const uint8_t kEventClicked = 2
 Event ID for button click (pressed and released within _clickInterval). More...
 
static const uint8_t kEventHeld = 3
 Event ID for button hold (held down for longer than _holdInterval). More...
 
static const uint8_t kEventPressed = 0
 Event ID for button press. More...
 
static const uint8_t kEventReleased = 1
 Event ID for button release. More...
 
static const uint8_t kEventTick = 4
 Event ID for button tick (released every _repeatInterval when button held). More...
 

Detailed Description

Event-driven button class.

Constructor & Destructor Documentation

◆ Button()

Button::Button ( int  pin,
int  id = 99 
)

Class constructor.

Member Function Documentation

◆ check()

void Button::check ( )

Polls the button's _inputFlag and detects events. This should be called in the sketch's loop() function.

◆ getClickInterval()

int Button::getClickInterval ( )

Returns button's click interval.

◆ getHoldInterval()

int Button::getHoldInterval ( )

Returns button's hold interval.

◆ getId()

int Button::getId ( )

Returns the button ID.

◆ getRepeatInterval()

int Button::getRepeatInterval ( )

Returns button's tick interval.

◆ getState()

bool Button::getState ( )

Returns the current button state.

◆ initInterrupts()

void Button::initInterrupts ( void(*)()  function)

Set the function to be called when a pin interrupt occurs. Ideally this wouldn't be needed and the pin interrupt would just call Button::tick(), but only static member functions can be used as callbacks for pin interrupts, so a wrapper function has to be written in the global scope and passed back into the button object.

◆ setEventHandler()

void Button::setEventHandler ( void(*)(Button *, uint8_t, bool)  function)

Set the function that is called any time a button event is detected. Some example callback functions can be found in the InputNode example.

◆ tick()

void ICACHE_RAM_ATTR Button::tick ( )

Raises the button's _inputFlag. This should be wrapped in a function in the global scope and fed into Button::initInterrupts()

Member Data Documentation

◆ kEventClicked

const uint8_t Button::kEventClicked = 2
static

Event ID for button click (pressed and released within _clickInterval).

◆ kEventHeld

const uint8_t Button::kEventHeld = 3
static

Event ID for button hold (held down for longer than _holdInterval).

◆ kEventPressed

const uint8_t Button::kEventPressed = 0
static

Event ID for button press.

◆ kEventReleased

const uint8_t Button::kEventReleased = 1
static

Event ID for button release.

◆ kEventTick

const uint8_t Button::kEventTick = 4
static

Event ID for button tick (released every _repeatInterval when button held).


The documentation for this class was generated from the following file: