#include <Button.h>
◆ ButtonCallback
Callback function signature for button events.
- Parameters
-
| button | Pointer to the Button instance that triggered the event |
| event | The type of event that occurred (CLICK or LONG_PRESS) |
◆ 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.
|
◆ 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
-
| pin | GPIO pin number connected to the button |
| activeLevel | Logic level that represents button press (HIGH or LOW) |
| longPressTicks | Number of execution ticks required for long press detection |
| commonCallback | Optional callback function for both click and long press events |
| autoResetTicks | Number of ticks after which button state will automatically reset |
◆ 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:
- Reads the current button state
- Detects if a long press has occurred
- Detects if a click has occurred (on button release)
- Triggers appropriate callbacks when events are detected
- Manages the auto-reset functionality to clear event flags
- Parameters
-
| times | The 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
-
Implements uniot::IWithType.
◆ resetClick()
| bool uniot::Button::resetClick |
( |
| ) |
|
|
inline |
Resets the click detection flag.
- Return values
-
| true | Click event was detected since the last reset |
| false | No click event was detected since the last reset |
◆ resetLongPress()
| bool uniot::Button::resetLongPress |
( |
| ) |
|
|
inline |
Resets the long press detection flag.
- Return values
-
| true | Long press event was detected since the last reset |
| false | No long press event was detected since the last reset |
◆ 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
Callback function for click events.
◆ OnLongPress
Callback function for long press events.
The documentation for this class was generated from the following file: