blob: 40b730d0142312ed96ee1d66ca3d97d8bf349f7e [file] [log] [blame]
Neil Balch6040a352018-03-04 16:02:56 -08001#include "y2018/control_loops/superstructure/debouncer.h"
2
3namespace y2018 {
4namespace control_loops {
5namespace superstructure {
6
7void Debouncer::Update(bool new_state) {
8 // If the incoming state is different from the one we have stored, increment
9 // the counter.
10 if (new_state != current_state_) {
11 consistent_count_++;
12 } else {
13 consistent_count_ = 0;
14 }
15
16 // If we have reached the number required to change the state, change it.
17 if (consistent_count_ >= inputs_before_change_) {
18 current_state_ = new_state;
19 consistent_count_ = 0;
20 }
21}
22
23} // namespace superstructure
24} // namespace control_loops
25} // namespace y2018