IoAbstraction
Public Member Functions | List of all members
MockedIoAbstraction Class Reference

#include <MockIoAbstraction.h>

Inheritance diagram for MockedIoAbstraction:
BasicIoAbstraction

Public Member Functions

 MockedIoAbstraction (int numberOfCycles=6)
 
void resetIo ()
 
void pinDirection (pinid_t pin, uint8_t mode) override
 
void writeValue (pinid_t pin, uint8_t value) override
 
uint8_t readValue (pinid_t pin) override
 
void attachInterrupt (pinid_t pin, RawIntHandler interruptHandler, uint8_t mode) override
 
bool runLoop () override
 
void writePort (pinid_t pin, uint8_t portVal) override
 
virtual uint8_t readPort (pinid_t pin)
 
int getNumberOfRunLoops ()
 
uint16_t getWrittenValuesForRunLoop (int runLoop)
 
void setValueForReading (int runLoopNo, uint16_t val)
 
uint16_t getWrittenValue (int runLoopNo)
 
MockIoError getErrorMode ()
 
void clearError ()
 
RawIntHandler getInterruptFunction ()
 
bool isIntRegisteredAs (uint8_t pin, uint8_t mode)
 
- Public Member Functions inherited from BasicIoAbstraction
uint8_t digitalRead (pinid_t p)
 
void digitalWrite (pinid_t p, uint8_t v)
 
uint8_t digitalReadS (pinid_t p)
 
void digitalWriteS (pinid_t p, uint8_t v)
 
void writePortS (pinid_t p, uint8_t v)
 
uint8_t readPortS (pinid_t p)
 
void pinMode (pinid_t pin, uint8_t mode)
 
bool sync ()
 

Detailed Description

This class implements the IoAbstraction interface but does not do anything other than record the pinMode and write calls, it also allows the read values to be set upfront. There are up to 16 pins in this abstraction and each run loop cycles to another buffer. In the constructor you can set the number of storage slots (the point they will cycle back to slot 0).

It is very useful when trying to work with IoAbstraction in unit tests.

Member Function Documentation

◆ resetIo()

void MockedIoAbstraction::resetIo ( )
inline

Resets this abstraction back to its initial state, ready for the next test.

◆ pinDirection()

void MockedIoAbstraction::pinDirection ( pinid_t  pin,
uint8_t  mode 
)
inlineoverridevirtual

sets the pin direction for a pin controlled by this abstraction - as per pinMode

Parameters
pinthe pin to be changed
modethe new mode, as per pinMode (or on Mbed you can use PinMode enum values)

Reimplemented from BasicIoAbstraction.

◆ writeValue()

void MockedIoAbstraction::writeValue ( pinid_t  pin,
uint8_t  value 
)
inlineoverridevirtual

Writes a value to a pin on this abstraction, as per digitalWrite. For serial devices, may need a sync first.

Parameters
pinthe pin to be written to
valuethe new value such as HIGH / LOW

Reimplemented from BasicIoAbstraction.

◆ readValue()

uint8_t MockedIoAbstraction::readValue ( pinid_t  pin)
inlineoverridevirtual

Reads a value from a pin for this abstraction as per digitalRead. For serial devices may need a sync first.

Parameters
pinthe pin to be read

Reimplemented from BasicIoAbstraction.

◆ attachInterrupt()

void MockedIoAbstraction::attachInterrupt ( pinid_t  pin,
RawIntHandler  interruptHandler,
uint8_t  mode 
)
inlineoverridevirtual

Overrides the usual interrupt handler to just record the details of the interrupt requested

Reimplemented from BasicIoAbstraction.

◆ runLoop()

bool MockedIoAbstraction::runLoop ( )
inlineoverridevirtual

This method is not needed on Arduino pins, but for most serial implementations it causes the device and abstraction to be synced. Returns true if the write call worked, normally true, false indicates error

Reimplemented from BasicIoAbstraction.

◆ writePort()

void MockedIoAbstraction::writePort ( pinid_t  pin,
uint8_t  portVal 
)
inlineoverridevirtual

Writes out a whole port at once, on Arduino pins this is achieved by providing any pin within that port. On Arduino pins you should take care not to use ports that are providing core functions.

Parameters
pinthe pin determines the hardware port to use.
portValthe 8 bit value to write to the port. Use with care.

Reimplemented from BasicIoAbstraction.

◆ readPort()

virtual uint8_t MockedIoAbstraction::readPort ( pinid_t  pin)
inlinevirtual

Reads a whole port at once, on Arduino pins this is achieved by providing any pin within that port. On Arduino pins you should take care not to use ports that are providing core functions.

Parameters
pinthe pin determines the hardware port to use.
Returns
the 8 bit value read from the port.

Reimplemented from BasicIoAbstraction.

◆ getNumberOfRunLoops()

int MockedIoAbstraction::getNumberOfRunLoops ( )
inline

get the number of run loops that have been performed

◆ getWrittenValuesForRunLoop()

uint16_t MockedIoAbstraction::getWrittenValuesForRunLoop ( int  runLoop)
inline

get the data that's been written in a given run loop

◆ setValueForReading()

void MockedIoAbstraction::setValueForReading ( int  runLoopNo,
uint16_t  val 
)
inline

set the value that will be used to return during read functions

◆ getWrittenValue()

uint16_t MockedIoAbstraction::getWrittenValue ( int  runLoopNo)
inline

get the value that was written using the write functions

◆ getErrorMode()

MockIoError MockedIoAbstraction::getErrorMode ( )
inline

get any error in usage of the class

◆ clearError()

void MockedIoAbstraction::clearError ( )
inline

clear down the error state

◆ getInterruptFunction()

RawIntHandler MockedIoAbstraction::getInterruptFunction ( )
inline

get the interrupt function registered using the attachInterrupt call

◆ isIntRegisteredAs()

bool MockedIoAbstraction::isIntRegisteredAs ( uint8_t  pin,
uint8_t  mode 
)
inline

check if the registered interrupt pin and mode are right


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