Accessories
Arduino for motors and lights library.
Port Class Reference

#include "Port.hpp"

Inheritance diagram for Port:
PortOnePin PortServo PortShieldL293d PortSpeedDirBrake PortStepper PortTwoPins PortTwoPinsEnable

Public Member Functions

 Port ()
 
virtual void begin ()
 
virtual void beginByAccessory (int inStartingPosition)
 
PORT_STATE GetState () const
 
int GetSpeed () const
 
virtual int SetSpeed (int inSpeed)
 
bool IsLeftDir () const
 
bool IsRightDir () const
 
bool IsStopped () const
 
virtual void MoveLeftDir (unsigned long inDuration = 0)
 
virtual void MoveRightDir (unsigned long inDuration = 0)
 
void MoveLeftDir (unsigned long inDuration, int inSpeed)
 
void MoveRightDir (unsigned long inDuration, int inSpeed)
 
PORT_STATE MoveToggle (unsigned long inDuration = 0)
 
virtual void MoveStop ()
 
virtual void MovePosition (unsigned long inDuration, int inEndPosition)
 
virtual int GetPosition ()
 

Protected Member Functions

int MapValue (int inValue, PIN_TYPE inType = UNDEFINED) const
 
int beginPin (int inPin, PIN_TYPE inType = UNDEFINED) const
 
void MovePin (int inPin, int inValue, PIN_TYPE inType = UNDEFINED) const
 

Protected Attributes

PIN_TYPE pinType
 
PORT_STATE state
 
int speed
 

Detailed Description

A port is the way for an accessory to get current for power source. The port gives an interface by pins to allow the power source to distribute or not its current.

A port can drive ANALOG or DIGITAL pins, with an inverted way by using the pull-up resistor of the pins. Internally, an activated pin has always a state of HIGH. The MapValue() function will convert physical states to logical -library- states:

pin type physical state logical/analog state after MapValue
DIGITAL HIGH HIGH
DIGITAL LOW LOW
DIGITAL_INVERTED HIGH LOW
DIGITAL_INVERTED LOW HIGH
ANALOG 255 255
ANALOG 0 0
ANALOG_INVERTED 255 0
ANALOG_INVERTED 0 255

A port have a current state : left, right or stop, and a speed giving the amount of voltage used on the pins.

This is a base class for all kind of ports, DO NOT INSTANCIATE IT !

Definition at line 61 of file Port.hpp.

Constructor & Destructor Documentation

Port::Port ( )

Default constructor.

Definition at line 49 of file Port.cpp.

Member Function Documentation

virtual void Port::begin ( )
inlinevirtual

Initialize the instance.

Definition at line 99 of file Port.hpp.

virtual void Port::beginByAccessory ( int  inStartingPosition)
inlinevirtual

Initialize the instance. Variant with a starting position.

Parameters
inStartingPositionStarting position.
Remarks
The accessory will move to its starting position, it is not only a way to set internal data...

Reimplemented in PortServo.

Definition at line 105 of file Port.hpp.

int Port::beginPin ( int  inPin,
PIN_TYPE  inType = UNDEFINED 
) const
protected

Initialize the instance of the pin.

Parameters
inPinpin to initialize.
inTypepin type
Returns
Arduino pin number in analog mode, or DIO2 pin number for a digital pin.

Definition at line 74 of file Port.cpp.

virtual int Port::GetPosition ( )
inlinevirtual

Gets the current position of the port.

Returns
Current position of the port.
Remarks
This function is only available on relevant accessories, like stepper or servo.

Reimplemented in PortStepper, and PortServo.

Definition at line 174 of file Port.hpp.

int Port::GetSpeed ( ) const
inline

Gets the current speed of the port.

Returns
current speed of the port.
Remarks
Speed is only available on ANALOG or ANALOG_INVERTED type of pin.

Definition at line 115 of file Port.hpp.

PORT_STATE Port::GetState ( ) const
inline

Gets the current state of the port.

Returns
current state of the port.

Definition at line 110 of file Port.hpp.

bool Port::IsLeftDir ( ) const
inline

Checks if the current state of the port is PORT_LEFT.

Returns
true if the current state of the port is PORT_LEFT.

Definition at line 126 of file Port.hpp.

bool Port::IsRightDir ( ) const
inline

Checks if the current state of the port is PORT_RIGHT.

Returns
true if the current state of the port is PORT_RIGHT.

Definition at line 130 of file Port.hpp.

bool Port::IsStopped ( ) const
inline

Checks if the current state of the port is PORT_STOP.

Returns
true if the current state of the port is PORT_STOP.

