This class handles {{ ConsoleName }} 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. + * + *
Only first party controllers from {{ Manufacturer }} 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 {{ ConsoleName }}Controller extends GenericHID { + /** Represents a digital button on a {{ ConsoleName }}Controller. */ + public enum Button { +{%- for button in buttons %} + /** {{ capitalize_first(button.DocName|default(button.name)) }} button. */ + k{{ capitalize_first(button.name) }}({{ button.value }}){{ ";" if loop.last else ","}} +{%- endfor %} + + /** 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 appending `Button`. + * + *
Primarily used for automated unit tests. + * + * @return the human-friendly name of the button. + */ + @Override + public String toString() { + // Remove leading `k` + return this.name().substring(1) + "Button"; + } + } + + /** Represents an axis on an {{ ConsoleName }}Controller. */ + public enum Axis { +{%- for stick in sticks %} + /** {{ stick.NameParts|map("capitalize")|join(" ") }} axis. */ + k{{ stick.NameParts|map("capitalize")|join }}({{ stick.value }}){{ "," if triggers|length > 0 or not loop.last else ";"}} +{%- endfor %} +{%- for trigger in triggers %} + /** {{ trigger.DocName|capitalize }}. */ + k{{ capitalize_first(trigger.name) }}({{ trigger.value }}){{ ";" if loop.last else ","}} +{%- endfor %} + + /** 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 appending `Axis` if the name ends with `{{ AxisNameSuffix }}`. + * + *
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("{{ AxisNameSuffix }}")) { + 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 (0-5). + */ + public {{ ConsoleName }}Controller(final int port) { + super(port); + {{ "// " if SkipReporting }}HAL.report(tResourceType.kResourceType_{{ ConsoleName }}Controller, port + 1); + } +{% for stick in sticks %} + /** + * Get the {{ stick.NameParts[1] }} axis value of {{ stick.NameParts[0] }} side of the controller. + * + * @return The axis value. + */ + public double get{{ stick.NameParts|map("capitalize")|join }}() { + return getRawAxis(Axis.k{{ stick.NameParts|map("capitalize")|join }}.value); + } +{% endfor -%} +{% for trigger in triggers %} + /** + * Get the {{ trigger.DocName }} 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 get{{ capitalize_first(trigger.name) }}Axis() { + return getRawAxis(Axis.k{{ capitalize_first(trigger.name) }}.value); + } +{% if trigger.UseThresholdMethods %} + /** + * Constructs an event instance around the axis value of the {{ trigger.DocName }}. 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 {{ trigger.DocName }}'s axis exceeds the provided + * threshold, attached to the given event loop + */ + public BooleanEvent {{ trigger.name }}(double threshold, EventLoop loop) { + return new BooleanEvent(loop, () -> get{{ capitalize_first(trigger.name) }}Axis() > threshold); + } + + /** + * Constructs an event instance around the axis value of the {{ trigger.DocName }}. 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 {{ trigger.DocName }}'s axis exceeds the provided + * threshold, attached to the given event loop + */ + public BooleanEvent {{ trigger.name }}(EventLoop loop) { + return {{ trigger.name }}(0.5, loop); + } +{% endif -%} +{% endfor -%} +{% for button in buttons %} + /** + * Read the value of the {{ button.DocName|default(button.name) }} button on the controller. + * + * @return The state of the button. + */ + public boolean get{{ capitalize_first(button.name) }}Button() { + return getRawButton(Button.k{{ capitalize_first(button.name) }}.value); + } + + /** + * Whether the {{ button.DocName|default(button.name) }} button was pressed since the last check. + * + * @return Whether the button was pressed since the last check. + */ + public boolean get{{ capitalize_first(button.name) }}ButtonPressed() { + return getRawButtonPressed(Button.k{{ capitalize_first(button.name) }}.value); + } + + /** + * Whether the {{ button.DocName|default(button.name) }} button was released since the last check. + * + * @return Whether the button was released since the last check. + */ + public boolean get{{ capitalize_first(button.name) }}ButtonReleased() { + return getRawButtonReleased(Button.k{{ capitalize_first(button.name) }}.value); + } + + /** + * Constructs an event instance around the {{ button.DocName|default(button.name) }} button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the {{ button.DocName|default(button.name) }} button's digital signal + * attached to the given loop. + */ + public BooleanEvent {{ button.name }}(EventLoop loop) { + return new BooleanEvent(loop, this::get{{ capitalize_first(button.name) }}Button); + } +{% endfor -%} +{% if ConsoleName == "Xbox" or ConsoleName == "Stadia" %} + /** + * Read the value of the left bumper (LB) button on the controller. + * + * @return The state of the button. + * @deprecated Use {@link getLeftBumperButton} instead + */ + @Deprecated(since = "2025", forRemoval = true) + 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. + * @deprecated Use {@link getRightBumperButton} instead + */ + @Deprecated(since = "2025", forRemoval = true) + 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. + * @deprecated Use {@link getLeftBumperButtonPressed} instead + */ + @Deprecated(since = "2025", forRemoval = true) + 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. + * @deprecated Use {@link getRightBumperButtonPressed} instead + */ + @Deprecated(since = "2025", forRemoval = true) + 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. + * @deprecated Use {@link getLeftBumperButtonReleased} instead + */ + @Deprecated(since = "2025", forRemoval = true) + 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. + * @deprecated Use {@link getRightBumperButtonReleased} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public boolean getRightBumperReleased() { + return getRawButtonReleased(Button.kRightBumper.value); + } +{% elif ConsoleName == "PS4" or ConsoleName == "PS5" %} + /** + * Read the value of the touchpad on the controller. + * + * @return The state of the touchpad. + * @deprecated Use {@link getTouchpadButton} instead + */ + @Deprecated(since = "2025", forRemoval = true) + 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. + * @deprecated Use {@link getTouchpadButtonPressed} instead + */ + @Deprecated(since = "2025", forRemoval = true) + 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. + * @deprecated Use {@link getTouchpadButtonReleased} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public boolean getTouchpadReleased() { + return getRawButtonReleased(Button.kTouchpad.value); + } +{% endif -%} +} diff --git a/wpilibj/src/generate/hids.json b/wpilibj/src/generate/hids.json new file mode 100644 index 0000000000..f27806458a --- /dev/null +++ b/wpilibj/src/generate/hids.json @@ -0,0 +1,440 @@ +[ + { + "ConsoleName": "Xbox", + "Manufacturer": "Microsoft", + "SkipReporting": false, + "AxisNameSuffix": "Trigger", + "buttons": [ + { + "name": "a", + "value": 1, + "DocName": "A" + }, + { + "name": "b", + "value": 2, + "DocName": "B" + }, + { + "name": "x", + "value": 3, + "DocName": "X" + }, + { + "name": "y", + "value": 4, + "DocName": "Y" + }, + { + "name": "leftBumper", + "value": 5, + "DocName": "left bumper" + }, + { + "name": "rightBumper", + "value": 6, + "DocName": "right bumper" + }, + { + "name": "back", + "value": 7 + }, + { + "name": "start", + "value": 8 + }, + { + "name": "leftStick", + "value": 9, + "DocName": "left stick" + }, + { + "name": "rightStick", + "value": 10, + "DocName": "right stick" + } + ], + "sticks": [ + { + "NameParts": [ + "left", + "X" + ], + "value": 0 + }, + { + "NameParts": [ + "right", + "X" + ], + "value": 4 + }, + { + "NameParts": [ + "left", + "Y" + ], + "value": 1 + }, + { + "NameParts": [ + "right", + "Y" + ], + "value": 5 + } + ], + "triggers": [ + { + "name": "leftTrigger", + "value": 2, + "DocName": "left trigger", + "UseThresholdMethods": true + }, + { + "name": "rightTrigger", + "value": 3, + "DocName": "right trigger", + "UseThresholdMethods": true + } + ] + }, + { + "ConsoleName": "PS4", + "Manufacturer": "Sony", + "SkipReporting": false, + "AxisNameSuffix": "2", + "buttons": [ + { + "name": "square", + "value": 1 + }, + { + "name": "cross", + "value": 2 + }, + { + "name": "circle", + "value": 3 + }, + { + "name": "triangle", + "value": 4 + }, + { + "name": "L1", + "value": 5, + "DocName": "left trigger 1" + }, + { + "name": "R1", + "value": 6, + "DocName": "right trigger 1" + }, + { + "name": "L2", + "value": 7, + "DocName": "left trigger 2" + }, + { + "name": "R2", + "value": 8, + "DocName": "right trigger 2" + }, + { + "name": "share", + "value": 9 + }, + { + "name": "options", + "value": 10 + }, + { + "name": "L3", + "value": 11, + "DocName": "L3 (left stick)" + }, + { + "name": "R3", + "value": 12, + "DocName": "R3 (right stick)" + }, + { + "name": "PS", + "value": 13, + "DocName": "PlayStation" + }, + { + "name": "touchpad", + "value": 14 + } + ], + "sticks": [ + { + "NameParts": [ + "left", + "X" + ], + "value": 0 + }, + { + "NameParts": [ + "left", + "Y" + ], + "value": 1 + }, + { + "NameParts": [ + "right", + "X" + ], + "value": 2 + }, + { + "NameParts": [ + "right", + "Y" + ], + "value": 5 + } + ], + "triggers": [ + { + "name": "L2", + "value": 3, + "DocName": "left trigger 2", + "UseThresholdMethods": false + }, + { + "name": "R2", + "value": 4, + "DocName": "right trigger 2", + "UseThresholdMethods": false + } + ] + }, + { + "ConsoleName": "PS5", + "Manufacturer": "Sony", + "SkipReporting": true, + "AxisNameSuffix": "2", + "buttons": [ + { + "name": "square", + "value": 1 + }, + { + "name": "cross", + "value": 2 + }, + { + "name": "circle", + "value": 3 + }, + { + "name": "triangle", + "value": 4 + }, + { + "name": "L1", + "value": 5, + "DocName": "left trigger 1" + }, + { + "name": "R1", + "value": 6, + "DocName": "right trigger 1" + }, + { + "name": "L2", + "value": 7, + "DocName": "left trigger 2" + }, + { + "name": "R2", + "value": 8, + "DocName": "right trigger 2" + }, + { + "name": "create", + "value": 9 + }, + { + "name": "options", + "value": 10 + }, + { + "name": "L3", + "value": 11, + "DocName": "L3 (left stick)" + }, + { + "name": "R3", + "value": 12, + "DocName": "R3 (right stick)" + }, + { + "name": "PS", + "value": 13, + "DocName": "PlayStation" + }, + { + "name": "touchpad", + "value": 14 + } + ], + "sticks": [ + { + "NameParts": [ + "left", + "X" + ], + "value": 0 + }, + { + "NameParts": [ + "left", + "Y" + ], + "value": 1 + }, + { + "NameParts": [ + "right", + "X" + ], + "value": 2 + }, + { + "NameParts": [ + "right", + "Y" + ], + "value": 5 + } + ], + "triggers": [ + { + "name": "L2", + "value": 3, + "DocName": "left trigger 2", + "UseThresholdMethods": false + }, + { + "name": "R2", + "value": 4, + "DocName": "right trigger 2", + "UseThresholdMethods": false + } + ] + }, + { + "ConsoleName": "Stadia", + "Manufacturer": "Google", + "SkipReporting": true, + "AxisNameSuffix": "Trigger", + "buttons": [ + { + "name": "a", + "value": 1, + "DocName": "A" + }, + { + "name": "b", + "value": 2, + "DocName": "B" + }, + { + "name": "x", + "value": 3, + "DocName": "X" + }, + { + "name": "y", + "value": 4, + "DocName": "Y" + }, + { + "name": "leftBumper", + "value": 5, + "DocName": "left bumper" + }, + { + "name": "rightBumper", + "value": 6, + "DocName": "right bumper" + }, + { + "name": "leftStick", + "value": 7, + "DocName": "left stick" + }, + { + "name": "rightStick", + "value": 8, + "DocName": "right stick" + }, + { + "name": "ellipses", + "value": 9 + }, + { + "name": "hamburger", + "value": 10 + }, + { + "name": "stadia", + "value": 11 + }, + { + "name": "rightTrigger", + "value": 12, + "DocName": "right trigger" + }, + { + "name": "leftTrigger", + "value": 13, + "DocName": "left trigger" + }, + { + "name": "google", + "value": 14 + }, + { + "name": "frame", + "value": 15 + } + ], + "sticks": [ + { + "NameParts": [ + "left", + "X" + ], + "value": 0 + }, + { + "NameParts": [ + "right", + "X" + ], + "value": 3 + }, + { + "NameParts": [ + "left", + "Y" + ], + "value": 1 + }, + { + "NameParts": [ + "right", + "Y" + ], + "value": 4 + } + ] + } +] diff --git a/wpilibj/src/generate/hids.schema.json b/wpilibj/src/generate/hids.schema.json new file mode 100644 index 0000000000..3b9dca3015 --- /dev/null +++ b/wpilibj/src/generate/hids.schema.json @@ -0,0 +1,120 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "https://raw.githubusercontent.com/wpilibsuite/allwpilib/main/wpilibj/src/generate/hids.schema.json", + "title": "A schema for defining HIDs with JSON", + "type": "array", + "default": [], + "items": { + "title": "A Schema", + "type": "object", + "required": [ + "ConsoleName", + "Manufacturer", + "SkipReporting", + "AxisNameSuffix", + "buttons", + "sticks" + ], + "properties": { + "ConsoleName": { + "description": "The name of the console this controller is associated with", + "type": "string" + }, + "Manufacturer": { + "description": "The manufacturer of the console", + "type": "string" + }, + "SkipReporting": { + "description": "Whether or not to skip the usage reporting call", + "type": "boolean" + }, + "AxisNameSuffix": { + "description": "The suffix of an axis that shouldn't have Axis appended to its name", + "type": "string" + }, + "buttons": { + "description": "A list of buttons on the controller", + "type": "array", + "items": { + "description": "A description of a button on the controller", + "type": "object", + "required": [ + "name", + "value" + ], + "properties": { + "name": { + "description": "The name in lowerCamelCase", + "type": "string" + }, + "value": { + "description": "The button value", + "type": "integer" + }, + "DocName": { + "description": "The name of the button to use in docs", + "type": "string" + } + } + } + }, + "sticks": { + "description": "A list of joysticks on the controller", + "type": "array", + "items": { + "description": "A description of a joystick", + "type": "object", + "required": [ + "NameParts", + "value" + ], + "properties": { + "NameParts": { + "description": "The parts of the joystick name in lowerCamelCase", + "type": "array", + "items": { + "description": "The different components of a joystick name, direction and axis", + "type": "string" + } + }, + "value": { + "description": "The axis value", + "type": "integer" + } + } + } + }, + "triggers": { + "description": "A list of triggers on the controller", + "type": "array", + "items": { + "description": "A description of a trigger on the controller", + "type": "object", + "required": [ + "name", + "value", + "UseThresholdMethods" + ], + "properties": { + "name": { + "description": "The name of the trigger to use in code", + "type": "string" + }, + "value": { + "description": "The axis value", + "type": "integer" + }, + "DocName": { + "description": "The name of the trigger for use in docs", + "type": "string" + }, + "UseThresholdMethods": { + "description": "Whether or not an method is created where an event fires based on the axis value", + "type": "boolean" + } + } + } + } + } + } +} diff --git a/wpilibj/src/generate/hidsim.java.jinja b/wpilibj/src/generate/hidsim.java.jinja new file mode 100644 index 0000000000..c2f2704bef --- /dev/null +++ b/wpilibj/src/generate/hidsim.java.jinja @@ -0,0 +1,115 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./wpilibj/generate_hids.py. DO NOT MODIFY +{% macro capitalize_first(string) -%} +{{ string[0]|capitalize + string[1:] }} +{%- endmacro %} +package edu.wpi.first.wpilibj.simulation; + +import edu.wpi.first.wpilibj.{{ ConsoleName }}Controller; + +/** Class to control a simulated {{ ConsoleName }} controller. */ +public class {{ ConsoleName }}ControllerSim extends GenericHIDSim { + /** + * Constructs from a {{ ConsoleName }}Controller object. + * + * @param joystick controller to simulate + */ + @SuppressWarnings("this-escape") + public {{ ConsoleName }}ControllerSim({{ ConsoleName }}Controller joystick) { + super(joystick); + setAxisCount({{ sticks|length + triggers|length }}); + setButtonCount({{ buttons|length }}); + setPOVCount(1); + } + + /** + * Constructs from a joystick port number. + * + * @param port port number + */ + @SuppressWarnings("this-escape") + public {{ ConsoleName }}ControllerSim(int port) { + super(port); + setAxisCount({{ sticks|length + triggers|length }}); + setButtonCount({{ buttons|length }}); + setPOVCount(1); + } +{% for stick in sticks %} + /** + * Change the {{ stick.NameParts|join(" ") }} value of the controller's joystick. + * + * @param value the new value + */ + public void set{{ stick.NameParts|map("capitalize")|join }}(double value) { + setRawAxis({{ ConsoleName }}Controller.Axis.k{{ stick.NameParts|map("capitalize")|join }}.value, value); + } +{% endfor -%} +{% for trigger in triggers %} + /** + * Change the value of the {{ trigger.DocName }} axis on the controller. + * + * @param value the new value + */ + public void set{{ capitalize_first(trigger.name) }}Axis(double value) { + setRawAxis({{ ConsoleName }}Controller.Axis.k{{ capitalize_first(trigger.name) }}.value, value); + } +{% endfor -%} +{% for button in buttons %} + /** + * Change the value of the {{ button.DocName|default(button.name) }} button on the controller. + * + * @param value the new value + */ + public void set{{ capitalize_first(button.name) }}Button(boolean value) { + setRawButton({{ ConsoleName }}Controller.Button.k{{ capitalize_first(button.name) }}.value, value); + } +{% endfor -%} +{% if ConsoleName == "Xbox" %} + /** + * Change the value of the left bumper on the joystick. + * + * @param state the new value + * @deprecated Use {@link setLeftBumperButton} instead + */ + @Deprecated(since = "2025", forRemoval = true) + 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 + * @deprecated Use {@link setRightBumperButton} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public void setRightBumper(boolean state) { + setRawButton(XboxController.Button.kRightBumper.value, state); + } +{% elif ConsoleName == "PS4" %} + /** + * Change the value of the touchpad button on the controller. + * + * @param value the new value + * @deprecated Use {@link setTouchpadButton} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public void setTouchpad(boolean value) { + setRawButton(PS4Controller.Button.kTouchpad.value, value); + } +{% elif ConsoleName == "PS5" %} + /** + * Change the value of the touchpad button on the controller. + * + * @param value the new value + * @deprecated Use {@link setTouchpadButton} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public void setTouchpad(boolean value) { + setRawButton(PS5Controller.Button.kTouchpad.value, value); + } +{% endif -%} +} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PS4Controller.java b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/PS4Controller.java similarity index 68% rename from wpilibj/src/main/java/edu/wpi/first/wpilibj/PS4Controller.java rename to wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/PS4Controller.java index e000c6f51d..3195c5122b 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PS4Controller.java +++ b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/PS4Controller.java @@ -2,6 +2,8 @@ // 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. +// THIS FILE WAS AUTO-GENERATED BY ./wpilibj/generate_hids.py. DO NOT MODIFY + package edu.wpi.first.wpilibj; import edu.wpi.first.hal.FRCNetComm.tResourceType; @@ -16,63 +18,52 @@ import edu.wpi.first.wpilibj.event.EventLoop; * 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. * - *
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. + *
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. */ + /** Cross button. */ kCross(2), /** Circle button. */ kCircle(3), /** Triangle button. */ kTriangle(4), - /** Left Trigger 1 button. */ + /** Left trigger 1 button. */ kL1(5), - /** Right Trigger 1 button. */ + /** Right trigger 1 button. */ kR1(6), - /** Left Trigger 2 button. */ + /** Left trigger 2 button. */ kL2(7), - /** Right Trigger 2 button. */ + /** Right trigger 2 button. */ kR2(8), /** Share button. */ kShare(9), - /** Option button. */ + /** Options button. */ kOptions(10), - /** Left stick button. */ + /** L3 (left stick) button. */ kL3(11), - /** Right stick button. */ + /** R3 (right stick) button. */ kR3(12), /** PlayStation button. */ kPS(13), - /** Touchpad click button. */ + /** Touchpad button. */ kTouchpad(14); /** Button value. */ public final int value; - Button(int index) { - this.value = index; + 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 the touchpad append `Button`. + * stripping the leading `k`, and appending `Button`. * *
Primarily used for automated unit tests. * @@ -80,15 +71,12 @@ public class PS4Controller extends GenericHID { */ @Override public String toString() { - var name = this.name().substring(1); // Remove leading `k` - if (this == kTouchpad) { - return name; - } - return name + "Button"; + // Remove leading `k` + return this.name().substring(1) + "Button"; } } - /** Represents an axis on a PS4Controller. */ + /** Represents an axis on an PS4Controller. */ public enum Axis { /** Left X axis. */ kLeftX(0), @@ -98,21 +86,21 @@ public class PS4Controller extends GenericHID { kRightX(2), /** Right Y axis. */ kRightY(5), - /** Left Trigger 2. */ + /** Left trigger 2. */ kL2(3), - /** Right Trigger 2. */ + /** Right trigger 2. */ kR2(4); /** Axis value. */ public final int value; - Axis(int index) { - value = index; + 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 one of L2/R2 append `Axis`. + * stripping the leading `k`, and appending `Axis` if the name ends with `2`. * *
Primarily used for automated unit tests. * @@ -128,298 +116,74 @@ public class PS4Controller extends GenericHID { } } + /** + * Construct an instance of a controller. + * + * @param port The port index on the Driver Station that the controller is plugged into (0-5). + */ + public PS4Controller(final int port) { + super(port); + HAL.report(tResourceType.kResourceType_PS4Controller, port + 1); + } + /** * Get the X axis value of left side of the controller. * - * @return the axis value. + * @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. + * @return The axis value. */ public double getLeftY() { return getRawAxis(Axis.kLeftY.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 right side of the controller. * - * @return the axis value. + * @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]. + * Get the left trigger 2 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. + * @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]. + * Get the right trigger 2 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. + * @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. + * Read the value of the square button on the controller. * * @return The state of the button. */ @@ -428,7 +192,7 @@ public class PS4Controller extends GenericHID { } /** - * Whether the Square button was pressed since the last check. + * Whether the square button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ @@ -437,7 +201,7 @@ public class PS4Controller extends GenericHID { } /** - * Whether the Square button was released since the last check. + * Whether the square button was released since the last check. * * @return Whether the button was released since the last check. */ @@ -449,15 +213,15 @@ public class PS4Controller extends GenericHID { * 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. + * @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. + * Read the value of the cross button on the controller. * * @return The state of the button. */ @@ -466,7 +230,7 @@ public class PS4Controller extends GenericHID { } /** - * Whether the Cross button was pressed since the last check. + * Whether the cross button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ @@ -475,7 +239,7 @@ public class PS4Controller extends GenericHID { } /** - * Whether the Cross button was released since the last check. + * Whether the cross button was released since the last check. * * @return Whether the button was released since the last check. */ @@ -487,53 +251,15 @@ public class PS4Controller extends GenericHID { * 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. + * @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. + * Read the value of the circle button on the controller. * * @return The state of the button. */ @@ -542,7 +268,7 @@ public class PS4Controller extends GenericHID { } /** - * Whether the Circle button was pressed since the last check. + * Whether the circle button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ @@ -551,7 +277,7 @@ public class PS4Controller extends GenericHID { } /** - * Whether the Circle button was released since the last check. + * Whether the circle button was released since the last check. * * @return Whether the button was released since the last check. */ @@ -563,13 +289,203 @@ public class PS4Controller extends GenericHID { * 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. + * @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 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 left trigger 1 button on the controller. + * + * @return The state of the button. + */ + public boolean getL1Button() { + return getRawButton(Button.kL1.value); + } + + /** + * Whether the left trigger 1 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 left trigger 1 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); + } + + /** + * Constructs an event instance around the left trigger 1 button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the left trigger 1 button's digital signal + * attached to the given loop. + */ + public BooleanEvent L1(EventLoop loop) { + return new BooleanEvent(loop, this::getL1Button); + } + + /** + * Read the value of the right trigger 1 button on the controller. + * + * @return The state of the button. + */ + public boolean getR1Button() { + return getRawButton(Button.kR1.value); + } + + /** + * Whether the right trigger 1 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 right trigger 1 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 right trigger 1 button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the right trigger 1 button's digital signal + * attached to the given loop. + */ + public BooleanEvent R1(EventLoop loop) { + return new BooleanEvent(loop, this::getR1Button); + } + + /** + * Read the value of the left trigger 2 button on the controller. + * + * @return The state of the button. + */ + public boolean getL2Button() { + return getRawButton(Button.kL2.value); + } + + /** + * Whether the left trigger 2 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 left trigger 2 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); + } + + /** + * Constructs an event instance around the left trigger 2 button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the left trigger 2 button's digital signal + * attached to the given loop. + */ + public BooleanEvent L2(EventLoop loop) { + return new BooleanEvent(loop, this::getL2Button); + } + + /** + * Read the value of the right trigger 2 button on the controller. + * + * @return The state of the button. + */ + public boolean getR2Button() { + return getRawButton(Button.kR2.value); + } + + /** + * Whether the right trigger 2 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 right trigger 2 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 right trigger 2 button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the right trigger 2 button's digital signal + * attached to the given loop. + */ + public BooleanEvent R2(EventLoop loop) { + return new BooleanEvent(loop, this::getR2Button); + } + /** * Read the value of the share button on the controller. * @@ -601,53 +517,13 @@ public class PS4Controller extends GenericHID { * 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. + * @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. * @@ -679,18 +555,172 @@ public class PS4Controller extends GenericHID { * 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. + * @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 L3 (left stick) button on the controller. + * + * @return The state of the button. + */ + public boolean getL3Button() { + return getRawButton(Button.kL3.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 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); + } + + /** + * Constructs an event instance around the L3 (left stick) button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the L3 (left stick) button's digital signal + * attached to the given loop. + */ + public BooleanEvent L3(EventLoop loop) { + return new BooleanEvent(loop, this::getL3Button); + } + + /** + * Read the value of the R3 (right stick) button on the controller. + * + * @return The state of the button. + */ + public boolean getR3Button() { + return getRawButton(Button.kR3.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 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 R3 (right stick) button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the R3 (right stick) button's digital signal + * attached to the given loop. + */ + public BooleanEvent R3(EventLoop loop) { + return new BooleanEvent(loop, this::getR3Button); + } + + /** + * Read the value of the PlayStation button on the controller. + * + * @return The state of the button. + */ + public boolean getPSButton() { + return getRawButton(Button.kPS.value); + } + + /** + * Whether the PlayStation 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 PlayStation 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 PlayStation button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the PlayStation button's digital signal + * attached to the given loop. + */ + public BooleanEvent PS(EventLoop loop) { + return new BooleanEvent(loop, this::getPSButton); + } + + /** + * Read the value of the touchpad button on the controller. + * + * @return The state of the button. + */ + public boolean getTouchpadButton() { + return getRawButton(Button.kTouchpad.value); + } + + /** + * Whether the touchpad button was pressed since the last check. + * + * @return Whether the button was pressed since the last check. + */ + public boolean getTouchpadButtonPressed() { + return getRawButtonPressed(Button.kTouchpad.value); + } + + /** + * Whether the touchpad button was released since the last check. + * + * @return Whether the button was released since the last check. + */ + public boolean getTouchpadButtonReleased() { + return getRawButtonReleased(Button.kTouchpad.value); + } + + /** + * Constructs an event instance around the touchpad button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the touchpad button's digital signal + * attached to the given loop. + */ + public BooleanEvent touchpad(EventLoop loop) { + return new BooleanEvent(loop, this::getTouchpadButton); + } + /** * Read the value of the touchpad on the controller. * * @return The state of the touchpad. + * @deprecated Use {@link getTouchpadButton} instead */ + @Deprecated(since = "2025", forRemoval = true) public boolean getTouchpad() { return getRawButton(Button.kTouchpad.value); } @@ -699,7 +729,9 @@ public class PS4Controller extends GenericHID { * Whether the touchpad was pressed since the last check. * * @return Whether the touchpad was pressed since the last check. + * @deprecated Use {@link getTouchpadButtonPressed} instead */ + @Deprecated(since = "2025", forRemoval = true) public boolean getTouchpadPressed() { return getRawButtonPressed(Button.kTouchpad.value); } @@ -708,19 +740,10 @@ public class PS4Controller extends GenericHID { * Whether the touchpad was released since the last check. * * @return Whether the touchpad was released since the last check. + * @deprecated Use {@link getTouchpadButtonReleased} instead */ + @Deprecated(since = "2025", forRemoval = true) 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); - } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PS5Controller.java b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/PS5Controller.java similarity index 67% rename from wpilibj/src/main/java/edu/wpi/first/wpilibj/PS5Controller.java rename to wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/PS5Controller.java index 18cb738e88..7b0e3083ab 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PS5Controller.java +++ b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/PS5Controller.java @@ -2,8 +2,12 @@ // 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. +// THIS FILE WAS AUTO-GENERATED BY ./wpilibj/generate_hids.py. DO NOT MODIFY + 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; @@ -14,26 +18,16 @@ import edu.wpi.first.wpilibj.event.EventLoop; * 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. * - *
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. + *
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. */ + /** Cross button. */ kCross(2), /** Circle button. */ kCircle(3), @@ -51,25 +45,25 @@ public class PS5Controller extends GenericHID { kCreate(9), /** Options button. */ kOptions(10), - /** Left stick button. */ + /** L3 (left stick) button. */ kL3(11), - /** Right stick button. */ + /** R3 (right stick) button. */ kR3(12), /** PlayStation button. */ kPS(13), - /** Touchpad click button. */ + /** Touchpad button. */ kTouchpad(14); /** Button value. */ public final int value; - Button(int index) { - this.value = index; + 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 the touchpad append `Button`. + * stripping the leading `k`, and appending `Button`. * *
Primarily used for automated unit tests. * @@ -77,15 +71,12 @@ public class PS5Controller extends GenericHID { */ @Override public String toString() { - var name = this.name().substring(1); // Remove leading `k` - if (this == kTouchpad) { - return name; - } - return name + "Button"; + // Remove leading `k` + return this.name().substring(1) + "Button"; } } - /** Represents an axis on a PS5Controller. */ + /** Represents an axis on an PS5Controller. */ public enum Axis { /** Left X axis. */ kLeftX(0), @@ -95,21 +86,21 @@ public class PS5Controller extends GenericHID { kRightX(2), /** Right Y axis. */ kRightY(5), - /** Left Trigger 2. */ + /** Left trigger 2. */ kL2(3), - /** Right Trigger 2. */ + /** Right trigger 2. */ kR2(4); /** Axis value. */ public final int value; - Axis(int index) { - value = index; + 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 one of L2/R2 append `Axis`. + * stripping the leading `k`, and appending `Axis` if the name ends with `2`. * *
Primarily used for automated unit tests. * @@ -125,298 +116,74 @@ public class PS5Controller extends GenericHID { } } + /** + * Construct an instance of a controller. + * + * @param port The port index on the Driver Station that the controller is plugged into (0-5). + */ + public PS5Controller(final int port) { + super(port); + // HAL.report(tResourceType.kResourceType_PS5Controller, port + 1); + } + /** * Get the X axis value of left side of the controller. * - * @return the axis value. + * @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. + * @return The axis value. */ public double getLeftY() { return getRawAxis(Axis.kLeftY.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 right side of the controller. * - * @return the axis value. + * @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]. + * Get the left trigger 2 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. + * @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]. + * Get the right trigger 2 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. + * @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. + * Read the value of the square button on the controller. * * @return The state of the button. */ @@ -425,7 +192,7 @@ public class PS5Controller extends GenericHID { } /** - * Whether the Square button was pressed since the last check. + * Whether the square button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ @@ -434,7 +201,7 @@ public class PS5Controller extends GenericHID { } /** - * Whether the Square button was released since the last check. + * Whether the square button was released since the last check. * * @return Whether the button was released since the last check. */ @@ -446,15 +213,15 @@ public class PS5Controller extends GenericHID { * 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. + * @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. + * Read the value of the cross button on the controller. * * @return The state of the button. */ @@ -463,7 +230,7 @@ public class PS5Controller extends GenericHID { } /** - * Whether the Cross button was pressed since the last check. + * Whether the cross button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ @@ -472,7 +239,7 @@ public class PS5Controller extends GenericHID { } /** - * Whether the Cross button was released since the last check. + * Whether the cross button was released since the last check. * * @return Whether the button was released since the last check. */ @@ -484,53 +251,15 @@ public class PS5Controller extends GenericHID { * 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. + * @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. + * Read the value of the circle button on the controller. * * @return The state of the button. */ @@ -539,7 +268,7 @@ public class PS5Controller extends GenericHID { } /** - * Whether the Circle button was pressed since the last check. + * Whether the circle button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ @@ -548,7 +277,7 @@ public class PS5Controller extends GenericHID { } /** - * Whether the Circle button was released since the last check. + * Whether the circle button was released since the last check. * * @return Whether the button was released since the last check. */ @@ -560,15 +289,205 @@ public class PS5Controller extends GenericHID { * 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. + * @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. + * 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 left trigger 1 button on the controller. + * + * @return The state of the button. + */ + public boolean getL1Button() { + return getRawButton(Button.kL1.value); + } + + /** + * Whether the left trigger 1 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 left trigger 1 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); + } + + /** + * Constructs an event instance around the left trigger 1 button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the left trigger 1 button's digital signal + * attached to the given loop. + */ + public BooleanEvent L1(EventLoop loop) { + return new BooleanEvent(loop, this::getL1Button); + } + + /** + * Read the value of the right trigger 1 button on the controller. + * + * @return The state of the button. + */ + public boolean getR1Button() { + return getRawButton(Button.kR1.value); + } + + /** + * Whether the right trigger 1 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 right trigger 1 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 right trigger 1 button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the right trigger 1 button's digital signal + * attached to the given loop. + */ + public BooleanEvent R1(EventLoop loop) { + return new BooleanEvent(loop, this::getR1Button); + } + + /** + * Read the value of the left trigger 2 button on the controller. + * + * @return The state of the button. + */ + public boolean getL2Button() { + return getRawButton(Button.kL2.value); + } + + /** + * Whether the left trigger 2 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 left trigger 2 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); + } + + /** + * Constructs an event instance around the left trigger 2 button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the left trigger 2 button's digital signal + * attached to the given loop. + */ + public BooleanEvent L2(EventLoop loop) { + return new BooleanEvent(loop, this::getL2Button); + } + + /** + * Read the value of the right trigger 2 button on the controller. + * + * @return The state of the button. + */ + public boolean getR2Button() { + return getRawButton(Button.kR2.value); + } + + /** + * Whether the right trigger 2 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 right trigger 2 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 right trigger 2 button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the right trigger 2 button's digital signal + * attached to the given loop. + */ + public BooleanEvent R2(EventLoop loop) { + return new BooleanEvent(loop, this::getR2Button); + } + + /** + * Read the value of the create button on the controller. * * @return The state of the button. */ @@ -577,7 +496,7 @@ public class PS5Controller extends GenericHID { } /** - * Whether the share button was pressed since the last check. + * Whether the create button was pressed since the last check. * * @return Whether the button was pressed since the last check. */ @@ -586,7 +505,7 @@ public class PS5Controller extends GenericHID { } /** - * Whether the share button was released since the last check. + * Whether the create button was released since the last check. * * @return Whether the button was released since the last check. */ @@ -595,56 +514,16 @@ public class PS5Controller extends GenericHID { } /** - * Constructs an event instance around the share button's digital signal. + * Constructs an event instance around the create 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. + * @return an event instance representing the create 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. * @@ -676,18 +555,172 @@ public class PS5Controller extends GenericHID { * 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. + * @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 L3 (left stick) button on the controller. + * + * @return The state of the button. + */ + public boolean getL3Button() { + return getRawButton(Button.kL3.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 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); + } + + /** + * Constructs an event instance around the L3 (left stick) button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the L3 (left stick) button's digital signal + * attached to the given loop. + */ + public BooleanEvent L3(EventLoop loop) { + return new BooleanEvent(loop, this::getL3Button); + } + + /** + * Read the value of the R3 (right stick) button on the controller. + * + * @return The state of the button. + */ + public boolean getR3Button() { + return getRawButton(Button.kR3.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 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 R3 (right stick) button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the R3 (right stick) button's digital signal + * attached to the given loop. + */ + public BooleanEvent R3(EventLoop loop) { + return new BooleanEvent(loop, this::getR3Button); + } + + /** + * Read the value of the PlayStation button on the controller. + * + * @return The state of the button. + */ + public boolean getPSButton() { + return getRawButton(Button.kPS.value); + } + + /** + * Whether the PlayStation 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 PlayStation 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 PlayStation button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the PlayStation button's digital signal + * attached to the given loop. + */ + public BooleanEvent PS(EventLoop loop) { + return new BooleanEvent(loop, this::getPSButton); + } + + /** + * Read the value of the touchpad button on the controller. + * + * @return The state of the button. + */ + public boolean getTouchpadButton() { + return getRawButton(Button.kTouchpad.value); + } + + /** + * Whether the touchpad button was pressed since the last check. + * + * @return Whether the button was pressed since the last check. + */ + public boolean getTouchpadButtonPressed() { + return getRawButtonPressed(Button.kTouchpad.value); + } + + /** + * Whether the touchpad button was released since the last check. + * + * @return Whether the button was released since the last check. + */ + public boolean getTouchpadButtonReleased() { + return getRawButtonReleased(Button.kTouchpad.value); + } + + /** + * Constructs an event instance around the touchpad button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the touchpad button's digital signal + * attached to the given loop. + */ + public BooleanEvent touchpad(EventLoop loop) { + return new BooleanEvent(loop, this::getTouchpadButton); + } + /** * Read the value of the touchpad on the controller. * * @return The state of the touchpad. + * @deprecated Use {@link getTouchpadButton} instead */ + @Deprecated(since = "2025", forRemoval = true) public boolean getTouchpad() { return getRawButton(Button.kTouchpad.value); } @@ -696,7 +729,9 @@ public class PS5Controller extends GenericHID { * Whether the touchpad was pressed since the last check. * * @return Whether the touchpad was pressed since the last check. + * @deprecated Use {@link getTouchpadButtonPressed} instead */ + @Deprecated(since = "2025", forRemoval = true) public boolean getTouchpadPressed() { return getRawButtonPressed(Button.kTouchpad.value); } @@ -705,19 +740,10 @@ public class PS5Controller extends GenericHID { * Whether the touchpad was released since the last check. * * @return Whether the touchpad was released since the last check. + * @deprecated Use {@link getTouchpadButtonReleased} instead */ + @Deprecated(since = "2025", forRemoval = true) 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); - } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/StadiaController.java b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/StadiaController.java similarity index 78% rename from wpilibj/src/main/java/edu/wpi/first/wpilibj/StadiaController.java rename to wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/StadiaController.java index d092d8b937..916ab3979d 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/StadiaController.java +++ b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/StadiaController.java @@ -2,6 +2,8 @@ // 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. +// THIS FILE WAS AUTO-GENERATED BY ./wpilibj/generate_hids.py. DO NOT MODIFY + package edu.wpi.first.wpilibj; // import edu.wpi.first.hal.FRCNetComm.tResourceType; @@ -15,6 +17,10 @@ import edu.wpi.first.wpilibj.event.EventLoop; *
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. + * + *
Only first party controllers from Google 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 StadiaController extends GenericHID { /** Represents a digital button on a StadiaController. */ @@ -23,9 +29,9 @@ public class StadiaController extends GenericHID { kA(1), /** B button. */ kB(2), - /** X Button. */ + /** X button. */ kX(3), - /** Y Button. */ + /** Y button. */ kY(4), /** Left bumper button. */ kLeftBumper(5), @@ -59,7 +65,7 @@ public class StadiaController extends GenericHID { /** * 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`. + * stripping the leading `k`, and appending `Button`. * *
Primarily used for automated unit tests. * @@ -67,15 +73,12 @@ public class StadiaController extends GenericHID { */ @Override public String toString() { - var name = this.name().substring(1); // Remove leading `k` - if (name.endsWith("Bumper")) { - return name; - } - return name + "Button"; + // Remove leading `k` + return this.name().substring(1) + "Button"; } } - /** Represents an axis on a StadiaController. */ + /** Represents an axis on an StadiaController. */ public enum Axis { /** Left X axis. */ kLeftX(0), @@ -95,7 +98,7 @@ public class StadiaController extends GenericHID { /** * 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`. + * stripping the leading `k`, and appending `Axis` if the name ends with `Trigger`. * *
Primarily used for automated unit tests. * @@ -114,12 +117,11 @@ public class StadiaController extends GenericHID { /** * Construct an instance of a controller. * - * @param port The port index on the Driver Station that the controller is plugged into. + * @param port The port index on the Driver Station that the controller is plugged into (0-5). */ public StadiaController(final int port) { super(port); - // re-enable when StadiaController is added to Usage Reporting - // HAL.report(tResourceType.kResourceType_Joystick, port + 1); + // HAL.report(tResourceType.kResourceType_StadiaController, port + 1); } /** @@ -158,234 +160,6 @@ public class StadiaController extends GenericHID { 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. * @@ -417,10 +191,9 @@ public class StadiaController extends GenericHID { * 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. + * @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); } @@ -456,10 +229,9 @@ public class StadiaController extends GenericHID { * 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. + * @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); } @@ -495,10 +267,9 @@ public class StadiaController extends GenericHID { * 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. + * @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); } @@ -534,14 +305,165 @@ public class StadiaController extends GenericHID { * 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. + * @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 left bumper button on the controller. + * + * @return The state of the button. + */ + public boolean getLeftBumperButton() { + return getRawButton(Button.kLeftBumper.value); + } + + /** + * Whether the left bumper button was pressed since the last check. + * + * @return Whether the button was pressed since the last check. + */ + public boolean getLeftBumperButtonPressed() { + return getRawButtonPressed(Button.kLeftBumper.value); + } + + /** + * Whether the left bumper button was released since the last check. + * + * @return Whether the button was released since the last check. + */ + public boolean getLeftBumperButtonReleased() { + return getRawButtonReleased(Button.kLeftBumper.value); + } + + /** + * Constructs an event instance around the left bumper button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the left bumper button's digital signal + * attached to the given loop. + */ + public BooleanEvent leftBumper(EventLoop loop) { + return new BooleanEvent(loop, this::getLeftBumperButton); + } + + /** + * Read the value of the right bumper button on the controller. + * + * @return The state of the button. + */ + public boolean getRightBumperButton() { + return getRawButton(Button.kRightBumper.value); + } + + /** + * Whether the right bumper button was pressed since the last check. + * + * @return Whether the button was pressed since the last check. + */ + public boolean getRightBumperButtonPressed() { + return getRawButtonPressed(Button.kRightBumper.value); + } + + /** + * Whether the right bumper button was released since the last check. + * + * @return Whether the button was released since the last check. + */ + public boolean getRightBumperButtonReleased() { + return getRawButtonReleased(Button.kRightBumper.value); + } + + /** + * Constructs an event instance around the right bumper button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the right bumper button's digital signal + * attached to the given loop. + */ + public BooleanEvent rightBumper(EventLoop loop) { + return new BooleanEvent(loop, this::getRightBumperButton); + } + + /** + * Read the value of the left stick button on the controller. + * + * @return The state of the button. + */ + public boolean getLeftStickButton() { + return getRawButton(Button.kLeftStick.value); + } + + /** + * Whether the left stick button 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 left stick button was released since the last check. + * + * @return Whether the button was released since the last check. + */ + public boolean getLeftStickButtonReleased() { + return getRawButtonReleased(Button.kLeftStick.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); + } + + /** + * Read the value of the right stick button on the controller. + * + * @return The state of the button. + */ + public boolean getRightStickButton() { + return getRawButton(Button.kRightStick.value); + } + + /** + * Whether the right stick button 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 right stick 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 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 ellipses button on the controller. * @@ -573,8 +495,8 @@ public class StadiaController extends GenericHID { * 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. + * @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); @@ -611,8 +533,8 @@ public class StadiaController extends GenericHID { * 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. + * @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); @@ -649,14 +571,89 @@ public class StadiaController extends GenericHID { * 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. + * @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 right trigger button on the controller. + * + * @return The state of the button. + */ + public boolean getRightTriggerButton() { + return getRawButton(Button.kRightTrigger.value); + } + + /** + * Whether the right trigger button 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 right trigger 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 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 left trigger button on the controller. + * + * @return The state of the button. + */ + public boolean getLeftTriggerButton() { + return getRawButton(Button.kLeftTrigger.value); + } + + /** + * Whether the left trigger button 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 left trigger button was released since the last check. + * + * @return Whether the button was released since the last check. + */ + public boolean getLeftTriggerButtonReleased() { + return getRawButtonReleased(Button.kLeftTrigger.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); + } + /** * Read the value of the google button on the controller. * @@ -688,10 +685,9 @@ public class StadiaController extends GenericHID { * 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. + * @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); } @@ -727,11 +723,76 @@ public class StadiaController extends GenericHID { * 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. + * @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); } + + /** + * Read the value of the left bumper (LB) button on the controller. + * + * @return The state of the button. + * @deprecated Use {@link getLeftBumperButton} instead + */ + @Deprecated(since = "2025", forRemoval = true) + 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. + * @deprecated Use {@link getRightBumperButton} instead + */ + @Deprecated(since = "2025", forRemoval = true) + 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. + * @deprecated Use {@link getLeftBumperButtonPressed} instead + */ + @Deprecated(since = "2025", forRemoval = true) + 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. + * @deprecated Use {@link getRightBumperButtonPressed} instead + */ + @Deprecated(since = "2025", forRemoval = true) + 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. + * @deprecated Use {@link getLeftBumperButtonReleased} instead + */ + @Deprecated(since = "2025", forRemoval = true) + 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. + * @deprecated Use {@link getRightBumperButtonReleased} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public boolean getRightBumperReleased() { + return getRawButtonReleased(Button.kRightBumper.value); + } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/XboxController.java b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/XboxController.java similarity index 77% rename from wpilibj/src/main/java/edu/wpi/first/wpilibj/XboxController.java rename to wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/XboxController.java index 5bd7a01927..3bf77e11f6 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/XboxController.java +++ b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/XboxController.java @@ -2,6 +2,8 @@ // 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. +// THIS FILE WAS AUTO-GENERATED BY ./wpilibj/generate_hids.py. DO NOT MODIFY + package edu.wpi.first.wpilibj; import edu.wpi.first.hal.FRCNetComm.tResourceType; @@ -10,7 +12,7 @@ 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. + * Handle input from Xbox controllers connected to the Driver Station. * *
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 @@ -21,28 +23,28 @@ import edu.wpi.first.wpilibj.event.EventLoop; * 3rd party controllers. */ public class XboxController extends GenericHID { - /** Represents a digital button on an XboxController. */ + /** Represents a digital button on a XboxController. */ public enum Button { - /** Left bumper. */ - kLeftBumper(5), - /** Right bumper. */ - kRightBumper(6), - /** Left stick. */ - kLeftStick(9), - /** Right stick. */ - kRightStick(10), - /** A. */ + /** A button. */ kA(1), - /** B. */ + /** B button. */ kB(2), - /** X. */ + /** X button. */ kX(3), - /** Y. */ + /** Y button. */ kY(4), - /** Back. */ + /** Left bumper button. */ + kLeftBumper(5), + /** Right bumper button. */ + kRightBumper(6), + /** Back button. */ kBack(7), - /** Start. */ - kStart(8); + /** Start button. */ + kStart(8), + /** Left stick button. */ + kLeftStick(9), + /** Right stick button. */ + kRightStick(10); /** Button value. */ public final int value; @@ -53,7 +55,7 @@ public class XboxController extends GenericHID { /** * 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`. + * stripping the leading `k`, and appending `Button`. * *
Primarily used for automated unit tests. * @@ -61,23 +63,20 @@ public class XboxController extends GenericHID { */ @Override public String toString() { - var name = this.name().substring(1); // Remove leading `k` - if (name.endsWith("Bumper")) { - return name; - } - return name + "Button"; + // Remove leading `k` + return this.name().substring(1) + "Button"; } } /** Represents an axis on an XboxController. */ public enum Axis { - /** Left X. */ + /** Left X axis. */ kLeftX(0), - /** Right X. */ + /** Right X axis. */ kRightX(4), - /** Left Y. */ + /** Left Y axis. */ kLeftY(1), - /** Right Y. */ + /** Right Y axis. */ kRightY(5), /** Left trigger. */ kLeftTrigger(2), @@ -93,7 +92,7 @@ public class XboxController extends GenericHID { /** * 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`. + * stripping the leading `k`, and appending `Axis` if the name ends with `Trigger`. * *
Primarily used for automated unit tests. * @@ -112,11 +111,10 @@ public class XboxController extends GenericHID { /** * Construct an instance of a controller. * - * @param port The port index on the Driver Station that the controller is plugged into. + * @param port The port index on the Driver Station that the controller is plugged into (0-5). */ public XboxController(final int port) { super(port); - HAL.report(tResourceType.kResourceType_XboxController, port + 1); } @@ -157,7 +155,7 @@ public class XboxController extends GenericHID { } /** - * Get the left trigger (LT) axis value of the controller. Note that this axis is bound to the + * 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. @@ -167,7 +165,33 @@ public class XboxController extends GenericHID { } /** - * Get the right trigger (RT) axis value of the controller. Note that this axis is bound to the + * 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); + } + + /** + * 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. @@ -177,155 +201,29 @@ public class XboxController extends GenericHID { } /** - * Read the value of the left bumper (LB) button on the controller. + * 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}. * - * @return The state of the button. + * @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 boolean getLeftBumper() { - return getRawButton(Button.kLeftBumper.value); + public BooleanEvent rightTrigger(double threshold, EventLoop loop) { + return new BooleanEvent(loop, () -> getRightTriggerAxis() > threshold); } /** - * 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. + * 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 representing the right bumper's digital signal attached to the given - * loop. + * @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 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); + public BooleanEvent rightTrigger(EventLoop loop) { + return rightTrigger(0.5, loop); } /** @@ -359,10 +257,9 @@ public class XboxController extends GenericHID { * 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. + * @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); } @@ -398,10 +295,9 @@ public class XboxController extends GenericHID { * 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. + * @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); } @@ -437,10 +333,9 @@ public class XboxController extends GenericHID { * 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. + * @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); } @@ -476,14 +371,89 @@ public class XboxController extends GenericHID { * 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. + * @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 left bumper button on the controller. + * + * @return The state of the button. + */ + public boolean getLeftBumperButton() { + return getRawButton(Button.kLeftBumper.value); + } + + /** + * Whether the left bumper button was pressed since the last check. + * + * @return Whether the button was pressed since the last check. + */ + public boolean getLeftBumperButtonPressed() { + return getRawButtonPressed(Button.kLeftBumper.value); + } + + /** + * Whether the left bumper button was released since the last check. + * + * @return Whether the button was released since the last check. + */ + public boolean getLeftBumperButtonReleased() { + return getRawButtonReleased(Button.kLeftBumper.value); + } + + /** + * Constructs an event instance around the left bumper button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the left bumper button's digital signal + * attached to the given loop. + */ + public BooleanEvent leftBumper(EventLoop loop) { + return new BooleanEvent(loop, this::getLeftBumperButton); + } + + /** + * Read the value of the right bumper button on the controller. + * + * @return The state of the button. + */ + public boolean getRightBumperButton() { + return getRawButton(Button.kRightBumper.value); + } + + /** + * Whether the right bumper button was pressed since the last check. + * + * @return Whether the button was pressed since the last check. + */ + public boolean getRightBumperButtonPressed() { + return getRawButtonPressed(Button.kRightBumper.value); + } + + /** + * Whether the right bumper button was released since the last check. + * + * @return Whether the button was released since the last check. + */ + public boolean getRightBumperButtonReleased() { + return getRawButtonReleased(Button.kRightBumper.value); + } + + /** + * Constructs an event instance around the right bumper button's digital signal. + * + * @param loop the event loop instance to attach the event to. + * @return an event instance representing the right bumper button's digital signal + * attached to the given loop. + */ + public BooleanEvent rightBumper(EventLoop loop) { + return new BooleanEvent(loop, this::getRightBumperButton); + } + /** * Read the value of the back button on the controller. * @@ -515,8 +485,8 @@ public class XboxController extends GenericHID { * 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. + * @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); @@ -553,62 +523,152 @@ public class XboxController extends GenericHID { * 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. + * @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}. + * Read the value of the left stick button on the controller. * - * @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 + * @return The state of the button. */ - public BooleanEvent leftTrigger(double threshold, EventLoop loop) { - return new BooleanEvent(loop, () -> getLeftTriggerAxis() > threshold); + public boolean getLeftStickButton() { + return getRawButton(Button.kLeftStick.value); } /** - * 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. + * Whether the left stick button was pressed since the last check. * - * @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 + * @return Whether the button was pressed since the last check. */ - public BooleanEvent leftTrigger(EventLoop loop) { - return leftTrigger(0.5, loop); + public boolean getLeftStickButtonPressed() { + return getRawButtonPressed(Button.kLeftStick.value); } /** - * 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}. + * Whether the left stick button was released since the last check. * - * @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 + * @return Whether the button was released since the last check. */ - public BooleanEvent rightTrigger(double threshold, EventLoop loop) { - return new BooleanEvent(loop, () -> getRightTriggerAxis() > threshold); + public boolean getLeftStickButtonReleased() { + return getRawButtonReleased(Button.kLeftStick.value); } /** - * 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. + * 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 that is true when the right trigger's axis exceeds the provided - * threshold, attached to the given event loop + * @return an event instance representing the left stick button's digital signal + * attached to the given loop. */ - public BooleanEvent rightTrigger(EventLoop loop) { - return rightTrigger(0.5, loop); + public BooleanEvent leftStick(EventLoop loop) { + return new BooleanEvent(loop, this::getLeftStickButton); + } + + /** + * Read the value of the right stick button on the controller. + * + * @return The state of the button. + */ + public boolean getRightStickButton() { + return getRawButton(Button.kRightStick.value); + } + + /** + * Whether the right stick button 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 right stick 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 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 bumper (LB) button on the controller. + * + * @return The state of the button. + * @deprecated Use {@link getLeftBumperButton} instead + */ + @Deprecated(since = "2025", forRemoval = true) + 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. + * @deprecated Use {@link getRightBumperButton} instead + */ + @Deprecated(since = "2025", forRemoval = true) + 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. + * @deprecated Use {@link getLeftBumperButtonPressed} instead + */ + @Deprecated(since = "2025", forRemoval = true) + 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. + * @deprecated Use {@link getRightBumperButtonPressed} instead + */ + @Deprecated(since = "2025", forRemoval = true) + 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. + * @deprecated Use {@link getLeftBumperButtonReleased} instead + */ + @Deprecated(since = "2025", forRemoval = true) + 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. + * @deprecated Use {@link getRightBumperButtonReleased} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public boolean getRightBumperReleased() { + return getRawButtonReleased(Button.kRightBumper.value); } } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/PS4ControllerSim.java b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/simulation/PS4ControllerSim.java similarity index 73% rename from wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/PS4ControllerSim.java rename to wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/simulation/PS4ControllerSim.java index 822b1db58f..a2f1141abc 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/PS4ControllerSim.java +++ b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/simulation/PS4ControllerSim.java @@ -2,6 +2,8 @@ // 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. +// THIS FILE WAS AUTO-GENERATED BY ./wpilibj/generate_hids.py. DO NOT MODIFY + package edu.wpi.first.wpilibj.simulation; import edu.wpi.first.wpilibj.PS4Controller; @@ -35,7 +37,7 @@ public class PS4ControllerSim extends GenericHIDSim { } /** - * Change the X axis value of the controller's left stick. + * Change the left X value of the controller's joystick. * * @param value the new value */ @@ -44,16 +46,7 @@ public class PS4ControllerSim extends GenericHIDSim { } /** - * 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. + * Change the left Y value of the controller's joystick. * * @param value the new value */ @@ -62,7 +55,16 @@ public class PS4ControllerSim extends GenericHIDSim { } /** - * Change the Y axis value of the controller's right stick. + * Change the right X value of the controller's joystick. + * + * @param value the new value + */ + public void setRightX(double value) { + setRawAxis(PS4Controller.Axis.kRightX.value, value); + } + + /** + * Change the right Y value of the controller's joystick. * * @param value the new value */ @@ -71,7 +73,7 @@ public class PS4ControllerSim extends GenericHIDSim { } /** - * Change the L2 axis value of the controller. + * Change the value of the left trigger 2 axis on the controller. * * @param value the new value */ @@ -80,7 +82,7 @@ public class PS4ControllerSim extends GenericHIDSim { } /** - * Change the R2 axis value of the controller. + * Change the value of the right trigger 2 axis on the controller. * * @param value the new value */ @@ -89,7 +91,7 @@ public class PS4ControllerSim extends GenericHIDSim { } /** - * Change the value of the Square button on the controller. + * Change the value of the square button on the controller. * * @param value the new value */ @@ -98,7 +100,7 @@ public class PS4ControllerSim extends GenericHIDSim { } /** - * Change the value of the Cross button on the controller. + * Change the value of the cross button on the controller. * * @param value the new value */ @@ -107,7 +109,7 @@ public class PS4ControllerSim extends GenericHIDSim { } /** - * Change the value of the Circle button on the controller. + * Change the value of the circle button on the controller. * * @param value the new value */ @@ -116,7 +118,7 @@ public class PS4ControllerSim extends GenericHIDSim { } /** - * Change the value of the Triangle button on the controller. + * Change the value of the triangle button on the controller. * * @param value the new value */ @@ -125,7 +127,7 @@ public class PS4ControllerSim extends GenericHIDSim { } /** - * Change the value of the L1 button on the controller. + * Change the value of the left trigger 1 button on the controller. * * @param value the new value */ @@ -134,7 +136,7 @@ public class PS4ControllerSim extends GenericHIDSim { } /** - * Change the value of the R1 button on the controller. + * Change the value of the right trigger 1 button on the controller. * * @param value the new value */ @@ -143,7 +145,7 @@ public class PS4ControllerSim extends GenericHIDSim { } /** - * Change the value of the L2 button on the controller. + * Change the value of the left trigger 2 button on the controller. * * @param value the new value */ @@ -152,7 +154,7 @@ public class PS4ControllerSim extends GenericHIDSim { } /** - * Change the value of the R2 button on the controller. + * Change the value of the right trigger 2 button on the controller. * * @param value the new value */ @@ -161,7 +163,7 @@ public class PS4ControllerSim extends GenericHIDSim { } /** - * Change the value of the Share button on the controller. + * Change the value of the share button on the controller. * * @param value the new value */ @@ -170,7 +172,7 @@ public class PS4ControllerSim extends GenericHIDSim { } /** - * Change the value of the Options button on the controller. + * Change the value of the options button on the controller. * * @param value the new value */ @@ -197,7 +199,7 @@ public class PS4ControllerSim extends GenericHIDSim { } /** - * Change the value of the PS button on the controller. + * Change the value of the PlayStation button on the controller. * * @param value the new value */ @@ -210,6 +212,17 @@ public class PS4ControllerSim extends GenericHIDSim { * * @param value the new value */ + public void setTouchpadButton(boolean value) { + setRawButton(PS4Controller.Button.kTouchpad.value, value); + } + + /** + * Change the value of the touchpad button on the controller. + * + * @param value the new value + * @deprecated Use {@link setTouchpadButton} instead + */ + @Deprecated(since = "2025", forRemoval = true) public void setTouchpad(boolean value) { setRawButton(PS4Controller.Button.kTouchpad.value, value); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/PS5ControllerSim.java b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/simulation/PS5ControllerSim.java similarity index 73% rename from wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/PS5ControllerSim.java rename to wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/simulation/PS5ControllerSim.java index e11cdd084c..090e74435e 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/PS5ControllerSim.java +++ b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/simulation/PS5ControllerSim.java @@ -2,6 +2,8 @@ // 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. +// THIS FILE WAS AUTO-GENERATED BY ./wpilibj/generate_hids.py. DO NOT MODIFY + package edu.wpi.first.wpilibj.simulation; import edu.wpi.first.wpilibj.PS5Controller; @@ -35,7 +37,7 @@ public class PS5ControllerSim extends GenericHIDSim { } /** - * Change the X axis value of the controller's left stick. + * Change the left X value of the controller's joystick. * * @param value the new value */ @@ -44,16 +46,7 @@ public class PS5ControllerSim extends GenericHIDSim { } /** - * 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. + * Change the left Y value of the controller's joystick. * * @param value the new value */ @@ -62,7 +55,16 @@ public class PS5ControllerSim extends GenericHIDSim { } /** - * Change the Y axis value of the controller's right stick. + * Change the right X value of the controller's joystick. + * + * @param value the new value + */ + public void setRightX(double value) { + setRawAxis(PS5Controller.Axis.kRightX.value, value); + } + + /** + * Change the right Y value of the controller's joystick. * * @param value the new value */ @@ -71,7 +73,7 @@ public class PS5ControllerSim extends GenericHIDSim { } /** - * Change the L2 axis value of the controller. + * Change the value of the left trigger 2 axis on the controller. * * @param value the new value */ @@ -80,7 +82,7 @@ public class PS5ControllerSim extends GenericHIDSim { } /** - * Change the R2 axis value of the controller. + * Change the value of the right trigger 2 axis on the controller. * * @param value the new value */ @@ -89,7 +91,7 @@ public class PS5ControllerSim extends GenericHIDSim { } /** - * Change the value of the Square button on the controller. + * Change the value of the square button on the controller. * * @param value the new value */ @@ -98,7 +100,7 @@ public class PS5ControllerSim extends GenericHIDSim { } /** - * Change the value of the Cross button on the controller. + * Change the value of the cross button on the controller. * * @param value the new value */ @@ -107,7 +109,7 @@ public class PS5ControllerSim extends GenericHIDSim { } /** - * Change the value of the Circle button on the controller. + * Change the value of the circle button on the controller. * * @param value the new value */ @@ -116,7 +118,7 @@ public class PS5ControllerSim extends GenericHIDSim { } /** - * Change the value of the Triangle button on the controller. + * Change the value of the triangle button on the controller. * * @param value the new value */ @@ -125,7 +127,7 @@ public class PS5ControllerSim extends GenericHIDSim { } /** - * Change the value of the L1 button on the controller. + * Change the value of the left trigger 1 button on the controller. * * @param value the new value */ @@ -134,7 +136,7 @@ public class PS5ControllerSim extends GenericHIDSim { } /** - * Change the value of the R1 button on the controller. + * Change the value of the right trigger 1 button on the controller. * * @param value the new value */ @@ -143,7 +145,7 @@ public class PS5ControllerSim extends GenericHIDSim { } /** - * Change the value of the L2 button on the controller. + * Change the value of the left trigger 2 button on the controller. * * @param value the new value */ @@ -152,7 +154,7 @@ public class PS5ControllerSim extends GenericHIDSim { } /** - * Change the value of the R2 button on the controller. + * Change the value of the right trigger 2 button on the controller. * * @param value the new value */ @@ -161,7 +163,7 @@ public class PS5ControllerSim extends GenericHIDSim { } /** - * Change the value of the Create button on the controller. + * Change the value of the create button on the controller. * * @param value the new value */ @@ -170,7 +172,7 @@ public class PS5ControllerSim extends GenericHIDSim { } /** - * Change the value of the Options button on the controller. + * Change the value of the options button on the controller. * * @param value the new value */ @@ -197,7 +199,7 @@ public class PS5ControllerSim extends GenericHIDSim { } /** - * Change the value of the PS button on the controller. + * Change the value of the PlayStation button on the controller. * * @param value the new value */ @@ -210,6 +212,17 @@ public class PS5ControllerSim extends GenericHIDSim { * * @param value the new value */ + public void setTouchpadButton(boolean value) { + setRawButton(PS5Controller.Button.kTouchpad.value, value); + } + + /** + * Change the value of the touchpad button on the controller. + * + * @param value the new value + * @deprecated Use {@link setTouchpadButton} instead + */ + @Deprecated(since = "2025", forRemoval = true) public void setTouchpad(boolean value) { setRawButton(PS5Controller.Button.kTouchpad.value, value); } diff --git a/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/simulation/StadiaControllerSim.java b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/simulation/StadiaControllerSim.java new file mode 100644 index 0000000000..4bde45da27 --- /dev/null +++ b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/simulation/StadiaControllerSim.java @@ -0,0 +1,209 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./wpilibj/generate_hids.py. DO NOT MODIFY + +package edu.wpi.first.wpilibj.simulation; + +import edu.wpi.first.wpilibj.StadiaController; + +/** Class to control a simulated Stadia controller. */ +public class StadiaControllerSim extends GenericHIDSim { + /** + * Constructs from a StadiaController object. + * + * @param joystick controller to simulate + */ + @SuppressWarnings("this-escape") + public StadiaControllerSim(StadiaController joystick) { + super(joystick); + setAxisCount(4); + setButtonCount(15); + setPOVCount(1); + } + + /** + * Constructs from a joystick port number. + * + * @param port port number + */ + @SuppressWarnings("this-escape") + public StadiaControllerSim(int port) { + super(port); + setAxisCount(4); + setButtonCount(15); + setPOVCount(1); + } + + /** + * Change the left X value of the controller's joystick. + * + * @param value the new value + */ + public void setLeftX(double value) { + setRawAxis(StadiaController.Axis.kLeftX.value, value); + } + + /** + * Change the right X value of the controller's joystick. + * + * @param value the new value + */ + public void setRightX(double value) { + setRawAxis(StadiaController.Axis.kRightX.value, value); + } + + /** + * Change the left Y value of the controller's joystick. + * + * @param value the new value + */ + public void setLeftY(double value) { + setRawAxis(StadiaController.Axis.kLeftY.value, value); + } + + /** + * Change the right Y value of the controller's joystick. + * + * @param value the new value + */ + public void setRightY(double value) { + setRawAxis(StadiaController.Axis.kRightY.value, value); + } + + /** + * Change the value of the A button on the controller. + * + * @param value the new value + */ + public void setAButton(boolean value) { + setRawButton(StadiaController.Button.kA.value, value); + } + + /** + * Change the value of the B button on the controller. + * + * @param value the new value + */ + public void setBButton(boolean value) { + setRawButton(StadiaController.Button.kB.value, value); + } + + /** + * Change the value of the X button on the controller. + * + * @param value the new value + */ + public void setXButton(boolean value) { + setRawButton(StadiaController.Button.kX.value, value); + } + + /** + * Change the value of the Y button on the controller. + * + * @param value the new value + */ + public void setYButton(boolean value) { + setRawButton(StadiaController.Button.kY.value, value); + } + + /** + * Change the value of the left bumper button on the controller. + * + * @param value the new value + */ + public void setLeftBumperButton(boolean value) { + setRawButton(StadiaController.Button.kLeftBumper.value, value); + } + + /** + * Change the value of the right bumper button on the controller. + * + * @param value the new value + */ + public void setRightBumperButton(boolean value) { + setRawButton(StadiaController.Button.kRightBumper.value, value); + } + + /** + * Change the value of the left stick button on the controller. + * + * @param value the new value + */ + public void setLeftStickButton(boolean value) { + setRawButton(StadiaController.Button.kLeftStick.value, value); + } + + /** + * Change the value of the right stick button on the controller. + * + * @param value the new value + */ + public void setRightStickButton(boolean value) { + setRawButton(StadiaController.Button.kRightStick.value, value); + } + + /** + * Change the value of the ellipses button on the controller. + * + * @param value the new value + */ + public void setEllipsesButton(boolean value) { + setRawButton(StadiaController.Button.kEllipses.value, value); + } + + /** + * Change the value of the hamburger button on the controller. + * + * @param value the new value + */ + public void setHamburgerButton(boolean value) { + setRawButton(StadiaController.Button.kHamburger.value, value); + } + + /** + * Change the value of the stadia button on the controller. + * + * @param value the new value + */ + public void setStadiaButton(boolean value) { + setRawButton(StadiaController.Button.kStadia.value, value); + } + + /** + * Change the value of the right trigger button on the controller. + * + * @param value the new value + */ + public void setRightTriggerButton(boolean value) { + setRawButton(StadiaController.Button.kRightTrigger.value, value); + } + + /** + * Change the value of the left trigger button on the controller. + * + * @param value the new value + */ + public void setLeftTriggerButton(boolean value) { + setRawButton(StadiaController.Button.kLeftTrigger.value, value); + } + + /** + * Change the value of the google button on the controller. + * + * @param value the new value + */ + public void setGoogleButton(boolean value) { + setRawButton(StadiaController.Button.kGoogle.value, value); + } + + /** + * Change the value of the frame button on the controller. + * + * @param value the new value + */ + public void setFrameButton(boolean value) { + setRawButton(StadiaController.Button.kFrame.value, value); + } +} diff --git a/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/simulation/XboxControllerSim.java b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/simulation/XboxControllerSim.java new file mode 100644 index 0000000000..8417b777f7 --- /dev/null +++ b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/simulation/XboxControllerSim.java @@ -0,0 +1,204 @@ +// 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. + +// THIS FILE WAS AUTO-GENERATED BY ./wpilibj/generate_hids.py. DO NOT MODIFY + +package edu.wpi.first.wpilibj.simulation; + +import edu.wpi.first.wpilibj.XboxController; + +/** Class to control a simulated Xbox 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 controller's joystick. + * + * @param value the new value + */ + public void setLeftX(double value) { + setRawAxis(XboxController.Axis.kLeftX.value, value); + } + + /** + * Change the right X value of the controller's joystick. + * + * @param value the new value + */ + public void setRightX(double value) { + setRawAxis(XboxController.Axis.kRightX.value, value); + } + + /** + * Change the left Y value of the controller's joystick. + * + * @param value the new value + */ + public void setLeftY(double value) { + setRawAxis(XboxController.Axis.kLeftY.value, value); + } + + /** + * Change the right Y value of the controller's 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 controller. + * + * @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 controller. + * + * @param value the new value + */ + public void setRightTriggerAxis(double value) { + setRawAxis(XboxController.Axis.kRightTrigger.value, value); + } + + /** + * Change the value of the A button on the controller. + * + * @param value the new value + */ + public void setAButton(boolean value) { + setRawButton(XboxController.Button.kA.value, value); + } + + /** + * Change the value of the B button on the controller. + * + * @param value the new value + */ + public void setBButton(boolean value) { + setRawButton(XboxController.Button.kB.value, value); + } + + /** + * Change the value of the X button on the controller. + * + * @param value the new value + */ + public void setXButton(boolean value) { + setRawButton(XboxController.Button.kX.value, value); + } + + /** + * Change the value of the Y button on the controller. + * + * @param value the new value + */ + public void setYButton(boolean value) { + setRawButton(XboxController.Button.kY.value, value); + } + + /** + * Change the value of the left bumper button on the controller. + * + * @param value the new value + */ + public void setLeftBumperButton(boolean value) { + setRawButton(XboxController.Button.kLeftBumper.value, value); + } + + /** + * Change the value of the right bumper button on the controller. + * + * @param value the new value + */ + public void setRightBumperButton(boolean value) { + setRawButton(XboxController.Button.kRightBumper.value, value); + } + + /** + * Change the value of the back button on the controller. + * + * @param value the new value + */ + public void setBackButton(boolean value) { + setRawButton(XboxController.Button.kBack.value, value); + } + + /** + * Change the value of the start button on the controller. + * + * @param value the new value + */ + public void setStartButton(boolean value) { + setRawButton(XboxController.Button.kStart.value, value); + } + + /** + * Change the value of the left stick button on the controller. + * + * @param value the new value + */ + public void setLeftStickButton(boolean value) { + setRawButton(XboxController.Button.kLeftStick.value, value); + } + + /** + * Change the value of the right stick button on the controller. + * + * @param value the new value + */ + public void setRightStickButton(boolean value) { + setRawButton(XboxController.Button.kRightStick.value, value); + } + + /** + * Change the value of the left bumper on the joystick. + * + * @param state the new value + * @deprecated Use {@link setLeftBumperButton} instead + */ + @Deprecated(since = "2025", forRemoval = true) + 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 + * @deprecated Use {@link setRightBumperButton} instead + */ + @Deprecated(since = "2025", forRemoval = true) + public void setRightBumper(boolean state) { + setRawButton(XboxController.Button.kRightBumper.value, state); + } +} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/XboxControllerSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/XboxControllerSim.java deleted file mode 100644 index 37e0bda32d..0000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/XboxControllerSim.java +++ /dev/null @@ -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); - } -}