SCRIPT Move java files

This commit is contained in:
PJ Reiniger
2025-11-07 19:55:40 -05:00
committed by Peter Johnson
parent 7ca1be9bae
commit c350c5f112
1486 changed files with 0 additions and 0 deletions

View File

@@ -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();
}
}

View File

@@ -0,0 +1,343 @@
// 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.math.Pair;
import edu.wpi.first.wpilibj.DriverStation.POVDirection;
import edu.wpi.first.wpilibj.GenericHID;
import edu.wpi.first.wpilibj.event.EventLoop;
import java.util.HashMap;
import java.util.Map;
import org.wpilib.commands3.Scheduler;
import org.wpilib.commands3.Trigger;
/**
* A version of {@link GenericHID} with {@link Trigger} factories for command-based.
*
* @see GenericHID
*/
public class CommandGenericHID {
private final Scheduler m_scheduler;
private final GenericHID m_hid;
private final Map<EventLoop, Map<Integer, Trigger>> m_buttonCache = new HashMap<>();
private final Map<EventLoop, Map<Pair<Integer, Double>, Trigger>> m_axisLessThanCache =
new HashMap<>();
private final Map<EventLoop, Map<Pair<Integer, Double>, Trigger>> m_axisGreaterThanCache =
new HashMap<>();
private final Map<EventLoop, Map<Pair<Integer, Double>, Trigger>>
m_axisMagnitudeGreaterThanCache = new HashMap<>();
private final Map<EventLoop, Map<Integer, Trigger>> m_povCache = new HashMap<>();
/**
* Construct an instance of a device.
*
* @param scheduler The scheduler that should execute the triggered commands.
* @param port The port index on the Driver Station that the device is plugged into.
*/
public CommandGenericHID(Scheduler scheduler, int port) {
m_scheduler = scheduler;
m_hid = new GenericHID(port);
}
/**
* Construct an instance of a device.
*
* @param port The port index on the Driver Station that the device is plugged into.
*/
public CommandGenericHID(int port) {
this(Scheduler.getDefault(), port);
}
/**
* Get the underlying GenericHID object.
*
* @return the wrapped GenericHID object
*/
public GenericHID getHID() {
return m_hid;
}
/**
* Constructs an event instance around this button's digital signal.
*
* @param button the button index
* @return an event instance representing the button's digital signal attached to the {@link
* Scheduler#getDefaultEventLoop() default scheduler button loop}.
* @see #button(int, EventLoop)
*/
public Trigger button(int button) {
return button(button, m_scheduler.getDefaultEventLoop());
}
/**
* Constructs an event instance around this button's digital signal.
*
* @param button the button index
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the button's digital signal attached to the given loop.
*/
public Trigger button(int button, EventLoop loop) {
var cache = m_buttonCache.computeIfAbsent(loop, k -> new HashMap<>());
return cache.computeIfAbsent(
button, k -> new Trigger(m_scheduler, loop, () -> m_hid.getRawButton(k)));
}
/**
* Constructs a Trigger instance based around this angle of the default (index 0) POV on the HID,
* attached to {@link Scheduler#getDefaultEventLoop() the default command scheduler button loop}.
*
* @param angle POV angle
* @return a Trigger instance based around this angle of a POV on the HID.
*/
public Trigger pov(POVDirection angle) {
return pov(0, angle, m_scheduler.getDefaultEventLoop());
}
/**
* Constructs a Trigger instance based around this angle of a POV on the HID.
*
* @param pov index of the POV to read (starting at 0). Defaults to 0.
* @param angle POV angle
* @param loop the event loop instance to attach the event to. Defaults to {@link
* Scheduler#getDefaultEventLoop() the default command scheduler button loop}.
* @return a Trigger instance based around this angle of a POV on the HID.
*/
public Trigger pov(int pov, POVDirection angle, EventLoop loop) {
var cache = m_povCache.computeIfAbsent(loop, k -> new HashMap<>());
// angle.value is a 4 bit bitfield
return cache.computeIfAbsent(
pov * 16 + angle.value,
k -> new Trigger(m_scheduler, loop, () -> m_hid.getPOV(pov) == angle));
}
/**
* Constructs a Trigger instance based around the 0 degree angle (up) of the default (index 0) POV
* on the HID, attached to {@link Scheduler#getDefaultEventLoop() the default command scheduler
* button loop}.
*
* @return a Trigger instance based around the 0 degree angle of a POV on the HID.
*/
public Trigger povUp() {
return pov(POVDirection.Up);
}
/**
* Constructs a Trigger instance based around the 45 degree angle (right up) of the default (index
* 0) POV on the HID, attached to {@link Scheduler#getDefaultEventLoop() the default command
* scheduler button loop}.
*
* @return a Trigger instance based around the 45 degree angle of a POV on the HID.
*/
public Trigger povUpRight() {
return pov(POVDirection.UpRight);
}
/**
* Constructs a Trigger instance based around the 90 degree angle (right) of the default (index 0)
* POV on the HID, attached to {@link Scheduler#getDefaultEventLoop() the default command
* scheduler button loop}.
*
* @return a Trigger instance based around the 90 degree angle of a POV on the HID.
*/
public Trigger povRight() {
return pov(POVDirection.Right);
}
/**
* Constructs a Trigger instance based around the 135 degree angle (right down) of the default
* (index 0) POV on the HID, attached to {@link Scheduler#getDefaultEventLoop() the default
* command scheduler button loop}.
*
* @return a Trigger instance based around the 135 degree angle of a POV on the HID.
*/
public Trigger povDownRight() {
return pov(POVDirection.DownRight);
}
/**
* Constructs a Trigger instance based around the 180 degree angle (down) of the default (index 0)
* POV on the HID, attached to {@link Scheduler#getDefaultEventLoop() the default command
* scheduler button loop}.
*
* @return a Trigger instance based around the 180 degree angle of a POV on the HID.
*/
public Trigger povDown() {
return pov(POVDirection.Down);
}
/**
* Constructs a Trigger instance based around the 225 degree angle (down left) of the default
* (index 0) POV on the HID, attached to {@link Scheduler#getDefaultEventLoop() the default
* command scheduler button loop}.
*
* @return a Trigger instance based around the 225 degree angle of a POV on the HID.
*/
public Trigger povDownLeft() {
return pov(POVDirection.DownLeft);
}
/**
* Constructs a Trigger instance based around the 270 degree angle (left) of the default (index 0)
* POV on the HID, attached to {@link Scheduler#getDefaultEventLoop() the default command
* scheduler button loop}.
*
* @return a Trigger instance based around the 270 degree angle of a POV on the HID.
*/
public Trigger povLeft() {
return pov(POVDirection.Left);
}
/**
* Constructs a Trigger instance based around the 315 degree angle (left up) of the default (index
* 0) POV on the HID, attached to {@link Scheduler#getDefaultEventLoop() the default command
* scheduler button loop}.
*
* @return a Trigger instance based around the 315 degree angle of a POV on the HID.
*/
public Trigger povUpLeft() {
return pov(POVDirection.UpLeft);
}
/**
* Constructs a Trigger instance based around the center (not pressed) position of the default
* (index 0) POV on the HID, attached to {@link Scheduler#getDefaultEventLoop() the default
* command scheduler button loop}.
*
* @return a Trigger instance based around the center position of a POV on the HID.
*/
public Trigger povCenter() {
return pov(POVDirection.Center);
}
/**
* Constructs a Trigger instance that is true when the axis value is less than {@code threshold},
* attached to {@link Scheduler#getDefaultEventLoop() the default command scheduler button loop}.
*
* @param axis The axis to read, starting at 0
* @param threshold The value below which this trigger should return true.
* @return a Trigger instance that is true when the axis value is less than the provided
* threshold.
*/
public Trigger axisLessThan(int axis, double threshold) {
return axisLessThan(axis, threshold, m_scheduler.getDefaultEventLoop());
}
/**
* Constructs a Trigger instance that is true when the axis value is less than {@code threshold},
* attached to the given loop.
*
* @param axis The axis to read, starting at 0
* @param threshold The value below which this trigger should return true.
* @param loop the event loop instance to attach the trigger to
* @return a Trigger instance that is true when the axis value is less than the provided
* threshold.
*/
public Trigger axisLessThan(int axis, double threshold, EventLoop loop) {
var cache = m_axisLessThanCache.computeIfAbsent(loop, k -> new HashMap<>());
return cache.computeIfAbsent(
Pair.of(axis, threshold),
k -> new Trigger(m_scheduler, loop, () -> getRawAxis(axis) < threshold));
}
/**
* Constructs a Trigger instance that is true when the axis value is less than {@code threshold},
* attached to {@link Scheduler#getDefaultEventLoop() the default command scheduler button loop}.
*
* @param axis The axis to read, starting at 0
* @param threshold The value above which this trigger should return true.
* @return a Trigger instance that is true when the axis value is greater than the provided
* threshold.
*/
public Trigger axisGreaterThan(int axis, double threshold) {
return axisGreaterThan(axis, threshold, m_scheduler.getDefaultEventLoop());
}
/**
* Constructs a Trigger instance that is true when the axis value is greater than {@code
* threshold}, attached to the given loop.
*
* @param axis The axis to read, starting at 0
* @param threshold The value above which this trigger should return true.
* @param loop the event loop instance to attach the trigger to.
* @return a Trigger instance that is true when the axis value is greater than the provided
* threshold.
*/
public Trigger axisGreaterThan(int axis, double threshold, EventLoop loop) {
var cache = m_axisGreaterThanCache.computeIfAbsent(loop, k -> new HashMap<>());
return cache.computeIfAbsent(
Pair.of(axis, threshold),
k -> new Trigger(m_scheduler, loop, () -> getRawAxis(axis) > threshold));
}
/**
* Constructs a Trigger instance that is true when the axis magnitude value is greater than {@code
* threshold}, attached to the given loop.
*
* @param axis The axis to read, starting at 0
* @param threshold The value above which this trigger should return true.
* @param loop the event loop instance to attach the trigger to.
* @return a Trigger instance that is true when the axis magnitude value is greater than the
* provided threshold.
*/
public Trigger axisMagnitudeGreaterThan(int axis, double threshold, EventLoop loop) {
var cache = m_axisMagnitudeGreaterThanCache.computeIfAbsent(loop, k -> new HashMap<>());
return cache.computeIfAbsent(
Pair.of(axis, threshold),
k -> new Trigger(m_scheduler, loop, () -> Math.abs(getRawAxis(axis)) > threshold));
}
/**
* Constructs a Trigger instance that is true when the axis magnitude value is greater than {@code
* threshold}, attached to {@link Scheduler#getDefaultEventLoop() the default command scheduler
* button loop}.
*
* @param axis The axis to read, starting at 0
* @param threshold The value above which this trigger should return true.
* @return a Trigger instance that is true when the deadbanded axis value is active (non-zero).
*/
public Trigger axisMagnitudeGreaterThan(int axis, double threshold) {
return axisMagnitudeGreaterThan(axis, threshold, m_scheduler.getDefaultEventLoop());
}
/**
* Get the value of the axis.
*
* @param axis The axis to read, starting at 0.
* @return The value of the axis.
*/
public double getRawAxis(int axis) {
return m_hid.getRawAxis(axis);
}
/**
* Set the rumble output for the HID. The DS currently supports 2 rumble values, left rumble and
* right rumble.
*
* @param type Which rumble value to set
* @param value The normalized value (0 to 1) to set the rumble to
*/
public void setRumble(GenericHID.RumbleType type, double value) {
m_hid.setRumble(type, value);
}
/**
* Get if the HID is connected.
*
* @return true if the HID is connected
*/
public boolean isConnected() {
return m_hid.isConnected();
}
/**
* Gets the scheduler that should execute the triggered commands. This scheduler is set in the
* constructor, defaulting to {@link Scheduler#getDefault()} if one was not provided.
*
* @return the scheduler that should execute the triggered commands
*/
protected final Scheduler getScheduler() {
return m_scheduler;
}
}

