mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
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:
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user