13#include "EventInputBase.h"
14#include "PinAdapter/FoltmanDebounceAdapter.h"
15#include "PinAdapter/GpioPinAdapter.h"
37 #if defined(FUNCTIONAL_SUPPORTED)
72 EventSwitch(
byte switchPin,
bool useDefaultDebouncer=
true);
126 #if defined(FUNCTIONAL_SUPPORTED)
128 template <
typename T>
132 (instance->*method)(et, ie);
165 bool isOn() {
return currentState == onState; }
173 bool isOff() {
return currentState != onState; }
249 bool turningOff() {
return stateChanged && previousState == onState; }
257 bool turningOn() {
return stateChanged && previousState != onState; }
267 unsigned char currentState = HIGH;
268 bool previousState = HIGH;
270 bool currentPinState = HIGH;
271 bool previousPinState = HIGH;
273 bool stateChanged =
false;
274 uint32_t stateChangeLastTime;
275 uint32_t durationOfPreviousState;
This is the interface/base class for debounce adapters.
Definition: DebounceAdapter.h:11
The EventSwitch class is for standard on/off inputs. Like the EventButton the switch must be wired be...
Definition: EventSwitch.h:33
void unsetCallback() override
Unset a previously set callback function or method.
Definition: EventSwitch.cpp:45
unsigned long currentDuration()
Duration in milliseconds of the current state.
Definition: EventSwitch.cpp:114
void begin()
Initialise the EventButton.
Definition: EventSwitch.cpp:36
bool setDebounceInterval(unsigned int intervalMs=10)
Set the DebounceAdapter debounce interval. Default is 10ms.
Definition: EventSwitch.cpp:106
std::function< void(InputEventType et, EventSwitch &ie)> CallbackFunction
If std::function is supported, this creates the callback type.
Definition: EventSwitch.h:41
unsigned long previousDuration()
Duration in milliseconds of the previous state.
Definition: EventSwitch.h:183
void setCallback(CallbackFunction f)
Set the Callback function.
Definition: EventSwitch.h:112
void invoke(InputEventType et) override
Override of the EventInputBase::invoke() virtual method.
Definition: EventSwitch.cpp:66
bool turningOn()
Returns true if state has changed and previous state is not onState.
Definition: EventSwitch.h:257
CallbackFunction callbackFunction
The callback function member.
Definition: EventSwitch.h:52
bool changedPinState()
Returns true if pinAdapter read() has changed since last call.
Definition: EventSwitch.cpp:92
void changeState(bool newState)
Change the switch state and flag as changed.
Definition: EventSwitch.cpp:98
bool turningOff()
Returns true if state has changed and previous state is onState.
Definition: EventSwitch.h:249
void setDebouncer(DebounceAdapter *debounceAdapter)
Set the debouncer. Note: When planning to use setDebouncer() you must ensure useDefaultDebouncer is s...
Definition: EventSwitch.cpp:72
void setCallback(T *instance, void(T::*method)(InputEventType, EventSwitch &))
Set the Callback function to a class method.
Definition: EventSwitch.h:129
EventSwitch(byte switchPin, bool useDefaultDebouncer=true)
Construct an EventSwitch input.
Definition: EventSwitch.cpp:12
bool changedState()
Returns true if pinAdapter changed the switch state.
Definition: EventSwitch.cpp:80
void update()
Update the state from the switch pin input.
Definition: EventSwitch.cpp:50
bool isOn()
Return true if switch is on.
Definition: EventSwitch.h:165
void setOnState(bool state=LOW)
Set the pin state that represents 'on'. By default this is LOW (ie pulled down).
Definition: EventSwitch.h:216
bool isOff()
Return true if switch is off.
Definition: EventSwitch.h:173
The interface specification for button, encoder button and switch pins.
Definition: PinAdapter.h:8