mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-30 02:31:44 +00:00
[wpilib] Implement Sendable for HID classes (#6782)
This commit is contained in:
@@ -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