Button
The Button class represents a hardware button within the Uniot Core. It provides mechanisms for detecting clicks and long presses, executing callbacks in response to these events, and managing internal state for debouncing and event triggering. By encapsulating button functionality, Button simplifies the integration of physical buttons.
Methods:
Button(uint8_t pin, uint8_t activeLevel, uint8_t longPressTicks, ButtonCallback commonCallback = nullptr, uint8_t autoResetTicks = 100)Constructs aButtoninstance with specified pin configurations and callback functions. Initializes the pin mode and sets up parameters for long press detection and automatic event resetting.bool resetClick()Resets the click event flag. Returnstrueif a click was previously detected,falseotherwise.bool resetLongPress()Resets the long press event flag. Returnstrueif a long press was previously detected,falseotherwise.virtual void execute(short _) overrideExecutes the button state checking routine. Detects button state changes, determines if a click or long press event has occurred, and invokes the corresponding callbacks.virtual type_id getTypeId() const overrideReturns the type identifier for theButtonclass, enabling type-safe casting and identification within the system.
Private Members:
uint8_t mPinStores the GPIO pin number to which the button is connected.uint8_t mActiveLevelIndicates the active level (HIGH or LOW) that signifies a button press.uint8_t mLongPressTicksSpecifies the number of ticks required to recognize a long press event.uint8_t mAutoResetTicksDefines the number of ticks after which the event flags are automatically reset.bool mWasClickFlags whether a click event has been detected.bool mWasLongPressFlags whether a long press event has been detected.ButtonCallback OnLongPressCallback function to be invoked when a long press event is detected.ButtonCallback OnClickCallback function to be invoked when a click event is detected.bool mPrevStateStores the previous state of the button for change detection.uint8_t mLongPressTickerTicker counting ticks towards recognizing a long press event.uint8_t mAutoResetTickerTicker counting ticks towards automatic event flag resetting.
Last updated