diff --git a/commandsv3/src/main/java/org/wpilib/commands3/button/CommandGamepad.java b/commandsv3/src/main/java/org/wpilib/commands3/button/CommandGamepad.java new file mode 100644 index 0000000000..d0514dd5f7 --- /dev/null +++ b/commandsv3/src/main/java/org/wpilib/commands3/button/CommandGamepad.java @@ -0,0 +1,813 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +package org.wpilib.commands3.button; + +import edu.wpi.first.wpilibj.Gamepad; +import edu.wpi.first.wpilibj.event.EventLoop; +import org.wpilib.commands3.Scheduler; +import org.wpilib.commands3.Trigger; + +/** + * A version of {@link Gamepad} with {@link Trigger} factories for command-based. + * + * @see Gamepad + */ +@SuppressWarnings("MethodName") +public class CommandGamepad extends CommandGenericHID { + private final Gamepad m_hid; + + /** + * Construct an instance of a controller. + * + * @param port The port index on the Driver Station that the controller is plugged into. + */ + public CommandGamepad(int port) { + super(port); + m_hid = new Gamepad(port); + } + + /** + * Construct an instance of a controller. + * + * @param scheduler The scheduler that should execute the triggered commands. + * @param port The port index on the Driver Station that the controller is plugged into. + */ + public CommandGamepad(Scheduler scheduler, int port) { + super(scheduler, port); + m_hid = new Gamepad(port); + } + + /** + * Get the underlying GenericHID object. + * + * @return the wrapped GenericHID object + */ + @Override + public Gamepad getHID() { + return m_hid; + } + + /** + * Constructs a Trigger instance around the South Face button's digital signal. + * + * @return a Trigger instance representing the South Face button's digital signal attached to the + * {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the scheduler + * passed to the controller's constructor, or the {@link Scheduler#getDefault default + * scheduler} if a scheduler was not explicitly provided. + * @see #southFace(EventLoop) + */ + public Trigger southFace() { + return southFace(getScheduler().getDefaultEventLoop()); + } + + /** + * Constructs a Trigger instance around the South Face button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the South Face button's digital signal attached to the + * given loop. + */ + public Trigger southFace(EventLoop loop) { + return button(Gamepad.Button.kSouthFace.value, loop); + } + + /** + * Constructs a Trigger instance around the East Face button's digital signal. + * + * @return a Trigger instance representing the East Face button's digital signal attached to the + * {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the scheduler + * passed to the controller's constructor, or the {@link Scheduler#getDefault default + * scheduler} if a scheduler was not explicitly provided. + * @see #eastFace(EventLoop) + */ + public Trigger eastFace() { + return eastFace(getScheduler().getDefaultEventLoop()); + } + + /** + * Constructs a Trigger instance around the East Face button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the East Face button's digital signal attached to the + * given loop. + */ + public Trigger eastFace(EventLoop loop) { + return button(Gamepad.Button.kEastFace.value, loop); + } + + /** + * Constructs a Trigger instance around the West Face button's digital signal. + * + * @return a Trigger instance representing the West Face button's digital signal attached to the + * {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the scheduler + * passed to the controller's constructor, or the {@link Scheduler#getDefault default + * scheduler} if a scheduler was not explicitly provided. + * @see #westFace(EventLoop) + */ + public Trigger westFace() { + return westFace(getScheduler().getDefaultEventLoop()); + } + + /** + * Constructs a Trigger instance around the West Face button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the West Face button's digital signal attached to the + * given loop. + */ + public Trigger westFace(EventLoop loop) { + return button(Gamepad.Button.kWestFace.value, loop); + } + + /** + * Constructs a Trigger instance around the North Face button's digital signal. + * + * @return a Trigger instance representing the North Face button's digital signal attached to the + * {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the scheduler + * passed to the controller's constructor, or the {@link Scheduler#getDefault default + * scheduler} if a scheduler was not explicitly provided. + * @see #northFace(EventLoop) + */ + public Trigger northFace() { + return northFace(getScheduler().getDefaultEventLoop()); + } + + /** + * Constructs a Trigger instance around the North Face button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the North Face button's digital signal attached to the + * given loop. + */ + public Trigger northFace(EventLoop loop) { + return button(Gamepad.Button.kNorthFace.value, loop); + } + + /** + * Constructs a Trigger instance around the Back button's digital signal. + * + * @return a Trigger instance representing the Back button's digital signal attached to the {@link + * Scheduler#getDefaultEventLoop() default scheduler event loop} on the scheduler passed to + * the controller's constructor, or the {@link Scheduler#getDefault default scheduler} if a + * scheduler was not explicitly provided. + * @see #back(EventLoop) + */ + public Trigger back() { + return back(getScheduler().getDefaultEventLoop()); + } + + /** + * Constructs a Trigger instance around the Back button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the Back button's digital signal attached to the given + * loop. + */ + public Trigger back(EventLoop loop) { + return button(Gamepad.Button.kBack.value, loop); + } + + /** + * Constructs a Trigger instance around the Guide button's digital signal. + * + * @return a Trigger instance representing the Guide button's digital signal attached to the + * {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the scheduler + * passed to the controller's constructor, or the {@link Scheduler#getDefault default + * scheduler} if a scheduler was not explicitly provided. + * @see #guide(EventLoop) + */ + public Trigger guide() { + return guide(getScheduler().getDefaultEventLoop()); + } + + /** + * Constructs a Trigger instance around the Guide button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the Guide button's digital signal attached to the given + * loop. + */ + public Trigger guide(EventLoop loop) { + return button(Gamepad.Button.kGuide.value, loop); + } + + /** + * Constructs a Trigger instance around the Start button's digital signal. + * + * @return a Trigger instance representing the Start button's digital signal attached to the + * {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the scheduler + * passed to the controller's constructor, or the {@link Scheduler#getDefault default + * scheduler} if a scheduler was not explicitly provided. + * @see #start(EventLoop) + */ + public Trigger start() { + return start(getScheduler().getDefaultEventLoop()); + } + + /** + * Constructs a Trigger instance around the Start button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the Start button's digital signal attached to the given + * loop. + */ + public Trigger start(EventLoop loop) { + return button(Gamepad.Button.kStart.value, loop); + } + + /** + * Constructs a Trigger instance around the left stick button's digital signal. + * + * @return a Trigger instance representing the left stick button's digital signal attached to the + * {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the scheduler + * passed to the controller's constructor, or the {@link Scheduler#getDefault default + * scheduler} if a scheduler was not explicitly provided. + * @see #leftStick(EventLoop) + */ + public Trigger leftStick() { + return leftStick(getScheduler().getDefaultEventLoop()); + } + + /** + * Constructs a Trigger instance around the left stick button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the left stick button's digital signal attached to the + * given loop. + */ + public Trigger leftStick(EventLoop loop) { + return button(Gamepad.Button.kLeftStick.value, loop); + } + + /** + * Constructs a Trigger instance around the right stick button's digital signal. + * + * @return a Trigger instance representing the right stick button's digital signal attached to the + * {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the scheduler + * passed to the controller's constructor, or the {@link Scheduler#getDefault default + * scheduler} if a scheduler was not explicitly provided. + * @see #rightStick(EventLoop) + */ + public Trigger rightStick() { + return rightStick(getScheduler().getDefaultEventLoop()); + } + + /** + * Constructs a Trigger instance around the right stick button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the right stick button's digital signal attached to the + * given loop. + */ + public Trigger rightStick(EventLoop loop) { + return button(Gamepad.Button.kRightStick.value, loop); + } + + /** + * Constructs a Trigger instance around the right shoulder button's digital signal. + * + * @return a Trigger instance representing the right shoulder button's digital signal attached to + * the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the scheduler + * passed to the controller's constructor, or the {@link Scheduler#getDefault default + * scheduler} if a scheduler was not explicitly provided. + * @see #leftShoulder(EventLoop) + */ + public Trigger leftShoulder() { + return leftShoulder(getScheduler().getDefaultEventLoop()); + } + + /** + * Constructs a Trigger instance around the right shoulder button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the right shoulder button's digital signal attached to + * the given loop. + */ + public Trigger leftShoulder(EventLoop loop) { + return button(Gamepad.Button.kLeftShoulder.value, loop); + } + + /** + * Constructs a Trigger instance around the right shoulder button's digital signal. + * + * @return a Trigger instance representing the right shoulder button's digital signal attached to + * the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the scheduler + * passed to the controller's constructor, or the {@link Scheduler#getDefault default + * scheduler} if a scheduler was not explicitly provided. + * @see #rightShoulder(EventLoop) + */ + public Trigger rightShoulder() { + return rightShoulder(getScheduler().getDefaultEventLoop()); + } + + /** + * Constructs a Trigger instance around the right shoulder button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the right shoulder button's digital signal attached to + * the given loop. + */ + public Trigger rightShoulder(EventLoop loop) { + return button(Gamepad.Button.kRightShoulder.value, loop); + } + + /** + * Constructs a Trigger instance around the D-pad up button's digital signal. + * + * @return a Trigger instance representing the D-pad up button's digital signal attached to the + * {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the scheduler + * passed to the controller's constructor, or the {@link Scheduler#getDefault default + * scheduler} if a scheduler was not explicitly provided. + * @see #dpadUp(EventLoop) + */ + public Trigger dpadUp() { + return dpadUp(getScheduler().getDefaultEventLoop()); + } + + /** + * Constructs a Trigger instance around the D-pad up button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the D-pad up button's digital signal attached to the + * given loop. + */ + public Trigger dpadUp(EventLoop loop) { + return button(Gamepad.Button.kDpadUp.value, loop); + } + + /** + * Constructs a Trigger instance around the D-pad down button's digital signal. + * + * @return a Trigger instance representing the D-pad down button's digital signal attached to the + * {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the scheduler + * passed to the controller's constructor, or the {@link Scheduler#getDefault default + * scheduler} if a scheduler was not explicitly provided. + * @see #dpadDown(EventLoop) + */ + public Trigger dpadDown() { + return dpadDown(getScheduler().getDefaultEventLoop()); + } + + /** + * Constructs a Trigger instance around the D-pad down button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the D-pad down button's digital signal attached to the + * given loop. + */ + public Trigger dpadDown(EventLoop loop) { + return button(Gamepad.Button.kDpadDown.value, loop); + } + + /** + * Constructs a Trigger instance around the D-pad left button's digital signal. + * + * @return a Trigger instance representing the D-pad left button's digital signal attached to the + * {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the scheduler + * passed to the controller's constructor, or the {@link Scheduler#getDefault default + * scheduler} if a scheduler was not explicitly provided. + * @see #dpadLeft(EventLoop) + */ + public Trigger dpadLeft() { + return dpadLeft(getScheduler().getDefaultEventLoop()); + } + + /** + * Constructs a Trigger instance around the D-pad left button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the D-pad left button's digital signal attached to the + * given loop. + */ + public Trigger dpadLeft(EventLoop loop) { + return button(Gamepad.Button.kDpadLeft.value, loop); + } + + /** + * Constructs a Trigger instance around the D-pad right button's digital signal. + * + * @return a Trigger instance representing the D-pad right button's digital signal attached to the + * {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the scheduler + * passed to the controller's constructor, or the {@link Scheduler#getDefault default + * scheduler} if a scheduler was not explicitly provided. + * @see #dpadRight(EventLoop) + */ + public Trigger dpadRight() { + return dpadRight(getScheduler().getDefaultEventLoop()); + } + + /** + * Constructs a Trigger instance around the D-pad right button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the D-pad right button's digital signal attached to the + * given loop. + */ + public Trigger dpadRight(EventLoop loop) { + return button(Gamepad.Button.kDpadRight.value, loop); + } + + /** + * Constructs a Trigger instance around the Miscellaneous 1 button's digital signal. + * + * @return a Trigger instance representing the Miscellaneous 1 button's digital signal attached to + * the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the scheduler + * passed to the controller's constructor, or the {@link Scheduler#getDefault default + * scheduler} if a scheduler was not explicitly provided. + * @see #misc1(EventLoop) + */ + public Trigger misc1() { + return misc1(getScheduler().getDefaultEventLoop()); + } + + /** + * Constructs a Trigger instance around the Miscellaneous 1 button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the Miscellaneous 1 button's digital signal attached to + * the given loop. + */ + public Trigger misc1(EventLoop loop) { + return button(Gamepad.Button.kMisc1.value, loop); + } + + /** + * Constructs a Trigger instance around the Right Paddle 1 button's digital signal. + * + * @return a Trigger instance representing the Right Paddle 1 button's digital signal attached to + * the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the scheduler + * passed to the controller's constructor, or the {@link Scheduler#getDefault default + * scheduler} if a scheduler was not explicitly provided. + * @see #rightPaddle1(EventLoop) + */ + public Trigger rightPaddle1() { + return rightPaddle1(getScheduler().getDefaultEventLoop()); + } + + /** + * Constructs a Trigger instance around the Right Paddle 1 button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the Right Paddle 1 button's digital signal attached to + * the given loop. + */ + public Trigger rightPaddle1(EventLoop loop) { + return button(Gamepad.Button.kRightPaddle1.value, loop); + } + + /** + * Constructs a Trigger instance around the Left Paddle 1 button's digital signal. + * + * @return a Trigger instance representing the Left Paddle 1 button's digital signal attached to + * the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the scheduler + * passed to the controller's constructor, or the {@link Scheduler#getDefault default + * scheduler} if a scheduler was not explicitly provided. + * @see #leftPaddle1(EventLoop) + */ + public Trigger leftPaddle1() { + return leftPaddle1(getScheduler().getDefaultEventLoop()); + } + + /** + * Constructs a Trigger instance around the Left Paddle 1 button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the Left Paddle 1 button's digital signal attached to + * the given loop. + */ + public Trigger leftPaddle1(EventLoop loop) { + return button(Gamepad.Button.kLeftPaddle1.value, loop); + } + + /** + * Constructs a Trigger instance around the Right Paddle 2 button's digital signal. + * + * @return a Trigger instance representing the Right Paddle 2 button's digital signal attached to + * the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the scheduler + * passed to the controller's constructor, or the {@link Scheduler#getDefault default + * scheduler} if a scheduler was not explicitly provided. + * @see #rightPaddle2(EventLoop) + */ + public Trigger rightPaddle2() { + return rightPaddle2(getScheduler().getDefaultEventLoop()); + } + + /** + * Constructs a Trigger instance around the Right Paddle 2 button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the Right Paddle 2 button's digital signal attached to + * the given loop. + */ + public Trigger rightPaddle2(EventLoop loop) { + return button(Gamepad.Button.kRightPaddle2.value, loop); + } + + /** + * Constructs a Trigger instance around the Left Paddle 2 button's digital signal. + * + * @return a Trigger instance representing the Left Paddle 2 button's digital signal attached to + * the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the scheduler + * passed to the controller's constructor, or the {@link Scheduler#getDefault default + * scheduler} if a scheduler was not explicitly provided. + * @see #leftPaddle2(EventLoop) + */ + public Trigger leftPaddle2() { + return leftPaddle2(getScheduler().getDefaultEventLoop()); + } + + /** + * Constructs a Trigger instance around the Left Paddle 2 button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the Left Paddle 2 button's digital signal attached to + * the given loop. + */ + public Trigger leftPaddle2(EventLoop loop) { + return button(Gamepad.Button.kLeftPaddle2.value, loop); + } + + /** + * Constructs a Trigger instance around the Touchpad button's digital signal. + * + * @return a Trigger instance representing the Touchpad button's digital signal attached to the + * {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the scheduler + * passed to the controller's constructor, or the {@link Scheduler#getDefault default + * scheduler} if a scheduler was not explicitly provided. + * @see #touchpad(EventLoop) + */ + public Trigger touchpad() { + return touchpad(getScheduler().getDefaultEventLoop()); + } + + /** + * Constructs a Trigger instance around the Touchpad button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the Touchpad button's digital signal attached to the + * given loop. + */ + public Trigger touchpad(EventLoop loop) { + return button(Gamepad.Button.kTouchpad.value, loop); + } + + /** + * Constructs a Trigger instance around the Miscellaneous 2 button's digital signal. + * + * @return a Trigger instance representing the Miscellaneous 2 button's digital signal attached to + * the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the scheduler + * passed to the controller's constructor, or the {@link Scheduler#getDefault default + * scheduler} if a scheduler was not explicitly provided. + * @see #misc2(EventLoop) + */ + public Trigger misc2() { + return misc2(getScheduler().getDefaultEventLoop()); + } + + /** + * Constructs a Trigger instance around the Miscellaneous 2 button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the Miscellaneous 2 button's digital signal attached to + * the given loop. + */ + public Trigger misc2(EventLoop loop) { + return button(Gamepad.Button.kMisc2.value, loop); + } + + /** + * Constructs a Trigger instance around the Miscellaneous 3 button's digital signal. + * + * @return a Trigger instance representing the Miscellaneous 3 button's digital signal attached to + * the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the scheduler + * passed to the controller's constructor, or the {@link Scheduler#getDefault default + * scheduler} if a scheduler was not explicitly provided. + * @see #misc3(EventLoop) + */ + public Trigger misc3() { + return misc3(getScheduler().getDefaultEventLoop()); + } + + /** + * Constructs a Trigger instance around the Miscellaneous 3 button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the Miscellaneous 3 button's digital signal attached to + * the given loop. + */ + public Trigger misc3(EventLoop loop) { + return button(Gamepad.Button.kMisc3.value, loop); + } + + /** + * Constructs a Trigger instance around the Miscellaneous 4 button's digital signal. + * + * @return a Trigger instance representing the Miscellaneous 4 button's digital signal attached to + * the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the scheduler + * passed to the controller's constructor, or the {@link Scheduler#getDefault default + * scheduler} if a scheduler was not explicitly provided. + * @see #misc4(EventLoop) + */ + public Trigger misc4() { + return misc4(getScheduler().getDefaultEventLoop()); + } + + /** + * Constructs a Trigger instance around the Miscellaneous 4 button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the Miscellaneous 4 button's digital signal attached to + * the given loop. + */ + public Trigger misc4(EventLoop loop) { + return button(Gamepad.Button.kMisc4.value, loop); + } + + /** + * Constructs a Trigger instance around the Miscellaneous 5 button's digital signal. + * + * @return a Trigger instance representing the Miscellaneous 5 button's digital signal attached to + * the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the scheduler + * passed to the controller's constructor, or the {@link Scheduler#getDefault default + * scheduler} if a scheduler was not explicitly provided. + * @see #misc5(EventLoop) + */ + public Trigger misc5() { + return misc5(getScheduler().getDefaultEventLoop()); + } + + /** + * Constructs a Trigger instance around the Miscellaneous 5 button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the Miscellaneous 5 button's digital signal attached to + * the given loop. + */ + public Trigger misc5(EventLoop loop) { + return button(Gamepad.Button.kMisc5.value, loop); + } + + /** + * Constructs a Trigger instance around the Miscellaneous 6 button's digital signal. + * + * @return a Trigger instance representing the Miscellaneous 6 button's digital signal attached to + * the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the scheduler + * passed to the controller's constructor, or the {@link Scheduler#getDefault default + * scheduler} if a scheduler was not explicitly provided. + * @see #misc6(EventLoop) + */ + public Trigger misc6() { + return misc6(getScheduler().getDefaultEventLoop()); + } + + /** + * Constructs a Trigger instance around the Miscellaneous 6 button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return a Trigger instance representing the Miscellaneous 6 button's digital signal attached to + * the given loop. + */ + public Trigger misc6(EventLoop loop) { + return button(Gamepad.Button.kMisc6.value, loop); + } + + /** + * Constructs a Trigger instance around the axis value of the left trigger. The returned trigger + * will be true when the axis value is greater than {@code threshold}. + * + * @param threshold the minimum axis value for the returned {@link Trigger} to be true. This value + * should be in the range [0, 1] where 0 is the unpressed state of the axis. + * @param loop the event loop instance to attach the Trigger to. + * @return a Trigger instance that is true when the left trigger's axis exceeds the provided + * threshold, attached to the given event loop + */ + public Trigger leftTrigger(double threshold, EventLoop loop) { + return axisGreaterThan(Gamepad.Axis.kLeftTrigger.value, threshold, loop); + } + + /** + * Constructs a Trigger instance around the axis value of the left trigger. The returned trigger + * will be true when the axis value is greater than {@code threshold}. + * + * @param threshold the minimum axis value for the returned {@link Trigger} to be true. This value + * should be in the range [0, 1] where 0 is the unpressed state of the axis. + * @return a Trigger instance that is true when the left trigger's axis exceeds the provided + * threshold, attached to the {@link Scheduler#getDefaultEventLoop() default scheduler button + * loop}. + */ + public Trigger leftTrigger(double threshold) { + return leftTrigger(threshold, getScheduler().getDefaultEventLoop()); + } + + /** + * Constructs a Trigger instance around the axis value of the left trigger. The returned trigger + * will be true when the axis value is greater than 0.5. + * + * @return a Trigger instance that is true when the left trigger's axis exceeds 0.5, attached to + * the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the scheduler + * passed to the controller's constructor, or the {@link Scheduler#getDefault default + * scheduler} if a scheduler was not explicitly provided. + */ + public Trigger leftTrigger() { + return leftTrigger(0.5); + } + + /** + * Constructs a Trigger instance around the axis value of the right trigger. The returned trigger + * will be true when the axis value is greater than {@code threshold}. + * + * @param threshold the minimum axis value for the returned {@link Trigger} to be true. This value + * should be in the range [0, 1] where 0 is the unpressed state of the axis. + * @param loop the event loop instance to attach the Trigger to. + * @return a Trigger instance that is true when the right trigger's axis exceeds the provided + * threshold, attached to the given event loop + */ + public Trigger rightTrigger(double threshold, EventLoop loop) { + return axisGreaterThan(Gamepad.Axis.kRightTrigger.value, threshold, loop); + } + + /** + * Constructs a Trigger instance around the axis value of the right trigger. The returned trigger + * will be true when the axis value is greater than {@code threshold}. + * + * @param threshold the minimum axis value for the returned {@link Trigger} to be true. This value + * should be in the range [0, 1] where 0 is the unpressed state of the axis. + * @return a Trigger instance that is true when the right trigger's axis exceeds the provided + * threshold, attached to the {@link Scheduler#getDefaultEventLoop() default scheduler button + * loop}. + */ + public Trigger rightTrigger(double threshold) { + return rightTrigger(threshold, getScheduler().getDefaultEventLoop()); + } + + /** + * Constructs a Trigger instance around the axis value of the right trigger. The returned trigger + * will be true when the axis value is greater than 0.5. + * + * @return a Trigger instance that is true when the right trigger's axis exceeds 0.5, attached to + * the {@link Scheduler#getDefaultEventLoop() default scheduler event loop} on the scheduler + * passed to the controller's constructor, or the {@link Scheduler#getDefault default + * scheduler} if a scheduler was not explicitly provided. + */ + public Trigger rightTrigger() { + return rightTrigger(0.5); + } + + /** + * Get the X axis value of left side of the controller. Right is positive. + * + * @return The axis value. + */ + public double getLeftX() { + return m_hid.getLeftX(); + } + + /** + * Get the Y axis value of left side of the controller. Back is positive. + * + * @return The axis value. + */ + public double getLeftY() { + return m_hid.getLeftY(); + } + + /** + * Get the X axis value of right side of the controller. Right is positive. + * + * @return The axis value. + */ + public double getRightX() { + return m_hid.getRightX(); + } + + /** + * Get the Y axis value of right side of the controller. Back is positive. + * + * @return The axis value. + */ + public double getRightY() { + return m_hid.getRightY(); + } + + /** + * Get the left trigger axis value of the controller. Note that this axis is bound to the range of + * [0, 1] as opposed to the usual [-1, 1]. + * + * @return The axis value. + */ + public double getLeftTriggerAxis() { + return m_hid.getLeftTriggerAxis(); + } + + /** + * Get the right trigger axis value of the controller. Note that this axis is bound to the range + * of [0, 1] as opposed to the usual [-1, 1]. + * + * @return The axis value. + */ + public double getRightTriggerAxis() { + return m_hid.getRightTriggerAxis(); + } +} diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGamepad.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGamepad.java index efa9374b14..646b503074 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGamepad.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGamepad.java @@ -108,10 +108,10 @@ public class CommandGamepad extends CommandGenericHID { * * @return a Trigger instance representing the North Face button's digital signal attached to the * {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}. - * @see #northFacen(EventLoop) + * @see #northFace(EventLoop) */ - public Trigger northFacen() { - return northFacen(CommandScheduler.getInstance().getDefaultButtonLoop()); + public Trigger northFace() { + return northFace(CommandScheduler.getInstance().getDefaultButtonLoop()); } /** @@ -121,8 +121,8 @@ public class CommandGamepad extends CommandGenericHID { * @return a Trigger instance representing the North Face button's digital signal attached to the * given loop. */ - public Trigger northFacen(EventLoop loop) { - return button(Gamepad.Button.kNorthFacen.value, loop); + public Trigger northFace(EventLoop loop) { + return button(Gamepad.Button.kNorthFace.value, loop); } /** diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandGamepad.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandGamepad.cpp index df7dd11b71..b1f16ad4e7 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandGamepad.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandGamepad.cpp @@ -25,8 +25,8 @@ Trigger CommandGamepad::WestFace(frc::EventLoop* loop) const { return Button(frc::Gamepad::Button::kWestFace, loop); } -Trigger CommandGamepad::NorthFacen(frc::EventLoop* loop) const { - return Button(frc::Gamepad::Button::kNorthFacen, loop); +Trigger CommandGamepad::NorthFace(frc::EventLoop* loop) const { + return Button(frc::Gamepad::Button::kNorthFace, loop); } Trigger CommandGamepad::Back(frc::EventLoop* loop) const { diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandGamepad.h b/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandGamepad.h index d02b60bb07..81e088a051 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandGamepad.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandGamepad.h @@ -78,8 +78,8 @@ class CommandGamepad : public CommandGenericHID { * @return a Trigger instance representing the North Face button's * digital signal attached to the given loop. */ - Trigger NorthFacen(frc::EventLoop* loop = CommandScheduler::GetInstance() - .GetDefaultButtonLoop()) const; + Trigger NorthFace(frc::EventLoop* loop = CommandScheduler::GetInstance() + .GetDefaultButtonLoop()) const; /** * Constructs a Trigger instance around the Back button's diff --git a/wpilibc/src/main/native/cpp/Gamepad.cpp b/wpilibc/src/main/native/cpp/Gamepad.cpp index b215c8b528..897f712995 100644 --- a/wpilibc/src/main/native/cpp/Gamepad.cpp +++ b/wpilibc/src/main/native/cpp/Gamepad.cpp @@ -107,20 +107,20 @@ BooleanEvent Gamepad::WestFace(EventLoop* loop) const { return BooleanEvent(loop, [this]() { return this->GetWestFaceButton(); }); } -bool Gamepad::GetNorthFacenButton() const { - return GetRawButton(Button::kNorthFacen); +bool Gamepad::GetNorthFaceButton() const { + return GetRawButton(Button::kNorthFace); } -bool Gamepad::GetNorthFacenButtonPressed() { - return GetRawButtonPressed(Button::kNorthFacen); +bool Gamepad::GetNorthFaceButtonPressed() { + return GetRawButtonPressed(Button::kNorthFace); } -bool Gamepad::GetNorthFacenButtonReleased() { - return GetRawButtonReleased(Button::kNorthFacen); +bool Gamepad::GetNorthFaceButtonReleased() { + return GetRawButtonReleased(Button::kNorthFace); } -BooleanEvent Gamepad::NorthFacen(EventLoop* loop) const { - return BooleanEvent(loop, [this]() { return this->GetNorthFacenButton(); }); +BooleanEvent Gamepad::NorthFace(EventLoop* loop) const { + return BooleanEvent(loop, [this]() { return this->GetNorthFaceButton(); }); } bool Gamepad::GetBackButton() const { @@ -512,8 +512,8 @@ void Gamepad::InitSendable(wpi::SendableBuilder& builder) { "WestFace", [this] { return GetButtonForSendable(Button::kWestFace); }, nullptr); builder.AddBooleanProperty( - "NorthFacen", - [this] { return GetButtonForSendable(Button::kNorthFacen); }, nullptr); + "NorthFace", [this] { return GetButtonForSendable(Button::kNorthFace); }, + nullptr); builder.AddBooleanProperty( "Back", [this] { return GetButtonForSendable(Button::kBack); }, nullptr); builder.AddBooleanProperty( diff --git a/wpilibc/src/main/native/cpp/simulation/GamepadSim.cpp b/wpilibc/src/main/native/cpp/simulation/GamepadSim.cpp index 1b265e5e4d..8d993b05c0 100644 --- a/wpilibc/src/main/native/cpp/simulation/GamepadSim.cpp +++ b/wpilibc/src/main/native/cpp/simulation/GamepadSim.cpp @@ -57,8 +57,8 @@ void GamepadSim::SetWestFaceButton(bool value) { SetRawButton(Gamepad::Button::kWestFace, value); } -void GamepadSim::SetNorthFacenButton(bool value) { - SetRawButton(Gamepad::Button::kNorthFacen, value); +void GamepadSim::SetNorthFaceButton(bool value) { + SetRawButton(Gamepad::Button::kNorthFace, value); } void GamepadSim::SetBackButton(bool value) { diff --git a/wpilibc/src/main/native/include/frc/Gamepad.h b/wpilibc/src/main/native/include/frc/Gamepad.h index 8c72c33684..94b88a0e66 100644 --- a/wpilibc/src/main/native/include/frc/Gamepad.h +++ b/wpilibc/src/main/native/include/frc/Gamepad.h @@ -228,21 +228,21 @@ class Gamepad : public GenericHID, * * @return The state of the button. */ - bool GetNorthFacenButton() const; + bool GetNorthFaceButton() const; /** * Whether the North Face button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ - bool GetNorthFacenButtonPressed(); + bool GetNorthFaceButtonPressed(); /** * Whether the North Face button was released since the last check. * * @return Whether the button was released since the last check. */ - bool GetNorthFacenButtonReleased(); + bool GetNorthFaceButtonReleased(); /** * Constructs an event instance around the North Face button's @@ -252,7 +252,7 @@ class Gamepad : public GenericHID, * @return an event instance representing the North Face button's * digital signal attached to the given loop. */ - BooleanEvent NorthFacen(EventLoop* loop) const; + BooleanEvent NorthFace(EventLoop* loop) const; /** * Read the value of the Back button on the controller. @@ -945,7 +945,7 @@ class Gamepad : public GenericHID, /// West Face button. static constexpr int kWestFace = 2; /// North Face button. - static constexpr int kNorthFacen = 3; + static constexpr int kNorthFace = 3; /// Back button. static constexpr int kBack = 4; /// Guide button. diff --git a/wpilibc/src/main/native/include/frc/simulation/GamepadSim.h b/wpilibc/src/main/native/include/frc/simulation/GamepadSim.h index b0162684da..0c9eaa115d 100644 --- a/wpilibc/src/main/native/include/frc/simulation/GamepadSim.h +++ b/wpilibc/src/main/native/include/frc/simulation/GamepadSim.h @@ -99,7 +99,7 @@ class GamepadSim : public GenericHIDSim { * * @param value the new value */ - void SetNorthFacenButton(bool value); + void SetNorthFaceButton(bool value); /** * Change the value of the Back button on the controller. diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Gamepad.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Gamepad.java index 4c235aa1e5..853f8cb59f 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Gamepad.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Gamepad.java @@ -31,7 +31,7 @@ public class Gamepad extends GenericHID implements Sendable { /** West Face button. */ kWestFace(2), /** North Face button. */ - kNorthFacen(3), + kNorthFace(3), /** Back button. */ kBack(4), /** Guide button. */ @@ -376,8 +376,8 @@ public class Gamepad extends GenericHID implements Sendable { * * @return The state of the button. */ - public boolean getNorthFacenButton() { - return getRawButton(Button.kNorthFacen.value); + public boolean getNorthFaceButton() { + return getRawButton(Button.kNorthFace.value); } /** @@ -385,8 +385,8 @@ public class Gamepad extends GenericHID implements Sendable { * * @return Whether the button was pressed since the last check. */ - public boolean getNorthFacenButtonPressed() { - return getRawButtonPressed(Button.kNorthFacen.value); + public boolean getNorthFaceButtonPressed() { + return getRawButtonPressed(Button.kNorthFace.value); } /** @@ -394,8 +394,8 @@ public class Gamepad extends GenericHID implements Sendable { * * @return Whether the button was released since the last check. */ - public boolean getNorthFacenButtonReleased() { - return getRawButtonReleased(Button.kNorthFacen.value); + public boolean getNorthFaceButtonReleased() { + return getRawButtonReleased(Button.kNorthFace.value); } /** @@ -405,8 +405,8 @@ public class Gamepad extends GenericHID implements Sendable { * @return an event instance representing the North Face button's digital signal attached to the * given loop. */ - public BooleanEvent northFacen(EventLoop loop) { - return button(Button.kNorthFacen.value, loop); + public BooleanEvent northFace(EventLoop loop) { + return button(Button.kNorthFace.value, loop); } /** @@ -1272,7 +1272,7 @@ public class Gamepad extends GenericHID implements Sendable { builder.addBooleanProperty( "WestFace", () -> getButtonForSendable(Button.kWestFace.value), null); builder.addBooleanProperty( - "NorthFacen", () -> getButtonForSendable(Button.kNorthFacen.value), null); + "NorthFace", () -> getButtonForSendable(Button.kNorthFace.value), null); builder.addBooleanProperty("Back", () -> getButtonForSendable(Button.kBack.value), null); builder.addBooleanProperty("Guide", () -> getButtonForSendable(Button.kGuide.value), null); builder.addBooleanProperty("Start", () -> getButtonForSendable(Button.kStart.value), null); diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/GamepadSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/GamepadSim.java index 3502e1cccc..d5681c5679 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/GamepadSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/GamepadSim.java @@ -120,8 +120,8 @@ public class GamepadSim extends GenericHIDSim { * * @param value the new value */ - public void setNorthFacenButton(boolean value) { - setRawButton(Gamepad.Button.kNorthFacen.value, value); + public void setNorthFaceButton(boolean value) { + setRawButton(Gamepad.Button.kNorthFace.value, value); } /**