mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
SCRIPT Move subprojects
This commit is contained in:
committed by
Peter Johnson
parent
8cfc158790
commit
a5492d30da
129
commandsv2/src/generate/main/java/commandhid.java.jinja
Normal file
129
commandsv2/src/generate/main/java/commandhid.java.jinja
Normal file
@@ -0,0 +1,129 @@
|
||||
// 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 ./wpilibNewCommands/generate_hids.py. DO NOT MODIFY
|
||||
{% macro capitalize_first(string) -%}
|
||||
{{ string[0]|capitalize + string[1:] }}
|
||||
{%- endmacro %}
|
||||
package edu.wpi.first.wpilibj2.command.button;
|
||||
|
||||
import edu.wpi.first.wpilibj.{{ ConsoleName }}Controller;
|
||||
import edu.wpi.first.wpilibj.event.EventLoop;
|
||||
import edu.wpi.first.wpilibj2.command.CommandScheduler;
|
||||
|
||||
/**
|
||||
* A version of {@link {{ ConsoleName }}Controller} with {@link Trigger} factories for command-based.
|
||||
*
|
||||
* @see {{ ConsoleName }}Controller
|
||||
*/
|
||||
@SuppressWarnings("MethodName")
|
||||
public class Command{{ ConsoleName }}Controller extends CommandGenericHID {
|
||||
private final {{ ConsoleName }}Controller m_hid;
|
||||
|
||||
/**
|
||||
* Construct an instance of a controller.
|
||||
*
|
||||
* @param port The port index on the Driver Station that the controller is plugged into.
|
||||
*/
|
||||
public Command{{ ConsoleName }}Controller(int port) {
|
||||
super(port);
|
||||
m_hid = new {{ ConsoleName }}Controller(port);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
*/
|
||||
@Override
|
||||
public {{ ConsoleName }}Controller getHID() {
|
||||
return m_hid;
|
||||
}
|
||||
{% for button in buttons %}
|
||||
/**
|
||||
* Constructs a Trigger instance around the {{ button.DocName|default(button.name) }} button's digital signal.
|
||||
*
|
||||
* @return a Trigger instance representing the {{ button.DocName|default(button.name) }} button's digital signal attached
|
||||
* to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
|
||||
* @see #{{ button.name }}(EventLoop)
|
||||
*/
|
||||
public Trigger {{ button.name }}() {
|
||||
return {{ button.name }}(CommandScheduler.getInstance().getDefaultButtonLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the {{ button.DocName|default(button.name) }} button's digital signal.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to.
|
||||
* @return a Trigger instance representing the {{ button.DocName|default(button.name) }} button's digital signal attached
|
||||
* to the given loop.
|
||||
*/
|
||||
public Trigger {{ button.name }}(EventLoop loop) {
|
||||
return button({{ ConsoleName }}Controller.Button.k{{ capitalize_first(button.name) }}.value, loop);
|
||||
}
|
||||
{% endfor -%}
|
||||
{% for trigger in triggers -%}
|
||||
{% if trigger.UseThresholdMethods %}
|
||||
/**
|
||||
* Constructs a Trigger 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 Trigger} to be true. This value
|
||||
* should be in the range [0, 1] where 0 is the unpressed state of the axis.
|
||||
* @param loop the event loop instance to attach the Trigger to.
|
||||
* @return a Trigger instance that is true when the {{ trigger.DocName }}'s axis exceeds the provided
|
||||
* threshold, attached to the given event loop
|
||||
*/
|
||||
public Trigger {{ trigger.name }}(double threshold, EventLoop loop) {
|
||||
return axisGreaterThan({{ ConsoleName }}Controller.Axis.k{{ capitalize_first(trigger.name) }}.value, threshold, loop);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a Trigger 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 Trigger} to be true. This value
|
||||
* should be in the range [0, 1] where 0 is the unpressed state of the axis.
|
||||
* @return a Trigger instance that is true when the {{ trigger.DocName }}'s axis exceeds the provided
|
||||
* threshold, attached to the {@link CommandScheduler#getDefaultButtonLoop() default scheduler
|
||||
* button loop}.
|
||||
*/
|
||||
public Trigger {{ trigger.name }}(double threshold) {
|
||||
return {{ trigger.name }}(threshold, CommandScheduler.getInstance().getDefaultButtonLoop());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance around the axis value of the {{ trigger.DocName }}. The returned trigger
|
||||
* will be true when the axis value is greater than 0.5.
|
||||
*
|
||||
* @return a Trigger instance that is true when the {{ trigger.DocName }}'s axis exceeds 0.5, attached to
|
||||
* the {@link CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
|
||||
*/
|
||||
public Trigger {{ trigger.name }}() {
|
||||
return {{ trigger.name }}(0.5);
|
||||
}
|
||||
{% endif -%}
|
||||
{% endfor -%}
|
||||
{% for stick in sticks %}
|
||||
/**
|
||||
* Get the {{ stick.NameParts[1] }} axis value of {{ stick.NameParts[0] }} side of the controller. {{ stick.PositiveDirection }} is positive.
|
||||
*
|
||||
* @return The axis value.
|
||||
*/
|
||||
public double get{{ stick.NameParts|map("capitalize")|join }}() {
|
||||
return m_hid.get{{ stick.NameParts|map("capitalize")|join }}();
|
||||
}
|
||||
{% 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 m_hid.get{{ capitalize_first(trigger.name) }}Axis();
|
||||
}
|
||||
{% endfor -%}
|
||||
}
|
||||
Reference in New Issue
Block a user