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

@@ -9,6 +9,7 @@
#include <memory>
#include <utility>
#include <units/time.h>
#include <wpi/span.h>
#include "frc2/command/Command.h"
@@ -345,6 +346,15 @@ class Trigger {
return Trigger([*this] { return !m_isActive(); });
}
/**
* Creates a new debounced trigger from this trigger - it will become active
* when this trigger has been active for longer than the specified period.
*
* @param debounceTime the debounce period
* @return the debounced trigger
*/
Trigger Debounce(units::second_t debounceTime);
private:
std::function<bool()> m_isActive;
};