mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
128 lines
4.7 KiB
Plaintext
128 lines
4.7 KiB
Plaintext
|
|
// 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 ./commandsv2/generate_hids.py. DO NOT MODIFY
|
||
|
|
|
||
|
|
package org.wpilib.command2.button;
|
||
|
|
|
||
|
|
import org.wpilib.command2.CommandScheduler;
|
||
|
|
import org.wpilib.driverstation.{{ ClassName }}Controller;
|
||
|
|
import org.wpilib.event.EventLoop;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* A version of {@link {{ ClassName }}Controller} with {@link Trigger} factories for command-based.
|
||
|
|
*
|
||
|
|
* @see {{ ClassName }}Controller
|
||
|
|
*/
|
||
|
|
@SuppressWarnings("MethodName")
|
||
|
|
public class Command{{ ClassName }}Controller {
|
||
|
|
private final CommandGenericHID m_hid;
|
||
|
|
private final {{ ClassName }}Controller m_controller;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Construct an instance of a controller.
|
||
|
|
*
|
||
|
|
* @param port The port index on the Driver Station that the controller is plugged into.
|
||
|
|
*/
|
||
|
|
public Command{{ ClassName }}Controller(int port) {
|
||
|
|
m_hid = CommandGenericHID.getCommandGenericHID(port);
|
||
|
|
m_controller = new {{ ClassName }}Controller(m_hid.getHID());
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get the underlying CommandGenericHID object.
|
||
|
|
*
|
||
|
|
* @return the wrapped CommandGenericHID object
|
||
|
|
*/
|
||
|
|
public CommandGenericHID getHID() {
|
||
|
|
return m_hid;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get the wrapped controller object.
|
||
|
|
*
|
||
|
|
* @return the wrapped controller object
|
||
|
|
*/
|
||
|
|
public {{ ClassName }}Controller getController() {
|
||
|
|
return m_controller;
|
||
|
|
}
|
||
|
|
{% for button in buttons %}
|
||
|
|
/**
|
||
|
|
* Constructs a Trigger instance around the {{ button.DocName }} button's digital signal.
|
||
|
|
*
|
||
|
|
* @return a Trigger instance representing the {{ button.DocName }} 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 }} button's digital signal.
|
||
|
|
*
|
||
|
|
* @param loop the event loop instance to attach the event to.
|
||
|
|
* @return a Trigger instance representing the {{ button.DocName }} button's digital signal attached
|
||
|
|
* to the given loop.
|
||
|
|
*/
|
||
|
|
public Trigger {{ button.Name }}(EventLoop loop) {
|
||
|
|
return m_hid.button({{ ClassName }}Controller.Button.{{ button.ConstantName }}.value, loop);
|
||
|
|
}
|
||
|
|
{% endfor -%}
|
||
|
|
{% for trigger in triggerAxes %}
|
||
|
|
/**
|
||
|
|
* 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 }} axis exceeds the provided
|
||
|
|
* threshold, attached to the given event loop
|
||
|
|
*/
|
||
|
|
public Trigger {{ trigger.Name }}(double threshold, EventLoop loop) {
|
||
|
|
return m_hid.axisGreaterThan(
|
||
|
|
{{ ClassName }}Controller.Axis.{{ trigger.AxisConstantName }}.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 }} 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());
|
||
|
|
}
|
||
|
|
{% if trigger.HasDefaultThresholdMethod %}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 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 }} 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 axis in axes %}
|
||
|
|
/**
|
||
|
|
* Get the {{ axis.DocName }} value of the controller.
|
||
|
|
*
|
||
|
|
* @return The axis value.
|
||
|
|
*/
|
||
|
|
public double get{{ axis.MethodName }}() {
|
||
|
|
return m_controller.get{{ axis.MethodName }}();
|
||
|
|
}
|
||
|
|
{% endfor -%}
|
||
|
|
}
|