DUDS
Distributed Update of Data from Something
duds::hardware::interface::DigitalPinSet Class Reference

Represents a set of pins on a single DigitalPort. More...

#include <DigitalPinSet.hpp>

Inheritance diagram for duds::hardware::interface::DigitalPinSet:
Collaboration diagram for duds::hardware::interface::DigitalPinSet:

Public Member Functions

 DigitalPinSet ()=default
 Constructs DigitalPinSet object with nothing to represent. More...
 
 DigitalPinSet (const std::shared_ptr< DigitalPort > &port, const std::vector< unsigned int > &pvec)
 Constructs a DigitalPinSet object with the given port and pins. More...
 
 DigitalPinSet (const std::shared_ptr< DigitalPort > &port, std::vector< unsigned int > &&pvec)
 Constructs a DigitalPinSet object with the given port and pins. More...
 
std::unique_ptr< DigitalPinSetAccessaccess () const
 Obtains an access object for all the pins in this set. More...
 
void access (DigitalPinSetAccess &acc) const
 Obtains an access object for all the pins in this set. More...
 
bool canBeInput (unsigned int pos) const
 Returns true if the pin can operate as an input. More...
 
bool canBeOutput (unsigned int pos) const
 Returns true if the pin can operate as an output. More...
 
bool canFloat (unsigned int pos) const
 Returns true if the pin can provide a non-input high impedence state (or maybe allow input state?). More...
 
DigitalPinCap capabilities (unsigned int pos) const
 Returns the capabilities of the specified pin. More...
 
std::vector< DigitalPinCapcapabilities () const
 Returns the capabilities of all the pins in this set. More...
 
DigitalPinConfig configuration (unsigned int pos) const
 Returns the current configuration of the specified pin. More...
 
std::vector< DigitalPinConfigconfiguration () const
 Returns the current configuration all pins in this set. More...
 
bool exists (unsigned int pos) const
 Returns true if the given position is for an existent pin rather than a gap or a position past the end. More...
 
unsigned int globalId (unsigned int pos) const
 Returns the global pin ID of the pin at the given position inside this set of pins. More...
 
const std::vector< unsigned int > & globalIds () const
 Provides access to the internal vector of global pin IDs. More...
 
bool havePins () const
 Returns true if this object has been given any pins to represent. More...
 
bool independentConfig () const
 Returns true if all pins on the port always have an independent configuration from all other pins. More...
 
unsigned int localId (unsigned int pos) const
 Returns the local pin ID of the pin at the given position inside this set of pins. More...
 
std::vector< unsigned int > localIds () const
 Returns a vector of port-local pin IDs for the pins represented by this object. More...
 
DigitalPinRejectedConfiguration::Reason proposeConfig (unsigned int pos, DigitalPinConfig &conf) const
 Propose a new configuration for the given pin using the current configuration as the initial configuration. More...
 
DigitalPinRejectedConfiguration::Reason proposeConfig (unsigned int pos, DigitalPinConfig &proposed, DigitalPinConfig &initial) const
 Propose a new configuration for the given pin using a hypothetical given initial configuration. More...
 
bool proposeConfig (std::vector< DigitalPinConfig > &propConf, std::vector< DigitalPinConfig > &initConf, std::function< void(DigitalPinRejectedConfiguration::Reason)> insertReason=std::function< void(DigitalPinRejectedConfiguration::Reason)>())
 Propose a new configuration for the entire pin set using a hypothetical given initial configuration. More...
 
bool simultaneousOperations () const
 True if the port supports operating on multiple pins simultaneously. More...
 
unsigned int size () const
 Returns the number of pins in this object. More...
 
- Public Member Functions inherited from duds::hardware::interface::DigitalPinBase
const std::shared_ptr< DigitalPort > & port () const
 Returns the port that grants access to the pin(s) referenced by this object. More...
 
void reset ()
 Resets the shared pointer to the DigitalPort so that this object no longer represents a pin. More...
 

Private Attributes

std::vector< unsigned int > pinvec
 The port global pin IDs this object will represent. More...
 

Additional Inherited Members

- Protected Member Functions inherited from duds::hardware::interface::DigitalPinBase
 DigitalPinBase ()=default
 Cannot be constructed using this base class, but allows the construction of a useless object without a DigitalPort. More...
 
 DigitalPinBase (const std::shared_ptr< DigitalPort > &port)
 Initializes the port. More...
 
 ~DigitalPinBase ()=default
 Cannot be destructed using this base class to avoid the need for a virtual destructor. More...
 

Detailed Description

Represents a set of pins on a single DigitalPort.

Author
Jeff Jackowski
Examples:
bppmenu.cpp, clockLCD.cpp, rendertext.cpp, st7920.cpp, and textdisplay.cpp.

Definition at line 22 of file DigitalPinSet.hpp.

Constructor & Destructor Documentation

◆ DigitalPinSet() [1/3]

duds::hardware::interface::DigitalPinSet::DigitalPinSet ( )
default

Constructs DigitalPinSet object with nothing to represent.

◆ DigitalPinSet() [2/3]

