ESPectro32 Library
Library for using ESPectro32 board
 All Classes Functions Variables Enumerations Enumerator Pages
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
ESPectro32_Button Class Reference

ESPectro32 button. More...

#include <ESPectro32_Button.h>

Inheritance diagram for ESPectro32_Button:
Task

Public Types

enum  Button_State {
  ESPectro32ButtonUnknown = 0, ESPectro32ButtonPressed, ESPectro32ButtonReleased, ESPectro32ButtonSecondPressed,
  ESPectro32ButtonWaitingForLongPressed, ESPectro32ButtonLongPressed
}
 
typedef std::function< void()> ButtonActionCallback
 

Public Member Functions

 ESPectro32_Button (uint8_t gpio, boolean activeHigh=false)
 
void begin ()
 Must be called as soon as possible to do initialization stuffs.
 
void start (void *taskData=nullptr)
 
Button_State getState ()
 
void run ()
 
void runAsync (void *data)
 Body of the task to execute. More...
 
void onButtonDown (ButtonActionCallback cb)
 
void onButtonUp (ButtonActionCallback cb)
 
void onPressed (ButtonActionCallback cb)
 
void onLongPressed (ButtonActionCallback cb)
 
void onDoublePressed (ButtonActionCallback cb)
 
- Public Member Functions inherited from Task
 Task (std::string taskName="Task", uint16_t stackSize=2048, UBaseType_t priority=5)
 
 Task (BaseType_t coreId, std::string taskName="Task", uint16_t stackSize=2048, UBaseType_t priority=5)
 
void setStackSize (uint16_t stackSize)
 
void setPriority (UBaseType_t priority)
 
void setTaskName (std::string &taskN)
 
void start (void *taskData=nullptr)
 Start an instance of the task. More...
 
void stop ()
 
void delay (int ms)
 Suspend the task for the specified milliseconds. More...
 

Private Member Functions

bool isActive ()
 
void examine ()
 

Private Attributes

uint8_t gpioNumber_
 
bool activeHigh_ = false
 
bool trackLongPressed_ = false
 
Button_State buttonState_ = ESPectro32ButtonUnknown
 
unsigned long lastButtonChangedMillis_ = 0
 
unsigned long lastButtonPressedMillis_ = 0
 
unsigned long checkingStartTime_ = 0
 
unsigned long checkingEndTime_ = 0
 
volatile bool interruptTriggered_ = false
 
volatile bool runAlreadyCalled_ = false
 
ButtonActionCallback btnDownCallback_
 
ButtonActionCallback btnUpCallback_
 
ButtonActionCallback pressedCallback_
 
ButtonActionCallback longPressedCallback_
 
ButtonActionCallback doublePressedCallback_
 
uint8_t pressCount_ = 0
 

Detailed Description

ESPectro32 button.

This class is for working with button, especially attached button "A" and "B" on ESPectro32. But nothing will stop you for working with external buttons.

Creating object:

ESPectro32_Button buttonA(ESPECTRO32_BUTTON_A_PIN);

Attaching event handlers:

buttonA.onButtonUp([]() {
ESP_LOGI(TAG, "Button A up");
});

That's for handling "on button up" event.

Member Function Documentation

void ESPectro32_Button::runAsync ( void *  data)
virtual

Body of the task to execute.

This function must be implemented in the subclass that represents the actual task to run. When a task is started by calling start(), this is the code that is executed in the newly created task.

Parameters
[in]dataThe data passed in to the newly started task.

Implements Task.


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