InputEvents v1.4.0
An easy to use but comprehensive Event Library for Buttons, Encoders, Encoder Buttons, Analog Inputs, Joysticks and Switches.
Protected Member Functions | Protected Attributes | List of all members
EventInputBase Class Referenceabstract

Description

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>

Inheritance diagram for EventInputBase:
Inheritance graph
[legend]

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...
 

Protected Attributes

uint8_t input_id = 0
 Input ID, not used internally.
 
uint8_t input_value = 0
 Input value, not used internally.
 
bool _enabled = true
 Input enabled flag.
 
bool idleFlagged = true
 True if input is idle.
 
unsigned long lastEventMs = millis()
 number of milliseconds since the last event
 
unsigned long idleTimeout = 10000
 The idle timeout in milliseconds.
 
bool callbackIsSet = false
 Required because in C/C++ callback has to be defined in derived classes... :-/.
 

Member Function Documentation

◆ allowEvent()

void EventInputBase::allowEvent ( InputEventType  et)

Allow a a previously blocked event tto fire.

Parameters
etInputEventType The event you want to allow

◆ begin()

virtual void EventInputBase::begin ( )
pure virtual

Must be called from setup().

Implemented in EventAnalog, EventButton, EventEncoder, EventEncoderButton, EventJoystick, and EventSwitch.

◆ blockEvent()

void EventInputBase::blockEvent ( InputEventType  et)

Stop an event from firing.

Parameters
etInputEventType The event you want to block

◆ enable()

void EventInputBase::enable ( bool  e = true)

Enable or disable an input.

Parameters
ePass false to disable (default is true)

◆ invoke()

virtual void EventInputBase::invoke ( InputEventType  et)
protectedpure virtual

To be overriden by derived classes.

Parameters
etEnum of type InputEventType

Implemented in EventAnalog, EventButton, EventEncoder, EventEncoderButton, EventJoystick, and EventSwitch.

◆ isEnabled()

bool EventInputBase::isEnabled ( )
inline

Returns true if input is enabled.

Returns
true Input is enabled
false Input is not enabled

◆ isIdle()

bool EventInputBase::isIdle ( )
inline

Return true if no activity for longer than setIdleTimeout - irrespective of whether the idle (or changed) callback has been fired.

Returns
true Idle timer has ended
false Not idle

◆ isInvokable()

bool EventInputBase::isInvokable ( InputEventType  et)
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.

◆ onDisabled()

void EventInputBase::onDisabled ( )
protectedvirtual

Can be ovrriden by derived classes but base method must be called.

Reimplemented in EventButton, EventEncoderButton, and EventJoystick.

◆ onEnabled()

void EventInputBase::onEnabled ( )
protectedvirtual

Can be ovrriden by derived classes but base method must be called.

Reimplemented in EventEncoder, EventEncoderButton, and EventJoystick.

◆ onIdle()

void EventInputBase::onIdle ( )
protectedvirtual

Can be ovrriden by derived classes but base method must be called.

Reimplemented in EventEncoderButton, and EventJoystick.

◆ resetIdleTimer()

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

◆ setIdleTimeout()

void EventInputBase::setIdleTimeout ( unsigned int  timeoutMs = 10000)
inline

Set the idle timeout in milliseconds (default 10000, 10 seconds)

Parameters
timeoutMsThe number of milliseconds after which the IDLE event will fire

◆ unsetCallback()

void EventInputBase::unsetCallback ( )
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.

◆ update()

void EventInputBase::update ( )

Update the state of the input.

Must be called from within loop()


The documentation for this class was generated from the following files: