Abstracted Threshold Check

This commit is contained in:
ElectronicsArchiver
2022-05-25 21:59:08 -04:00
parent db9a24919f
commit eed0ef8022
2 changed files with 9 additions and 3 deletions
+8 -3
View File
@@ -43,7 +43,7 @@ bool Debouncer::update(){
// Ignore everything if we are locked out
if(millis() - previous_millis >= interval_millis){
if(thresholdPassed()){
bool currentState = readCurrentState();
@@ -85,7 +85,7 @@ bool Debouncer::update(){
* - DEBOUNCED_STATE
*/
if(millis() - previous_millis >= interval_millis)
if(thresholdPassed())
changeState();
}
@@ -136,7 +136,7 @@ bool Debouncer::update(){
previous_millis = millis();
toggleStateFlag(UNSTABLE_STATE);
} else
if(millis() - previous_millis >= interval_millis){
if(thresholdPassed()){
/*
* We have passed the threshold time
@@ -202,3 +202,8 @@ bool Debouncer::fell() const {
return ! getStateFlag(DEBOUNCED_STATE)
&& getStateFlag(CHANGED_STATE);
}
inline bool Debouncer::thresholdPassed(){
return millis() - previous_millis >= interval_millis;
}