blob: 98e80f3cd3fb0eb135a15e931ef0d326a068b9fb [file] [log] [blame]
#include "y2018/control_loops/superstructure/debouncer.h"
namespace y2018::control_loops::superstructure {
void Debouncer::Update(bool new_state) {
// If the incoming state is different from the one we have stored, increment
// the counter.
if (new_state != current_state_) {
consistent_count_++;
} else {
consistent_count_ = 0;
}
// If we have reached the number required to change the state, change it.
if (consistent_count_ >= inputs_before_change_) {
current_state_ = new_state;
consistent_count_ = 0;
}
}
} // namespace y2018::control_loops::superstructure