duds::hardware::interface::DigitalPinSet::DigitalPinSet ( const std::shared_ptr< DigitalPort > &  port,
const std::vector< unsigned int > &  pvec 
)

Constructs a DigitalPinSet object with the given port and pins.

Parameters
portA shared pointer to the DigitalPort object that handles the pins.
pvecA vector with the global pin IDs for all the pins to represent. A value of -1 represents a gap, the lack of a pin at the corresponding position. The only value that may be repeated is -1.
Exceptions
PinDoesNotExistA given pin does not exist in the given port.
DigitalPortDoesNotExistError

Definition at line 14 of file DigitalPinSet.cpp.

◆ DigitalPinSet() [3/3]

duds::hardware::interface::DigitalPinSet::DigitalPinSet ( const std::shared_ptr< DigitalPort > &  port,
std::vector< unsigned int > &&  pvec 
)

Constructs a DigitalPinSet object with the given port and pins.

Parameters
portA shared pointer to the DigitalPort object that handles the pins.
pvecA vector with the global pin IDs for all the pins to represent. A value of -1 represents a gap, the lack of a pin at the corresponding position. The only value that may be repeated is -1. The value is moved to an internal vector. If an exception is thrown, the value is moved back.
Exceptions
PinDoesNotExistA given pin does not exist in the given port.
DigitalPortDoesNotExistError

Definition at line 34 of file DigitalPinSet.cpp.

Member Function Documentation

◆ access() [1/2]

std::unique_ptr<DigitalPinSetAccess> duds::hardware::interface::DigitalPinSet::access ( ) const
inline

Obtains an access object for all the pins in this set.

Returns
The access object inside a unique_ptr.

Definition at line 70 of file DigitalPinSet.hpp.

Referenced by duds::hardware::devices::displays::HD44780::preparePins(), and duds::hardware::devices::displays::ST7920::preparePins().

◆ access() [2/2]

void duds::hardware::interface::DigitalPinSet::access ( DigitalPinSetAccess acc) const
inline

Obtains an access object for all the pins in this set.

Parameters
accThe access object that will be given control over the pins. If it already grants access to pins, it will relinquish that access first.

Definition at line 79 of file DigitalPinSet.hpp.

◆ canBeInput()

bool duds::hardware::interface::DigitalPinSet::canBeInput ( unsigned int  pos) const
inline

Returns true if the pin can operate as an input.

Parameters
posThe position of the pin in this set.

Definition at line 271 of file DigitalPinSet.hpp.

◆ canBeOutput()

bool duds::hardware::interface::DigitalPinSet::canBeOutput ( unsigned int  pos) const
inline

Returns true if the pin can operate as an output.

Parameters
posThe position of the pin in this set.

Definition at line 278 of file DigitalPinSet.hpp.

◆ canFloat()

bool duds::hardware::interface::DigitalPinSet::canFloat ( unsigned int  pos) const
inline

Returns true if the pin can provide a non-input high impedence state (or maybe allow input state?).

Parameters
posThe position of the pin in this set.

Definition at line 286 of file DigitalPinSet.hpp.

◆ capabilities() [1/2]

DigitalPinCap duds::hardware::interface::DigitalPinSet::capabilities ( unsigned int  pos) const
inline

Returns the capabilities of the specified pin.

Parameters
posThe position of the pin in this set.

Definition at line 139 of file DigitalPinSet.hpp.

Referenced by duds::hardware::interface::DigitalPinMasterSyncSerial::checkPins().

◆ capabilities() [2/2]

std::vector<DigitalPinCap> duds::hardware::interface::DigitalPinSet::capabilities ( ) const
inline

Returns the capabilities of all the pins in this set.

Any gaps in the set (ID is -1) will have a value of DigitalPinCap::Nonexistent.

Definition at line 147 of file DigitalPinSet.hpp.

Referenced by canBeInput(), canBeOutput(), and canFloat().

◆ configuration() [1/2]

DigitalPinConfig duds::hardware::interface::DigitalPinSet::configuration ( unsigned int  pos) const
inline

Returns the current configuration of the specified pin.

Parameters
posThe position of the pin in this set.
Warning
While the configuration will be correct for the time of the query inside the DigitalPort::configuration() function, it may change after that, even by the time this function returns, if the configuration is altered on another thread. The only way to ensure the configuration doesn't change this way is to either not use more than one thread with the port, or query from an access object for the pin. For this reason, convenience functions for querying the current configuration are omitted from this class.

Definition at line 163 of file DigitalPinSet.hpp.

◆ configuration() [2/2]

std::vector<DigitalPinConfig> duds::hardware::interface::DigitalPinSet::configuration ( ) const
inline

Returns the current configuration all pins in this set.

Any gaps in the set (ID is -1) will have a configuration of DigitalPinConfig::OperationNoChange.

Warning
While the configuration will be correct for the time of the query inside the DigitalPort::configuration() function, it may change after that, even by the time this function returns, if the configuration is altered on another thread. The only way to ensure the configuration doesn't change this way is to either not use more than one thread with the port, or query from an access object for the set of pins. For this reason, convenience functions for querying the current configuration are omitted from this class.

Definition at line 180 of file DigitalPinSet.hpp.

◆ exists()

