DUDS
Distributed Update of Data from Something
duds::hardware::interface::linux::SysFsPort::FsPin Class Reference
Collaboration diagram for duds::hardware::interface::linux::SysFsPort::FsPin:

Public Member Functions

void open (DigitalPinConfig &conf, DigitalPinCap &cap, unsigned int pin)
 Opens the value and direction files for the pin. More...
 
bool read ()
 Reads from the value file of the pin and returns the result. More...
 
void setDirection (bool output)
 Changes the pin's direction between input and output. More...
 
void write (bool state)
 Changes the output value of the pin. More...
 

Private Attributes

bool curoutval
 The current output value for the pin. More...
 
std::fstream direction
 The file used to control the I/O direction of the pin. More...
 
unsigned int fsid
 The GPIO's ID number from the filesystem. More...
 
bool isoutput
 True when the pin is configured as an output. More...
 
bool reqoutval
 The requested output value for the pin. More...
 
std::fstream value
 The file used to query the pin's input state and change the pins output state. More...
 

Detailed Description

Definition at line 46 of file SysFsPort.hpp.

Member Function Documentation

◆ open()

void duds::hardware::interface::linux::SysFsPort::FsPin::open ( DigitalPinConfig conf,
DigitalPinCap cap,
unsigned int  pin 
)

Opens the value and direction files for the pin.

Precondition
open() was not previously called (it is called by SysFsGpio(unsigned int) ), or failed with an exception in all previous calls.
Postcondition
The provided capabilities and configuration objects will be changed to best match what is known about the pins and available file access.
Parameters
confThe configuration to change based on the state of the pin.
capThe capabilities to change based on file access.
pinThe number used by the kernel to identify the pin.
Exceptions
PinIoErrorThe pin's value or direction file cannot be opened, or the data read from the direction file is neither "in" nor "out".
PinUnsupportedOperationThe pin has read-only value and direction files with the direction set to output.
Todo:
Flag events and interrupts when support is added.

Definition at line 116 of file SysFsPort.cpp.

◆ read()

bool duds::hardware::interface::linux::SysFsPort::FsPin::read ( )

Reads from the value file of the pin and returns the result.

Definition at line 226 of file SysFsPort.cpp.

◆ setDirection()

void duds::hardware::interface::linux::SysFsPort::FsPin::setDirection ( bool  output)

Changes the pin's direction between input and output.

The direction file is only written if the pin's direction changes. Some testing suggests that the pin's output state may strobe when the direction or value file is written with the same value that should already be there. This issue may not exist with all hardware, and the checks should prevent trouble when it does exist as long as other processes on the host are not also modifying the pin.

Parameters
outputTrue to make the pin an output, false for input.

Definition at line 204 of file SysFsPort.cpp.

◆ write()

void duds::hardware::interface::linux::SysFsPort::FsPin::write ( bool  state)

Changes the output value of the pin.

If the pin is not an output, the requested value is stored and will be set later by setDirection() when the pin changes to an output. Ensuring a particular output state before beginning to output is not supported by the filesystem interface.

The output state is only written to the value file if it changed. Some testing suggests that the pin's output state may strobe when the value or direction file is written with the same value that should already be there. This issue may not exist with all hardware, and the checks should prevent trouble when it does exist as long as other processes on the host are not also modifying the pin.

Parameters
stateThe output state, true for high.

Definition at line 238 of file SysFsPort.cpp.

Member Data Documentation

◆ curoutval

bool duds::hardware::interface::linux::SysFsPort::FsPin::curoutval
private

The current output value for the pin.

This is meaningless when the pin is an input. When it is an output, this value is used to avoid writting state changes to the already current state to the value file.

Definition at line 76 of file SysFsPort.hpp.

◆ direction

std::fstream duds::hardware::interface::linux::SysFsPort::FsPin::direction
private

The file used to control the I/O direction of the pin.

If the file cannot be opened for reading and writing, it will be opened for reading only long enough to record the direction.

Definition at line 52 of file SysFsPort.hpp.

◆ fsid

unsigned int duds::hardware::interface::linux::SysFsPort::FsPin::fsid
private

The GPIO's ID number from the filesystem.

This may be different from the local and global IDs used by the port object.

Definition at line 62 of file SysFsPort.hpp.

◆ isoutput

bool duds::hardware::interface::linux::SysFsPort::FsPin::isoutput
private

True when the pin is configured as an output.

This is easier, and possibly a little faster, to check than inspecting the pin configuration inside DigitalPort::PinEntry::conf, and it doesn't make this data structure any larger.

Definition at line 83 of file SysFsPort.hpp.

◆ reqoutval

bool duds::hardware::interface::linux::SysFsPort::FsPin::reqoutval
private

The requested output value for the pin.

This may be changed while the pin is an input so that when it is changed to an output this software can quickly change the state to the requested value. This seems to be the best possible implementation with the filesystem interface.

Definition at line 69 of file SysFsPort.hpp.

◆ value

std::fstream duds::hardware::interface::linux::SysFsPort::FsPin::value
private

The file used to query the pin's input state and change the pins output state.

Definition at line 57 of file SysFsPort.hpp.


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