[wpilib,commands] Use Jinja to generate HID classes (#6274)

This commit is contained in:
Gold856
2024-06-08 12:59:07 -04:00
committed by GitHub
parent a0efc9ca31
commit 65c6306047
75 changed files with 7622 additions and 4546 deletions

View File

@@ -1,726 +0,0 @@
// 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 edu.wpi.first.wpilibj;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.event.BooleanEvent;
import edu.wpi.first.wpilibj.event.EventLoop;
/**
* Handle input from PS4 controllers connected to the Driver Station.
*
* <p>This class handles PS4 input that comes from the Driver Station. Each time a value is
* requested the most recent value is returned. There is a single class instance for each controller
* and the mapping of ports to hardware buttons depends on the code in the Driver Station.
*
* <p>Only first party controllers from Sony are guaranteed to have the correct mapping, and only
* through the official NI DS. Sim is not guaranteed to have the same mapping, as well as any 3rd
* party controllers.
*/
public class PS4Controller extends GenericHID {
/**
* Construct an instance of a device.
*
* @param port The port index on the Driver Station that the device is plugged into.
*/
public PS4Controller(int port) {
super(port);
HAL.report(tResourceType.kResourceType_PS4Controller, port + 1);
}
/** Represents a digital button on a PS4Controller. */
public enum Button {
/** Square button. */
kSquare(1),
/** X button. */
kCross(2),
/** Circle button. */
kCircle(3),
/** Triangle button. */
kTriangle(4),
/** Left Trigger 1 button. */
kL1(5),
/** Right Trigger 1 button. */
kR1(6),
/** Left Trigger 2 button. */
kL2(7),
/** Right Trigger 2 button. */
kR2(8),
/** Share button. */
kShare(9),
/** Option button. */
kOptions(10),
/** Left stick button. */
kL3(11),
/** Right stick button. */
kR3(12),
/** PlayStation button. */
kPS(13),
/** Touchpad click button. */
kTouchpad(14);
/** Button value. */
public final int value;
Button(int index) {
this.value = index;
}
/**
* Get the human-friendly name of the button, matching the relevant methods. This is done by
* stripping the leading `k`, and if not the touchpad append `Button`.
*
* <p>Primarily used for automated unit tests.
*
* @return the human-friendly name of the button.
*/
@Override
public String toString() {
var name = this.name().substring(1); // Remove leading `k`
if (this == kTouchpad) {
return name;
}
return name + "Button";
}
}
/** Represents an axis on a PS4Controller. */
public enum Axis {
/** Left X axis. */
kLeftX(0),
/** Left Y axis. */
kLeftY(1),
/** Right X axis. */
kRightX(2),
/** Right Y axis. */
kRightY(5),
/** Left Trigger 2. */
kL2(3),
/** Right Trigger 2. */
kR2(4);
/** Axis value. */
public final int value;
Axis(int index) {
value = index;
}
/**
* Get the human-friendly name of the axis, matching the relevant methods. This is done by
* stripping the leading `k`, and if one of L2/R2 append `Axis`.
*
* <p>Primarily used for automated unit tests.
*
* @return the human-friendly name of the axis.
*/
@Override
public String toString() {
var name = this.name().substring(1); // Remove leading `k`
if (name.endsWith("2")) {
return name + "Axis";
}
return name;
}
}
/**
* Get the X axis value of left side of the controller.
*
* @return the axis value.
*/
public double getLeftX() {
return getRawAxis(Axis.kLeftX.value);
}
/**
* Get the X axis value of right side of the controller.
*
* @return the axis value.
*/
public double getRightX() {
return getRawAxis(Axis.kRightX.value);
}
/**
* Get the Y axis value of left side of the controller.
*
* @return the axis value.
*/
public double getLeftY() {
return getRawAxis(Axis.kLeftY.value);
}
/**
* Get the Y axis value of right side of the controller.
*
* @return the axis value.
*/
public double getRightY() {
return getRawAxis(Axis.kRightY.value);
}
/**
* Get the L2 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 getL2Axis() {
return getRawAxis(Axis.kL2.value);
}
/**
* Get the R2 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 getR2Axis() {
return getRawAxis(Axis.kR2.value);
}
/**
* Read the value of the left trigger button on the controller.
*
* @return The state of the button.
*/
public boolean getL2Button() {
return getRawButton(Button.kL2.value);
}
/**
* Read the value of the right trigger button on the controller.
*
* @return The state of the button.
*/
public boolean getR2Button() {
return getRawButton(Button.kR2.value);
}
/**
* Whether the L2 button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getL2ButtonPressed() {
return getRawButtonPressed(Button.kL2.value);
}
/**
* Whether the R2 button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getR2ButtonPressed() {
return getRawButtonPressed(Button.kR2.value);
}
/**
* Whether the L2 button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getL2ButtonReleased() {
return getRawButtonReleased(Button.kL2.value);
}
/**
* Whether the R2 button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getR2ButtonReleased() {
return getRawButtonReleased(Button.kR2.value);
}
/**
* Constructs an event instance around the L2 button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the L2 button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent L2(EventLoop loop) {
return new BooleanEvent(loop, this::getL2Button);
}
/**
* Constructs an event instance around the R2 button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the R2 button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent R2(EventLoop loop) {
return new BooleanEvent(loop, this::getR2Button);
}
/**
* Read the value of the L1 button on the controller.
*
* @return The state of the button.
*/
public boolean getL1Button() {
return getRawButton(Button.kL1.value);
}
/**
* Read the value of the R1 button on the controller.
*
* @return The state of the button.
*/
public boolean getR1Button() {
return getRawButton(Button.kR1.value);
}
/**
* Whether the L1 button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getL1ButtonPressed() {
return getRawButtonPressed(Button.kL1.value);
}
/**
* Whether the R1 button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getR1ButtonPressed() {
return getRawButtonPressed(Button.kR1.value);
}
/**
* Whether the L1 button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getL1ButtonReleased() {
return getRawButtonReleased(Button.kL1.value);
}
/**
* Whether the R1 button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getR1ButtonReleased() {
return getRawButtonReleased(Button.kR1.value);
}
/**
* Constructs an event instance around the L1 button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the L1 button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent L1(EventLoop loop) {
return new BooleanEvent(loop, this::getL1Button);
}
/**
* Constructs an event instance around the R1 button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the R1 button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent R1(EventLoop loop) {
return new BooleanEvent(loop, this::getR1Button);
}
/**
* Read the value of the L3 button (pressing the left analog stick) on the controller.
*
* @return The state of the button.
*/
public boolean getL3Button() {
return getRawButton(Button.kL3.value);
}
/**
* Read the value of the R3 button (pressing the right analog stick) on the controller.
*
* @return The state of the button.
*/
public boolean getR3Button() {
return getRawButton(Button.kR3.value);
}
/**
* Whether the L3 (left stick) button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getL3ButtonPressed() {
return getRawButtonPressed(Button.kL3.value);
}
/**
* Whether the R3 (right stick) button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getR3ButtonPressed() {
return getRawButtonPressed(Button.kR3.value);
}
/**
* Whether the L3 (left stick) button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getL3ButtonReleased() {
return getRawButtonReleased(Button.kL3.value);
}
/**
* Whether the R3 (right stick) button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getR3ButtonReleased() {
return getRawButtonReleased(Button.kR3.value);
}
/**
* Constructs an event instance around the L3 button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the L3 button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent L3(EventLoop loop) {
return new BooleanEvent(loop, this::getL3Button);
}
/**
* Constructs an event instance around the R3 button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the R3 button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent R3(EventLoop loop) {
return new BooleanEvent(loop, this::getR3Button);
}
/**
* Read the value of the Square button on the controller.
*
* @return The state of the button.
*/
public boolean getSquareButton() {
return getRawButton(Button.kSquare.value);
}
/**
* Whether the Square button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getSquareButtonPressed() {
return getRawButtonPressed(Button.kSquare.value);
}
/**
* Whether the Square button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getSquareButtonReleased() {
return getRawButtonReleased(Button.kSquare.value);
}
/**
* Constructs an event instance around the square button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the square button's digital signal attached to the given
* loop.
*/
public BooleanEvent square(EventLoop loop) {
return new BooleanEvent(loop, this::getSquareButton);
}
/**
* Read the value of the Cross button on the controller.
*
* @return The state of the button.
*/
public boolean getCrossButton() {
return getRawButton(Button.kCross.value);
}
/**
* Whether the Cross button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getCrossButtonPressed() {
return getRawButtonPressed(Button.kCross.value);
}
/**
* Whether the Cross button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getCrossButtonReleased() {
return getRawButtonReleased(Button.kCross.value);
}
/**
* Constructs an event instance around the cross button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the cross button's digital signal attached to the given
* loop.
*/
public BooleanEvent cross(EventLoop loop) {
return new BooleanEvent(loop, this::getCrossButton);
}
/**
* Read the value of the Triangle button on the controller.
*
* @return The state of the button.
*/
public boolean getTriangleButton() {
return getRawButton(Button.kTriangle.value);
}
/**
* Whether the Triangle button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getTriangleButtonPressed() {
return getRawButtonPressed(Button.kTriangle.value);
}
/**
* Whether the Triangle button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getTriangleButtonReleased() {
return getRawButtonReleased(Button.kTriangle.value);
}
/**
* Constructs an event instance around the triangle button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the triangle button's digital signal attached to the
* given loop.
*/
public BooleanEvent triangle(EventLoop loop) {
return new BooleanEvent(loop, this::getTriangleButton);
}
/**
* Read the value of the Circle button on the controller.
*
* @return The state of the button.
*/
public boolean getCircleButton() {
return getRawButton(Button.kCircle.value);
}
/**
* Whether the Circle button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getCircleButtonPressed() {
return getRawButtonPressed(Button.kCircle.value);
}
/**
* Whether the Circle button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getCircleButtonReleased() {
return getRawButtonReleased(Button.kCircle.value);
}
/**
* Constructs an event instance around the circle button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the circle button's digital signal attached to the given
* loop.
*/
public BooleanEvent circle(EventLoop loop) {
return new BooleanEvent(loop, this::getCircleButton);
}
/**
* Read the value of the share button on the controller.
*
* @return The state of the button.
*/
public boolean getShareButton() {
return getRawButton(Button.kShare.value);
}
/**
* Whether the share button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getShareButtonPressed() {
return getRawButtonPressed(Button.kShare.value);
}
/**
* Whether the share button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getShareButtonReleased() {
return getRawButtonReleased(Button.kShare.value);
}
/**
* Constructs an event instance around the share button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the share button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent share(EventLoop loop) {
return new BooleanEvent(loop, this::getShareButton);
}
/**
* Read the value of the PS button on the controller.
*
* @return The state of the button.
*/
public boolean getPSButton() {
return getRawButton(Button.kPS.value);
}
/**
* Whether the PS button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getPSButtonPressed() {
return getRawButtonPressed(Button.kPS.value);
}
/**
* Whether the PS button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getPSButtonReleased() {
return getRawButtonReleased(Button.kPS.value);
}
/**
* Constructs an event instance around the PS button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the PS button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent PS(EventLoop loop) {
return new BooleanEvent(loop, this::getPSButton);
}
/**
* Read the value of the options button on the controller.
*
* @return The state of the button.
*/
public boolean getOptionsButton() {
return getRawButton(Button.kOptions.value);
}
/**
* Whether the options button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getOptionsButtonPressed() {
return getRawButtonPressed(Button.kOptions.value);
}
/**
* Whether the options button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getOptionsButtonReleased() {
return getRawButtonReleased(Button.kOptions.value);
}
/**
* Constructs an event instance around the options button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the options button's digital signal attached to the
* given loop.
*/
public BooleanEvent options(EventLoop loop) {
return new BooleanEvent(loop, this::getOptionsButton);
}
/**
* Read the value of the touchpad on the controller.
*
* @return The state of the touchpad.
*/
public boolean getTouchpad() {
return getRawButton(Button.kTouchpad.value);
}
/**
* Whether the touchpad was pressed since the last check.
*
* @return Whether the touchpad was pressed since the last check.
*/
public boolean getTouchpadPressed() {
return getRawButtonPressed(Button.kTouchpad.value);
}
/**
* Whether the touchpad was released since the last check.
*
* @return Whether the touchpad was released since the last check.
*/
public boolean getTouchpadReleased() {
return getRawButtonReleased(Button.kTouchpad.value);
}
/**
* Constructs an event instance around the touchpad's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the touchpad's digital signal attached to the given
* loop.
*/
public BooleanEvent touchpad(EventLoop loop) {
return new BooleanEvent(loop, this::getTouchpad);
}
}

View File

@@ -1,723 +0,0 @@
// 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 edu.wpi.first.wpilibj;
import edu.wpi.first.wpilibj.event.BooleanEvent;
import edu.wpi.first.wpilibj.event.EventLoop;
/**
* Handle input from PS5 controllers connected to the Driver Station.
*
* <p>This class handles PS5 input that comes from the Driver Station. Each time a value is
* requested the most recent value is returned. There is a single class instance for each controller
* and the mapping of ports to hardware buttons depends on the code in the Driver Station.
*
* <p>Only first party controllers from Sony are guaranteed to have the correct mapping, and only
* through the official NI DS. Sim is not guaranteed to have the same mapping, as well as any 3rd
* party controllers.
*/
public class PS5Controller extends GenericHID {
/**
* Construct an instance of a device.
*
* @param port The port index on the Driver Station that the device is plugged into.
*/
public PS5Controller(int port) {
super(port);
// HAL.report(tResourceType.kResourceType_PS5Controller, port + 1);
}
/** Represents a digital button on a PS5Controller. */
public enum Button {
/** Square button. */
kSquare(1),
/** X button. */
kCross(2),
/** Circle button. */
kCircle(3),
/** Triangle button. */
kTriangle(4),
/** Left trigger 1 button. */
kL1(5),
/** Right trigger 1 button. */
kR1(6),
/** Left trigger 2 button. */
kL2(7),
/** Right trigger 2 button. */
kR2(8),
/** Create button. */
kCreate(9),
/** Options button. */
kOptions(10),
/** Left stick button. */
kL3(11),
/** Right stick button. */
kR3(12),
/** PlayStation button. */
kPS(13),
/** Touchpad click button. */
kTouchpad(14);
/** Button value. */
public final int value;
Button(int index) {
this.value = index;
}
/**
* Get the human-friendly name of the button, matching the relevant methods. This is done by
* stripping the leading `k`, and if not the touchpad append `Button`.
*
* <p>Primarily used for automated unit tests.
*
* @return the human-friendly name of the button.
*/
@Override
public String toString() {
var name = this.name().substring(1); // Remove leading `k`
if (this == kTouchpad) {
return name;
}
return name + "Button";
}
}
/** Represents an axis on a PS5Controller. */
public enum Axis {
/** Left X axis. */
kLeftX(0),
/** Left Y axis. */
kLeftY(1),
/** Right X axis. */
kRightX(2),
/** Right Y axis. */
kRightY(5),
/** Left Trigger 2. */
kL2(3),
/** Right Trigger 2. */
kR2(4);
/** Axis value. */
public final int value;
Axis(int index) {
value = index;
}
/**
* Get the human-friendly name of the axis, matching the relevant methods. This is done by
* stripping the leading `k`, and if one of L2/R2 append `Axis`.
*
* <p>Primarily used for automated unit tests.
*
* @return the human-friendly name of the axis.
*/
@Override
public String toString() {
var name = this.name().substring(1); // Remove leading `k`
if (name.endsWith("2")) {
return name + "Axis";
}
return name;
}
}
/**
* Get the X axis value of left side of the controller.
*
* @return the axis value.
*/
public double getLeftX() {
return getRawAxis(Axis.kLeftX.value);
}
/**
* Get the X axis value of right side of the controller.
*
* @return the axis value.
*/
public double getRightX() {
return getRawAxis(Axis.kRightX.value);
}
/**
* Get the Y axis value of left side of the controller.
*
* @return the axis value.
*/
public double getLeftY() {
return getRawAxis(Axis.kLeftY.value);
}
/**
* Get the Y axis value of right side of the controller.
*
* @return the axis value.
*/
public double getRightY() {
return getRawAxis(Axis.kRightY.value);
}
/**
* Get the L2 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 getL2Axis() {
return getRawAxis(Axis.kL2.value);
}
/**
* Get the R2 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 getR2Axis() {
return getRawAxis(Axis.kR2.value);
}
/**
* Read the value of the left trigger button on the controller.
*
* @return The state of the button.
*/
public boolean getL2Button() {
return getRawButton(Button.kL2.value);
}
/**
* Read the value of the right trigger button on the controller.
*
* @return The state of the button.
*/
public boolean getR2Button() {
return getRawButton(Button.kR2.value);
}
/**
* Whether the L2 button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getL2ButtonPressed() {
return getRawButtonPressed(Button.kL2.value);
}
/**
* Whether the R2 button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getR2ButtonPressed() {
return getRawButtonPressed(Button.kR2.value);
}
/**
* Whether the L2 button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getL2ButtonReleased() {
return getRawButtonReleased(Button.kL2.value);
}
/**
* Whether the R2 button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getR2ButtonReleased() {
return getRawButtonReleased(Button.kR2.value);
}
/**
* Constructs an event instance around the L2 button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the L2 button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent L2(EventLoop loop) {
return new BooleanEvent(loop, this::getL2Button);
}
/**
* Constructs an event instance around the R2 button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the R2 button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent R2(EventLoop loop) {
return new BooleanEvent(loop, this::getR2Button);
}
/**
* Read the value of the L1 button on the controller.
*
* @return The state of the button.
*/
public boolean getL1Button() {
return getRawButton(Button.kL1.value);
}
/**
* Read the value of the R1 button on the controller.
*
* @return The state of the button.
*/
public boolean getR1Button() {
return getRawButton(Button.kR1.value);
}
/**
* Whether the L1 button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getL1ButtonPressed() {
return getRawButtonPressed(Button.kL1.value);
}
/**
* Whether the R1 button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getR1ButtonPressed() {
return getRawButtonPressed(Button.kR1.value);
}
/**
* Whether the L1 button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getL1ButtonReleased() {
return getRawButtonReleased(Button.kL1.value);
}
/**
* Whether the R1 button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getR1ButtonReleased() {
return getRawButtonReleased(Button.kR1.value);
}
/**
* Constructs an event instance around the L1 button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the L1 button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent L1(EventLoop loop) {
return new BooleanEvent(loop, this::getL1Button);
}
/**
* Constructs an event instance around the R1 button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the R1 button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent R1(EventLoop loop) {
return new BooleanEvent(loop, this::getR1Button);
}
/**
* Read the value of the L3 button (pressing the left analog stick) on the controller.
*
* @return The state of the button.
*/
public boolean getL3Button() {
return getRawButton(Button.kL3.value);
}
/**
* Read the value of the R3 button (pressing the right analog stick) on the controller.
*
* @return The state of the button.
*/
public boolean getR3Button() {
return getRawButton(Button.kR3.value);
}
/**
* Whether the L3 (left stick) button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getL3ButtonPressed() {
return getRawButtonPressed(Button.kL3.value);
}
/**
* Whether the R3 (right stick) button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getR3ButtonPressed() {
return getRawButtonPressed(Button.kR3.value);
}
/**
* Whether the L3 (left stick) button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getL3ButtonReleased() {
return getRawButtonReleased(Button.kL3.value);
}
/**
* Whether the R3 (right stick) button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getR3ButtonReleased() {
return getRawButtonReleased(Button.kR3.value);
}
/**
* Constructs an event instance around the L3 button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the L3 button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent L3(EventLoop loop) {
return new BooleanEvent(loop, this::getL3Button);
}
/**
* Constructs an event instance around the R3 button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the R3 button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent R3(EventLoop loop) {
return new BooleanEvent(loop, this::getR3Button);
}
/**
* Read the value of the Square button on the controller.
*
* @return The state of the button.
*/
public boolean getSquareButton() {
return getRawButton(Button.kSquare.value);
}
/**
* Whether the Square button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getSquareButtonPressed() {
return getRawButtonPressed(Button.kSquare.value);
}
/**
* Whether the Square button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getSquareButtonReleased() {
return getRawButtonReleased(Button.kSquare.value);
}
/**
* Constructs an event instance around the square button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the square button's digital signal attached to the given
* loop.
*/
public BooleanEvent square(EventLoop loop) {
return new BooleanEvent(loop, this::getSquareButton);
}
/**
* Read the value of the Cross button on the controller.
*
* @return The state of the button.
*/
public boolean getCrossButton() {
return getRawButton(Button.kCross.value);
}
/**
* Whether the Cross button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getCrossButtonPressed() {
return getRawButtonPressed(Button.kCross.value);
}
/**
* Whether the Cross button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getCrossButtonReleased() {
return getRawButtonReleased(Button.kCross.value);
}
/**
* Constructs an event instance around the cross button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the cross button's digital signal attached to the given
* loop.
*/
public BooleanEvent cross(EventLoop loop) {
return new BooleanEvent(loop, this::getCrossButton);
}
/**
* Read the value of the Triangle button on the controller.
*
* @return The state of the button.
*/
public boolean getTriangleButton() {
return getRawButton(Button.kTriangle.value);
}
/**
* Whether the Triangle button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getTriangleButtonPressed() {
return getRawButtonPressed(Button.kTriangle.value);
}
/**
* Whether the Triangle button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getTriangleButtonReleased() {
return getRawButtonReleased(Button.kTriangle.value);
}
/**
* Constructs an event instance around the triangle button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the triangle button's digital signal attached to the
* given loop.
*/
public BooleanEvent triangle(EventLoop loop) {
return new BooleanEvent(loop, this::getTriangleButton);
}
/**
* Read the value of the Circle button on the controller.
*
* @return The state of the button.
*/
public boolean getCircleButton() {
return getRawButton(Button.kCircle.value);
}
/**
* Whether the Circle button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getCircleButtonPressed() {
return getRawButtonPressed(Button.kCircle.value);
}
/**
* Whether the Circle button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getCircleButtonReleased() {
return getRawButtonReleased(Button.kCircle.value);
}
/**
* Constructs an event instance around the circle button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the circle button's digital signal attached to the given
* loop.
*/
public BooleanEvent circle(EventLoop loop) {
return new BooleanEvent(loop, this::getCircleButton);
}
/**
* Read the value of the share button on the controller.
*
* @return The state of the button.
*/
public boolean getCreateButton() {
return getRawButton(Button.kCreate.value);
}
/**
* Whether the share button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getCreateButtonPressed() {
return getRawButtonPressed(Button.kCreate.value);
}
/**
* Whether the share button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getCreateButtonReleased() {
return getRawButtonReleased(Button.kCreate.value);
}
/**
* Constructs an event instance around the share button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the share button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent create(EventLoop loop) {
return new BooleanEvent(loop, this::getCreateButton);
}
/**
* Read the value of the PS button on the controller.
*
* @return The state of the button.
*/
public boolean getPSButton() {
return getRawButton(Button.kPS.value);
}
/**
* Whether the PS button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getPSButtonPressed() {
return getRawButtonPressed(Button.kPS.value);
}
/**
* Whether the PS button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getPSButtonReleased() {
return getRawButtonReleased(Button.kPS.value);
}
/**
* Constructs an event instance around the PS button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the PS button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent PS(EventLoop loop) {
return new BooleanEvent(loop, this::getPSButton);
}
/**
* Read the value of the options button on the controller.
*
* @return The state of the button.
*/
public boolean getOptionsButton() {
return getRawButton(Button.kOptions.value);
}
/**
* Whether the options button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getOptionsButtonPressed() {
return getRawButtonPressed(Button.kOptions.value);
}
/**
* Whether the options button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getOptionsButtonReleased() {
return getRawButtonReleased(Button.kOptions.value);
}
/**
* Constructs an event instance around the options button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the options button's digital signal attached to the
* given loop.
*/
public BooleanEvent options(EventLoop loop) {
return new BooleanEvent(loop, this::getOptionsButton);
}
/**
* Read the value of the touchpad on the controller.
*
* @return The state of the touchpad.
*/
public boolean getTouchpad() {
return getRawButton(Button.kTouchpad.value);
}
/**
* Whether the touchpad was pressed since the last check.
*
* @return Whether the touchpad was pressed since the last check.
*/
public boolean getTouchpadPressed() {
return getRawButtonPressed(Button.kTouchpad.value);
}
/**
* Whether the touchpad was released since the last check.
*
* @return Whether the touchpad was released since the last check.
*/
public boolean getTouchpadReleased() {
return getRawButtonReleased(Button.kTouchpad.value);
}
/**
* Constructs an event instance around the touchpad's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the touchpad's digital signal attached to the given
* loop.
*/
public BooleanEvent touchpad(EventLoop loop) {
return new BooleanEvent(loop, this::getTouchpad);
}
}

View File

@@ -1,737 +0,0 @@
// 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 edu.wpi.first.wpilibj;
// import edu.wpi.first.hal.FRCNetComm.tResourceType;
// import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.event.BooleanEvent;
import edu.wpi.first.wpilibj.event.EventLoop;
/**
* Handle input from Stadia controllers connected to the Driver Station.
*
* <p>This class handles Stadia input that comes from the Driver Station. Each time a value is
* requested the most recent value is returned. There is a single class instance for each controller
* and the mapping of ports to hardware buttons depends on the code in the Driver Station.
*/
public class StadiaController extends GenericHID {
/** Represents a digital button on a StadiaController. */
public enum Button {
/** A button. */
kA(1),
/** B button. */
kB(2),
/** X Button. */
kX(3),
/** Y Button. */
kY(4),
/** Left bumper button. */
kLeftBumper(5),
/** Right bumper button. */
kRightBumper(6),
/** Left stick button. */
kLeftStick(7),
/** Right stick button. */
kRightStick(8),
/** Ellipses button. */
kEllipses(9),
/** Hamburger button. */
kHamburger(10),
/** Stadia button. */
kStadia(11),
/** Right trigger button. */
kRightTrigger(12),
/** Left trigger button. */
kLeftTrigger(13),
/** Google button. */
kGoogle(14),
/** Frame button. */
kFrame(15);
/** Button value. */
public final int value;
Button(int value) {
this.value = value;
}
/**
* Get the human-friendly name of the button, matching the relevant methods. This is done by
* stripping the leading `k`, and if not a Bumper button append `Button`.
*
* <p>Primarily used for automated unit tests.
*
* @return the human-friendly name of the button.
*/
@Override
public String toString() {
var name = this.name().substring(1); // Remove leading `k`
if (name.endsWith("Bumper")) {
return name;
}
return name + "Button";
}
}
/** Represents an axis on a StadiaController. */
public enum Axis {
/** Left X axis. */
kLeftX(0),
/** Right X axis. */
kRightX(3),
/** Left Y axis. */
kLeftY(1),
/** Right Y axis. */
kRightY(4);
/** Axis value. */
public final int value;
Axis(int value) {
this.value = value;
}
/**
* Get the human-friendly name of the axis, matching the relevant methods. This is done by
* stripping the leading `k`, and if a trigger axis append `Axis`.
*
* <p>Primarily used for automated unit tests.
*
* @return the human-friendly name of the axis.
*/
@Override
public String toString() {
var name = this.name().substring(1); // Remove leading `k`
if (name.endsWith("Trigger")) {
return name + "Axis";
}
return name;
}
}
/**
* Construct an instance of a controller.
*
* @param port The port index on the Driver Station that the controller is plugged into.
*/
public StadiaController(final int port) {
super(port);
// re-enable when StadiaController is added to Usage Reporting
// HAL.report(tResourceType.kResourceType_Joystick, port + 1);
}
/**
* Get the X axis value of left side of the controller.
*
* @return The axis value.
*/
public double getLeftX() {
return getRawAxis(Axis.kLeftX.value);
}
/**
* Get the X axis value of right side of the controller.
*
* @return The axis value.
*/
public double getRightX() {
return getRawAxis(Axis.kRightX.value);
}
/**
* Get the Y axis value of left side of the controller.
*
* @return The axis value.
*/
public double getLeftY() {
return getRawAxis(Axis.kLeftY.value);
}
/**
* Get the Y axis value of right side of the controller.
*
* @return The axis value.
*/
public double getRightY() {
return getRawAxis(Axis.kRightY.value);
}
/**
* Read the value of the left bumper (LB) button on the controller.
*
* @return The state of the button.
*/
public boolean getLeftBumper() {
return getRawButton(Button.kLeftBumper.value);
}
/**
* Read the value of the right bumper (RB) button on the controller.
*
* @return The state of the button.
*/
public boolean getRightBumper() {
return getRawButton(Button.kRightBumper.value);
}
/**
* Whether the left bumper (LB) was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getLeftBumperPressed() {
return getRawButtonPressed(Button.kLeftBumper.value);
}
/**
* Whether the right bumper (RB) was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getRightBumperPressed() {
return getRawButtonPressed(Button.kRightBumper.value);
}
/**
* Whether the left bumper (LB) was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getLeftBumperReleased() {
return getRawButtonReleased(Button.kLeftBumper.value);
}
/**
* Whether the right bumper (RB) was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getRightBumperReleased() {
return getRawButtonReleased(Button.kRightBumper.value);
}
/**
* Constructs an event instance around the right bumper's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the right bumper's digital signal attached to the given
* loop.
*/
public BooleanEvent leftBumper(EventLoop loop) {
return new BooleanEvent(loop, this::getLeftBumper);
}
/**
* Constructs an event instance around the left bumper's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the left bumper's digital signal attached to the given
* loop.
*/
public BooleanEvent rightBumper(EventLoop loop) {
return new BooleanEvent(loop, this::getRightBumper);
}
/**
* Read the value of the left stick button (LSB) on the controller.
*
* @return The state of the button.
*/
public boolean getLeftStickButton() {
return getRawButton(Button.kLeftStick.value);
}
/**
* Read the value of the right stick button (RSB) on the controller.
*
* @return The state of the button.
*/
public boolean getRightStickButton() {
return getRawButton(Button.kRightStick.value);
}
/**
* Whether the left stick button (LSB) was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getLeftStickButtonPressed() {
return getRawButtonPressed(Button.kLeftStick.value);
}
/**
* Whether the right stick button (RSB) was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getRightStickButtonPressed() {
return getRawButtonPressed(Button.kRightStick.value);
}
/**
* Whether the left stick button (LSB) was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getLeftStickButtonReleased() {
return getRawButtonReleased(Button.kLeftStick.value);
}
/**
* Whether the right stick (RSB) button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getRightStickButtonReleased() {
return getRawButtonReleased(Button.kRightStick.value);
}
/**
* Constructs an event instance around the left stick button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the left stick button's digital signal attached to the
* given loop.
*/
public BooleanEvent leftStick(EventLoop loop) {
return new BooleanEvent(loop, this::getLeftStickButton);
}
/**
* Constructs an event instance around the right stick button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the right stick button's digital signal attached to the
* given loop.
*/
public BooleanEvent rightStick(EventLoop loop) {
return new BooleanEvent(loop, this::getRightStickButton);
}
/**
* Read the value of the left trigger button (LTB) on the controller.
*
* @return The state of the button.
*/
public boolean getLeftTriggerButton() {
return getRawButton(Button.kLeftTrigger.value);
}
/**
* Read the value of the right trigger button (RTB) on the controller.
*
* @return The state of the button.
*/
public boolean getRightTriggerButton() {
return getRawButton(Button.kRightTrigger.value);
}
/**
* Whether the left trigger button (LTB) was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getLeftTriggerButtonPressed() {
return getRawButtonPressed(Button.kLeftTrigger.value);
}
/**
* Whether the right trigger button (RTB) was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getRightTriggerButtonPressed() {
return getRawButtonPressed(Button.kRightTrigger.value);
}
/**
* Whether the left trigger button (LTB) was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getLeftTriggerButtonReleased() {
return getRawButtonReleased(Button.kLeftTrigger.value);
}
/**
* Whether the right trigger (RTB) button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getRightTriggerButtonReleased() {
return getRawButtonReleased(Button.kRightTrigger.value);
}
/**
* Constructs an event instance around the left trigger button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the left trigger button's digital signal attached to the
* given loop.
*/
public BooleanEvent leftTrigger(EventLoop loop) {
return new BooleanEvent(loop, this::getLeftTriggerButton);
}
/**
* Constructs an event instance around the right trigger button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the right trigger button's digital signal attached to
* the given loop.
*/
public BooleanEvent rightTrigger(EventLoop loop) {
return new BooleanEvent(loop, this::getRightTriggerButton);
}
/**
* Read the value of the A button on the controller.
*
* @return The state of the button.
*/
public boolean getAButton() {
return getRawButton(Button.kA.value);
}
/**
* Whether the A button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getAButtonPressed() {
return getRawButtonPressed(Button.kA.value);
}
/**
* Whether the A button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getAButtonReleased() {
return getRawButtonReleased(Button.kA.value);
}
/**
* Constructs an event instance around the A button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the A button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent a(EventLoop loop) {
return new BooleanEvent(loop, this::getAButton);
}
/**
* Read the value of the B button on the controller.
*
* @return The state of the button.
*/
public boolean getBButton() {
return getRawButton(Button.kB.value);
}
/**
* Whether the B button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getBButtonPressed() {
return getRawButtonPressed(Button.kB.value);
}
/**
* Whether the B button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getBButtonReleased() {
return getRawButtonReleased(Button.kB.value);
}
/**
* Constructs an event instance around the B button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the B button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent b(EventLoop loop) {
return new BooleanEvent(loop, this::getBButton);
}
/**
* Read the value of the X button on the controller.
*
* @return The state of the button.
*/
public boolean getXButton() {
return getRawButton(Button.kX.value);
}
/**
* Whether the X button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getXButtonPressed() {
return getRawButtonPressed(Button.kX.value);
}
/**
* Whether the X button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getXButtonReleased() {
return getRawButtonReleased(Button.kX.value);
}
/**
* Constructs an event instance around the X button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the X button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent x(EventLoop loop) {
return new BooleanEvent(loop, this::getXButton);
}
/**
* Read the value of the Y button on the controller.
*
* @return The state of the button.
*/
public boolean getYButton() {
return getRawButton(Button.kY.value);
}
/**
* Whether the Y button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getYButtonPressed() {
return getRawButtonPressed(Button.kY.value);
}
/**
* Whether the Y button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getYButtonReleased() {
return getRawButtonReleased(Button.kY.value);
}
/**
* Constructs an event instance around the Y button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the Y button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent y(EventLoop loop) {
return new BooleanEvent(loop, this::getYButton);
}
/**
* Read the value of the ellipses button on the controller.
*
* @return The state of the button.
*/
public boolean getEllipsesButton() {
return getRawButton(Button.kEllipses.value);
}
/**
* Whether the ellipses button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getEllipsesButtonPressed() {
return getRawButtonPressed(Button.kEllipses.value);
}
/**
* Whether the ellipses button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getEllipsesButtonReleased() {
return getRawButtonReleased(Button.kEllipses.value);
}
/**
* Constructs an event instance around the ellipses button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the ellipses button's digital signal attached to the
* given loop.
*/
public BooleanEvent ellipses(EventLoop loop) {
return new BooleanEvent(loop, this::getEllipsesButton);
}
/**
* Read the value of the hamburger button on the controller.
*
* @return The state of the button.
*/
public boolean getHamburgerButton() {
return getRawButton(Button.kHamburger.value);
}
/**
* Whether the hamburger button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getHamburgerButtonPressed() {
return getRawButtonPressed(Button.kHamburger.value);
}
/**
* Whether the hamburger button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getHamburgerButtonReleased() {
return getRawButtonReleased(Button.kHamburger.value);
}
/**
* Constructs an event instance around the hamburger button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the hamburger button's digital signal attached to the
* given loop.
*/
public BooleanEvent hamburger(EventLoop loop) {
return new BooleanEvent(loop, this::getHamburgerButton);
}
/**
* Read the value of the stadia button on the controller.
*
* @return The state of the button.
*/
public boolean getStadiaButton() {
return getRawButton(Button.kStadia.value);
}
/**
* Whether the stadia button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getStadiaButtonPressed() {
return getRawButtonPressed(Button.kStadia.value);
}
/**
* Whether the stadia button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getStadiaButtonReleased() {
return getRawButtonReleased(Button.kStadia.value);
}
/**
* Constructs an event instance around the stadia button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the stadia button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent stadia(EventLoop loop) {
return new BooleanEvent(loop, this::getStadiaButton);
}
/**
* Read the value of the google button on the controller.
*
* @return The state of the button.
*/
public boolean getGoogleButton() {
return getRawButton(Button.kGoogle.value);
}
/**
* Whether the google button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getGoogleButtonPressed() {
return getRawButtonPressed(Button.kGoogle.value);
}
/**
* Whether the google button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getGoogleButtonReleased() {
return getRawButtonReleased(Button.kGoogle.value);
}
/**
* Constructs an event instance around the google button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the google button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent google(EventLoop loop) {
return new BooleanEvent(loop, this::getGoogleButton);
}
/**
* Read the value of the frame button on the controller.
*
* @return The state of the button.
*/
public boolean getFrameButton() {
return getRawButton(Button.kFrame.value);
}
/**
* Whether the frame button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getFrameButtonPressed() {
return getRawButtonPressed(Button.kFrame.value);
}
/**
* Whether the frame button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getFrameButtonReleased() {
return getRawButtonReleased(Button.kFrame.value);
}
/**
* Constructs an event instance around the frame button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the frame button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent frame(EventLoop loop) {
return new BooleanEvent(loop, this::getFrameButton);
}
}

View File

@@ -1,614 +0,0 @@
// 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 edu.wpi.first.wpilibj;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.event.BooleanEvent;
import edu.wpi.first.wpilibj.event.EventLoop;
/**
* Handle input from Xbox 360 or Xbox One controllers connected to the Driver Station.
*
* <p>This class handles Xbox input that comes from the Driver Station. Each time a value is
* requested the most recent value is returned. There is a single class instance for each controller
* and the mapping of ports to hardware buttons depends on the code in the Driver Station.
*
* <p>Only first party controllers from Microsoft are guaranteed to have the correct mapping, and
* only through the official NI DS. Sim is not guaranteed to have the same mapping, as well as any
* 3rd party controllers.
*/
public class XboxController extends GenericHID {
/** Represents a digital button on an XboxController. */
public enum Button {
/** Left bumper. */
kLeftBumper(5),
/** Right bumper. */
kRightBumper(6),
/** Left stick. */
kLeftStick(9),
/** Right stick. */
kRightStick(10),
/** A. */
kA(1),
/** B. */
kB(2),
/** X. */
kX(3),
/** Y. */
kY(4),
/** Back. */
kBack(7),
/** Start. */
kStart(8);
/** Button value. */
public final int value;
Button(int value) {
this.value = value;
}
/**
* Get the human-friendly name of the button, matching the relevant methods. This is done by
* stripping the leading `k`, and if not a Bumper button append `Button`.
*
* <p>Primarily used for automated unit tests.
*
* @return the human-friendly name of the button.
*/
@Override
public String toString() {
var name = this.name().substring(1); // Remove leading `k`
if (name.endsWith("Bumper")) {
return name;
}
return name + "Button";
}
}
/** Represents an axis on an XboxController. */
public enum Axis {
/** Left X. */
kLeftX(0),
/** Right X. */
kRightX(4),
/** Left Y. */
kLeftY(1),
/** Right Y. */
kRightY(5),
/** Left trigger. */
kLeftTrigger(2),
/** Right trigger. */
kRightTrigger(3);
/** Axis value. */
public final int value;
Axis(int value) {
this.value = value;
}
/**
* Get the human-friendly name of the axis, matching the relevant methods. This is done by
* stripping the leading `k`, and if a trigger axis append `Axis`.
*
* <p>Primarily used for automated unit tests.
*
* @return the human-friendly name of the axis.
*/
@Override
public String toString() {
var name = this.name().substring(1); // Remove leading `k`
if (name.endsWith("Trigger")) {
return name + "Axis";
}
return name;
}
}
/**
* Construct an instance of a controller.
*
* @param port The port index on the Driver Station that the controller is plugged into.
*/
public XboxController(final int port) {
super(port);
HAL.report(tResourceType.kResourceType_XboxController, port + 1);
}
/**
* Get the X axis value of left side of the controller.
*
* @return The axis value.
*/
public double getLeftX() {
return getRawAxis(Axis.kLeftX.value);
}
/**
* Get the X axis value of right side of the controller.
*
* @return The axis value.
*/
public double getRightX() {
return getRawAxis(Axis.kRightX.value);
}
/**
* Get the Y axis value of left side of the controller.
*
* @return The axis value.
*/
public double getLeftY() {
return getRawAxis(Axis.kLeftY.value);
}
/**
* Get the Y axis value of right side of the controller.
*
* @return The axis value.
*/
public double getRightY() {
return getRawAxis(Axis.kRightY.value);
}
/**
* Get the left trigger (LT) 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 getRawAxis(Axis.kLeftTrigger.value);
}
/**
* Get the right trigger (RT) 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 getRawAxis(Axis.kRightTrigger.value);
}
/**
* Read the value of the left bumper (LB) button on the controller.
*
* @return The state of the button.
*/
public boolean getLeftBumper() {
return getRawButton(Button.kLeftBumper.value);
}
/**
* Read the value of the right bumper (RB) button on the controller.
*
* @return The state of the button.
*/
public boolean getRightBumper() {
return getRawButton(Button.kRightBumper.value);
}
/**
* Whether the left bumper (LB) was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getLeftBumperPressed() {
return getRawButtonPressed(Button.kLeftBumper.value);
}
/**
* Whether the right bumper (RB) was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getRightBumperPressed() {
return getRawButtonPressed(Button.kRightBumper.value);
}
/**
* Whether the left bumper (LB) was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getLeftBumperReleased() {
return getRawButtonReleased(Button.kLeftBumper.value);
}
/**
* Whether the right bumper (RB) was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getRightBumperReleased() {
return getRawButtonReleased(Button.kRightBumper.value);
}
/**
* Constructs an event instance around the right bumper's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the right bumper's digital signal attached to the given
* loop.
*/
public BooleanEvent leftBumper(EventLoop loop) {
return new BooleanEvent(loop, this::getLeftBumper);
}
/**
* Constructs an event instance around the left bumper's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the left bumper's digital signal attached to the given
* loop.
*/
public BooleanEvent rightBumper(EventLoop loop) {
return new BooleanEvent(loop, this::getRightBumper);
}
/**
* Read the value of the left stick button (LSB) on the controller.
*
* @return The state of the button.
*/
public boolean getLeftStickButton() {
return getRawButton(Button.kLeftStick.value);
}
/**
* Read the value of the right stick button (RSB) on the controller.
*
* @return The state of the button.
*/
public boolean getRightStickButton() {
return getRawButton(Button.kRightStick.value);
}
/**
* Whether the left stick button (LSB) was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getLeftStickButtonPressed() {
return getRawButtonPressed(Button.kLeftStick.value);
}
/**
* Whether the right stick button (RSB) was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getRightStickButtonPressed() {
return getRawButtonPressed(Button.kRightStick.value);
}
/**
* Whether the left stick button (LSB) was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getLeftStickButtonReleased() {
return getRawButtonReleased(Button.kLeftStick.value);
}
/**
* Whether the right stick (RSB) button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getRightStickButtonReleased() {
return getRawButtonReleased(Button.kRightStick.value);
}
/**
* Constructs an event instance around the left stick button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the left stick button's digital signal attached to the
* given loop.
*/
public BooleanEvent leftStick(EventLoop loop) {
return new BooleanEvent(loop, this::getLeftStickButton);
}
/**
* Constructs an event instance around the right stick button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the right stick button's digital signal attached to the
* given loop.
*/
public BooleanEvent rightStick(EventLoop loop) {
return new BooleanEvent(loop, this::getRightStickButton);
}
/**
* Read the value of the A button on the controller.
*
* @return The state of the button.
*/
public boolean getAButton() {
return getRawButton(Button.kA.value);
}
/**
* Whether the A button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getAButtonPressed() {
return getRawButtonPressed(Button.kA.value);
}
/**
* Whether the A button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getAButtonReleased() {
return getRawButtonReleased(Button.kA.value);
}
/**
* Constructs an event instance around the A button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the A button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent a(EventLoop loop) {
return new BooleanEvent(loop, this::getAButton);
}
/**
* Read the value of the B button on the controller.
*
* @return The state of the button.
*/
public boolean getBButton() {
return getRawButton(Button.kB.value);
}
/**
* Whether the B button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getBButtonPressed() {
return getRawButtonPressed(Button.kB.value);
}
/**
* Whether the B button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getBButtonReleased() {
return getRawButtonReleased(Button.kB.value);
}
/**
* Constructs an event instance around the B button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the B button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent b(EventLoop loop) {
return new BooleanEvent(loop, this::getBButton);
}
/**
* Read the value of the X button on the controller.
*
* @return The state of the button.
*/
public boolean getXButton() {
return getRawButton(Button.kX.value);
}
/**
* Whether the X button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getXButtonPressed() {
return getRawButtonPressed(Button.kX.value);
}
/**
* Whether the X button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getXButtonReleased() {
return getRawButtonReleased(Button.kX.value);
}
/**
* Constructs an event instance around the X button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the X button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent x(EventLoop loop) {
return new BooleanEvent(loop, this::getXButton);
}
/**
* Read the value of the Y button on the controller.
*
* @return The state of the button.
*/
public boolean getYButton() {
return getRawButton(Button.kY.value);
}
/**
* Whether the Y button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getYButtonPressed() {
return getRawButtonPressed(Button.kY.value);
}
/**
* Whether the Y button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getYButtonReleased() {
return getRawButtonReleased(Button.kY.value);
}
/**
* Constructs an event instance around the Y button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the Y button's digital signal attached to the given
* loop.
*/
@SuppressWarnings("MethodName")
public BooleanEvent y(EventLoop loop) {
return new BooleanEvent(loop, this::getYButton);
}
/**
* Read the value of the back button on the controller.
*
* @return The state of the button.
*/
public boolean getBackButton() {
return getRawButton(Button.kBack.value);
}
/**
* Whether the back button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getBackButtonPressed() {
return getRawButtonPressed(Button.kBack.value);
}
/**
* Whether the back button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getBackButtonReleased() {
return getRawButtonReleased(Button.kBack.value);
}
/**
* Constructs an event instance around the back button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the back button's digital signal attached to the given
* loop.
*/
public BooleanEvent back(EventLoop loop) {
return new BooleanEvent(loop, this::getBackButton);
}
/**
* Read the value of the start button on the controller.
*
* @return The state of the button.
*/
public boolean getStartButton() {
return getRawButton(Button.kStart.value);
}
/**
* Whether the start button was pressed since the last check.
*
* @return Whether the button was pressed since the last check.
*/
public boolean getStartButtonPressed() {
return getRawButtonPressed(Button.kStart.value);
}
/**
* Whether the start button was released since the last check.
*
* @return Whether the button was released since the last check.
*/
public boolean getStartButtonReleased() {
return getRawButtonReleased(Button.kStart.value);
}
/**
* Constructs an event instance around the start button's digital signal.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the start button's digital signal attached to the given
* loop.
*/
public BooleanEvent start(EventLoop loop) {
return new BooleanEvent(loop, this::getStartButton);
}
/**
* Constructs an event 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 BooleanEvent} 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 event to.
* @return an event instance that is true when the left trigger's axis exceeds the provided
* threshold, attached to the given event loop
*/
public BooleanEvent leftTrigger(double threshold, EventLoop loop) {
return new BooleanEvent(loop, () -> getLeftTriggerAxis() > threshold);
}
/**
* Constructs an event instance around the axis value of the left trigger. The returned trigger
* will be true when the axis value is greater than 0.5.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance that is true when the left trigger's axis exceeds the provided
* threshold, attached to the given event loop
*/
public BooleanEvent leftTrigger(EventLoop loop) {
return leftTrigger(0.5, loop);
}
/**
* Constructs an event 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 BooleanEvent} 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 event to.
* @return an event instance that is true when the right trigger's axis exceeds the provided
* threshold, attached to the given event loop
*/
public BooleanEvent rightTrigger(double threshold, EventLoop loop) {
return new BooleanEvent(loop, () -> getRightTriggerAxis() > threshold);
}
/**
* Constructs an event instance around the axis value of the right trigger. The returned trigger
* will be true when the axis value is greater than 0.5.
*
* @param loop the event loop instance to attach the event to.
* @return an event instance that is true when the right trigger's axis exceeds the provided
* threshold, attached to the given event loop
*/
public BooleanEvent rightTrigger(EventLoop loop) {
return rightTrigger(0.5, loop);
}
}

View File

@@ -1,216 +0,0 @@
// 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 edu.wpi.first.wpilibj.simulation;
import edu.wpi.first.wpilibj.PS4Controller;
/** Class to control a simulated PS4 controller. */
public class PS4ControllerSim extends GenericHIDSim {
/**
* Constructs from a PS4Controller object.
*
* @param joystick controller to simulate
*/
@SuppressWarnings("this-escape")
public PS4ControllerSim(PS4Controller joystick) {
super(joystick);
setAxisCount(6);
setButtonCount(14);
setPOVCount(1);
}
/**
* Constructs from a joystick port number.
*
* @param port port number
*/
@SuppressWarnings("this-escape")
public PS4ControllerSim(int port) {
super(port);
setAxisCount(6);
setButtonCount(14);
setPOVCount(1);
}
/**
* Change the X axis value of the controller's left stick.
*
* @param value the new value
*/
public void setLeftX(double value) {
setRawAxis(PS4Controller.Axis.kLeftX.value, value);
}
/**
* Change the X axis value of the controller's right stick.
*
* @param value the new value
*/
public void setRightX(double value) {
setRawAxis(PS4Controller.Axis.kRightX.value, value);
}
/**
* Change the Y axis value of the controller's left stick.
*
* @param value the new value
*/
public void setLeftY(double value) {
setRawAxis(PS4Controller.Axis.kLeftY.value, value);
}
/**
* Change the Y axis value of the controller's right stick.
*
* @param value the new value
*/
public void setRightY(double value) {
setRawAxis(PS4Controller.Axis.kRightY.value, value);
}
/**
* Change the L2 axis value of the controller.
*
* @param value the new value
*/
public void setL2Axis(double value) {
setRawAxis(PS4Controller.Axis.kL2.value, value);
}
/**
* Change the R2 axis value of the controller.
*
* @param value the new value
*/
public void setR2Axis(double value) {
setRawAxis(PS4Controller.Axis.kR2.value, value);
}
/**
* Change the value of the Square button on the controller.
*
* @param value the new value
*/
public void setSquareButton(boolean value) {
setRawButton(PS4Controller.Button.kSquare.value, value);
}
/**
* Change the value of the Cross button on the controller.
*
* @param value the new value
*/
public void setCrossButton(boolean value) {
setRawButton(PS4Controller.Button.kCross.value, value);
}
/**
* Change the value of the Circle button on the controller.
*
* @param value the new value
*/
public void setCircleButton(boolean value) {
setRawButton(PS4Controller.Button.kCircle.value, value);
}
/**
* Change the value of the Triangle button on the controller.
*
* @param value the new value
*/
public void setTriangleButton(boolean value) {
setRawButton(PS4Controller.Button.kTriangle.value, value);
}
/**
* Change the value of the L1 button on the controller.
*
* @param value the new value
*/
public void setL1Button(boolean value) {
setRawButton(PS4Controller.Button.kL1.value, value);
}
/**
* Change the value of the R1 button on the controller.
*
* @param value the new value
*/
public void setR1Button(boolean value) {
setRawButton(PS4Controller.Button.kR1.value, value);
}
/**
* Change the value of the L2 button on the controller.
*
* @param value the new value
*/
public void setL2Button(boolean value) {
setRawButton(PS4Controller.Button.kL2.value, value);
}
/**
* Change the value of the R2 button on the controller.
*
* @param value the new value
*/
public void setR2Button(boolean value) {
setRawButton(PS4Controller.Button.kR2.value, value);
}
/**
* Change the value of the Share button on the controller.
*
* @param value the new value
*/
public void setShareButton(boolean value) {
setRawButton(PS4Controller.Button.kShare.value, value);
}
/**
* Change the value of the Options button on the controller.
*
* @param value the new value
*/
public void setOptionsButton(boolean value) {
setRawButton(PS4Controller.Button.kOptions.value, value);
}
/**
* Change the value of the L3 (left stick) button on the controller.
*
* @param value the new value
*/
public void setL3Button(boolean value) {
setRawButton(PS4Controller.Button.kL3.value, value);
}
/**
* Change the value of the R3 (right stick) button on the controller.
*
* @param value the new value
*/
public void setR3Button(boolean value) {
setRawButton(PS4Controller.Button.kR3.value, value);
}
/**
* Change the value of the PS button on the controller.
*
* @param value the new value
*/
public void setPSButton(boolean value) {
setRawButton(PS4Controller.Button.kPS.value, value);
}
/**
* Change the value of the touchpad button on the controller.
*
* @param value the new value
*/
public void setTouchpad(boolean value) {
setRawButton(PS4Controller.Button.kTouchpad.value, value);
}
}

View File

@@ -1,216 +0,0 @@
// 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 edu.wpi.first.wpilibj.simulation;
import edu.wpi.first.wpilibj.PS5Controller;
/** Class to control a simulated PS5 controller. */
public class PS5ControllerSim extends GenericHIDSim {
/**
* Constructs from a PS5Controller object.
*
* @param joystick controller to simulate
*/
@SuppressWarnings("this-escape")
public PS5ControllerSim(PS5Controller joystick) {
super(joystick);
setAxisCount(6);
setButtonCount(14);
setPOVCount(1);
}
/**
* Constructs from a joystick port number.
*
* @param port port number
*/
@SuppressWarnings("this-escape")
public PS5ControllerSim(int port) {
super(port);
setAxisCount(6);
setButtonCount(14);
setPOVCount(1);
}
/**
* Change the X axis value of the controller's left stick.
*
* @param value the new value
*/
public void setLeftX(double value) {
setRawAxis(PS5Controller.Axis.kLeftX.value, value);
}
/**
* Change the X axis value of the controller's right stick.
*
* @param value the new value
*/
public void setRightX(double value) {
setRawAxis(PS5Controller.Axis.kRightX.value, value);
}
/**
* Change the Y axis value of the controller's left stick.
*
* @param value the new value
*/
public void setLeftY(double value) {
setRawAxis(PS5Controller.Axis.kLeftY.value, value);
}
/**
* Change the Y axis value of the controller's right stick.
*
* @param value the new value
*/
public void setRightY(double value) {
setRawAxis(PS5Controller.Axis.kRightY.value, value);
}
/**
* Change the L2 axis value of the controller.
*
* @param value the new value
*/
public void setL2Axis(double value) {
setRawAxis(PS5Controller.Axis.kL2.value, value);
}
/**
* Change the R2 axis value of the controller.
*
* @param value the new value
*/
public void setR2Axis(double value) {
setRawAxis(PS5Controller.Axis.kR2.value, value);
}
/**
* Change the value of the Square button on the controller.
*
* @param value the new value
*/
public void setSquareButton(boolean value) {
setRawButton(PS5Controller.Button.kSquare.value, value);
}
/**
* Change the value of the Cross button on the controller.
*
* @param value the new value
*/
public void setCrossButton(boolean value) {
setRawButton(PS5Controller.Button.kCross.value, value);
}
/**
* Change the value of the Circle button on the controller.
*
* @param value the new value
*/
public void setCircleButton(boolean value) {
setRawButton(PS5Controller.Button.kCircle.value, value);
}
/**
* Change the value of the Triangle button on the controller.
*
* @param value the new value
*/
public void setTriangleButton(boolean value) {
setRawButton(PS5Controller.Button.kTriangle.value, value);
}
/**
* Change the value of the L1 button on the controller.
*
* @param value the new value
*/
public void setL1Button(boolean value) {
setRawButton(PS5Controller.Button.kL1.value, value);
}
/**
* Change the value of the R1 button on the controller.
*
* @param value the new value
*/
public void setR1Button(boolean value) {
setRawButton(PS5Controller.Button.kR1.value, value);
}
/**
* Change the value of the L2 button on the controller.
*
* @param value the new value
*/
public void setL2Button(boolean value) {
setRawButton(PS5Controller.Button.kL2.value, value);
}
/**
* Change the value of the R2 button on the controller.
*
* @param value the new value
*/
public void setR2Button(boolean value) {
setRawButton(PS5Controller.Button.kR2.value, value);
}
/**
* Change the value of the Create button on the controller.
*
* @param value the new value
*/
public void setCreateButton(boolean value) {
setRawButton(PS5Controller.Button.kCreate.value, value);
}
/**
* Change the value of the Options button on the controller.
*
* @param value the new value
*/
public void setOptionsButton(boolean value) {
setRawButton(PS5Controller.Button.kOptions.value, value);
}
/**
* Change the value of the L3 (left stick) button on the controller.
*
* @param value the new value
*/
public void setL3Button(boolean value) {
setRawButton(PS5Controller.Button.kL3.value, value);
}
/**
* Change the value of the R3 (right stick) button on the controller.
*
* @param value the new value
*/
public void setR3Button(boolean value) {
setRawButton(PS5Controller.Button.kR3.value, value);
}
/**
* Change the value of the PS button on the controller.
*
* @param value the new value
*/
public void setPSButton(boolean value) {
setRawButton(PS5Controller.Button.kPS.value, value);
}
/**
* Change the value of the touchpad button on the controller.
*
* @param value the new value
*/
public void setTouchpad(boolean value) {
setRawButton(PS5Controller.Button.kTouchpad.value, value);
}
}

View File

@@ -1,180 +0,0 @@
// 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 edu.wpi.first.wpilibj.simulation;
import edu.wpi.first.wpilibj.XboxController;
/** Class to control a simulated Xbox 360 or Xbox One controller. */
public class XboxControllerSim extends GenericHIDSim {
/**
* Constructs from a XboxController object.
*
* @param joystick controller to simulate
*/
@SuppressWarnings("this-escape")
public XboxControllerSim(XboxController joystick) {
super(joystick);
setAxisCount(6);
setButtonCount(10);
setPOVCount(1);
}
/**
* Constructs from a joystick port number.
*
* @param port port number
*/
@SuppressWarnings("this-escape")
public XboxControllerSim(int port) {
super(port);
setAxisCount(6);
setButtonCount(10);
setPOVCount(1);
}
/**
* Change the left X value of the joystick.
*
* @param value the new value
*/
public void setLeftX(double value) {
setRawAxis(XboxController.Axis.kLeftX.value, value);
}
/**
* Change the right X value of the joystick.
*
* @param value the new value
*/
public void setRightX(double value) {
setRawAxis(XboxController.Axis.kRightX.value, value);
}
/**
* Change the left Y value of the joystick.
*
* @param value the new value
*/
public void setLeftY(double value) {
setRawAxis(XboxController.Axis.kLeftY.value, value);
}
/**
* Change the right Y value of the joystick.
*
* @param value the new value
*/
public void setRightY(double value) {
setRawAxis(XboxController.Axis.kRightY.value, value);
}
/**
* Change the value of the left trigger axis on the joystick.
*
* @param value the new value
*/
public void setLeftTriggerAxis(double value) {
setRawAxis(XboxController.Axis.kLeftTrigger.value, value);
}
/**
* Change the value of the right trigger axis on the joystick.
*
* @param value the new value
*/
public void setRightTriggerAxis(double value) {
setRawAxis(XboxController.Axis.kRightTrigger.value, value);
}
/**
* Change the value of the left bumper on the joystick.
*
* @param state the new value
*/
public void setLeftBumper(boolean state) {
setRawButton(XboxController.Button.kLeftBumper.value, state);
}
/**
* Change the value of the right bumper on the joystick.
*
* @param state the new value
*/
public void setRightBumper(boolean state) {
setRawButton(XboxController.Button.kRightBumper.value, state);
}
/**
* Change the value of the left stick button on the joystick.
*
* @param state the new value
*/
public void setLeftStickButton(boolean state) {
setRawButton(XboxController.Button.kLeftStick.value, state);
}
/**
* Change the value of the right stick button on the joystick.
*
* @param state the new value
*/
public void setRightStickButton(boolean state) {
setRawButton(XboxController.Button.kRightStick.value, state);
}
/**
* Change the value of the A button.
*
* @param state the new value
*/
public void setAButton(boolean state) {
setRawButton(XboxController.Button.kA.value, state);
}
/**
* Change the value of the B button.
*
* @param state the new value
*/
public void setBButton(boolean state) {
setRawButton(XboxController.Button.kB.value, state);
}
/**
* Change the value of the X button.
*
* @param state the new value
*/
public void setXButton(boolean state) {
setRawButton(XboxController.Button.kX.value, state);
}
/**
* Change the value of the Y button.
*
* @param state the new value
*/
public void setYButton(boolean state) {
setRawButton(XboxController.Button.kY.value, state);
}
/**
* Change the value of the Back button.
*
* @param state the new value
*/
public void setBackButton(boolean state) {
setRawButton(XboxController.Button.kBack.value, state);
}
/**
* Change the value of the Start button.
*
* @param state the new value
*/
public void setStartButton(boolean state) {
setRawButton(XboxController.Button.kStart.value, state);
}
}