Accessories
Arduino for motors and lights library.
PortExpander.cpp
1 #include "Accessories.h"
2 
3 #ifndef NO_EXPANDER
4 
5 PortExpander *PortExpander::pFirstExpander = NULL;
6 
8 {
9  this->id = (int) UNDEFINED_ID;
10  this->pNextExpander = NULL;
11 }
12 
13 void PortExpander::Add(PortExpander *inExpander)
14 {
15  if (PortExpander::pFirstExpander == NULL)
16  {
17  PortExpander::pFirstExpander = inExpander;
18  inExpander->SetNextExpander(NULL);
19  }
20 
21  PortExpander *pCurr = PortExpander::pFirstExpander;
22 
23  while (pCurr->GetNextExpander() != NULL)
24  pCurr = pCurr->GetNextExpander();
25 
26  pCurr->SetNextExpander(inExpander);
27  inExpander->SetNextExpander(NULL);
28 }
29 
30 PortExpander *PortExpander::GetById(int inId)
31 {
32  PortExpander *pCurr = PortExpander::pFirstExpander;
33 
34  while (pCurr != NULL)
35  {
36  if (pCurr->id == inId)
37  return pCurr;
38  pCurr = pCurr->GetNextExpander();
39  }
40 
41  return NULL;
42 }
43 
44 #ifdef ACCESSORIES_DEBUG_MODE
45 void PortExpander::CheckExpanderId(int inId)
46 {
47  PortExpander *pExp = PortExpander::GetById(inId);
48 
49  if ( pExp == NULL)
50  {
51  Serial.print(F("Expander "));
52  Serial.print(inId);
53  Serial.println(F(" unknown !"));
54  }
55 }
56 #endif
57 
58 void PortExpander::beginPin(int inPin, int inExpId, PIN_TYPE inType)
59 {
60  PortExpander *pCurr = PortExpander::GetById(inExpId);
61  if (pCurr != NULL)
62  pCurr->beginPin(inPin, inType);
63 }
64 
65 void PortExpander::digitalWrite(int inPin, int inExpId, int inValue)
66 {
67  PortExpander *pCcurr = PortExpander::GetById(inExpId);
68  if (pCcurr != NULL)
69  pCcurr->digitalWrite(inPin, inValue);
70 }
71 
72 void PortExpander::analogWrite(int inPin, int inExpId, int inValue)
73 {
74  PortExpander *pCurr = PortExpander::GetById(inExpId);
75  if (pCurr != NULL)
76  pCurr->analogWrite(inPin, inValue);
77 }
78 #endif
virtual void analogWrite(int inPin, int inValue) = 0
virtual void digitalWrite(int inPin, int inValue) = 0
virtual void beginPin(int inPin, PIN_TYPE inType) = 0