Move generated files to more consistent locations (#6906)

Java templates always go under src/generate/main/java. JSON files go to src/generate.
This commit is contained in:
Gold856
2024-09-25 01:13:49 -04:00
committed by GitHub
parent b8ff3fcee2
commit f0a1955fd7
7 changed files with 3 additions and 3 deletions

View File

@@ -0,0 +1,306 @@
// 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;
{{ "// " if SkipReporting }}import edu.wpi.first.hal.FRCNetComm.tResourceType;
{{ "// " if SkipReporting }}import edu.wpi.first.hal.HAL;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.wpilibj.event.BooleanEvent;
import edu.wpi.first.wpilibj.event.EventLoop;
/**
* Handle input from {{ ConsoleName }} controllers connected to the Driver Station.
*
* <p>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.
*
* <p>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 implements Sendable {
/** 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`.
*
* <p>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 }}`.
*
* <p>Primarily used for automated unit tests.
*
* @return the human-friendly name of the axis.
*/
@Override
public String toString() {
var name = this.name().substring(1); // Remove leading `k`
if (name.endsWith("{{ 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 axisGreaterThan(Axis.k{{ capitalize_first(trigger.name) }}.value, threshold, loop);
}
/**
* 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 button(Button.k{{ capitalize_first(button.name) }}.value, loop);
}
{% 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 %}
@Override
public void initSendable(SendableBuilder builder) {
builder.setSmartDashboardType("HID");
builder.publishConstString("ControllerType", "{{ ConsoleName }}");
{%- for trigger in triggers %}
builder.addDoubleProperty("{{ capitalize_first(trigger.name) }}", this::get{{ capitalize_first(trigger.name) }}Axis, null);
{%- endfor -%}
{% for stick in sticks %}
builder.addDoubleProperty("{{ stick.NameParts|map("capitalize")|join }}", this::get{{ stick.NameParts|map("capitalize")|join }}, null);
{%- endfor -%}
{% for button in buttons %}
builder.addBooleanProperty("{{ capitalize_first(button.name) }}", this::get{{ capitalize_first(button.name) }}Button, null);
{%- endfor %}
}
}

View File

@@ -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 -%}
}

View File

@@ -0,0 +1,48 @@
// 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_pwm_motor_controllers.py. DO NOT MODIFY
package edu.wpi.first.wpilibj.motorcontrol;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.PWM;
/**
* {{ Manufacturer }} {{ DisplayName }} Motor Controller.
*
* <p>Note that the {{ DisplayName }} uses the following bounds for PWM values. These values should work
* reasonably well for most controllers, but if users experience issues such as asymmetric behavior
* around the deadband or inability to saturate the controller in either direction, calibration is
* recommended. The calibration procedure can be found in the {{ DisplayName }} User Manual available from
* {{ Manufacturer }}.
*
* <ul>
* <li>{{ "{:.3f}".format(pulse_width_ms.max) }}ms = full "forward"
* <li>{{ "{:.3f}".format(pulse_width_ms.deadbandMax) }}ms = the "high end" of the deadband range
* <li>{{ "{:.3f}".format(pulse_width_ms.center) }}ms = center of the deadband range (off)
* <li>{{ "{:.3f}".format(pulse_width_ms.deadbandMin) }}ms = the "low end" of the deadband range
* <li>{{ "{:.3f}".format(pulse_width_ms.min) }}ms = full "reverse"
* </ul>
*/
public class {{ name }} extends PWMMotorController {
/**
* Constructor.
*
* @param channel The PWM channel that the {{ DisplayName }} is attached to. 0-9 are on-board, 10-19
* are on the MXP port
*/
@SuppressWarnings("this-escape")
public {{ name }}(final int channel) {
super("{{ name }}", channel);
m_pwm.setBoundsMicroseconds({{ (pulse_width_ms.max * 1000) | int }}, {{ (pulse_width_ms.deadbandMax * 1000) | int }}, {{ (pulse_width_ms.center * 1000) | int }}, {{ (pulse_width_ms.deadbandMin * 1000) | int }}, {{ (pulse_width_ms.min * 1000) | int }});
m_pwm.setPeriodMultiplier(PWM.PeriodMultiplier.k{{ PeriodMultiplier | default("1", true)}}X);
m_pwm.setSpeed(0.0);
m_pwm.setZeroLatch();
HAL.report(tResourceType.kResourceType_{{ ResourceName }}, getChannel() + 1);
}
}