diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/Trigger.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/Trigger.java index d692f96f04..50abf962f0 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/Trigger.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/Trigger.java @@ -348,25 +348,25 @@ public class Trigger implements BooleanSupplier { } /** - * Composes this trigger with another trigger, returning a new trigger that is active when both + * Composes this trigger with a boolean supplier, returning a new trigger that is active when both * triggers are active. * - * @param trigger the trigger to compose with + * @param booleanSupplier the boolean supplier to compose with * @return the trigger that is active when both triggers are active */ - public Trigger and(Trigger trigger) { - return new Trigger(() -> get() && trigger.get()); + public Trigger and(BooleanSupplier booleanSupplier) { + return new Trigger(() -> get() && booleanSupplier.getAsBoolean()); } /** - * Composes this trigger with another trigger, returning a new trigger that is active when either - * trigger is active. + * Composes this trigger with a boolean supplier, returning a new trigger that is active when + * either trigger is active. * - * @param trigger the trigger to compose with + * @param booleanSupplier the boolean supplier to compose with * @return the trigger that is active when either trigger is active */ - public Trigger or(Trigger trigger) { - return new Trigger(() -> get() || trigger.get()); + public Trigger or(BooleanSupplier booleanSupplier) { + return new Trigger(() -> get() || booleanSupplier.getAsBoolean()); } /** diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/button/Trigger.h b/wpilibNewCommands/src/main/native/include/frc2/command/button/Trigger.h index d5fcb34bc0..cfaeefe0c1 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/button/Trigger.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/button/Trigger.h @@ -35,7 +35,7 @@ class Trigger { * * @param isActive Whether the trigger is active. */ - explicit Trigger(std::function isActive) + Trigger(std::function isActive) // NOLINT : m_isActive{std::move(isActive)} {} /** diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/button/ButtonTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/button/ButtonTest.java index 81b12ef865..f39f39cae6 100644 --- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/button/ButtonTest.java +++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/button/ButtonTest.java @@ -16,6 +16,7 @@ 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; +import java.util.function.BooleanSupplier; import org.junit.jupiter.api.Test; class ButtonTest extends CommandTestBase { @@ -174,6 +175,17 @@ class ButtonTest extends CommandTestBase { assertTrue(button1.and(button2.negate()).get()); } + @Test + void buttonCompositionSupplierTest() { + InternalButton button1 = new InternalButton(); + BooleanSupplier booleanSupplier = () -> false; + + button1.setPressed(true); + + assertFalse(button1.and(booleanSupplier).get()); + assertTrue(button1.or(booleanSupplier).get()); + } + @Test void debounceTest() { CommandScheduler scheduler = CommandScheduler.getInstance();