mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21: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:
@@ -12,6 +12,7 @@ import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import edu.wpi.first.wpilibj.simulation.SimHooks;
|
||||
import edu.wpi.first.wpilibj2.command.Command;
|
||||
import edu.wpi.first.wpilibj2.command.CommandScheduler;
|
||||
import edu.wpi.first.wpilibj2.command.CommandTestBase;
|
||||
@@ -172,4 +173,26 @@ class ButtonTest extends CommandTestBase {
|
||||
assertFalse(button1.negate().get());
|
||||
assertTrue(button1.and(button2.negate()).get());
|
||||
}
|
||||
|
||||
@Test
|
||||
void debounceTest() {
|
||||
CommandScheduler scheduler = CommandScheduler.getInstance();
|
||||
MockCommandHolder commandHolder = new MockCommandHolder(true);
|
||||
Command command = commandHolder.getMock();
|
||||
|
||||
InternalButton button = new InternalButton();
|
||||
Trigger debounced = button.debounce(0.1);
|
||||
|
||||
debounced.whenActive(command);
|
||||
|
||||
button.setPressed(true);
|
||||
scheduler.run();
|
||||
verify(command, never()).schedule(true);
|
||||
|
||||
SimHooks.stepTiming(0.3);
|
||||
|
||||
button.setPressed(true);
|
||||
scheduler.run();
|
||||
verify(command).schedule(true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user