#include "Port.hpp"
Public Member Functions | |
Port () | |
virtual void | begin () |
virtual void | beginByAccessory (int inStartingPosition) |
PIN_TYPE | GetPinType () const |
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 |
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 !
|
inlinevirtual |
|
inlinevirtual |
|
protected |
|
inline |
|
inlinevirtual |
Gets the current position of the port.
Reimplemented in PortStepper, and PortServo.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
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.
inValue | physical state of the pin : HIGH or LOW. |
inType | if UNDEFINED, the pin type is this->pinType, but if necessary the type (for this function only) can be forced to be inType. |
|
inlinevirtual |
Sets the current state of the port to PORT_LEFT.
inDuration | the pins will be activated to left for the given delay. |
Reimplemented in PortSpeedDirBrake, PortTwoPins, PortShieldL293d, PortOnePin, and PortTwoPinsEnable.
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.
inDuration | the pins will be activated to left for the given delay. |
inSpeed | the pins will be activated with the given speed. |
|
protected |
Sets the pin in a particular state. Accessories are not influenced by this change.
inPin | pin to update. |
inValue | new value to reach. |
inType | if UNDEFINED, the pin type is this->pinType, but if necessary the type (for this function only) can be forced to be inType. |
|
inlinevirtual |
Move the port to the given position using a given duration.
inDuration | the movement should take the time of this delay. |
inEndPosition | final position to reach. |
Reimplemented in PortStepper, and PortServo.
|
inlinevirtual |
Sets the current state of the port to PORT_RIGHT.
inDuration | the pins will be activated to right for the given delay. |
Reimplemented in PortSpeedDirBrake, PortTwoPins, PortShieldL293d, PortOnePin, and PortTwoPinsEnable.
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.
inDuration | the pins will be activated to left for the given delay. |
inSpeed | the pins will be activated with the given speed. |
|
inlinevirtual |
Sets the current state of the port to PORT_STOP.
Reimplemented in PortSpeedDirBrake, PortTwoPins, PortShieldL293d, PortOnePin, and PortTwoPinsEnable.
PORT_STATE Port::MoveToggle | ( | unsigned long | inDuration = 0 | ) |
|
virtual |
Sets the current speed of the port.
inSpeed | new current speed of the port. |
Reimplemented in PortOnePin.
|
protected |