8 #ifndef NO_BUTTONSCOMMANDER 9 #ifndef NO_BUTTONSCOMMANDERSWITCH 13 this->debounceDelay = 50;
14 this->lastSelectedPin = DP_INVALID;
19 if (inpIdPin->
Pin != DP_INVALID)
21 pinMode2f(inpIdPin->
Pin, INPUT_PULLUP);
27 #ifdef COMMANDERS_DEBUG_MODE 28 if (this->EventPins.
pFirst == NULL)
29 Serial.println(F(
"This switch button have no ID defined : begin() must be called AFTER AddEvent !"));
35 beginItem(pCurr->
Obj);
37 int reading = digitalRead2f(pCurr->
Obj->
Pin);
40 this->lastSelectedPin = pCurr->
Obj->
Pin;
51 if (inPin == pCurr->
Obj->
Pin)
52 return pCurr->
Obj->
Id;
63 pIdpin->
Pin = Arduino_to_GPIO_pin(inPin);
65 pIdpin->
Event = inEvent;
66 pIdpin->
Data = inData;
67 this->EventPins.
AddItem(pIdpin);
73 unsigned long *apDebounceDelay, GPIO_pin_t *apLastSelectedPin,
74 int *apLastButtonState,
unsigned long *apLastDebounceTime,
bool inSendEvent)
78 if (inPin != DP_INVALID)
81 int reading = digitalRead2f(inPin);
88 if (reading != *apLastButtonState)
91 *apLastButtonState = reading;
92 *apLastDebounceTime = millis();
96 if (*apLastDebounceTime > 0 && (millis() - *apLastDebounceTime) > *apDebounceDelay)
108 *apLastSelectedPin = inPin;
115 *apLastDebounceTime = 0;
120 *apLastButtonState = reading;
129 while (pCurr != NULL)
131 if (pCurr->
Obj->
Pin != DP_INVALID)
134 int reading = digitalRead2f(pCurr->
Obj->
Pin);
139 this->lastSelectedPin = pCurr->
Obj->
Pin;
141 this->lastButtonState = reading;
144 pCurr = pCurr->
pNext;
151 #ifdef COMMANDERS_DEBUG_MODE 152 if (this->EventPins.
pFirst == NULL)
153 Serial.println(F(
"This switch button have no ID defined : call AddEvent() and begin() !"));
157 this->GetId(this->lastSelectedPin),
158 &this->debounceDelay, &this->lastSelectedPin,
159 &this->lastButtonState, &this->lastDebounceTime,
false);
169 #ifdef COMMANDERS_PRINT_COMMANDERS 170 void ButtonsCommanderSwitch::printCommander()
172 Serial.println(F(
" Switch"));
175 while (pCurr != NULL)
177 Serial.print(F(
" Event - Pin: "));
178 Serial.print(GPIO_to_Arduino_pin(pCurr->
Obj->
Pin));
179 Serial.print(F(
" / Id: "));
180 Serial.print(pCurr->
Obj->
Id);
181 Serial.print(F(
" / Event type: "));
184 Serial.println(F(
""));
186 pCurr = pCurr->
pNext;
static void printEventData(COMMANDERS_EVENT_TYPE inEventType, int inEventData)
CMDRSCHAINEDLISTITEM< T > * pCurrentItem
static void printEventType(COMMANDERS_EVENT_TYPE inEventType, bool inDataFollow)
static unsigned long RaiseEvent(unsigned long inId, COMMANDERS_EVENT_TYPE inEvent = COMMANDERS_EVENT_MOVEPOSITIONID, int inData = 0)
CMDRSCHAINEDLISTITEM * pNext
CMDRSCHAINEDLISTITEM< T > * pFirst
COMMANDERS_EVENT_TYPE Event