mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Store DriverStation-owned GenericHID and Gamepad instances in Java and C++, and expose the cached objects to Python bindings. Move hand-written command gamepad and joystick wrappers to compose cached CommandGenericHID instances plus typed HID wrappers, including a Python CommandGamepad. This will let us remove UserControls, while helping ensure that we don't have state smashing between GenericHID objects. Another bonus is without inheritance, intellisense will no longer show a bunch of annoying methods, and instead just what actually exists. --------- Co-authored-by: Peter Johnson <johnson.peter@gmail.com>
71 lines
2.4 KiB
Django/Jinja
71 lines
2.4 KiB
Django/Jinja
// 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 org.wpilib.simulation;
|
|
|
|
import org.wpilib.driverstation.{{ 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.getHID());
|
|
setAxesMaximumIndex({{ sticks|length + triggers|length }});
|
|
setButtonsMaximumIndex({{ buttons|length }});
|
|
setPOVsMaximumIndex(1);
|
|
}
|
|
|
|
/**
|
|
* Constructs from a joystick port number.
|
|
*
|
|
* @param port port number
|
|
*/
|
|
@SuppressWarnings("this-escape")
|
|
public {{ ConsoleName }}ControllerSim(int port) {
|
|
super(port);
|
|
setAxesMaximumIndex({{ sticks|length + triggers|length }});
|
|
setButtonsMaximumIndex({{ buttons|length }});
|
|
setPOVsMaximumIndex(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 -%}
|
|
}
|