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