![]() |
InputEvents v1.4.0
An easy to use but comprehensive Event Library for Buttons, Encoders, Encoder Buttons, Analog Inputs, Joysticks and Switches.
|
The common base for InputEvents input classes.
Specifies a number of virtual methods and implements common methods for enable, timeout, event blocking and user ID/values.
#include <EventInputBase.h>
Public Member Functions | |
Common Methods | |
virtual void | begin ()=0 |
Must be called from setup(). More... | |
virtual void | unsetCallback () |
Unset the callback. Must be overriden in derived class & then base method called. More... | |
bool | isCallbackSet () |
Returns true if the callback is set. | |
void | update () |
Update the state of the input. More... | |
bool | isEnabled () |
Returns true if input is enabled. More... | |
void | enable (bool e=true) |
Enable or disable an input. More... | |
Idle methods | |
These methods allow you to set and get the state of the idle timer | |
void | setIdleTimeout (unsigned int timeoutMs=10000) |
Set the idle timeout in milliseconds (default 10000, 10 seconds) More... | |
unsigned long | msSinceLastEvent () |
Returns the number of ms since any event was fired for this input. | |
bool | isIdle () |
Return true if no activity for longer than setIdleTimeout - irrespective of whether the idle (or changed) callback has been fired. More... | |
void | resetIdleTimer () |
Reset the idle timer. The IDLE event will fire setIdleTimeout ms after this is called. More... | |
Blocking and Allowing events | |
All events are fired by default but you can block or allow certain events. | |
void | blockEvent (InputEventType et) |
Stop an event from firing. More... | |
void | allowEvent (InputEventType et) |
Allow a a previously blocked event tto fire. More... | |
void | blockAllEvents () |
Stop all events from firing - usually used in conjunction with allowEvent() | |
void | allowAllEvents () |
Clear all blocked events. | |
bool | isEventAllowed (InputEventType et) |
Returns true if the event is not blocked. | |
Input ID and Value | |
These methods are not used internally and are for developer use to identify a particular input, eg so multiple buttons can share a callback function or to set a vlaue for a multi-function button. Expected to be used with enums. | |
void | setInputId (uint8_t id) |
Set the input ID (for use by user, not used internally). Not unique, default is 0. | |
uint8_t | getInputId () |
Get the input ID (for use by user, not used internally). Not unique, default is 0. | |
void | setInputValue (uint8_t val) |
Set the input value (for use by user, not used internally). Not unique, default is 0. | |
uint8_t | getInputValue () |
Get the input value (for use by user, not used internally). Not unique, default is 0. | |
Protected Member Functions | |
bool | isInvokable (InputEventType et) |
virtual void | invoke (InputEventType et)=0 |
To be overriden by derived classes. More... | |
virtual void | onEnabled () |
Can be ovrriden by derived classes but base method must be called. More... | |
virtual void | onDisabled () |
Can be ovrriden by derived classes but base method must be called. More... | |
virtual void | onIdle () |
Can be ovrriden by derived classes but base method must be called. More... | |
void EventInputBase::allowEvent | ( | InputEventType | et | ) |
Allow a a previously blocked event tto fire.
et | InputEventType The event you want to allow |
|
pure virtual |
Must be called from setup().
Implemented in EventAnalog, EventButton, EventEncoder, EventEncoderButton, EventJoystick, and EventSwitch.
void EventInputBase::blockEvent | ( | InputEventType | et | ) |
Stop an event from firing.
et | InputEventType The event you want to block |
void EventInputBase::enable | ( | bool | e = true | ) |
Enable or disable an input.
e | Pass false to disable (default is true) |
|
protectedpure virtual |
To be overriden by derived classes.
et | Enum of type InputEventType |
Implemented in EventAnalog, EventButton, EventEncoder, EventEncoderButton, EventJoystick, and EventSwitch.
|
inline |
Returns true if input is enabled.
|
inline |
Return true if no activity for longer than setIdleTimeout - irrespective of whether the idle (or changed) callback has been fired.
|
protected |
Returns true if an event can be invoked and if so, will also reset the idle timeout timer if events are not ENABLED, DISABLED or IDLE. If you don't want to reset the idle timer, use isEventAllowed() The assumption is you will invoke() if this returns true.
|
protectedvirtual |
Can be ovrriden by derived classes but base method must be called.
Reimplemented in EventButton, EventEncoderButton, and EventJoystick.
|
protectedvirtual |
Can be ovrriden by derived classes but base method must be called.
Reimplemented in EventEncoder, EventEncoderButton, and EventJoystick.
|
protectedvirtual |
Can be ovrriden by derived classes but base method must be called.
Reimplemented in EventEncoderButton, and EventJoystick.
void EventInputBase::resetIdleTimer | ( | ) |
Reset the idle timer. The IDLE event will fire setIdleTimeout ms after this is called.
This is normally done automatically every time an event is fired but can be called to further delay and idle event
|
inline |
Set the idle timeout in milliseconds (default 10000, 10 seconds)
timeoutMs | The number of milliseconds after which the IDLE event will fire |
|
virtual |
Unset the callback. Must be overriden in derived class & then base method called.
GPLv2 Licence https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
Copyright (c) 2024 Philip Fletcher phili.nosp@m.p.fl.nosp@m.etche.nosp@m.r@st.nosp@m.utchb.nosp@m.ury..nosp@m.com
Reimplemented in EventAnalog, EventButton, EventEncoder, EventEncoderButton, EventJoystick, and EventSwitch.
void EventInputBase::update | ( | ) |
Update the state of the input.
Must be called from within loop()