Neil Balch | 6040a35 | 2018-03-04 16:02:56 -0800 | [diff] [blame] | 1 | #include "y2018/control_loops/superstructure/debouncer.h" |
| 2 | |
| 3 | namespace y2018 { |
| 4 | namespace control_loops { |
| 5 | namespace superstructure { |
| 6 | |
| 7 | void 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 |