[newCommands] Trigger: Allow override of debounce type (#3845)

Previously Trigger could only be debounced on rising edges.
This change preserves the default behavior but adds the capability to override it.
This commit is contained in:
Oblarg
2021-12-29 19:10:43 -05:00
committed by GitHub
parent aa9dfabde2
commit eee29daaf9
3 changed files with 28 additions and 10 deletions

View File

@@ -381,13 +381,25 @@ public class Trigger implements BooleanSupplier {
* 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 seconds the debounce period
* @return the debounced trigger
* @param seconds The debounce period.
* @return The debounced trigger (rising edges debounced only)
*/
public Trigger debounce(double seconds) {
return debounce(seconds, Debouncer.DebounceType.kRising);
}
/**
* 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 seconds The debounce period.
* @param type The debounce type.
* @return The debounced trigger.
*/
public Trigger debounce(double seconds, Debouncer.DebounceType type) {
return new Trigger(
new BooleanSupplier() {
Debouncer m_debouncer = new Debouncer(seconds);
Debouncer m_debouncer = new Debouncer(seconds, type);
@Override
public boolean getAsBoolean() {