This commit is contained in:
2025-12-12 08:35:20 +01:00
committed by example
parent 356d7de2cf
commit 0ce45a133b
23 changed files with 616 additions and 135 deletions

View File

@@ -73,3 +73,32 @@ int Rssi2Quality(sint8 rssi)
else
return 4;
}
Debounce::Debounce() : state(0xFF) {}
Debounce::Debounce(bool signal) { init(signal); }
void Debounce::init(bool signal)
{
if(signal)
state = 0xFF;
else
state = 0x00;
}
int8_t Debounce::debounce(bool signal)
{
const uint8_t current = state & UPPER;
const uint8_t history = (state << 1) & LOWER;
state = current | history | signal;
// Events are triggered when the history is saturated
// with the opposite of the active switch state.
// As a result, the events are guaranteed to alternate.
switch (state) {
case UPPER: state = 0x00; return -1; // LOW/False (falling edge)
case LOWER: state = 0xFF; return 1; // HIGH/True (rising edge)
}
return 0;//state & UPPER;
}