[wpilib] Implement Sendable for HID classes (#6782)

This commit is contained in:
Jade
2024-07-18 22:10:07 +08:00
committed by GitHub
parent 34b8b7a409
commit 7663211819
15 changed files with 287 additions and 14 deletions

View File

@@ -7,6 +7,7 @@
#include "frc/PS4Controller.h"
#include <hal/FRCUsageReporting.h>
#include <wpi/sendable/SendableBuilder.h>
#include "frc/event/BooleanEvent.h"
@@ -275,3 +276,28 @@ bool PS4Controller::GetTouchpadPressed() {
bool PS4Controller::GetTouchpadReleased() {
return GetRawButtonReleased(Button::kTouchpad);
}
void PS4Controller::InitSendable(wpi::SendableBuilder& builder) {
builder.SetSmartDashboardType("HID");
builder.PublishConstString("ControllerType", "PS4");
builder.AddDoubleProperty("L2", [this] { return GetL2Axis(); }, nullptr);
builder.AddDoubleProperty("R2", [this] { return GetR2Axis(); }, nullptr);
builder.AddDoubleProperty("LeftX", [this] { return GetLeftX(); }, nullptr);
builder.AddDoubleProperty("LeftY", [this] { return GetLeftY(); }, nullptr);
builder.AddDoubleProperty("RightX", [this] { return GetRightX(); }, nullptr);
builder.AddDoubleProperty("RightY", [this] { return GetRightY(); }, nullptr);
builder.AddBooleanProperty("Square", [this] { return GetSquareButton(); }, nullptr);
builder.AddBooleanProperty("Cross", [this] { return GetCrossButton(); }, nullptr);
builder.AddBooleanProperty("Circle", [this] { return GetCircleButton(); }, nullptr);
builder.AddBooleanProperty("Triangle", [this] { return GetTriangleButton(); }, nullptr);
builder.AddBooleanProperty("L1", [this] { return GetL1Button(); }, nullptr);
builder.AddBooleanProperty("R1", [this] { return GetR1Button(); }, nullptr);
builder.AddBooleanProperty("L2", [this] { return GetL2Button(); }, nullptr);
builder.AddBooleanProperty("R2", [this] { return GetR2Button(); }, nullptr);
builder.AddBooleanProperty("Share", [this] { return GetShareButton(); }, nullptr);
builder.AddBooleanProperty("Options", [this] { return GetOptionsButton(); }, nullptr);
builder.AddBooleanProperty("L3", [this] { return GetL3Button(); }, nullptr);
builder.AddBooleanProperty("R3", [this] { return GetR3Button(); }, nullptr);
builder.AddBooleanProperty("PS", [this] { return GetPSButton(); }, nullptr);
builder.AddBooleanProperty("Touchpad", [this] { return GetTouchpadButton(); }, nullptr);
}

View File

@@ -7,6 +7,7 @@
#include "frc/PS5Controller.h"
#include <hal/FRCUsageReporting.h>
#include <wpi/sendable/SendableBuilder.h>
#include "frc/event/BooleanEvent.h"
@@ -275,3 +276,28 @@ bool PS5Controller::GetTouchpadPressed() {
bool PS5Controller::GetTouchpadReleased() {
return GetRawButtonReleased(Button::kTouchpad);
}
void PS5Controller::InitSendable(wpi::SendableBuilder& builder) {
builder.SetSmartDashboardType("HID");
builder.PublishConstString("ControllerType", "PS5");
builder.AddDoubleProperty("L2", [this] { return GetL2Axis(); }, nullptr);
builder.AddDoubleProperty("R2", [this] { return GetR2Axis(); }, nullptr);
builder.AddDoubleProperty("LeftX", [this] { return GetLeftX(); }, nullptr);
builder.AddDoubleProperty("LeftY", [this] { return GetLeftY(); }, nullptr);
builder.AddDoubleProperty("RightX", [this] { return GetRightX(); }, nullptr);
builder.AddDoubleProperty("RightY", [this] { return GetRightY(); }, nullptr);
builder.AddBooleanProperty("Square", [this] { return GetSquareButton(); }, nullptr);
builder.AddBooleanProperty("Cross", [this] { return GetCrossButton(); }, nullptr);
builder.AddBooleanProperty("Circle", [this] { return GetCircleButton(); }, nullptr);
builder.AddBooleanProperty("Triangle", [this] { return GetTriangleButton(); }, nullptr);
builder.AddBooleanProperty("L1", [this] { return GetL1Button(); }, nullptr);
builder.AddBooleanProperty("R1", [this] { return GetR1Button(); }, nullptr);
builder.AddBooleanProperty("L2", [this] { return GetL2Button(); }, nullptr);
builder.AddBooleanProperty("R2", [this] { return GetR2Button(); }, nullptr);
builder.AddBooleanProperty("Create", [this] { return GetCreateButton(); }, nullptr);
builder.AddBooleanProperty("Options", [this] { return GetOptionsButton(); }, nullptr);
builder.AddBooleanProperty("L3", [this] { return GetL3Button(); }, nullptr);
builder.AddBooleanProperty("R3", [this] { return GetR3Button(); }, nullptr);
builder.AddBooleanProperty("PS", [this] { return GetPSButton(); }, nullptr);
builder.AddBooleanProperty("Touchpad", [this] { return GetTouchpadButton(); }, nullptr);
}

View File

@@ -7,6 +7,7 @@
#include "frc/StadiaController.h"
#include <hal/FRCUsageReporting.h>
#include <wpi/sendable/SendableBuilder.h>
#include "frc/event/BooleanEvent.h"
@@ -295,3 +296,27 @@ bool StadiaController::GetLeftBumperReleased() {
bool StadiaController::GetRightBumperReleased() {
return GetRawButtonReleased(Button::kRightBumper);
}
void StadiaController::InitSendable(wpi::SendableBuilder& builder) {
builder.SetSmartDashboardType("HID");
builder.PublishConstString("ControllerType", "Stadia");
builder.AddDoubleProperty("LeftX", [this] { return GetLeftX(); }, nullptr);
builder.AddDoubleProperty("RightX", [this] { return GetRightX(); }, nullptr);
builder.AddDoubleProperty("LeftY", [this] { return GetLeftY(); }, nullptr);
builder.AddDoubleProperty("RightY", [this] { return GetRightY(); }, nullptr);
builder.AddBooleanProperty("A", [this] { return GetAButton(); }, nullptr);
builder.AddBooleanProperty("B", [this] { return GetBButton(); }, nullptr);
builder.AddBooleanProperty("X", [this] { return GetXButton(); }, nullptr);
builder.AddBooleanProperty("Y", [this] { return GetYButton(); }, nullptr);
builder.AddBooleanProperty("LeftBumper", [this] { return GetLeftBumperButton(); }, nullptr);
builder.AddBooleanProperty("RightBumper", [this] { return GetRightBumperButton(); }, nullptr);
builder.AddBooleanProperty("LeftStick", [this] { return GetLeftStickButton(); }, nullptr);
builder.AddBooleanProperty("RightStick", [this] { return GetRightStickButton(); }, nullptr);
builder.AddBooleanProperty("Ellipses", [this] { return GetEllipsesButton(); }, nullptr);
builder.AddBooleanProperty("Hamburger", [this] { return GetHamburgerButton(); }, nullptr);
builder.AddBooleanProperty("Stadia", [this] { return GetStadiaButton(); }, nullptr);
builder.AddBooleanProperty("RightTrigger", [this] { return GetRightTriggerButton(); }, nullptr);
builder.AddBooleanProperty("LeftTrigger", [this] { return GetLeftTriggerButton(); }, nullptr);
builder.AddBooleanProperty("Google", [this] { return GetGoogleButton(); }, nullptr);
builder.AddBooleanProperty("Frame", [this] { return GetFrameButton(); }, nullptr);
}

View File

@@ -7,6 +7,7 @@
#include "frc/XboxController.h"
#include <hal/FRCUsageReporting.h>
#include <wpi/sendable/SendableBuilder.h>
#include "frc/event/BooleanEvent.h"
@@ -239,3 +240,24 @@ bool XboxController::GetLeftBumperReleased() {
bool XboxController::GetRightBumperReleased() {
return GetRawButtonReleased(Button::kRightBumper);
}
void XboxController::InitSendable(wpi::SendableBuilder& builder) {
builder.SetSmartDashboardType("HID");
builder.PublishConstString("ControllerType", "Xbox");
builder.AddDoubleProperty("LeftTrigger", [this] { return GetLeftTriggerAxis(); }, nullptr);
builder.AddDoubleProperty("RightTrigger", [this] { return GetRightTriggerAxis(); }, nullptr);
builder.AddDoubleProperty("LeftX", [this] { return GetLeftX(); }, nullptr);
builder.AddDoubleProperty("RightX", [this] { return GetRightX(); }, nullptr);
builder.AddDoubleProperty("LeftY", [this] { return GetLeftY(); }, nullptr);
builder.AddDoubleProperty("RightY", [this] { return GetRightY(); }, nullptr);
builder.AddBooleanProperty("A", [this] { return GetAButton(); }, nullptr);
builder.AddBooleanProperty("B", [this] { return GetBButton(); }, nullptr);
builder.AddBooleanProperty("X", [this] { return GetXButton(); }, nullptr);
builder.AddBooleanProperty("Y", [this] { return GetYButton(); }, nullptr);
builder.AddBooleanProperty("LeftBumper", [this] { return GetLeftBumperButton(); }, nullptr);
builder.AddBooleanProperty("RightBumper", [this] { return GetRightBumperButton(); }, nullptr);
builder.AddBooleanProperty("Back", [this] { return GetBackButton(); }, nullptr);
builder.AddBooleanProperty("Start", [this] { return GetStartButton(); }, nullptr);
builder.AddBooleanProperty("LeftStick", [this] { return GetLeftStickButton(); }, nullptr);
builder.AddBooleanProperty("RightStick", [this] { return GetRightStickButton(); }, nullptr);
}

View File

@@ -6,6 +6,9 @@
#pragma once
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
#include "frc/GenericHID.h"
namespace frc {
@@ -22,7 +25,9 @@ namespace frc {
* correct mapping, and only through the official NI DS. Sim is not guaranteed
* to have the same mapping, as well as any 3rd party controllers.
*/
class PS4Controller : public GenericHID {
class PS4Controller : public GenericHID,
public wpi::Sendable,
public wpi::SendableHelper<PS4Controller> {
public:
/**
* Construct an instance of a controller.
@@ -587,6 +592,8 @@ class PS4Controller : public GenericHID {
/// Right trigger 2.
static constexpr int kR2 = 4;
};
void InitSendable(wpi::SendableBuilder& builder) override;
};
} // namespace frc

View File

@@ -6,6 +6,9 @@
#pragma once
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
#include "frc/GenericHID.h"
namespace frc {
@@ -22,7 +25,9 @@ namespace frc {
* correct mapping, and only through the official NI DS. Sim is not guaranteed
* to have the same mapping, as well as any 3rd party controllers.
*/
class PS5Controller : public GenericHID {
class PS5Controller : public GenericHID,
public wpi::Sendable,
public wpi::SendableHelper<PS5Controller> {
public:
/**
* Construct an instance of a controller.
@@ -587,6 +592,8 @@ class PS5Controller : public GenericHID {
/// Right trigger 2.
static constexpr int kR2 = 4;
};
void InitSendable(wpi::SendableBuilder& builder) override;
};
} // namespace frc

View File

@@ -6,6 +6,9 @@
#pragma once
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
#include "frc/GenericHID.h"
namespace frc {
@@ -22,7 +25,9 @@ namespace frc {
* correct mapping, and only through the official NI DS. Sim is not guaranteed
* to have the same mapping, as well as any 3rd party controllers.
*/
class StadiaController : public GenericHID {
class StadiaController : public GenericHID,
public wpi::Sendable,
public wpi::SendableHelper<StadiaController> {
public:
/**
* Construct an instance of a controller.
@@ -625,6 +630,8 @@ class StadiaController : public GenericHID {
/// Right Y axis.
static constexpr int kRightY = 4;
};
void InitSendable(wpi::SendableBuilder& builder) override;
};
} // namespace frc

View File

@@ -6,6 +6,9 @@
#pragma once
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
#include "frc/GenericHID.h"
namespace frc {
@@ -22,7 +25,9 @@ namespace frc {
* correct mapping, and only through the official NI DS. Sim is not guaranteed
* to have the same mapping, as well as any 3rd party controllers.
*/
class XboxController : public GenericHID {
class XboxController : public GenericHID,
public wpi::Sendable,
public wpi::SendableHelper<XboxController> {
public:
/**
* Construct an instance of a controller.
@@ -524,6 +529,8 @@ class XboxController : public GenericHID {
/// Right trigger.
static constexpr int kRightTrigger = 3;
};
void InitSendable(wpi::SendableBuilder& builder) override;
};
} // namespace frc