bool duds::hardware::interface::DigitalPinSet::exists ( unsigned int  pos) const
inline

Returns true if the given position is for an existent pin rather than a gap or a position past the end.

Parameters
posThe position to check.

Definition at line 107 of file DigitalPinSet.hpp.

◆ globalId()

unsigned int duds::hardware::interface::DigitalPinSet::globalId ( unsigned int  pos) const
inline

Returns the global pin ID of the pin at the given position inside this set of pins.

Parameters
posThe position of the pin in this set.

Definition at line 131 of file DigitalPinSet.hpp.

Referenced by duds::hardware::interface::DigitalPinMasterSyncSerial::checkPins().

◆ globalIds()

const std::vector<unsigned int>& duds::hardware::interface::DigitalPinSet::globalIds ( ) const
inline

Provides access to the internal vector of global pin IDs.

Definition at line 86 of file DigitalPinSet.hpp.

◆ havePins()

bool duds::hardware::interface::DigitalPinSet::havePins ( ) const
inline

◆ independentConfig()

bool duds::hardware::interface::DigitalPinSet::independentConfig ( ) const
inline

Returns true if all pins on the port always have an independent configuration from all other pins.

Definition at line 264 of file DigitalPinSet.hpp.

◆ localId()

unsigned int duds::hardware::interface::DigitalPinSet::localId ( unsigned int  pos) const
inline

Returns the local pin ID of the pin at the given position inside this set of pins.

Parameters
posThe position of the pin in this set.

Definition at line 122 of file DigitalPinSet.hpp.

◆ localIds()

std::vector<unsigned int> duds::hardware::interface::DigitalPinSet::localIds ( ) const
inline

Returns a vector of port-local pin IDs for the pins represented by this object.

Definition at line 93 of file DigitalPinSet.hpp.

◆ proposeConfig() [1/3]

DigitalPinRejectedConfiguration::Reason duds::hardware::interface::DigitalPinSet::proposeConfig ( unsigned int  pos,
DigitalPinConfig conf 
) const
inline

Propose a new configuration for the given pin using the current configuration as the initial configuration.

The pin's configuration is not changed; this only checks for a valid supported change.

Parameters
confThe proposed configuration.
posThe position of the pin in this set.
Returns
The reason the configuration is bad, or DigitalPinRejectedConfiguration::NotRejected if it can be used.

Definition at line 193 of file DigitalPinSet.hpp.

◆ proposeConfig() [2/3]

DigitalPinRejectedConfiguration::Reason duds::hardware::interface::DigitalPinSet::proposeConfig ( unsigned int  pos,
DigitalPinConfig proposed,
DigitalPinConfig initial 
) const
inline

Propose a new configuration for the given pin using a hypothetical given initial configuration.

The pin's configuration is not changed; this only checks for a valid supported change.

Parameters
proposedThe proposed configuration.
initialThe initial configuration. It should be a valid configuration for the pin and port, but it doesn't need to be the current configuration.
posThe position of the pin in this set.
Returns
The reason the configuration is bad, or DigitalPinRejectedConfiguration::NotRejected if it can be used.

Definition at line 212 of file DigitalPinSet.hpp.

◆ proposeConfig() [3/3]

bool duds::hardware::interface::DigitalPinSet::proposeConfig ( std::vector< DigitalPinConfig > &  propConf,
std::vector< DigitalPinConfig > &  initConf,
std::function< void(DigitalPinRejectedConfiguration::Reason)>  insertReason = std::function<void(DigitalPinRejectedConfiguration::Reason)>() 
)
inline

Propose a new configuration for the entire pin set using a hypothetical given initial configuration.

The configuration is not changed; this only checks for a valid supported change.

Parameters
propConfThe proposed configuration.
initConfThe initial configuration. It should be a valid configuration for the pins and port, but it doesn't need to be the current configuration.
insertReasonA function that, if specified, will be called for each pin, in the order specified by this set, with the rejection reason for that pin. The reason will be DigitalPinRejectedConfiguration::NotRejected if the pin's proposed configuration is good. The function is optional.
Returns
True if the proposed configuration is good. False if there was any rejection.

Definition at line 236 of file DigitalPinSet.hpp.

◆ simultaneousOperations()

bool duds::hardware::interface::DigitalPinSet::simultaneousOperations ( ) const
inline

True if the port supports operating on multiple pins simultaneously.

If false, the pins may be modified on over a period of time in an implementation defined order.

Definition at line 257 of file DigitalPinSet.hpp.

◆ size()

unsigned int duds::hardware::interface::DigitalPinSet::size ( ) const
inline

Returns the number of pins in this object.

The count includes pins set as -1; gaps in the pins to access.

Definition at line 114 of file DigitalPinSet.hpp.

Referenced by duds::hardware::interface::DigitalPinMasterSyncSerial::checkPins().

Member Data Documentation

◆ pinvec

std::vector<unsigned int> duds::hardware::interface::DigitalPinSet::pinvec
private

The port global pin IDs this object will represent.

Definition at line 26 of file DigitalPinSet.hpp.

Referenced by DigitalPinSet(), and globalIds().


The documentation for this class was generated from the following files: