SpaIot Library
SpaIot::Multiplexer

Analog multiplexer for buttons. More...

Inheritance diagram for SpaIot::Multiplexer:

Public Types

enum  {
  A = 0 , B , C , D ,
  E , F , G , H
}
 

Public Member Functions

 Multiplexer (const std::initializer_list< int > &spins, int inhPin)
 Constructor. More...
 
 Multiplexer (const String &name, const std::initializer_list< int > &spins, int inhPin)
 Constructor with name. More...
 
 Multiplexer ()
 Default constructor. More...
 
 Multiplexer (const Multiplexer &other)
 Copy Constructor. (const ButtonController &other) More...
 
Multiplexeroperator= (const Multiplexer &other)
 Assignment operator. (const ButtonController &other) More...
 
 Multiplexer (Multiplexer &&other)
 Copy Constructor. (ButtonController &&other) More...
 
Multiplexeroperator= (Multiplexer &&other)
 Assignment operator. (const ButtonController &&other) More...
 
int selectPin (int order) const
 Given a order, return the corresponding value. More...
 
void setSelectPin (int order, int pin)
 It sets the pin number for the select pin of the given order. More...
 
int inhPin () const
 Get the pin number of the inhibit pin.
 
void setInhPin (int pin)
 Set the pin number of the inhibit pin.
 
int size () const
 Returns the number of multiplexer channels that are available. More...
 
virtual void clear ()
 Sets all attributes to their default values (same as the default constructor)
 
virtual bool isEmpty () const
 Checks if all attributes are set to their default values (same as the default constructor)
 
virtual bool operator== (const ButtonController &other) const
 Returns true if the two objects are equal.
 
virtual void begin ()
 Configures all ressources needed to use the object.
 
virtual void end ()
 Releases all ressources used by the object.
 
virtual int select (int button)
 Selects a button. More...
 
virtual void deselect ()
 Deselects the button After the call to this function, isSelected() must return false, and selected() must return -1.
 
bool isNull () const
 Returns true if the object is null (i.e. it has not been initialized, d_ptr is null)
 
virtual bool operator!= (const ButtonController &other) const
 Returns true if the two objects are not equal.
 
virtual int selected () const
 Returns the button number that is selected, or -1 if no button is selected.
 
virtual bool isOpen () const
 Returns true if begin() has been successfully called.
 
virtual bool isSelected () const
 Returns true if a button is selected.
 
virtual const String & name () const
 Returns the name of the ButtonController object if it has been set, otherwise it returns an empty string.
 

Static Public Member Functions

static bool addToRegister (const String &name, ButtonController &controller)
 Adds a ButtonController object to the register. More...
 
static ButtonControllergetFromRegister (const String &name)
 Returns a ButtonController object from the register. More...
 
static bool registerContains (const String &name)
 Returns true if the register contains a ButtonController object with the given name. More...
 

Detailed Description

Analog multiplexer for buttons.

This class implements a multiplexer for buttons. It is a concrete class, and can be instantiated. It is a ButtonController, and can be used as such.
This class is copyable and movable.
The multiplexer is controlled by a set of pins that select the channel to be used. The pins are connected to the multiplexer in ascending order of weight: A for the least significant bit, B for the second least significant bit, and so on. The pins are connected to the multiplexer in the following order: A, B, C, D, E, F, G, H. The multiplexer has an inhibit pin that is used to disable the multiplexer. The multiplexer is disabled when the inhibit pin is in high level. That corresponds to integrated circuits like CD4051, CD4052, CD4053, CD4067, etc.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator

The order for the least significant bit

The order for the second least significant bit

The order for the third least significant bit

The order for the fourth least significant bit

The order for the fifth least significant bit

The order for the sixth least significant bit

The order for the seventh least significant bit

The order for the eighth least significant bit

Constructor & Destructor Documentation

◆ Multiplexer() [1/5]