View File

@@ -0,0 +1,275 @@
// 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.Joystick;
import edu.wpi.first.wpilibj.event.EventLoop;
import org.wpilib.commands3.Scheduler;
import org.wpilib.commands3.Trigger;
/**
* A version of {@link Joystick} with {@link Trigger} factories for command-based.
*
* @see Joystick
*/
public class CommandJoystick extends CommandGenericHID {
private final Joystick m_hid;
/**
* Construct an instance of a controller.
*
* @param port The port index on the Driver Station that the controller is plugged into.
*/
public CommandJoystick(int port) {
super(port);
m_hid = new Joystick(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 CommandJoystick(Scheduler scheduler, int port) {
super(scheduler, port);
m_hid = new Joystick(port);
}
/**
* Get the underlying GenericHID object.
*
* @return the wrapped GenericHID object
*/
@Override
public Joystick getHID() {
return m_hid;
}
/**
* Constructs an event instance around the trigger button's digital signal.
*
* @return an event instance representing the trigger button's digital signal attached to the
* {@link Scheduler#getDefaultEventLoop() default scheduler button loop}.
* @see #trigger(EventLoop)
*/
public Trigger trigger() {
return trigger(getScheduler().getDefaultEventLoop());
}
/**
* Constructs an event instance around the trigger button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the trigger button's digital signal attached to the
* given loop.
*/
public Trigger trigger(EventLoop loop) {
return button(Joystick.ButtonType.kTrigger.value, loop);
}
/**
* Constructs an event instance around the top button's digital signal.
*
* @return an event instance representing the top button's digital signal attached to the {@link
* Scheduler#getDefaultEventLoop() default scheduler button loop}.
* @see #top(EventLoop)
*/
public Trigger top() {
return top(getScheduler().getDefaultEventLoop());
}
/**
* Constructs an event instance around the top button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the top button's digital signal attached to the given
* loop.
*/
public Trigger top(EventLoop loop) {
return button(Joystick.ButtonType.kTop.value, loop);
}
/**
* Set the channel associated with the X axis.
*
* @param channel The channel to set the axis to.
*/
public void setXChannel(int channel) {
m_hid.setXChannel(channel);
}
/**
* Set the channel associated with the Y axis.
*
* @param channel The channel to set the axis to.
*/
public void setYChannel(int channel) {
m_hid.setYChannel(channel);
}
/**
* Set the channel associated with the Z axis.
*
* @param channel The channel to set the axis to.
*/
public void setZChannel(int channel) {
m_hid.setZChannel(channel);
}
/**
* Set the channel associated with the throttle axis.
*
* @param channel The channel to set the axis to.
*/
public void setThrottleChannel(int channel) {
m_hid.setThrottleChannel(channel);
}
/**
* Set the channel associated with the twist axis.
*
* @param channel The channel to set the axis to.
*/
public void setTwistChannel(int channel) {
m_hid.setTwistChannel(channel);
}
/**
* Get the channel currently associated with the X axis.
*
* @return The channel for the axis.
*/
public int getXChannel() {
return m_hid.getXChannel();
}
/**
* Get the channel currently associated with the Y axis.
*
* @return The channel for the axis.
*/
public int getYChannel() {
return m_hid.getYChannel();
}
/**
* Get the channel currently associated with the Z axis.
*
* @return The channel for the axis.
*/
public int getZChannel() {
return m_hid.getZChannel();
}
/**
* Get the channel currently associated with the twist axis.
*
* @return The channel for the axis.
*/
public int getTwistChannel() {
return m_hid.getTwistChannel();
}
/**
* Get the channel currently associated with the throttle axis.
*
* @return The channel for the axis.
*/
public int getThrottleChannel() {
return m_hid.getThrottleChannel();
}
/**
* Get the x position of the HID.
*
* <p>This depends on the mapping of the joystick connected to the current port. On most
* joysticks, positive is to the right.
*
* @return the x position
*/
public double getX() {
return m_hid.getX();
}
/**
* Get the y position of the HID.
*
* <p>This depends on the mapping of the joystick connected to the current port. On most
* joysticks, positive is to the back.
*
* @return the y position
*/
public double getY() {
return m_hid.getY();
}
/**
* Get the z position of the HID.
*
* @return the z position
*/
public double getZ() {
return m_hid.getZ();
}
/**
* Get the twist value of the current joystick. This depends on the mapping of the joystick
* connected to the current port.
*
* @return The Twist value of the joystick.
*/
public double getTwist() {
return m_hid.getTwist();
}
/**
* Get the throttle value of the current joystick. This depends on the mapping of the joystick
* connected to the current port.
*
* @return The Throttle value of the joystick.
*/
public double getThrottle() {
return m_hid.getThrottle();
}
/**
* Get the magnitude of the vector formed by the joystick's current position relative to its
* origin.
*
* @return The magnitude of the direction vector
*/
public double getMagnitude() {
return m_hid.getMagnitude();
}
/**
* Get the direction of the vector formed by the joystick and its origin in radians. 0 is forward
* and clockwise is positive. (Straight right is π/2.)
*
* @return The direction of the vector in radians
*/
public double getDirectionRadians() {
// https://docs.wpilib.org/en/stable/docs/software/basic-programming/coordinate-system.html#joystick-and-controller-coordinate-system
// A positive rotation around the X axis moves the joystick right, and a
// positive rotation around the Y axis moves the joystick backward. When
// treating them as translations, 0 radians is measured from the right
// direction, and angle increases clockwise.
//
// It's rotated 90 degrees CCW (y is negated and the arguments are reversed)
// so that 0 radians is forward.
return m_hid.getDirectionRadians();
}
/**
* Get the direction of the vector formed by the joystick and its origin in degrees. 0 is forward
* and clockwise is positive. (Straight right is 90.)
*
* @return The direction of the vector in degrees
*/
public double getDirectionDegrees() {
return m_hid.getDirectionDegrees();
}
}

View File

@@ -0,0 +1,61 @@
// 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 java.util.concurrent.atomic.AtomicBoolean;
import org.wpilib.commands3.Trigger;
/**
* This class is intended to be used within a program. The programmer can manually set its value.
* Also includes a setting for whether it should invert its value.
*/
public class InternalButton extends Trigger {
// need to be references, so they can be mutated after being captured in the constructor.
private final AtomicBoolean m_pressed;
private final AtomicBoolean m_inverted;
/** Creates an InternalButton that is not inverted. */
public InternalButton() {
this(false);
}
/**
* Creates an InternalButton which is inverted depending on the input.
*
* @param inverted if false, then this button is pressed when set to true, otherwise it is pressed
* when set to false.
*/
public InternalButton(boolean inverted) {
this(new AtomicBoolean(), new AtomicBoolean(inverted));
}
/*
* Mock constructor so the AtomicBoolean objects can be constructed before the super
* constructor invocation.
*/
private InternalButton(AtomicBoolean state, AtomicBoolean inverted) {
super(() -> state.get() != inverted.get());
m_pressed = state;
m_inverted = inverted;
}
/**
* Sets whether to invert button state.
*
* @param inverted Whether button state should be inverted.
*/
public void setInverted(boolean inverted) {
m_inverted.set(inverted);
}
/**
* Sets whether button is pressed.
*
* @param pressed Whether button is pressed.
*/
public void setPressed(boolean pressed) {
m_pressed.set(pressed);
}
}

View File

@@ -0,0 +1,24 @@
// 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 static edu.wpi.first.util.ErrorMessages.requireNonNullParam;
import edu.wpi.first.wpilibj.GenericHID;
import org.wpilib.commands3.Trigger;
/** A {@link Trigger} that gets its state from a {@link GenericHID}. */
public class JoystickButton extends Trigger {
/**
* Creates a joystick button for triggering commands.
*
* @param joystick The GenericHID object that has the button (e.g. Joystick, KinectStick, etc)
* @param buttonNumber The button number (see {@link GenericHID#getRawButton(int) }
*/
public JoystickButton(GenericHID joystick, int buttonNumber) {
super(() -> joystick.getRawButton(buttonNumber));
requireNonNullParam(joystick, "joystick", "JoystickButton");
}
}

View File

@@ -0,0 +1,66 @@
// 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 static edu.wpi.first.util.ErrorMessages.requireNonNullParam;
import edu.wpi.first.networktables.BooleanSubscriber;
import edu.wpi.first.networktables.BooleanTopic;
import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.networktables.NetworkTableInstance;
import org.wpilib.commands3.Trigger;
/** A {@link Trigger} that uses a {@link NetworkTable} boolean field. */
public class NetworkButton extends Trigger {
/**
* Creates a NetworkButton that commands can be bound to.
*
* @param topic The boolean topic that contains the value.
*/
public NetworkButton(BooleanTopic topic) {
this(topic.subscribe(false));
}
/**
* Creates a NetworkButton that commands can be bound to.
*
* @param sub The boolean subscriber that provides the value.
*/
public NetworkButton(BooleanSubscriber sub) {
super(() -> sub.getTopic().getInstance().isConnected() && sub.get());
requireNonNullParam(sub, "sub", "NetworkButton");
}
/**
* Creates a NetworkButton that commands can be bound to.
*
* @param table The table where the networktable value is located.
* @param field The field that is the value.
*/
public NetworkButton(NetworkTable table, String field) {
this(table.getBooleanTopic(field));
}
/**
* Creates a NetworkButton that commands can be bound to.
*
* @param table The table where the networktable value is located.
* @param field The field that is the value.
*/
public NetworkButton(String table, String field) {
this(NetworkTableInstance.getDefault(), table, field);
}
/**
* Creates a NetworkButton that commands can be bound to.
*
* @param inst The NetworkTable instance to use
* @param table The table where the networktable value is located.
* @param field The field that is the value.
*/
public NetworkButton(NetworkTableInstance inst, String table, String field) {
this(inst.getTable(table), field);
}
}

View File

@@ -0,0 +1,36 @@
// 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 static edu.wpi.first.util.ErrorMessages.requireNonNullParam;
import edu.wpi.first.wpilibj.DriverStation.POVDirection;
import edu.wpi.first.wpilibj.GenericHID;
import org.wpilib.commands3.Trigger;
/** A {@link Trigger} that gets its state from a POV on a {@link GenericHID}. */
public class POVButton extends Trigger {
/**
* Creates a POV button for triggering commands.
*
* @param joystick The GenericHID object that has the POV
* @param angle The desired angle
* @param povNumber The POV number (see {@link GenericHID#getPOV(int)})
*/
public POVButton(GenericHID joystick, POVDirection angle, int povNumber) {
super(() -> joystick.getPOV(povNumber) == angle);
requireNonNullParam(joystick, "joystick", "POVButton");
}
/**
* Creates a POV button for triggering commands. By default, acts on POV 0
*
* @param joystick The GenericHID object that has the POV
* @param angle The desired angle
*/
public POVButton(GenericHID joystick, POVDirection angle) {
this(joystick, angle, 0);
}
}

View File

@@ -0,0 +1,53 @@
// 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.DriverStation;
import org.wpilib.commands3.Trigger;
/**
* A class containing static {@link Trigger} factories for running callbacks when the robot mode
* changes.
*/
public final class RobotModeTriggers {
// Utility class
private RobotModeTriggers() {}
/**
* Returns a trigger that is true when the robot is enabled in autonomous mode.
*
* @return A trigger that is true when the robot is enabled in autonomous mode.
*/
public static Trigger autonomous() {
return new Trigger(DriverStation::isAutonomousEnabled);
}
/**
* Returns a trigger that is true when the robot is enabled in teleop mode.
*
* @return A trigger that is true when the robot is enabled in teleop mode.
*/
public static Trigger teleop() {
return new Trigger(DriverStation::isTeleopEnabled);
}
/**
* Returns a trigger that is true when the robot is disabled.
*
* @return A trigger that is true when the robot is disabled.
*/
public static Trigger disabled() {
return new Trigger(DriverStation::isDisabled);
}
/**
* Returns a trigger that is true when the robot is enabled in test mode.
*
* @return A trigger that is true when the robot is enabled in test mode.
*/
public static Trigger test() {
return new Trigger(DriverStation::isTestEnabled);
}
}