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

Represents a single pin on a DigitalPort. More...

#include <DigitalPin.hpp>

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

Public Member Functions

 DigitalPin ()=default
 Constructs a DigitalPin object without a port or pin. More...
 
 DigitalPin (const std::shared_ptr< DigitalPort > &port, unsigned int pin)
 Constructs a DigitalPin object with the given port and pin. More...
 
std::unique_ptr< DigitalPinAccessaccess () const
 Obtains an access object to the pin. More...
 
void access (DigitalPinAccess *acc) const
 Obtains an access object to the pin. More...
 
bool canBeInput () const
 Returns true if the pin can operate as an input. More...
 
bool canBeOutput () const
 Returns true if the pin can operate as an output. More...
 
bool canFloat () const
 Returns true if the pin can provide a non-input high impedence state (or maybe allow input state?). More...
 
DigitalPinCap capabilities () const
 Returns the capabilities of the represented pin. More...
 
DigitalPinConfig configuration () const
 Returns the current configuration of the represented pin. More...
 
unsigned int globalId () const
 Returns the global pin ID of the represented pin. More...
 
bool havePin () const
 Returns true if this object has been given a pin to represent. More...
 
unsigned int localId () const
 Returns the local pin ID of the represented pin. More...
 
 operator unsigned int () const
 Returns the global pin ID of the represented pin. More...
 
DigitalPinRejectedConfiguration::Reason proposeConfig (DigitalPinConfig &conf) const
 Propose a new configuration for the represented pin using the current configuration as the initial configuration. More...
 
DigitalPinRejectedConfiguration::Reason proposeConfig (DigitalPinConfig &proposed, DigitalPinConfig &initial) const
 Propose a new configuration for the represented pin using a hypothetical given initial configuration. 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

unsigned int gid
 Global pin ID. 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 single pin on a DigitalPort.

Author
Jeff Jackowski

Definition at line 22 of file DigitalPin.hpp.

Constructor & Destructor Documentation

◆ DigitalPin() [1/2]

duds::hardware::interface::DigitalPin::DigitalPin ( )
default

Constructs a DigitalPin object without a port or pin.

Note
The pin ID will be uninitialized.

◆ DigitalPin() [2/2]

duds::hardware::interface::DigitalPin::DigitalPin ( const std::shared_ptr< DigitalPort > &  port,
unsigned int  pin 
)

Constructs a DigitalPin object with the given port and pin.

Parameters
portA shared pointer to the DigitalPort object that handles the pin.
pinThe global pin ID for the pin to represent.
Exceptions
PinDoesNotExistThe given pin does not exist in the given port.

Definition at line 14 of file DigitalPin.cpp.

Member Function Documentation

◆ access() [1/2]

std::unique_ptr<DigitalPinAccess> duds::hardware::interface::DigitalPin::access ( ) const
inline

Obtains an access object to the pin.

Returns
The access object inside a unique_ptr.

Definition at line 46 of file DigitalPin.hpp.

◆ access() [2/2]

void duds::hardware::interface::DigitalPin::access ( DigitalPinAccess acc) const
inline

Obtains an access object to the pin.

Parameters
accA pointer to where the access object will be constructed. It may be default constructed or uninitialized memory. It must not be an access object that currently grants access to any pin.

Definition at line 56 of file DigitalPin.hpp.

◆ canBeInput()

bool duds::hardware::interface::DigitalPin::canBeInput ( ) const
inline

Returns true if the pin can operate as an input.

Definition at line 142 of file DigitalPin.hpp.

◆ canBeOutput()

bool duds::hardware::interface::DigitalPin::canBeOutput ( ) const
inline

Returns true if the pin can operate as an output.

Definition at line 148 of file DigitalPin.hpp.

◆ canFloat()

bool duds::hardware::interface::DigitalPin::canFloat ( ) const
inline

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

Definition at line 159 of file DigitalPin.hpp.

◆ capabilities()

DigitalPinCap duds::hardware::interface::DigitalPin::capabilities ( ) const
inline

Returns the capabilities of the represented pin.

Definition at line 86 of file DigitalPin.hpp.

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

◆ configuration()

DigitalPinConfig duds::hardware::interface::DigitalPin::configuration ( ) const
inline

Returns the current configuration of the represented pin.

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 101 of file DigitalPin.hpp.

◆ globalId()

unsigned int duds::hardware::interface::DigitalPin::globalId ( ) const
inline

Returns the global pin ID of the represented pin.

Definition at line 74 of file DigitalPin.hpp.

◆ havePin()

bool duds::hardware::interface::DigitalPin::havePin ( ) const
inline

Returns true if this object has been given a pin to represent.

Definition at line 62 of file DigitalPin.hpp.

◆ localId()

unsigned int duds::hardware::interface::DigitalPin::localId ( ) const
inline

Returns the local pin ID of the represented pin.

Definition at line 68 of file DigitalPin.hpp.

◆ operator unsigned int()

duds::hardware::interface::DigitalPin::operator unsigned int ( ) const
inline

Returns the global pin ID of the represented pin.

Definition at line 80 of file DigitalPin.hpp.

◆ proposeConfig() [1/2]

DigitalPinRejectedConfiguration::Reason duds::hardware::interface::DigitalPin::proposeConfig ( DigitalPinConfig conf) const
inline

Propose a new configuration for the represented 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.
Returns
The reason the configuration is bad, or DigitalPinRejectedConfiguration::NotRejected if it can be used.

Definition at line 113 of file DigitalPin.hpp.

◆ proposeConfig() [2/2]

DigitalPinRejectedConfiguration::Reason duds::hardware::interface::DigitalPin::proposeConfig ( DigitalPinConfig proposed,
DigitalPinConfig initial 
) const
inline

Propose a new configuration for the represented 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.
Returns
The reason the configuration is bad, or DigitalPinRejectedConfiguration::NotRejected if it can be used.

Definition at line 130 of file DigitalPin.hpp.

Member Data Documentation

◆ gid

unsigned int duds::hardware::interface::DigitalPin::gid
private

Global pin ID.

Definition at line 26 of file DigitalPin.hpp.

Referenced by DigitalPin(), globalId(), and operator unsigned int().


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