AceButton
1.4.1
An adjustable, compact, event-driven button library for Arduino.
|
A ButtonConfig that handles an N-to-M binary encoder where N = 2^M. More...
#include <EncodedButtonConfig.h>
Public Member Functions | |
EncodedButtonConfig (uint8_t numPins, uint8_t const pins[], uint8_t numButtons, AceButton *const buttons[], uint8_t defaultReleasedState=HIGH) | |
Constructor. More... | |
int | readButton (uint8_t pin) override |
Return state of the encoded 'pin' number, corresponding to the pull-down states of the actual pins. More... | |
void | checkButtons () const |
Read the pins once, obtain the virtual pin number, then call each button's checkState() method to trigger any events. More... | |
![]() | |
ButtonConfig () | |
Constructor. More... | |
uint16_t | getDebounceDelay () |
Milliseconds to wait for debouncing. More... | |
uint16_t | getClickDelay () |
Milliseconds to wait for a possible click. More... | |
uint16_t | getDoubleClickDelay () |
Milliseconds between the first and second click to register as a double-click. | |
uint16_t | getLongPressDelay () |
Milliseconds for a long press event. More... | |
uint16_t | getRepeatPressDelay () |
Milliseconds that a button needs to be Pressed down before the start of the sequence of RepeatPressed events. More... | |
uint16_t | getRepeatPressInterval () |
Milliseconds between two successive RepeatPressed events. | |
void | setDebounceDelay (uint16_t debounceDelay) |
Set the debounceDelay. More... | |
void | setClickDelay (uint16_t clickDelay) |
Set the clickDelay. More... | |
void | setDoubleClickDelay (uint16_t doubleClickDelay) |
Set the doubleClickDelay. More... | |
void | setLongPressDelay (uint16_t longPressDelay) |
Set the longPressDelay. More... | |
void | setRepeatPressDelay (uint16_t repeatPressDelay) |
Set the repeatPressDelay. More... | |
void | setRepeatPressInterval (uint16_t repeatPressInterval) |
Set the repeatPressInterval. More... | |
virtual unsigned long | getClock () |
Return the milliseconds of the internal clock. More... | |
virtual unsigned long | getClockMicros () |
Return the microseconds of the internal clock. More... | |
bool | isFeature (FeatureFlagType features) |
Check if the given features are enabled. More... | |
void | setFeature (FeatureFlagType features) |
Enable the given features. More... | |
void | clearFeature (FeatureFlagType features) |
Disable the given features. More... | |
EventHandler | getEventHandler () |
Return the eventHandler. More... | |
void | setEventHandler (EventHandler eventHandler) |
Install the event handler. More... | |
void | setTimingStats (TimingStats *timingStats) |
Set the timing stats object. More... | |
TimingStats * | getTimingStats () |
Get the timing stats. More... | |
Protected Member Functions | |
virtual uint8_t | getVirtualPin () const |
Return the virtual pin number corresponding to the combinatorial states of the actual pins. More... | |
![]() | |
virtual void | init () |
Initialize to its pristine state, except for the EventHandler which is unchanged. More... | |
Additional Inherited Members | |
![]() | |
typedef uint16_t | FeatureFlagType |
Type of the feature flag. More... | |
typedef void(* | EventHandler) (AceButton *button, uint8_t eventType, uint8_t buttonState) |
The event handler signature. More... | |
![]() | |
static ButtonConfig * | getSystemButtonConfig () |
Return a pointer to the singleton instance of the ButtonConfig which is attached to all AceButton instances by default. | |
![]() | |
static const uint16_t | kDebounceDelay = 20 |
Default value returned by getDebounceDelay(). More... | |
static const uint16_t | kClickDelay = 200 |
Default value returned by getClickDelay(). More... | |
static const uint16_t | kDoubleClickDelay = 400 |
Default value returned by getDoubleClickDelay(). More... | |
static const uint16_t | kLongPressDelay = 1000 |
Default value returned by getLongPressDelay(). More... | |
static const uint16_t | kRepeatPressDelay = 1000 |
Default value returned by getRepeatPressDelay(). More... | |
static const uint16_t | kRepeatPressInterval = 200 |
Default value returned by getRepeatPressInterval(). More... | |
static const FeatureFlagType | kFeatureClick = 0x01 |
Flag to activate the AceButton::kEventClicked event. More... | |
static const FeatureFlagType | kFeatureDoubleClick = 0x02 |
Flag to activate the AceButton::kEventDoubleClicked event. More... | |
static const FeatureFlagType | kFeatureLongPress = 0x04 |
Flag to activate the AceButton::kEventLongPress event. More... | |
static const FeatureFlagType | kFeatureRepeatPress = 0x08 |
Flag to activate the AceButton::kEventRepeatPressed event. More... | |
static const FeatureFlagType | kFeatureSuppressAfterClick = 0x10 |
Flag to suppress kEventReleased after a kEventClicked. More... | |
static const FeatureFlagType | kFeatureSuppressAfterDoubleClick = 0x20 |
Flag to suppress kEventReleased after a kEventDoubleClicked. More... | |
static const FeatureFlagType | kFeatureSuppressAfterLongPress = 0x40 |
Flag to suppress kEventReleased after a kEventLongPressed. More... | |
static const FeatureFlagType | kFeatureSuppressAfterRepeatPress = 0x80 |
Flag to suppress kEventReleased after a kEventRepeatPressed. More... | |
static const FeatureFlagType | kFeatureSuppressClickBeforeDoubleClick = 0x100 |
Flag to suppress kEventClicked before a kEventDoubleClicked. More... | |
static const FeatureFlagType | kFeatureSuppressAll |
Convenience flag to suppress all suppressions. More... | |
A ButtonConfig that handles an N-to-M binary encoder where N = 2^M.
This is a generalized version of Encoded4To2ButtonConfig and Encoded8To3ButtonConfig.
Here is an example of how to make EncodedButtonConfig
act like an Encoded8To3ButtonConfig
:
Definition at line 71 of file EncodedButtonConfig.h.
ace_button::EncodedButtonConfig::EncodedButtonConfig | ( | uint8_t | numPins, |
uint8_t const | pins[], | ||
uint8_t | numButtons, | ||
AceButton *const | buttons[], | ||
uint8_t | defaultReleasedState = HIGH |
||
) |
Constructor.
numPins | number of pins used to encode the switches (corresponding to the M) |
pins | an array of actual pin numbers (e.g. [2, 4, 5]) |
numButtons | number buttons which are encoded; the maximum number of buttons is 2^{numPins} |
buttons | array of buttons attached to the pins using binary encoding; each button needs to be assigned a virtual pin number between 1 and (2^{numPins} - 1) inclusive; the buttons can be arranged in any order |
defaultReleasedState | state of the encoder bit when the button is in the released state. For a pull-up wiring, the state of the pin is HIGH when the button is released. This value is used to configure wiring of the virtual button, so that it matches the wiring of the physical buttons. The LS74148 encoder uses a pull-up wiring, so this should be set HIGH. The default value is HIGH. |
void ace_button::EncodedButtonConfig::checkButtons | ( | ) | const |
Read the pins once, obtain the virtual pin number, then call each button's checkState() method to trigger any events.
When the number of buttons becomes greater than 7 or 8, it is more efficient to call this method, instead of calling the check() of each AceButton.
Definition at line 49 of file EncodedButtonConfig.cpp.
|
protectedvirtual |
Return the virtual pin number corresponding to the combinatorial states of the actual pins.
Returns a number between 1 and (2^{numPins} - 1). 0 means "no button" pressed.
Definition at line 64 of file EncodedButtonConfig.cpp.
|
overridevirtual |
Return state of the encoded 'pin' number, corresponding to the pull-down states of the actual pins.
LOW means that the corresponding encoded virtual pin was pushed.
This method is not expected to be used. Use the checkButtons() method instead for this class.
Reimplemented from ace_button::ButtonConfig.
Definition at line 44 of file EncodedButtonConfig.cpp.