Skip to content

Commit

Permalink
feat: Adds inhPin() and setInhPin()
Browse files Browse the repository at this point in the history
  • Loading branch information
epsilonrt committed Sep 11, 2023
1 parent 068c702 commit af5d859
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 13 deletions.
46 changes: 37 additions & 9 deletions src/multiplexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,29 @@ namespace SpaIot {
@brief 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.
It is a ButtonController, and can be used as such. \n
This class is copyable and movable. \n
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.
*/
class Multiplexer : public ButtonController {
public:

enum {
A = 0, /**< The order for the least significant bit */
B, /**< The order for the second least significant bit */
C, /**< The order for the third least significant bit */
D, /**< The order for the fourth least significant bit */
E, /**< The order for the fifth least significant bit */
F, /**< The order for the sixth least significant bit */
G, /**< The order for the seventh least significant bit */
H /**< The order for the eighth least significant bit */
};

/**
@brief Constructor
Expand Down Expand Up @@ -79,20 +97,30 @@ namespace SpaIot {
Multiplexer &operator= (Multiplexer &&other);

/**
@brief Given a key, return the corresponding value
@brief Given a order, return the corresponding value
@param key The key of the parameter.
@return The pin number for the given key.
@param order The order of the parameter.
@return The pin number for the given order.
*/
int selectPin (int key) const;
int selectPin (int order) const;

/**
@brief It sets the pin number for the select pin of the given key.
@brief It sets the pin number for the select pin of the given order.
@param key the key to be used for the pin
@param order the order to be used for the pin
@param pin the pin number
*/
void setSelectPin (int key, int pin);
void setSelectPin (int order, int pin);

/**
@brief Get the pin number of the inhibit pin
*/
int inhPin() const;

/**
@brief Set the pin number of the inhibit pin
*/
void setInhPin (int pin);

/**
@brief Returns the number of multiplexer channels that are available
Expand Down
22 changes: 18 additions & 4 deletions src/private/multiplexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,33 @@ namespace SpaIot {
}

//----------------------------------------------------------------------------
int Multiplexer::selectPin (int key) const {
int Multiplexer::selectPin (int order) const {
PIMPL_D (const Multiplexer);

return d->spin.at (key);
return d->spin.at (order);
}

//----------------------------------------------------------------------------
void Multiplexer::setSelectPin (int key, int pin) {
void Multiplexer::setSelectPin (int order, int pin) {
PIMPL_D (Multiplexer);

d->spin[key] = pin;
d->spin[order] = pin;
}

//----------------------------------------------------------------------------
int Multiplexer::inhPin() const {
PIMPL_D (const Multiplexer);

return d->inh;
}

//----------------------------------------------------------------------------
void Multiplexer::setInhPin (int pin) {
PIMPL_D (Multiplexer);

d->inh = pin;
}

//----------------------------------------------------------------------------
int Multiplexer::size() const {
PIMPL_D (const Multiplexer);
Expand Down

0 comments on commit af5d859

Please sign in to comment.