Add Debouncer (#3590)

Supersedes #2358 with updates and cleanups.

Closes #2482 and closes #2487 because we shouldn't support both
time-based and count-based debouncing approaches.

Co-authored-by: oblarg <emichaelbarnett@gmail.com>
This commit is contained in:
Tyler Veness
2021-09-19 19:58:16 -07:00
committed by GitHub
parent 179fde3a7b
commit 1ca383b23b
10 changed files with 344 additions and 1 deletions

View File

@@ -4,6 +4,8 @@
#include "frc2/command/button/Trigger.h"
#include <frc/Debouncer.h>
#include "frc2/command/InstantCommand.h"
using namespace frc2;
@@ -136,3 +138,9 @@ Trigger Trigger::CancelWhenActive(Command* command) {
});
return *this;
}
Trigger Trigger::Debounce(units::second_t debounceTime) {
return Trigger([debouncer = frc::Debouncer(debounceTime), *this]() mutable {
return debouncer.Calculate(m_isActive());
});
}