change debouce logic
This commit is contained in:
parent
b62ef700ed
commit
d0ce4bf391
|
@ -137,25 +137,50 @@ void DigitalInputCard::handlePinChange(int pin, uint8_t ¤tBuffer, uint8_t
|
|||
// Handle Bank A
|
||||
if (((previousBuffer >> (7 - pin)) & 1) != ((currentBuffer >> (7 - pin)) & 1))
|
||||
{
|
||||
if (!pinChanged[pin]) {
|
||||
lastDebounceTime[pin] = millis();
|
||||
pinChanged[pin] = true;
|
||||
} else {
|
||||
if (millis() - lastDebounceTime[pin] > debounceTime[pin])
|
||||
{
|
||||
lastDebounceTime[pin] = millis();
|
||||
previousBuffer ^= (-((currentBuffer >> (7 - pin)) & 1) ^ previousBuffer) & (1UL << (7 - pin));
|
||||
for(const auto& callback : callbacks)
|
||||
for (const auto& callback : callbacks)
|
||||
callback.second(virtualPin, ((currentBuffer >> (7 - pin)) & 1));
|
||||
pinChanged[pin] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Handle Bank B
|
||||
if (((previousBuffer >> (15 - pin)) & 1) != ((currentBuffer >> (15 - pin)) & 1))
|
||||
{
|
||||
if (!pinChanged[pin]) {
|
||||
lastDebounceTime[pin] = millis();
|
||||
pinChanged[pin] = true;
|
||||
} else {
|
||||
if (millis() - lastDebounceTime[pin] > debounceTime[pin])
|
||||
{
|
||||
lastDebounceTime[pin] = millis();
|
||||
previousBuffer ^= (-((currentBuffer >> (15 - pin)) & 1) ^ previousBuffer) & (1UL << (15 - pin));
|
||||
for (const auto& callback : callbacks)
|
||||
callback.second(virtualPin, ((currentBuffer >> (15 - pin)) & 1));
|
||||
pinChanged[pin] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// // Handle Bank B
|
||||
// if (((previousBuffer >> (15 - pin)) & 1) != ((currentBuffer >> (15 - pin)) & 1))
|
||||
// {
|
||||
// if (millis() - lastDebounceTime[pin] > debounceTime[pin])
|
||||
// {
|
||||
// lastDebounceTime[pin] = millis();
|
||||
// previousBuffer ^= (-((currentBuffer >> (15 - pin)) & 1) ^ previousBuffer) & (1UL << (15 - pin));
|
||||
// for (const auto& callback : callbacks)
|
||||
// callback.second(virtualPin, ((currentBuffer >> (15 - pin)) & 1));
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -54,6 +54,7 @@ class DigitalInputCard : public ExpansionCard {
|
|||
uint8_t previousInputBufferB;
|
||||
uint32_t debounceTime[16];
|
||||
uint32_t lastDebounceTime[16];
|
||||
bool pinChanged[16];
|
||||
// A map of the physical pin to the virtual pin
|
||||
uint8_t pinMap[16];
|
||||
// A map of the virtual pin to the physical pin
|
||||
|
|
Loading…
Reference in New Issue