2021-08-14 20:00:46 +03:00
|
|
|
// 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.
|
|
|
|
|
|
2024-06-08 12:59:07 -04:00
|
|
|
// THIS FILE WAS AUTO-GENERATED BY ./wpilibc/generate_hids.py. DO NOT MODIFY
|
|
|
|
|
|
2025-11-07 19:56:21 -05:00
|
|
|
#include "wpi/driverstation/PS4Controller.hpp"
|
2021-08-14 20:00:46 +03:00
|
|
|
|
2025-11-07 19:56:21 -05:00
|
|
|
#include "wpi/hal/UsageReporting.h"
|
|
|
|
|
#include "wpi/util/sendable/SendableBuilder.hpp"
|
2021-08-14 20:00:46 +03:00
|
|
|
|
2025-11-07 19:56:21 -05:00
|
|
|
#include "wpi/event/BooleanEvent.hpp"
|
2022-06-14 08:48:16 +03:00
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
using namespace wpi;
|
2021-08-14 20:00:46 +03:00
|
|
|
|
|
|
|
|
PS4Controller::PS4Controller(int port) : GenericHID(port) {
|
2025-02-07 12:37:23 -08:00
|
|
|
HAL_ReportUsage("HID", port, "PS4Controller");
|
2021-08-14 20:00:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double PS4Controller::GetLeftX() const {
|
|
|
|
|
return GetRawAxis(Axis::kLeftX);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double PS4Controller::GetLeftY() const {
|
|
|
|
|
return GetRawAxis(Axis::kLeftY);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-08 12:59:07 -04:00
|
|
|
double PS4Controller::GetRightX() const {
|
|
|
|
|
return GetRawAxis(Axis::kRightX);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-14 20:00:46 +03:00
|
|
|
double PS4Controller::GetRightY() const {
|
|
|
|
|
return GetRawAxis(Axis::kRightY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double PS4Controller::GetL2Axis() const {
|
|
|
|
|
return GetRawAxis(Axis::kL2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double PS4Controller::GetR2Axis() const {
|
|
|
|
|
return GetRawAxis(Axis::kR2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PS4Controller::GetSquareButton() const {
|
|
|
|
|
return GetRawButton(Button::kSquare);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PS4Controller::GetSquareButtonPressed() {
|
|
|
|
|
return GetRawButtonPressed(Button::kSquare);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PS4Controller::GetSquareButtonReleased() {
|
|
|
|
|
return GetRawButtonReleased(Button::kSquare);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-14 08:48:16 +03:00
|
|
|
BooleanEvent PS4Controller::Square(EventLoop* loop) const {
|
|
|
|
|
return BooleanEvent(loop, [this]() { return this->GetSquareButton(); });
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-14 20:00:46 +03:00
|
|
|
bool PS4Controller::GetCrossButton() const {
|
|
|
|
|
return GetRawButton(Button::kCross);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PS4Controller::GetCrossButtonPressed() {
|
|
|
|
|
return GetRawButtonPressed(Button::kCross);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PS4Controller::GetCrossButtonReleased() {
|
|
|
|
|
return GetRawButtonReleased(Button::kCross);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-14 08:48:16 +03:00
|
|
|
BooleanEvent PS4Controller::Cross(EventLoop* loop) const {
|
|
|
|
|
return BooleanEvent(loop, [this]() { return this->GetCrossButton(); });
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-14 20:00:46 +03:00
|
|
|
bool PS4Controller::GetCircleButton() const {
|
|
|
|
|
return GetRawButton(Button::kCircle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PS4Controller::GetCircleButtonPressed() {
|
|
|
|
|
return GetRawButtonPressed(Button::kCircle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PS4Controller::GetCircleButtonReleased() {
|
|
|
|
|
return GetRawButtonReleased(Button::kCircle);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-14 08:48:16 +03:00
|
|
|
BooleanEvent PS4Controller::Circle(EventLoop* loop) const {
|
|
|
|
|
return BooleanEvent(loop, [this]() { return this->GetCircleButton(); });
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-14 20:00:46 +03:00
|
|
|
bool PS4Controller::GetTriangleButton() const {
|
|
|
|
|
return GetRawButton(Button::kTriangle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PS4Controller::GetTriangleButtonPressed() {
|
|
|
|
|
return GetRawButtonPressed(Button::kTriangle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PS4Controller::GetTriangleButtonReleased() {
|
|
|
|
|
return GetRawButtonReleased(Button::kTriangle);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-14 08:48:16 +03:00
|
|
|
BooleanEvent PS4Controller::Triangle(EventLoop* loop) const {
|
|
|
|
|
return BooleanEvent(loop, [this]() { return this->GetTriangleButton(); });
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-14 20:00:46 +03:00
|
|
|
bool PS4Controller::GetL1Button() const {
|
|
|
|
|
return GetRawButton(Button::kL1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PS4Controller::GetL1ButtonPressed() {
|
|
|
|
|
return GetRawButtonPressed(Button::kL1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PS4Controller::GetL1ButtonReleased() {
|
|
|
|
|
return GetRawButtonReleased(Button::kL1);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-14 08:48:16 +03:00
|
|
|
BooleanEvent PS4Controller::L1(EventLoop* loop) const {
|
|
|
|
|
return BooleanEvent(loop, [this]() { return this->GetL1Button(); });
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-14 20:00:46 +03:00
|
|
|
bool PS4Controller::GetR1Button() const {
|
|
|
|
|
return GetRawButton(Button::kR1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PS4Controller::GetR1ButtonPressed() {
|
|
|
|
|
return GetRawButtonPressed(Button::kR1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PS4Controller::GetR1ButtonReleased() {
|
|
|
|
|
return GetRawButtonReleased(Button::kR1);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-14 08:48:16 +03:00
|
|
|
BooleanEvent PS4Controller::R1(EventLoop* loop) const {
|
|
|
|
|
return BooleanEvent(loop, [this]() { return this->GetR1Button(); });
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-14 20:00:46 +03:00
|
|
|
bool PS4Controller::GetL2Button() const {
|
|
|
|
|
return GetRawButton(Button::kL2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PS4Controller::GetL2ButtonPressed() {
|
|
|
|
|
return GetRawButtonPressed(Button::kL2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PS4Controller::GetL2ButtonReleased() {
|
|
|
|
|
return GetRawButtonReleased(Button::kL2);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-14 08:48:16 +03:00
|
|
|
BooleanEvent PS4Controller::L2(EventLoop* loop) const {
|
|
|
|
|
return BooleanEvent(loop, [this]() { return this->GetL2Button(); });
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-14 20:00:46 +03:00
|
|
|
bool PS4Controller::GetR2Button() const {
|
|
|
|
|
return GetRawButton(Button::kR2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PS4Controller::GetR2ButtonPressed() {
|
|
|
|
|
return GetRawButtonPressed(Button::kR2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PS4Controller::GetR2ButtonReleased() {
|
|
|
|
|
return GetRawButtonReleased(Button::kR2);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-14 08:48:16 +03:00
|
|
|
BooleanEvent PS4Controller::R2(EventLoop* loop) const {
|
|
|
|
|
return BooleanEvent(loop, [this]() { return this->GetR2Button(); });
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-14 20:00:46 +03:00
|
|
|
bool PS4Controller::GetShareButton() const {
|
|
|
|
|
return GetRawButton(Button::kShare);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PS4Controller::GetShareButtonPressed() {
|
|
|
|
|
return GetRawButtonPressed(Button::kShare);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PS4Controller::GetShareButtonReleased() {
|
|
|
|
|
return GetRawButtonReleased(Button::kShare);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-14 08:48:16 +03:00
|
|
|
BooleanEvent PS4Controller::Share(EventLoop* loop) const {
|
|
|
|
|
return BooleanEvent(loop, [this]() { return this->GetShareButton(); });
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-14 20:00:46 +03:00
|
|
|
bool PS4Controller::GetOptionsButton() const {
|
|
|
|
|
return GetRawButton(Button::kOptions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PS4Controller::GetOptionsButtonPressed() {
|
|
|
|
|
return GetRawButtonPressed(Button::kOptions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PS4Controller::GetOptionsButtonReleased() {
|
|
|
|
|
return GetRawButtonReleased(Button::kOptions);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-14 08:48:16 +03:00
|
|
|
BooleanEvent PS4Controller::Options(EventLoop* loop) const {
|
|
|
|
|
return BooleanEvent(loop, [this]() { return this->GetOptionsButton(); });
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-14 20:00:46 +03:00
|
|
|
bool PS4Controller::GetL3Button() const {
|
|
|
|
|
return GetRawButton(Button::kL3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PS4Controller::GetL3ButtonPressed() {
|
|
|
|
|
return GetRawButtonPressed(Button::kL3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PS4Controller::GetL3ButtonReleased() {
|
|
|
|
|
return GetRawButtonReleased(Button::kL3);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-14 08:48:16 +03:00
|
|
|
BooleanEvent PS4Controller::L3(EventLoop* loop) const {
|
|
|
|
|
return BooleanEvent(loop, [this]() { return this->GetL3Button(); });
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-14 20:00:46 +03:00
|
|
|
bool PS4Controller::GetR3Button() const {
|
|
|
|
|
return GetRawButton(Button::kR3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PS4Controller::GetR3ButtonPressed() {
|
|
|
|
|
return GetRawButtonPressed(Button::kR3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PS4Controller::GetR3ButtonReleased() {
|
|
|
|
|
return GetRawButtonReleased(Button::kR3);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-14 08:48:16 +03:00
|
|
|
BooleanEvent PS4Controller::R3(EventLoop* loop) const {
|
|
|
|
|
return BooleanEvent(loop, [this]() { return this->GetR3Button(); });
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-14 20:00:46 +03:00
|
|
|
bool PS4Controller::GetPSButton() const {
|
|
|
|
|
return GetRawButton(Button::kPS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PS4Controller::GetPSButtonPressed() {
|
|
|
|
|
return GetRawButtonPressed(Button::kPS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PS4Controller::GetPSButtonReleased() {
|
|
|
|
|
return GetRawButtonReleased(Button::kPS);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-14 08:48:16 +03:00
|
|
|
BooleanEvent PS4Controller::PS(EventLoop* loop) const {
|
|
|
|
|
return BooleanEvent(loop, [this]() { return this->GetPSButton(); });
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-08 12:59:07 -04:00
|
|
|
bool PS4Controller::GetTouchpadButton() const {
|
2021-08-14 20:00:46 +03:00
|
|
|
return GetRawButton(Button::kTouchpad);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-08 12:59:07 -04:00
|
|
|
bool PS4Controller::GetTouchpadButtonPressed() {
|
2021-08-14 20:00:46 +03:00
|
|
|
return GetRawButtonPressed(Button::kTouchpad);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-08 12:59:07 -04:00
|
|
|
bool PS4Controller::GetTouchpadButtonReleased() {
|
2021-08-14 20:00:46 +03:00
|
|
|
return GetRawButtonReleased(Button::kTouchpad);
|
|
|
|
|
}
|
2022-06-14 08:48:16 +03:00
|
|
|
|
|
|
|
|
BooleanEvent PS4Controller::Touchpad(EventLoop* loop) const {
|
2024-06-08 12:59:07 -04:00
|
|
|
return BooleanEvent(loop, [this]() { return this->GetTouchpadButton(); });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PS4Controller::GetTouchpad() const {
|
|
|
|
|
return GetRawButton(Button::kTouchpad);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PS4Controller::GetTouchpadPressed() {
|
|
|
|
|
return GetRawButtonPressed(Button::kTouchpad);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PS4Controller::GetTouchpadReleased() {
|
|
|
|
|
return GetRawButtonReleased(Button::kTouchpad);
|
2022-06-14 08:48:16 +03:00
|
|
|
}
|
2024-07-18 22:10:07 +08:00
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
void PS4Controller::InitSendable(wpi::util::SendableBuilder& builder) {
|
2024-07-18 22:10:07 +08:00
|
|
|
builder.SetSmartDashboardType("HID");
|
|
|
|
|
builder.PublishConstString("ControllerType", "PS4");
|
2025-07-15 21:19:03 -07:00
|
|
|
builder.AddDoubleProperty("L2 Axis", [this] { return GetL2Axis(); }, nullptr);
|
|
|
|
|
builder.AddDoubleProperty("R2 Axis", [this] { return GetR2Axis(); }, nullptr);
|
2024-07-18 22:10:07 +08:00
|
|
|
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);
|
|
|
|
|
}
|