![]() |
ButtonToSwitch Library for ESP32 (Arduino) v4.4.0
A library that provides elaborated switch mechanism behavior simulation for digital signals inputs
|
Models a Slider Double Action LDD-MPB combo switch, a.k.a. off/on/dimmer, a.k.a. off/on/volume radio switch)(S-DALDD-MPB) More...
#include <ButtonToSwitch_ESP32.h>
Public Member Functions | |
SldrDALtchMPBttn () | |
Default constructor. | |
SldrDALtchMPBttn (const int8_t &mpbttnPin, const bool &pulledUp=true, const bool &typeNO=true, const unsigned long int &dbncTimeOrigSett=0, const unsigned long int &strtDelay=0, const uint16_t initVal=0xFFFF) | |
Class constructor. | |
~SldrDALtchMPBttn () | |
Virtual class destructor. | |
void | clrStatus (bool clrIsOn=true) |
uint16_t | getOtptCurVal () |
Returns the Output Current Value (otpCurVal) attribute. | |
bool | getOtptCurValIsMax () |
Returns a boolean value indicating if the "Output Current Value" equals the maximum limit. | |
bool | getOtptCurValIsMin () |
Returns the result of comparing the Output Current Value to the Minimum value setting | |
unsigned long | getOtptSldrSpd () |
Returns the current setting for the Output Slider Speed value. | |
uint16_t | getOtptSldrStpSize () |
Returns the current setting for the Output Slider Step Size value. | |
uint16_t | getOtptValMax () |
Returns the top output current value register setting. | |
uint16_t | getOtptValMin () |
Returns the bottom output current value register setting. | |
bool | getSldrDirUp () |
Returns the value of the curSldrDirUp attribute. | |
bool | setOtptCurVal (const uint16_t &newVal) |
Sets the output current value register. | |
bool | setOtptSldrSpd (const uint16_t &newVal) |
Sets the output slider speed (otptSldrSpd) attribute. | |
bool | setOtptSldrStpSize (const uint16_t &newVal) |
Sets the output slider step size (otptSldrStpSize) attribute value. | |
bool | setOtptValMax (const uint16_t &newVal) |
Sets the output current value register maximum value attribute (otptValMax attribute). | |
bool | setOtptValMin (const uint16_t &newVal) |
Sets the output current value register minimum value attribute (otptValMin attribute). | |
bool | setSldrDirDn () |
Sets the value of the curSldrDirUp attribute to false. | |
bool | setSldrDirUp () |
Sets the value of the curSldrDirUp attribute to true. | |
void | setSwpDirOnEnd (const bool &newVal) |
Sets the value of the "Auto-Swap Direction on Ends" (autoSwpDirOnEnd) attribute. | |
void | setSwpDirOnPrss (const bool &newVal) |
Sets the value of the "Auto-Swap Direction On Press" (autoSwpDirOnPrss) attribute. | |
bool | swapSldrDir () |
Inverts the current curSldrDirUp attribute value. | |
![]() | |
DblActnLtchMPBttn () | |
Abstract Class default constructor. | |
DblActnLtchMPBttn (const int8_t &mpbttnPin, const bool &pulledUp=true, const bool &typeNO=true, const unsigned long int &dbncTimeOrigSett=0, const unsigned long int &strtDelay=0) | |
Abstract Class constructor. | |
~DblActnLtchMPBttn () | |
Virtual destructor. | |
virtual bool | begin (const unsigned long int &pollDelayMs=_StdPollDelay) |
See DbncdMPBttn::begin(const unsigned long int) | |
void | clrStatus (bool clrIsOn=true) |
See DbncddMPBttn::clrStatus(bool) | |
fncPtrType | getFnWhnTrnOffScndry () |
returns the function that is set to execute every time the object enters the Secondary Off State. | |
fncPtrType | getFnWhnTrnOnScndry () |
Returns the function that is set to execute every time the object enters the Secondary On State. | |
bool | getIsOnScndry () |
Returns the current value of the isOnScndry attribute flag. | |
unsigned long | getScndModActvDly () |
Returns the current value of the scndModActvDly class attribute. | |
const TaskHandle_t | getTaskWhileOnScndry () |
Returns the task to be run while the object is in the Secondary On state. | |
void | setFnWhnTrnOffScndryPtr (void(*newFnWhnTrnOff)()) |
Sets the function that will be called to execute every time the object enters the Secondary Off State. | |
void | setFnWhnTrnOnScndryPtr (void(*newFnWhnTrnOn)()) |
Sets the function that will be called to execute every time the object enters the Secondary On State. | |
bool | setScndModActvDly (const unsigned long &newVal) |
Sets a new value for the scndModActvDly class attribute. | |
void | setTaskWhileOnScndry (const TaskHandle_t &newTaskHandle) |
Sets the task to be run while the object is in the On state. | |
![]() | |
LtchMPBttn () | |
Default constructor. | |
LtchMPBttn (const int8_t &mpbttnPin, const bool &pulledUp=true, const bool &typeNO=true, const unsigned long int &dbncTimeOrigSett=0, const unsigned long int &strtDelay=0) | |
Class constructor. | |
void | clrStatus (bool clrIsOn=true) |
See DbncdMPBttn::clrStatus(bool) | |
const bool | getIsLatched () const |
Returns the value of the isLatched attribute flag, indicating the Latched or Unlatched condition of the object. | |
bool | getTrnOffASAP () |
Returns the value of the trnOffASAP attribute flag. | |
const bool | getUnlatchPend () const |
Returns the value of the "Valid Unlatch Pending" attribute. | |
const bool | getUnlatchRlsPend () const |
Returns the value of the "Valid Unlatch Release Pending" attribute. | |
void | setTrnOffASAP (const bool &newVal) |
Sets the value of the trnOffASAP attribute. | |
void | setUnlatchPend (const bool &newVal) |
Sets the value of the "Valid Unlatch Pending" attribute. | |
void | setUnlatchRlsPend (const bool &newVal) |
Sets the value of the "Valid Unlatch Release Pending" attribute. | |
bool | unlatch () |
Sets the values of the flags needed to unlatch a latched MPB. | |
![]() | |
DbncdDlydMPBttn () | |
Default constructor. | |
DbncdDlydMPBttn (const int8_t &mpbttnPin, const bool &pulledUp=true, const bool &typeNO=true, const unsigned long int &dbncTimeOrigSett=0, const unsigned long int &strtDelay=0) | |
Class constructor. | |
bool | init (const int8_t &mpbttnPin, const bool &pulledUp=true, const bool &typeNO=true, const unsigned long int &dbncTimeOrigSett=0, const unsigned long int &strtDelay=0) |
see DbncdMPBttn::init(const int8_t, const bool, const bool, const unsigned long int) | |
void | setStrtDelay (const unsigned long int &newStrtDelay) |
Sets a new value to the "Start Delay" strtDelay attribute. | |
![]() | |
DbncdMPBttn () | |
Default class constructor. | |
DbncdMPBttn (const int8_t &mpbttnPin, const bool &pulledUp=true, const bool &typeNO=true, const unsigned long int &dbncTimeOrigSett=0) | |
Class constructor. | |
virtual | ~DbncdMPBttn () |
Default virtual destructor. | |
void | clrStatus (bool clrIsOn=true) |
Clears and resets flags, timers and counters modified through the object's signals processing. | |
void | disable () |
Disables the input signal processing, ignoring the changes of its values. | |
void | enable () |
Enables the input signal processing. | |
bool | end () |
Detaches the object from the timer that monitors the input pins, compute and updates the object's status. The timer daemon entry is deleted for the object. | |
const unsigned long int | getCurDbncTime () const |
Returns the current debounce period time set for the object. | |
fncPtrType | getFnWhnTrnOff () |
Returns the function that is set to execute every time the object enters the Off State. | |
fncPtrType | getFnWhnTrnOn () |
Returns the function that is set to execute every time the object enters the On State. | |
const bool | getIsEnabled () const |
Returns the value of the isEnabled attribute flag, indicating the Enabled or Disabled status of the object. | |
const bool | getIsOn () const |
Returns the value of the isOn attribute flag. | |
const bool | getIsOnDisabled () const |
Returns the value of the isOnDisabled attribute flag. | |
const uint32_t | getOtptsSttsPkgd () |
Returns the relevant attribute flags values for the object state encoded as a 32 bits value, required to pass current state of the object to another thread/task managing the outputs. | |
const bool | getOutputsChange () const |
Returns the value of the outputsChange attribute flag. | |
unsigned long int | getStrtDelay () |
Returns the current value of the outputs change task unblocking trigger (outputsChngTskTrggr) attribute flag. | |
const TaskHandle_t | getTaskToNotify () const |
Returns the task to be notified by the object when its output flags changes. | |
const TaskHandle_t | getTaskWhileOn () |
Returns the task to be run (resumed) while the object is in the On state. | |
bool | init (const int8_t &mpbttnPin, const bool &pulledUp=true, const bool &typeNO=true, const unsigned long int &dbncTimeOrigSett=0) |
Initializes an object instantiated by the default constructor. | |
bool | pause () |
Pauses the software timer updating the computation of the object's internal flags value. | |
void | resetDbncTime () |
Resets the debounce process time of the object to the value used at instantiation. | |
void | resetFda () |
Resets the MPB behavior automaton to it's Initial or Start State | |
bool | resume () |
Resets the outputs change task unblocking trigger (outputsChngTskTrggr) attribute flag. | |
void | setBeginDisabled (const bool &newBeginDisabled=false) |
Sets the starting isDisabled state. | |
bool | setDbncTime (const unsigned long int &newDbncTime) |
Sets the debounce process time. | |
void | setFnWhnTrnOffPtr (fncPtrType newFnWhnTrnOff) |
Sets the function that will be called to execute every time the object enters the Off State. | |
void | setFnWhnTrnOnPtr (fncPtrType newFnWhnTrnOn) |
Sets the function that will be called to execute every time the object enters the On State. | |
void | setIsOnDisabled (const bool &newIsOnDisabled) |
Sets the value of the isOnDisabled attribute flag. | |
void | setOutputsChange (bool newOutputsChange) |
Sets the value of the attribute flag indicating if a change took place in any of the output attribute flags (IsOn included). | |
void | setTaskToNotify (const TaskHandle_t &newTaskHandle) |
Sets the handle to the task to be notified by the object when its output attribute flags changes. | |
virtual void | setTaskWhileOn (const TaskHandle_t &newTaskHandle) |
Sets the task to be run while the object is in the On state. | |
Models a Slider Double Action LDD-MPB combo switch, a.k.a. off/on/dimmer, a.k.a. off/on/volume radio switch)(S-DALDD-MPB)
This is a subclass of the DALDD-MPB whose secondary behavior is analog to that of a Digital potentiometer (DigiPot) or a Discreet values increment/decrement register. That means that when in the second mode, while the MPB remains pressed, an attribute set as a register changes its value -the otptCurVal register-. When the timer callback function used to keep the MPB status updated is called -while in the secondary mode state- the time since the last call is calculated and the time lapse in milliseconds is converted into Steps, using as configurable factor the outputSliderSpeed in a pre-scaler fashion. At instantiation the outputSliderSpeed is configured to 1 (step/millisecond, i.e. 1 step for each millisecond). The resulting value in "steps" is then factored by the outputSliderStepSize, which holds the value that each step will modify the otptCurVal register. The implemented embedded behavior mechanisms of the class determine how the modification of the otpCurVal register will be made, and the associated effects to the instantiated object's attribute, such as (but not limited to):
class SldrDALtchMPBttn
SldrDALtchMPBttn::SldrDALtchMPBttn | ( | const int8_t & | mpbttnPin, |
const bool & | pulledUp = true, | ||
const bool & | typeNO = true, | ||
const unsigned long int & | dbncTimeOrigSett = 0, | ||
const unsigned long int & | strtDelay = 0, | ||
const uint16_t | initVal = 0xFFFF ) |
Class constructor.
initVal | (Optional) Initial value of the wiper (taking the analogy of a potentiometer working parts), in this implementation the value corresponds to the Output Current Value (otpCurVal) attribute of the class. As the attribute type is uint16_t and the minimum and maximum limits are set to 0x0000 and 0xFFFF respectively, the initial value might be set to any value of the type. If no value is provided 0xFFFF will be the instantiation value. |
void SldrDALtchMPBttn::clrStatus | ( | bool | clrIsOn = true | ) |
uint16_t SldrDALtchMPBttn::getOtptCurVal | ( | ) |
Returns the Output Current Value (otpCurVal) attribute.
bool SldrDALtchMPBttn::getOtptCurValIsMax | ( | ) |
Returns a boolean value indicating if the "Output Current Value" equals the maximum limit.
The value returned is the result of comparing the Output Current Value to the Maximum value setting
true | The Output Current Value is equal to the Maximum value setting, i.e. the otpCurVal has reached the "top" of the configured range of accepted values. |
false | The Output Current Value is not equal to the Maximum value setting. |
bool SldrDALtchMPBttn::getOtptCurValIsMin | ( | ) |
Returns the result of comparing the Output Current Value to the Minimum value setting
The value returned is the result of comparing the Output Current Value to the Minimum value setting
true | The Output Current Value is equal to the Minimum value setting, i.e. the otpCurVal has reached the "bottom" of the configured range of accepted values. |
false | The Output Current Value is not equal to the Minimum value setting. |
unsigned long SldrDALtchMPBttn::getOtptSldrSpd | ( | ) |
Returns the current setting for the Output Slider Speed value.
The outputSliderSpeed attribute is the configurable factor used to convert the time passed since the MPB entered it's secondary mode in milliseconds into Steps -Slider mode steps- in a pre-scaler fashion.
uint16_t SldrDALtchMPBttn::getOtptSldrStpSize | ( | ) |
Returns the current setting for the Output Slider Step Size value.
The outputSliderStepSize is the factor by which the change in steps is multiplied to calculate the total modification of the otpCurVal register. As the steps modification is calculated each time the timer callback function is called the variation is done in successive steps while the MPB is kept pressed, and not just when it is finally released.
uint16_t SldrDALtchMPBttn::getOtptValMax | ( | ) |
Returns the top output current value register setting.
uint16_t SldrDALtchMPBttn::getOtptValMin | ( | ) |
Returns the bottom output current value register setting.
bool SldrDALtchMPBttn::getSldrDirUp | ( | ) |
Returns the value of the curSldrDirUp attribute.
The curSldrDirUp attribute indicates the direction at which the outputCurrentValue register is being modified. If the current slider direction is up, means the change of value must be treated as an increment, while having the current slider direction down means it's value must be treated as a decrement.
true | The current slider direction is Up, the output current value will be incremented. |
false | The current slider direction is Down, the output current value will be decremented. |
bool SldrDALtchMPBttn::setOtptCurVal | ( | const uint16_t & | newVal | ) |
Sets the output current value register.
The new value for the output current value register must be in the range otptValMin <= newVal <= otptValMax
newVal | The new value for the output current value register. |
true | The new value was within valid range, the output current value register is set to the parameter passed. |
false | The new value was outside valid range, the change was not made. |
bool SldrDALtchMPBttn::setOtptSldrSpd | ( | const uint16_t & | newVal | ) |
Sets the output slider speed (otptSldrSpd) attribute.
As described in the SldrDALtchMPBttn class definition, the otptSldrSpd value is the factor by which the time between two readings of the MPB pressing state in secondary mode is converted into "slider steps". At instantiation the value is set to 1, meaning 1 millisecond is equivalent to 1 step, the "**slowest**" speed configuration. Rising the value will make each millisecond represent more steps, making the change of current value faster.
newVal | The new value for the otptSldrSpd attribute. |
true | The parameter was a valid value, the attribute is set to the new value. |
false | The parameter is an invalid value, the attribute is not changed. |
bool SldrDALtchMPBttn::setOtptSldrStpSize | ( | const uint16_t & | newVal | ) |
Sets the output slider step size (otptSldrStpSize) attribute value.
newVal | The new value for the outputSliderStepSize attribute. |
true | If newVal <= (otptValMax - otptValMin), the value of the outputSliderStepSize attribute is changed. |
false | Otherwise, and the value of the outputSliderStepSize attribute is not changed. |
bool SldrDALtchMPBttn::setOtptValMax | ( | const uint16_t & | newVal | ) |
Sets the output current value register maximum value attribute (otptValMax attribute).
The new value for the otptValMax attribute must be in the range otptValMin < newVal <= 0xFFFF
newVal | The new value for the otptValMax attribute. |
true | The new value was within valid range, the otptValMax attribute change was made. |
false | The new value was outside valid range, the change was not made. |
bool SldrDALtchMPBttn::setOtptValMin | ( | const uint16_t & | newVal | ) |
Sets the output current value register minimum value attribute (otptValMin attribute).
The new value for the otptValMin attribute must be in the range 0x0000<= newVal < otptValMax.
newVal | The new value for the otptValMin attribute. |
true | The new value was within valid range, the otptValMin attribute change was made. |
false | The new value was outside valid range, the change was not made. |
bool SldrDALtchMPBttn::setSldrDirDn | ( | ) |
Sets the value of the curSldrDirUp attribute to false.
The curSldrDirUp attribute dictates how the calculated output value change -resulting from the time lapse between checks, the otptSldrSpd and the otptSldrStpSize attributes- will be applied to the otptCurVal attribute.
true | The change of direction was successful |
true | The change of direction failed as the otptCurVal was equal to the extreme value |
bool SldrDALtchMPBttn::setSldrDirUp | ( | ) |
Sets the value of the curSldrDirUp attribute to true.
The curSldrDirUp attribute dictates how the calculated output value change -resulting from the time lapse between checks, the otptSldrSpd and the otptSldrStpSize attributes- will be applied to the otptCurVal attribute.
true | The change of direction was successful |
true | The change of direction failed as the otptCurVal was equal to the extreme value |
void SldrDALtchMPBttn::setSwpDirOnEnd | ( | const bool & | newVal | ) |
Sets the value of the "Auto-Swap Direction on Ends" (autoSwpDirOnEnd) attribute.
The autoSwpDirOnEnd is one of the attributes that configures the slider behavior, setting what the MPB must do when reaching one of the output values range limits. If a limit -otptValMin or otptValMax- is reached while the MPBttn is kept pressed and in secondary mode, the otptCurVal register increment/decrement can be stopped until a change of direction is invoked through setSldrDirUp(), setSldrDirDn() or swpSldrDir() methods, or automatically through the "Auto-Swap Direction on Ends" (autoSwpDirOnEnd) and the "Swap Direction on MPB press" (autoSwpDirOnPrss). If the autoSwpDirOnEnd attribute is set (true) the increment direction of the otptCurVal will be automatically inverted when it reaches otptValMax or otptValMin. If it's not set the otptCurVal will not change value until one of the described alternative methods is invoked, or the MPB is released and pushed back if the autoSwpDirOnPrss is set -see setSwpDirOnPrss(const bool).
newVal | The new value for the autoSwpDirOnEnd attribute |
void SldrDALtchMPBttn::setSwpDirOnPrss | ( | const bool & | newVal | ) |
Sets the value of the "Auto-Swap Direction On Press" (autoSwpDirOnPrss) attribute.
The autoSwpDirOnPrss is one of the attributes that configures the slider behavior, setting what the MPB must do when the MPB object enters in secondary mode, referring to the increment or decrement directions. If the autoSwpDirOnPrss attribute is set (true) the increment direction of the otptCurVal will be automatically inverted every time the MPB is pressed back into secondary mode. If the otptCurVal was incrementing when the MPB was last released. the otptCurVal will start decrementing the next time is pressed to enter secondary mode, and vice versa. If it's not set the otptCurVal will not change direction until it reaches one the limit values, or until one of the described alternative methods is invoked, or the MPB's autoSwpDirOnEnd attribute is set -see setSwpDirOnEnd(const bool) for more details.
newVal | The new value for the autoSwpDirOnPrss attribute |
bool SldrDALtchMPBttn::swapSldrDir | ( | ) |
Inverts the current curSldrDirUp attribute value.
Whatever the previous value of the curSldrDirUp flag, the method invocation inverts it's value, and as a consequence the inverts the direction of the otptCurVal update. If it was incrementing it will start decrementing, and vice versa, considering all the other factors, attributes and attribute flags involved in the embedded object behavior (minimum and maximum settings, the direction changes if pressed, reaches limits, etc.)