Class eva::Switch¶
template <class TReader>
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 () |
|
| Switch (IHandler * listener, unsigned short eventMask) |
|
| Switch * | enable (bool enabled) Enables or disables the switch. |
| signed short | getValue () Gets the current level code. |
| Switch * | setListener (IHandler * listener, unsigned short 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 |
|---|---|
| unsigned char | curiosity = 0 |
| signed 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:
TReaderInput 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 [1/2]¶
inline eva::Switch::Switch ()
function Switch [2/2]¶
inline eva::Switch::Switch (
IHandler * listener,
unsigned short eventMask
)
function enable¶
Enables or disables the switch.
inline Switch * eva::Switch::enable (
bool enabled
)
When disabled, the switch stops generating events.
Parameters:
enabledTrue 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 setListener¶
Sets the event listener for this switch.
inline Switch * eva::Switch::setListener (
IHandler * listener,
unsigned short eventMask
)
Parameters:
listenerCallback object implementing IHandlereventMaskBitmask of events to listen for (ON_PRESS, ON_RELEASE, ON_CHANGE)
Returns:
Pointer to this for method chaining
Protected Attributes Documentation¶
variable curiosity¶
unsigned char eva::Switch< TReader >::curiosity;
variable levelCode¶
signed 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