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

PIN_TYPE GetPinType () const
 
PORT_STATE GetPortState () const
 
void SetPinType (PIN_TYPE inType)
 
void SetPortState (PORT_STATE inState)
 
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
 
 Port ()
 
virtual void begin ()
 
virtual void beginByAccessory (int inStartingPosition)
 
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 Attributes

int speed
 
byte type_state
 

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 60 of file Port.hpp.

Constructor & Destructor Documentation

Port::Port ( )

Default constructor.

Definition at line 78 of file Port.cpp.

Member Function Documentation

virtual void Port::begin ( )
inlinevirtual

Initialize the instance.

Definition at line 117 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 123 of file Port.hpp.

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

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 103 of file Port.cpp.

PIN_TYPE Port::GetPinType ( ) const
inline

Gets the pin type.

Definition at line 77 of file Port.hpp.

PORT_STATE Port::GetPortState ( ) const
inline

Gets the current port state.

Definition at line 80 of file Port.hpp.

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 188 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 129 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 140 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 144 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 148 of file Port.hpp.

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

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 85 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 153 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 199 of file Port.cpp.

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

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 138 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 183 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 157 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 209 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, PortTwoPinsEnable, and PortServo.

Definition at line 177 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 185 of file Port.cpp.

void Port::SetPinType ( PIN_TYPE  inType)
inline

Sets the pin type...

Definition at line 84 of file Port.hpp.

void Port::SetPortState ( PORT_STATE  inState)
inline

Sets the port state.

Definition at line 87 of file Port.hpp.

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 178 of file Port.cpp.

Member Data Documentation

int Port::speed
protected

Speed of the port.

Definition at line 64 of file Port.hpp.

byte Port::type_state
protected

Kind of pin, analog or digital, inverted or not. and Current state of the port. Both values are stored inside the same byte of the form B00sskkkk where ss is two bits defining the state, and kkkk four bits for the kind of pin. The two last bits 00 are not used for the moment.

Definition at line 71 of file Port.hpp.


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