#include <Button.h>
|
| static uint8_t | _inputMode (uint8_t pin, uint8_t activeLevel) |
| | The input mode for a pin, with the internal pull matching the active level.
|
| |
◆ 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 |
◆ _inputMode()
| static uint8_t uniot::Button::_inputMode |
( |
uint8_t | pin, |
|
|
uint8_t | activeLevel ) |
|
inlinestaticprotected |
The input mode for a pin, with the internal pull matching the active level.
- Parameters
-
| pin | GPIO pin number |
| activeLevel | Logic level while pressed (LOW or HIGH) |
- Return values
-
| uint8_t | A mode for pinMode() |
◆ applyPinMode()
| void uniot::Button::applyPinMode |
( |
| ) |
|
|
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 |
Configure the pin as an input with the pull its active level needs.
A button that is active LOW must read HIGH when released, so it gets a pull-up; one that is active HIGH gets a pull-down. The internal resistor is used where the pin has one, and an external resistor on the board simply works alongside it. Where the pin has no suitable internal pull – ESP8266 GPIO0-15 have no pull-down and GPIO16 no pull-up, classic ESP32 GPIO34-39 have neither – the pin is set to plain INPUT and an external resistor is needed.
Called by the constructor, and again for every Lisp button by UniotCore::begin(). Calling pinMode() on the pin after begin() overrides it.
◆ 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 |
◆ 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: