Uniot Core
0.8.1
Loading...
Searching...
No Matches
uniot::Button Class Reference

#include <Button.h>

Inheritance diagram for uniot::Button:
[legend]

Public Types

enum  Event { CLICK , LONG_PRESS }
 Defines types of button events that can be triggered. More...
 
using ButtonCallback = std::function<void(Button *, Event)>
 Callback function signature for button events.
 

Public Member Functions

 Button (uint8_t pin, uint8_t activeLevel, uint8_t longPressTicks, ButtonCallback commonCallback=nullptr, uint8_t autoResetTicks=100)
 Constructs a Button instance.
 
bool resetClick ()
 Resets the click detection flag.
 
bool resetLongPress ()
 Resets the long press detection flag.
 
virtual void execute (short times) override
 Processes button state and detects events as part of the scheduler system.
 
virtual type_id getTypeId () const override
 Returns the type identifier for this class.
 
- Public Member Functions inherited from uniot::IExecutor
virtual ~IExecutor ()
 Virtual destructor for proper cleanup.
 
- Public Member Functions inherited from uniot::ObjectRegisterRecord
 ObjectRegisterRecord (const ObjectRegisterRecord &)=delete
 Deleted copy constructor to prevent copying.
 
void operator= (const ObjectRegisterRecord &)=delete
 Deleted assignment operator to prevent copying.
 
 ObjectRegisterRecord ()
 Constructor that automatically registers this instance.
 
virtual ~ObjectRegisterRecord ()
 Destructor that automatically unregisters this instance.
 

Protected Attributes

uint8_t mPin
 GPIO pin number connected to the button.
 
uint8_t mActiveLevel
 Logic level that represents button press (HIGH or LOW)
 
uint8_t mLongPressTicks
 Number of ticks to define a long press.
 
uint8_t mAutoResetTicks
 Number of ticks after which button state auto-resets.
 
bool mWasClick
 Flag indicating if a click has been detected.
 
bool mWasLongPress
 Flag indicating if a long press has been detected.
 
ButtonCallback OnLongPress
 Callback function for long press events.
 
ButtonCallback OnClick
 Callback function for click events.
 
bool mPrevState
 Previous state of the button.
 
uint8_t mLongPressTicker
 Counter for tracking potential long presses.
 
uint8_t mAutoResetTicker
 Counter for automatic state reset.
 

Additional Inherited Members

- Static Public Member Functions inherited from uniot::ObjectRegisterRecord
static bool exists (ObjectRegisterRecord *record)
 Checks if a record still exists in the registry.
 

Member Typedef Documentation

◆ ButtonCallback

using uniot::Button::ButtonCallback = std::function<void(Button *, Event)>

Callback function signature for button events.

Parameters
buttonPointer to the Button instance that triggered the event
eventThe type of event that occurred (CLICK or LONG_PRESS)

Member Enumeration Documentation

◆ Event

Defines types of button events that can be triggered.

Enumerator
CLICK 

Regular short button press and release.

LONG_PRESS 

Button held down for longer than the defined threshold.

Constructor & Destructor Documentation

◆ Button()

uniot::Button::Button ( uint8_t pin,
uint8_t activeLevel,
uint8_t longPressTicks,
ButtonCallback commonCallback = nullptr,
uint8_t autoResetTicks = 100 )
inline

Constructs a Button instance.

Parameters
pinGPIO pin number connected to the button
activeLevelLogic level that represents button press (HIGH or LOW)
longPressTicksNumber of execution ticks required for long press detection
commonCallbackOptional callback function for both click and long press events
autoResetTicksNumber of ticks after which button state will automatically reset

Member Function Documentation

◆ execute()

virtual void uniot::Button::execute ( short times)
inlineoverridevirtual

Processes button state and detects events as part of the scheduler system.

This method is called periodically by the TaskScheduler and implements the IExecutor interface. Each time it's called, it:

  1. Reads the current button state
  2. Detects if a long press has occurred
  3. Detects if a click has occurred (on button release)
  4. Triggers appropriate callbacks when events are detected
  5. Manages the auto-reset functionality to clear event flags
Parameters
timesThe number of remaining executions as passed from the scheduler:
  • Positive numbers indicate remaining executions count
  • Negative numbers indicate infinite executions (repeat forever)
  • Zero indicates the last execution has occurred

Implements uniot::IExecutor.

◆ getTypeId()

virtual type_id uniot::Button::getTypeId ( ) const
inlineoverridevirtual

Returns the type identifier for this class.

Return values
type_idThe type identifier for the Button class

Implements uniot::IWithType.

◆ resetClick()

bool uniot::Button::resetClick ( )
inline

Resets the click detection flag.

Return values
trueClick event was detected since the last reset
falseNo click event was detected since the last reset

◆ resetLongPress()

bool uniot::Button::resetLongPress ( )
inline

Resets the long press detection flag.

Return values
trueLong press event was detected since the last reset
falseNo long press event was detected since the last reset

Member Data Documentation

◆ mActiveLevel

uint8_t uniot::Button::mActiveLevel
protected

Logic level that represents button press (HIGH or LOW)

◆ mAutoResetTicker

uint8_t uniot::Button::mAutoResetTicker
protected

Counter for automatic state reset.

◆ mAutoResetTicks

uint8_t uniot::Button::mAutoResetTicks
protected

Number of ticks after which button state auto-resets.

◆ mLongPressTicker

uint8_t uniot::Button::mLongPressTicker
protected

Counter for tracking potential long presses.

◆ mLongPressTicks

uint8_t uniot::Button::mLongPressTicks
protected

Number of ticks to define a long press.

◆ mPin

uint8_t uniot::Button::mPin
protected

GPIO pin number connected to the button.

◆ mPrevState

bool uniot::Button::mPrevState
protected

Previous state of the button.

◆ mWasClick

bool uniot::Button::mWasClick
protected

Flag indicating if a click has been detected.

◆ mWasLongPress

bool uniot::Button::mWasLongPress
protected

Flag indicating if a long press has been detected.

◆ OnClick

ButtonCallback uniot::Button::OnClick
protected

Callback function for click events.

◆ OnLongPress

ButtonCallback uniot::Button::OnLongPress
protected

Callback function for long press events.


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