SpaIot::Multiplexer::Multiplexer ( const std::initializer_list< int > &  spins,
int  inhPin 
)

Constructor.

The constructor of Multiplexer takes a list of integers and an integer as input. The list of integers represents the selection pins that are connected to the multiplexer. The integer represents the pin that is connected to the inhibit pin

Parameters
spinsa list of integers that represent the pins that are connected to the multiplexer, in ascending order of weight
inhPinThe pin number of the inhibit pin ((active in high level)

◆ Multiplexer() [2/5]

SpaIot::Multiplexer::Multiplexer ( const String &  name,
const std::initializer_list< int > &  spins,
int  inhPin 
)

Constructor with name.

The constructor of Multiplexer takes a list of integers and an integer as input. The list of integers represents the selection pins that are connected to the multiplexer. The integer represents the pin that is connected to the inhibit pin

Parameters
nameThe name of the multiplexer
spinsa list of integers that represent the pins that are connected to the multiplexer, in ascending order of weight
inhPinThe pin number of the inhibit pin ((active in high level)

◆ Multiplexer() [3/5]

SpaIot::Multiplexer::Multiplexer ( )

Default constructor.

isEmpty() will return true after this constructor, used for copy or move

◆ Multiplexer() [4/5]

SpaIot::Multiplexer::Multiplexer ( const Multiplexer other)

Copy Constructor. (const ButtonController &other)

(const ButtonController &other)

◆ Multiplexer() [5/5]

SpaIot::Multiplexer::Multiplexer ( Multiplexer &&  other)

Copy Constructor. (ButtonController &&other)

(ButtonController &&other)

Member Function Documentation

◆ addToRegister()

static bool SpaIot::ButtonController::addToRegister ( const String &  name,
ButtonController controller 
)
staticinherited

Adds a ButtonController object to the register.

Parameters
nameThe name of the ButtonController object that will be used to retrieve it from the register
controllerThe ButtonController object

◆ getFromRegister()

static ButtonController& SpaIot::ButtonController::getFromRegister ( const String &  name)
staticinherited

Returns a ButtonController object from the register.

The user must call registerContains() before calling this function to check if the register contains a ButtonController object with the given name, otherwise an exception will be thrown std::out_of_range (and if exceptions are not enabled, the program will terminate)

Parameters
nameThe name of the ButtonController object that will be used to retrieve it from the register
Returns
The ButtonController object

◆ operator=() [1/2]

Multiplexer& SpaIot::Multiplexer::operator= ( const Multiplexer other)

Assignment operator. (const ButtonController &other)

(const ButtonController &other)

◆ operator=() [2/2]

Multiplexer& SpaIot::Multiplexer::operator= ( Multiplexer &&  other)

Assignment operator. (const ButtonController &&other)

(const ButtonController &&other)

◆ registerContains()

static bool SpaIot::ButtonController::registerContains ( const String &  name)
staticinherited

Returns true if the register contains a ButtonController object with the given name.

Parameters
nameThe name of the ButtonController object that will be used to retrieve it from the register
Returns
true if the register contains a ButtonController object with the given name

◆ select()

virtual int SpaIot::Multiplexer::select ( int  button)
virtual

Selects a button.

Parameters
buttonthe button to be selected
Returns
the value return by selected()

Implements SpaIot::ButtonController.

◆ selectPin()

int SpaIot::Multiplexer::selectPin ( int  order) const

Given a order, return the corresponding value.

Parameters
orderThe order of the parameter.
Returns
The pin number for the given order.

◆ setSelectPin()

void SpaIot::Multiplexer::setSelectPin ( int  order,
int  pin 
)

It sets the pin number for the select pin of the given order.

Parameters
orderthe order to be used for the pin
pinthe pin number

◆ size()

int SpaIot::Multiplexer::size ( ) const

Returns the number of multiplexer channels that are available.

That is the number of buttons that can be connected to the multiplexer