mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-05 03:21:42 +00:00
[wpilib] Implement Sendable for HID classes (#6782)
This commit is contained in:
@@ -10,6 +10,8 @@ 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;
|
||||
|
||||
@@ -24,7 +26,7 @@ import edu.wpi.first.wpilibj.event.EventLoop;
|
||||
* 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 {
|
||||
public class {{ ConsoleName }}Controller extends GenericHID implements Sendable {
|
||||
/** Represents a digital button on a {{ ConsoleName }}Controller. */
|
||||
public enum Button {
|
||||
{%- for button in buttons %}
|
||||
@@ -252,7 +254,7 @@ public class {{ ConsoleName }}Controller extends GenericHID {
|
||||
public boolean getRightBumperReleased() {
|
||||
return getRawButtonReleased(Button.kRightBumper.value);
|
||||
}
|
||||
{% elif ConsoleName == "PS4" or ConsoleName == "PS5" %}
|
||||
{%- elif ConsoleName == "PS4" or ConsoleName == "PS5" %}
|
||||
/**
|
||||
* Read the value of the touchpad on the controller.
|
||||
*
|
||||
@@ -285,5 +287,20 @@ public class {{ ConsoleName }}Controller extends GenericHID {
|
||||
public boolean getTouchpadReleased() {
|
||||
return getRawButtonReleased(Button.kTouchpad.value);
|
||||
}
|
||||
{% endif -%}
|
||||
{%- 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 %}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.hal.FRCNetComm.tResourceType;
|
||||
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;
|
||||
|
||||
@@ -22,7 +24,7 @@ import edu.wpi.first.wpilibj.event.EventLoop;
|
||||
* 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 {
|
||||
public class PS4Controller extends GenericHID implements Sendable {
|
||||
/** Represents a digital button on a PS4Controller. */
|
||||
public enum Button {
|
||||
/** Square button. */
|
||||
@@ -746,4 +748,30 @@ public class PS4Controller extends GenericHID {
|
||||
public boolean getTouchpadReleased() {
|
||||
return getRawButtonReleased(Button.kTouchpad.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initSendable(SendableBuilder builder) {
|
||||
builder.setSmartDashboardType("HID");
|
||||
builder.publishConstString("ControllerType", "PS4");
|
||||
builder.addDoubleProperty("L2", this::getL2Axis, null);
|
||||
builder.addDoubleProperty("R2", this::getR2Axis, null);
|
||||
builder.addDoubleProperty("LeftX", this::getLeftX, null);
|
||||
builder.addDoubleProperty("LeftY", this::getLeftY, null);
|
||||
builder.addDoubleProperty("RightX", this::getRightX, null);
|
||||
builder.addDoubleProperty("RightY", this::getRightY, null);
|
||||
builder.addBooleanProperty("Square", this::getSquareButton, null);
|
||||
builder.addBooleanProperty("Cross", this::getCrossButton, null);
|
||||
builder.addBooleanProperty("Circle", this::getCircleButton, null);
|
||||
builder.addBooleanProperty("Triangle", this::getTriangleButton, null);
|
||||
builder.addBooleanProperty("L1", this::getL1Button, null);
|
||||
builder.addBooleanProperty("R1", this::getR1Button, null);
|
||||
builder.addBooleanProperty("L2", this::getL2Button, null);
|
||||
builder.addBooleanProperty("R2", this::getR2Button, null);
|
||||
builder.addBooleanProperty("Share", this::getShareButton, null);
|
||||
builder.addBooleanProperty("Options", this::getOptionsButton, null);
|
||||
builder.addBooleanProperty("L3", this::getL3Button, null);
|
||||
builder.addBooleanProperty("R3", this::getR3Button, null);
|
||||
builder.addBooleanProperty("PS", this::getPSButton, null);
|
||||
builder.addBooleanProperty("Touchpad", this::getTouchpadButton, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ package edu.wpi.first.wpilibj;
|
||||
|
||||
// import edu.wpi.first.hal.FRCNetComm.tResourceType;
|
||||
// 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;
|
||||
|
||||
@@ -22,7 +24,7 @@ import edu.wpi.first.wpilibj.event.EventLoop;
|
||||
* 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 {
|
||||
public class PS5Controller extends GenericHID implements Sendable {
|
||||
/** Represents a digital button on a PS5Controller. */
|
||||
public enum Button {
|
||||
/** Square button. */
|
||||
@@ -746,4 +748,30 @@ public class PS5Controller extends GenericHID {
|
||||
public boolean getTouchpadReleased() {
|
||||
return getRawButtonReleased(Button.kTouchpad.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initSendable(SendableBuilder builder) {
|
||||
builder.setSmartDashboardType("HID");
|
||||
builder.publishConstString("ControllerType", "PS5");
|
||||
builder.addDoubleProperty("L2", this::getL2Axis, null);
|
||||
builder.addDoubleProperty("R2", this::getR2Axis, null);
|
||||
builder.addDoubleProperty("LeftX", this::getLeftX, null);
|
||||
builder.addDoubleProperty("LeftY", this::getLeftY, null);
|
||||
builder.addDoubleProperty("RightX", this::getRightX, null);
|
||||
builder.addDoubleProperty("RightY", this::getRightY, null);
|
||||
builder.addBooleanProperty("Square", this::getSquareButton, null);
|
||||
builder.addBooleanProperty("Cross", this::getCrossButton, null);
|
||||
builder.addBooleanProperty("Circle", this::getCircleButton, null);
|
||||
builder.addBooleanProperty("Triangle", this::getTriangleButton, null);
|
||||
builder.addBooleanProperty("L1", this::getL1Button, null);
|
||||
builder.addBooleanProperty("R1", this::getR1Button, null);
|
||||
builder.addBooleanProperty("L2", this::getL2Button, null);
|
||||
builder.addBooleanProperty("R2", this::getR2Button, null);
|
||||
builder.addBooleanProperty("Create", this::getCreateButton, null);
|
||||
builder.addBooleanProperty("Options", this::getOptionsButton, null);
|
||||
builder.addBooleanProperty("L3", this::getL3Button, null);
|
||||
builder.addBooleanProperty("R3", this::getR3Button, null);
|
||||
builder.addBooleanProperty("PS", this::getPSButton, null);
|
||||
builder.addBooleanProperty("Touchpad", this::getTouchpadButton, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ package edu.wpi.first.wpilibj;
|
||||
|
||||
// import edu.wpi.first.hal.FRCNetComm.tResourceType;
|
||||
// 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;
|
||||
|
||||
@@ -22,7 +24,7 @@ import edu.wpi.first.wpilibj.event.EventLoop;
|
||||
* 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 {
|
||||
public class StadiaController extends GenericHID implements Sendable {
|
||||
/** Represents a digital button on a StadiaController. */
|
||||
public enum Button {
|
||||
/** A button. */
|
||||
@@ -795,4 +797,29 @@ public class StadiaController extends GenericHID {
|
||||
public boolean getRightBumperReleased() {
|
||||
return getRawButtonReleased(Button.kRightBumper.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initSendable(SendableBuilder builder) {
|
||||
builder.setSmartDashboardType("HID");
|
||||
builder.publishConstString("ControllerType", "Stadia");
|
||||
builder.addDoubleProperty("LeftX", this::getLeftX, null);
|
||||
builder.addDoubleProperty("RightX", this::getRightX, null);
|
||||
builder.addDoubleProperty("LeftY", this::getLeftY, null);
|
||||
builder.addDoubleProperty("RightY", this::getRightY, null);
|
||||
builder.addBooleanProperty("A", this::getAButton, null);
|
||||
builder.addBooleanProperty("B", this::getBButton, null);
|
||||
builder.addBooleanProperty("X", this::getXButton, null);
|
||||
builder.addBooleanProperty("Y", this::getYButton, null);
|
||||
builder.addBooleanProperty("LeftBumper", this::getLeftBumperButton, null);
|
||||
builder.addBooleanProperty("RightBumper", this::getRightBumperButton, null);
|
||||
builder.addBooleanProperty("LeftStick", this::getLeftStickButton, null);
|
||||
builder.addBooleanProperty("RightStick", this::getRightStickButton, null);
|
||||
builder.addBooleanProperty("Ellipses", this::getEllipsesButton, null);
|
||||
builder.addBooleanProperty("Hamburger", this::getHamburgerButton, null);
|
||||
builder.addBooleanProperty("Stadia", this::getStadiaButton, null);
|
||||
builder.addBooleanProperty("RightTrigger", this::getRightTriggerButton, null);
|
||||
builder.addBooleanProperty("LeftTrigger", this::getLeftTriggerButton, null);
|
||||
builder.addBooleanProperty("Google", this::getGoogleButton, null);
|
||||
builder.addBooleanProperty("Frame", this::getFrameButton, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.hal.FRCNetComm.tResourceType;
|
||||
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;
|
||||
|
||||
@@ -22,7 +24,7 @@ import edu.wpi.first.wpilibj.event.EventLoop;
|
||||
* only through the official NI DS. Sim is not guaranteed to have the same mapping, as well as any
|
||||
* 3rd party controllers.
|
||||
*/
|
||||
public class XboxController extends GenericHID {
|
||||
public class XboxController extends GenericHID implements Sendable {
|
||||
/** Represents a digital button on a XboxController. */
|
||||
public enum Button {
|
||||
/** A button. */
|
||||
@@ -671,4 +673,26 @@ public class XboxController extends GenericHID {
|
||||
public boolean getRightBumperReleased() {
|
||||
return getRawButtonReleased(Button.kRightBumper.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initSendable(SendableBuilder builder) {
|
||||
builder.setSmartDashboardType("HID");
|
||||
builder.publishConstString("ControllerType", "Xbox");
|
||||
builder.addDoubleProperty("LeftTrigger", this::getLeftTriggerAxis, null);
|
||||
builder.addDoubleProperty("RightTrigger", this::getRightTriggerAxis, null);
|
||||
builder.addDoubleProperty("LeftX", this::getLeftX, null);
|
||||
builder.addDoubleProperty("RightX", this::getRightX, null);
|
||||
builder.addDoubleProperty("LeftY", this::getLeftY, null);
|
||||
builder.addDoubleProperty("RightY", this::getRightY, null);
|
||||
builder.addBooleanProperty("A", this::getAButton, null);
|
||||
builder.addBooleanProperty("B", this::getBButton, null);
|
||||
builder.addBooleanProperty("X", this::getXButton, null);
|
||||
builder.addBooleanProperty("Y", this::getYButton, null);
|
||||
builder.addBooleanProperty("LeftBumper", this::getLeftBumperButton, null);
|
||||
builder.addBooleanProperty("RightBumper", this::getRightBumperButton, null);
|
||||
builder.addBooleanProperty("Back", this::getBackButton, null);
|
||||
builder.addBooleanProperty("Start", this::getStartButton, null);
|
||||
builder.addBooleanProperty("LeftStick", this::getLeftStickButton, null);
|
||||
builder.addBooleanProperty("RightStick", this::getRightStickButton, null);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user