Definition at line 134 of file Port.hpp.

int Port::MapValue ( int  inValue,
PIN_TYPE  inType = UNDEFINED 
) const
protected

Maps the given value to the kind of pin, inverted or not. According to the INVERTED flag or not, activated pin can be LOW or HIGH for the Arduino... The goal of this function is to assure that an activated pin is always HIGH for the library.

Parameters
inValuephysical state of the pin : HIGH or LOW.
inTypeif UNDEFINED, the pin type is this->pinType, but if necessary the type (for this function only) can be forced to be inType.
Returns
Logical pin state. HIGH or LOW for digital pin, LOW or HIGH for digit inverted pin.

Definition at line 56 of file Port.cpp.

virtual void Port::MoveLeftDir ( unsigned long  inDuration = 0)
inlinevirtual

Sets the current state of the port to PORT_LEFT.

Parameters
inDurationthe pins will be activated to left for the given delay.

Reimplemented in PortSpeedDirBrake, PortTwoPins, PortShieldL293d, PortOnePin, and PortTwoPinsEnable.

Definition at line 139 of file Port.hpp.

void Port::MoveLeftDir ( unsigned long  inDuration,
int  inSpeed 
)

Sets the current state of the port to PORT_LEFT for a given duration, at the given speed.

Parameters
inDurationthe pins will be activated to left for the given delay.
inSpeedthe pins will be activated with the given speed.
Remarks
This function does not change the current speed of the port. Speed is only available on ANALOG or ANALOG_INVERTED type of pin.

Definition at line 129 of file Port.cpp.

void Port::MovePin ( int  inPin,
int  inValue,
PIN_TYPE  inType = UNDEFINED 
) const
protected

Sets the pin in a particular state. Accessories are not influenced by this change.

Parameters
inPinpin to update.
inValuenew value to reach.
inTypeif UNDEFINED, the pin type is this->pinType, but if necessary the type (for this function only) can be forced to be inType.

Definition at line 92 of file Port.cpp.

virtual void Port::MovePosition ( unsigned long  inDuration,
int  inEndPosition 
)
inlinevirtual

Move the port to the given position using a given duration.

Parameters
inDurationthe movement should take the time of this delay.
inEndPositionfinal position to reach.
Remarks
This function is only available on relevant accessories, like stepper or servo.

Reimplemented in PortStepper, and PortServo.

Definition at line 169 of file Port.hpp.

virtual void Port::MoveRightDir ( unsigned long  inDuration = 0)
inlinevirtual

Sets the current state of the port to PORT_RIGHT.

Parameters
inDurationthe pins will be activated to right for the given delay.

Reimplemented in PortSpeedDirBrake, PortTwoPins, PortShieldL293d, PortOnePin, and PortTwoPinsEnable.

Definition at line 143 of file Port.hpp.

void Port::MoveRightDir ( unsigned long  inDuration,
int  inSpeed 
)

Sets the current state of the port to PORT_RIGHT for a given duration, at the given speed.

Parameters
inDurationthe pins will be activated to left for the given delay.
inSpeedthe pins will be activated with the given speed.
Remarks
This function does not change the current speed of the port. Speed is only available on ANALOG or ANALOG_INVERTED type of pin.

Definition at line 139 of file Port.cpp.

virtual void Port::MoveStop ( )
inlinevirtual

Sets the current state of the port to PORT_STOP.

Reimplemented in PortSpeedDirBrake, PortTwoPins, PortShieldL293d, PortOnePin, and PortTwoPinsEnable.

Definition at line 163 of file Port.hpp.

PORT_STATE Port::MoveToggle ( unsigned long  inDuration = 0)

Sets the current state of the port to PORT_LEFT or PORT_RIGHT according to its current state for a given duration.

Parameters
inDurationthe pins will be activated to left for the given delay.

Definition at line 115 of file Port.cpp.

int Port::SetSpeed ( int  inSpeed)
virtual

Sets the current speed of the port.

Parameters
inSpeednew current speed of the port.
Returns
Previous speed.
Remarks
Speed is only available on ANALOG or ANALOG_INVERTED type of pin.

Reimplemented in PortOnePin.

Definition at line 108 of file Port.cpp.

Member Data Documentation

PIN_TYPE Port::pinType
protected

Kind of pin, analog or digital, inverted or not.

Definition at line 65 of file Port.hpp.

int Port::speed
protected

Speed of the port.

Definition at line 69 of file Port.hpp.

PORT_STATE Port::state
protected

Current state of the port.

Definition at line 67 of file Port.hpp.


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