update
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user