Accessories
Arduino for motors and lights library.
PortSpeedDirBrake.cpp
1 /*************************************************************
2 project: <Accessories>
3 author: <Thierry PARIS>
4 description: <Driver port for a LMD18200>
5 *************************************************************/
6 
7 #include "Accessories.h"
8 
9 #ifndef NO_MOTOR_LIGHT
10 
12 {
13  this->pinPWM = -1;
14 }
15 
16 void PortSpeedDirBrake::begin(int inPinPWM, int inPinDir, int inPinBrake, PIN_TYPE inPWMType, PIN_TYPE inDigitalType)
17 {
18 #ifdef ACCESSORIES_DEBUG_MODE
19  if ((int)inPWMType < ANALOG)
20  Serial.print(F(" PortSpeedDirBrake begin() : inPWMType must be ANALOG or ANALOG_INVERTED !"));
21  if ((int)inDigitalType >= ANALOG)
22  Serial.print(F(" PortSpeedDirBrake begin() : inDigitalType must be DIGITAL or DIGITAL_INVERTED !"));
23 #endif
24 
25  this->pinPWM = inPinPWM;
26  this->pinDir = Arduino_to_GPIO_pin(inPinDir);
27  this->pinBrake = Arduino_to_GPIO_pin(inPinBrake);
28 
29  this->SetPinType(inPWMType);
30  this->digitalType = inDigitalType;
31 
32  this->beginPin(this->pinPWM);
33  this->beginPin(this->pinDir, this->digitalType);
34  this->beginPin(this->pinBrake, this->digitalType);
35 }
36 
37 int PortSpeedDirBrake::MapDigitalValue(int inValue) const
38 {
39  if (this->GetPinType() == DIGITAL_INVERTED)
40  {
41  if (inValue == LOW)
42  return HIGH;
43  return LOW;
44  }
45 
46  return inValue;
47 }
48 
49 void PortSpeedDirBrake::MoveLeftDir(unsigned long inDuration)
50 {
51 #ifdef ACCESSORIES_DEBUG_MODE
52  Serial.print(F(" PortSpeedDirBrake MoveLeftDir() "));
53  if (inDuration != 0)
54  {
55  Serial.print(F("for "));
56  Serial.print(inDuration);
57  Serial.println(F("ms"));
58  }
59  else
60  Serial.println("");
61 #endif
62  this->SetPortState(PORT_LEFT);
63 
64  this->MovePin(this->pinPWM, HIGH);
65  this->MovePin(this->pinDir, LOW, this->digitalType);
66  this->MovePin(this->pinBrake, LOW, this->digitalType);
67 }
68 
69 void PortSpeedDirBrake::MoveRightDir(unsigned long inDuration)
70 {
71 #ifdef ACCESSORIES_DEBUG_MODE
72  Serial.print(F(" PortSpeedDirBrake MoveRightDir() "));
73  if (inDuration != 0)
74  {
75  Serial.print(F("for "));
76  Serial.print(inDuration);
77  Serial.println(F("ms"));
78  }
79  else
80  Serial.println("");
81 #endif
82  this->SetPortState(PORT_RIGHT);
83  this->MovePin(this->pinPWM, HIGH);
84  this->MovePin(this->pinDir, HIGH, this->digitalType);
85  this->MovePin(this->pinBrake, LOW, this->digitalType);
86 }
87 
89 {
90 #ifdef ACCESSORIES_DEBUG_MODE
91  Serial.println(F(" PortSpeedDirBrake MoveStop()"));
92 #endif
93  this->SetPortState(PORT_STOP);
94  this->MovePin(this->pinBrake, HIGH, this->digitalType);
95 }
96 
97 #ifdef ACCESSORIES_PRINT_ACCESSORIES
98 void PortSpeedDirBrake::printPort()
99 {
100  Serial.print(F("[PortSpeedDirBrake pinPWM:"));
101  Port::printPortPin(this->pinPWM, this->GetPinType());
102  Serial.print(F(" dir:"));
103  Port::printPortPin(this->pinDir, this->digitalType);
104  Serial.print(F(" brake:"));
105  Port::printPortPin(this->pinBrake, this->digitalType);
106  Serial.print(F("]"));
107 }
108 #endif
109 
110 #endif
void MovePin(int inPin, int inValue, PIN_TYPE inType = UNDEFINED) const
Definition: Port.cpp:138
void MoveLeftDir(unsigned long inDuration = 0)
PIN_TYPE GetPinType() const
Definition: Port.hpp:77
int MapDigitalValue(int inValue) const
int beginPin(int inPin, PIN_TYPE inType = UNDEFINED) const
Definition: Port.cpp:103
void SetPinType(PIN_TYPE inType)
Definition: Port.hpp:84
void MoveRightDir(unsigned long inDuration = 0)
void SetPortState(PORT_STATE inState)
Definition: Port.hpp:87
virtual void begin()
Definition: Port.hpp:117