Skip to content

Class eva::Switch

template <class TReader>

ClassList > eva > Switch

Universal switch/button class for multi-valued input sources. More...

  • #include <evaSwitch.h>

Inherits the following classes: TReader, eva::Tickable

Inherited by the following classes: eva::Button, eva::Button, eva::Button

Public Functions

Type Name
Switch (IHandler * listener=nullptr, unsigned char eventMask=0, Args... args)
Constructs a Switch .
Switch * enable (bool enabled)
Enables or disables the switch.
signed short getValue ()
Gets the current level code.
bool isEnabled () const
Checks if the switch is enabled.
Switch * setListener (IHandler * listener, unsigned char eventMask)
Sets the event listener for this switch.

Public Functions inherited from eva::Tickable

See eva::Tickable

Type Name
Tickable ()
Tickable (const Tickable &) = delete
Tickable (Tickable &&) = delete
Tickable & operator= (const Tickable &) = delete
Tickable & operator= (Tickable &&) = delete
virtual ~Tickable ()

Public Static Functions inherited from eva::Tickable

See eva::Tickable

Type Name
void tac ()
Triggers tick on this and all linked tickables.

Protected Attributes

Type Name
bool enabled
unsigned char eventMask
unsigned char levelCode = 0
IHandler * listener = nullptr

Protected Functions

Type Name
bool checkActivating (unsigned char wasLevelCode)
inactive or different -> active
bool checkChanging (unsigned char wasLevelCode)
bool checkDeactivating (unsigned char wasLevelCode)
active -> inactive or different state
void handleActivating ()
void handleChanging ()
void handleDeactivating (unsigned char wasLevelCode)
void notify (unsigned short eventType, signed short eventCode)
bool updateState ()

Detailed Description

This class handles both switch and button behavior within the same component. The difference is purely semantic: * React to ON_CHANGE for switch-like behavior * React to ON_PRESS/ON_RELEASE for button-like behavior

Typical applications: * Simple on/off switches (binary reader) * Push buttons with press/release detection * Resistor ladder buttons on a single ADC pin * Custom encoding schemes (rotary encoders, keypads) * Multiplexed inputs

Events include both the event type and the level code in argsMask, allowing identification of which specific input triggered the event.

Template parameters:

  • TReader Input reader type that returns numeric codes (0 = inactive, >0 = active state identifier)

See also: PinSwitch Digital pin switches with debouncing (typical use)

See also: PullUpSwitch Pull-up switches convenience alias

See also: PinMultiSwitch Multiple switches on one ADC pin

Public Functions Documentation

function Switch

Constructs a Switch .

template<typename... Args>
inline eva::Switch::Switch (
    IHandler * listener=nullptr,
    unsigned char eventMask=0,
    Args... args
) 

Parameters:

  • listener Handler to receive events
  • eventMask Bitmask of events to listen for (ON_PRESS, ON_RELEASE, ON_CHANGE)
  • args Additional arguments passed to TReader constructor

function enable

Enables or disables the switch.

inline Switch * eva::Switch::enable (
    bool enabled
) 

When disabled, the switch stops generating events.

Parameters:

  • enabled True to enable, false to disable

Returns:

Pointer to this for method chaining


function getValue

Gets the current level code.

inline signed short eva::Switch::getValue () 

Returns:

Level code (0 for inactive, positive value for active state)


function isEnabled

Checks if the switch is enabled.

inline bool eva::Switch::isEnabled () const

Returns:

True if enabled, false otherwise


function setListener

Sets the event listener for this switch.

inline Switch * eva::Switch::setListener (
    IHandler * listener,
    unsigned char eventMask
) 

Parameters:

  • listener Callback object implementing IHandler
  • eventMask Bitmask of events to listen for (ON_PRESS, ON_RELEASE, ON_CHANGE)

Returns:

Pointer to this for method chaining


Protected Attributes Documentation

variable enabled

bool eva::Switch< TReader >::enabled;

variable eventMask

unsigned char eva::Switch< TReader >::eventMask;

variable levelCode

unsigned char eva::Switch< TReader >::levelCode;

variable listener

IHandler* eva::Switch< TReader >::listener;

Protected Functions Documentation

function checkActivating

inactive or different -> active

inline bool eva::Switch::checkActivating (
    unsigned char wasLevelCode
) 

function checkChanging

inline bool eva::Switch::checkChanging (
    unsigned char wasLevelCode
) 

function checkDeactivating

active -> inactive or different state

inline bool eva::Switch::checkDeactivating (
    unsigned char wasLevelCode
) 

function handleActivating

inline void eva::Switch::handleActivating () 

function handleChanging

inline void eva::Switch::handleChanging () 

function handleDeactivating

inline void eva::Switch::handleDeactivating (
    unsigned char wasLevelCode
) 

function notify

inline void eva::Switch::notify (
    unsigned short eventType,
    signed short eventCode
) 

function updateState

inline bool eva::Switch::updateState () 


The documentation for this class was generated from the following file src/evaSwitch.h