in libs/core/input.cpp [53:91]
static void pinPollThread(void *ptr)
{
(void)ptr;
while (1)
{
delay(10);
for (int eventNo = 0; eventNo < event_count; eventNo++)
{
uint8_t mask = events[eventNo].event_mask;
uint8_t pin = (mask >> 5) & 7;
uint8_t counter = (mask >> 3) & 3;
uint8_t type = (mask >> 1) & 3;
uint8_t state = (mask >> 0) & 1;
// Ignore pins without events.
if (!events[eventNo].body)
{
;
}
// If the state matches the recorded state, don't change anything.
else if ((!!digitalRead(pin)) == (!!state))
{
counter = 0;
}
// The state is different, so increment the debounce counter.
else if (counter++ >= 3)
{
state = !state;
counter = 0;
if ((state && (type & EVENT_TYPE_FALLING)) || (!state && (type & EVENT_TYPE_RISING)))
runAction0(events[eventNo].body);
}
events[eventNo].event_mask = make_event_mask(pin, counter, type, state);
}
}
}