| ButtonToSwitch Library for Arduino v4.0.1 A library that provides elaborated switch mechanism behavior simulation for digital signals inputs

Loading...
Searching...
No Matches
Public Member Functions | List of all members
SldrDALtchMPBttn Class Reference

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

Inheritance diagram for SldrDALtchMPBttn:
[legend]
Collaboration diagram for SldrDALtchMPBttn:
[legend]

## Public Member Functions
| SldrDALtchMPBttn (const uint8_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.
Public Member Functions inherited from DblActnLtchMPBttn
| DblActnLtchMPBttn (const uint8_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.
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.
Public Member Functions inherited from LtchMPBttn
| LtchMPBttn (const uint8_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.
Public Member Functions inherited from DbncdDlydMPBttn
| DbncdDlydMPBttn ()
| Default constructor.
| DbncdDlydMPBttn (const uint8_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 uint8_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 uint8_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.
Public Member Functions inherited from DbncdMPBttn
| DbncdMPBttn ()
| Default class constructor.
| DbncdMPBttn (const uint8_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.
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.
const unsigned long int | getLstPollTime ()
| Returns the time stamp of the last state update for the object.
const uint32_t | getOtptsSttsPkgd ()
| Returns the relevant attribute flags values for the object state encoded as a 32 bits value.
const bool | getOutputsChange () const
| Returns the value of the outputsChange attribute flag.
const unsigned long int | getPollPeriodMs ()
| Returns the poll period time setting attribute's value.
unsigned long int | getStrtDelay ()
| Returns the current value of strtDelay attribute.
bool | getUpdTmrAttchd ()
| Returns the value of the Attached to the update timer attribute.
bool | init (const uint8_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 (object's state).
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 ()
| Restarts the software timer updating the calculation of the object internal flags.
bool | setDbncTime (const unsigned long int &newDbncTime)
| Sets the debounce process time.
void | setFnWhnTrnOffPtr (void(*newFnWhnTrnOff)())
| Sets the function that will be called to execute every time the object enters the Off State.
void | setFnWhnTrnOnPtr (void(*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.
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).

## Detailed Description

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):

- Incrementing otpCurVal register (by the quantity of steps multiplied by the step size) up to the "maximum value" setting.
- Decrementing otpCurVal register (by that quantity) down to the "minimum value" setting.
- Changing the modification's direction (from incrementing to decrementing or vice versa). The minimum and maximum values, the rate in steps/millisecond, the size of each step and the variation direction (sign of the variation, incrementing or decrementing) are all configurable, as is the starting value and the mechanism to revert the "direction" that includes:
- Revert directions in the next secondary mode entry.
- Automatically revert direction when reaching the minimum and maximum values setting.
- Revert direction by methods invocation (see setSldrDirDn(), setSldrDirUp(), swapSldrDir()).

class SldrDALtchMPBttn

## Constructor & Destructor Documentation

## ◆ SldrDALtchMPBttn()

SldrDALtchMPBttn::SldrDALtchMPBttn | ( | const uint8_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.

Parameters

  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.

Note
  For the remaining parameters see DbncdDlydMPBttn(const uint8_t, const bool, const bool, const unsigned long int, const unsigned long int)

## Member Function Documentation

## ◆ clrStatus()

void SldrDALtchMPBttn::clrStatus | ( | bool | clrIsOn = true | ) |

Note
  See DbncdMPBttn::clrStatus(bool)

Here is the call graph for this function:

## ◆ getOtptCurVal()

uint16_t SldrDALtchMPBttn::getOtptCurVal | ( |  | ) |

Returns the Output Current Value (otpCurVal) attribute.

Returns
  The otpCurVal register value.

## ◆ getOtptCurValIsMax()

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

Returns
  The logical result of the comparison

Return values

  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.

## ◆ getOtptCurValIsMin()

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

Returns
  The logical result of the comparison

Return values

  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.

## ◆ getOtptSldrSpd()

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.

Returns
  The outputSliderSpeed attribute value.

Note
  At instantiation the outputSliderSpeed is configured to 1 step/millisecond.

## ◆ getOtptSldrStpSize()

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.

Returns
  The outputSliderStepSize attribute value.

Note
  At instantiation the outputSliderStepSize is configured to 1 counts/step.

## ◆ getOtptValMax()

uint16_t SldrDALtchMPBttn::getOtptValMax | ( |  | ) |

Returns the top output current value register setting.

Returns
  The maximum output current value set.

## ◆ getOtptValMin()

uint16_t SldrDALtchMPBttn::getOtptValMin | ( |  | ) |

Returns the bottom output current value register setting.

Returns
  The minimum output current value set.

## ◆ getSldrDirUp()

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.

Returns
  The current slider direction value

Return values

  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.

## ◆ setOtptCurVal()

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

Parameters

  newVal | The new value for the output current value register.

Returns
  The success in the value change

Return values

  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.

## ◆ setOtptSldrSpd()

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.

Parameters

  newVal | The new value for the otptSldrSpd attribute.

Returns
  The success in the value of the attribute

Return values

  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.

Note
  Making the otptSldrSpd equal to 0 would void the ability to change the slider value, so the range of acceptable values is 1<= newVal <= (2^16-1).

Warning
  A "wrong" combination of otptSldrSpd and otptSldrStpSize might result in value change between readings greater than the range set by the otptValMin and the otptValMax values. The relation between the four parameters must be kept in mind if the application developed gives the final user the capability to configure those values at runtime.

## ◆ setOtptSldrStpSize()

bool SldrDALtchMPBttn::setOtptSldrStpSize | ( | const uint16_t & | newVal | ) |

Sets the output slider step size (otptSldrStpSize) attribute value.

Parameters

  newVal | The new value for the outputSliderStepSize attribute.

Note
  The new value for the step size must be smaller or equal than the size of the valid range of otptCurVal attribute

Return values

  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.

Note
  For the secondary function to work like a slider, the condition (newVal < ((_otptValMax - _otptValMin) / _otptSldrSpd)) must be kept
  For the secondary function to work like a slider or a toggle switch, the condition (newVal <= ((_otptValMax - _otptValMin) / _otptSldrSpd)) must be kept
  For the secondary function to work like a toggle switch, the condition (newVal = ((_otptValMax - _otptValMin) / _otptSldrSpd)) must be kept.

Warning
  As a consequence of the aforementioned notes, if both otptSldrStpSize and otptSldrSpd are being changed, the otptSldrSpd must be changed first to ensure the new otptSldrStpSize doesn't fail the range validation test included in this method.

## ◆ setOtptValMax()

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

Parameters

  newVal | The new value for the otptValMax attribute.

Returns
  The success in the value change

Return values

  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.

Note
  Due to type constrains, the failure in the value change must be consequence of the selected newVal <= otptValMin

Warning
  If the otpValMax attribute intended change is to a smaller value, the otpCurVal might be left outside the new valid range (newVal < otpCurVal). In this case the otptCurVal will be changed to be equal to newVal, and so otptCurVal will become equal to otptValMax.

Here is the call graph for this function:

## ◆ setOtptValMin()

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.

Parameters

  newVal | The new value for the otptValMin attribute.

Returns
  The success in the value change

Return values

  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.

Note
  Due to type constrains, the failure in the value change must be consequence of the selected newVal >= otptValMax

Warning
  If the otptValMin attribute intended change is to a greater value, the otptCurVal might be left outside the new valid range (newVal > otptCurVal). In this case the otptCurVal will be changed to be equal to newVal, and so otptCurVal will become equal to otptValMin.

Here is the call graph for this function:

## ◆ setSldrDirDn()

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.

- If curSldrDirUp = false, the output value change will be subtracted from otptCurVal, successively down to otptValMin.

Note
  If the method intends to set the curSldrDirUp to false when the otptCurVal = otptValMin the method will fail, returning false as result.

Returns
  The success in changing the slider direction

Return values

  true | The change of direction was successful
  true | The change of direction failed as the otptCurVal was equal to the extreme value

## ◆ setSldrDirUp()

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.

- If curSldrDirUp = true, the output value change will be added to otptCurVal, up to otptValMax.

Note
  If the method intends to set curSldrDirUp to true when the otptCurVal = otptValMax the method will fail, returning false as result.

Returns
  The success in changing the slider direction

Return values

  true | The change of direction was successful
  true | The change of direction failed as the otptCurVal was equal to the extreme value

## ◆ setSwpDirOnEnd()

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

Parameters

  newVal | The new value for the autoSwpDirOnEnd attribute

## ◆ setSwpDirOnPrss()

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.

Parameters

  newVal | The new value for the autoSwpDirOnPrss attribute

## ◆ swapSldrDir()

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

Returns
  The new value of the curSldrDirUp attribute.