mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[wpilib] Add PS4Controller, remove Hand from GenericHID/XboxController (#3345)
- GenericHID is now concrete, and has only getRawAxis/Button(int) functionality - getXxx() has been moved into Joystick as that's the only place where it makes sense - Hand (and therefore getXxx(Hand)) has been removed, replaced by specific getLeft/RightXxx() methods in XboxController and the new PS4Controller class - C++ ::Button:: and ::Axis:: enums have been converted to identically-namespaced static constexpr ints
This commit is contained in:
101
wpilibc/src/main/native/cpp/simulation/PS4ControllerSim.cpp
Normal file
101
wpilibc/src/main/native/cpp/simulation/PS4ControllerSim.cpp
Normal file
@@ -0,0 +1,101 @@
|
||||
// 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.
|
||||
|
||||
#include "frc/simulation/PS4ControllerSim.h"
|
||||
|
||||
#include "frc/PS4Controller.h"
|
||||
|
||||
using namespace frc;
|
||||
using namespace frc::sim;
|
||||
|
||||
PS4ControllerSim::PS4ControllerSim(const PS4Controller& joystick)
|
||||
: GenericHIDSim{joystick} {
|
||||
SetAxisCount(6);
|
||||
SetButtonCount(14);
|
||||
}
|
||||
|
||||
PS4ControllerSim::PS4ControllerSim(int port) : GenericHIDSim{port} {
|
||||
SetAxisCount(6);
|
||||
SetButtonCount(14);
|
||||
}
|
||||
|
||||
void PS4ControllerSim::SetLeftX(double value) {
|
||||
SetRawAxis(PS4Controller::Axis::kLeftX, value);
|
||||
}
|
||||
|
||||
void PS4ControllerSim::SetRightX(double value) {
|
||||
SetRawAxis(PS4Controller::Axis::kRightX, value);
|
||||
}
|
||||
|
||||
void PS4ControllerSim::SetLeftY(double value) {
|
||||
SetRawAxis(PS4Controller::Axis::kLeftY, value);
|
||||
}
|
||||
|
||||
void PS4ControllerSim::SetRightY(double value) {
|
||||
SetRawAxis(PS4Controller::Axis::kRightY, value);
|
||||
}
|
||||
|
||||
void PS4ControllerSim::SetL2Axis(double value) {
|
||||
SetRawAxis(PS4Controller::Axis::kL2, value);
|
||||
}
|
||||
|
||||
void PS4ControllerSim::SetR2Axis(double value) {
|
||||
SetRawAxis(PS4Controller::Axis::kR2, value);
|
||||
}
|
||||
|
||||
void PS4ControllerSim::SetSquareButton(bool value) {
|
||||
SetRawButton(PS4Controller::Button::kSquare, value);
|
||||
}
|
||||
|
||||
void PS4ControllerSim::SetCrossButton(bool value) {
|
||||
SetRawButton(PS4Controller::Button::kCross, value);
|
||||
}
|
||||
|
||||
void PS4ControllerSim::SetCircleButton(bool value) {
|
||||
SetRawButton(PS4Controller::Button::kCircle, value);
|
||||
}
|
||||
|
||||
void PS4ControllerSim::SetTriangleButton(bool value) {
|
||||
SetRawButton(PS4Controller::Button::kTriangle, value);
|
||||
}
|
||||
|
||||
void PS4ControllerSim::SetL1Button(bool value) {
|
||||
SetRawButton(PS4Controller::Button::kL1, value);
|
||||
}
|
||||
|
||||
void PS4ControllerSim::SetR1Button(bool value) {
|
||||
SetRawButton(PS4Controller::Button::kR1, value);
|
||||
}
|
||||
|
||||
void PS4ControllerSim::SetL2Button(bool value) {
|
||||
SetRawButton(PS4Controller::Button::kL2, value);
|
||||
}
|
||||
|
||||
void PS4ControllerSim::SetR2Button(bool value) {
|
||||
SetRawButton(PS4Controller::Button::kR2, value);
|
||||
}
|
||||
|
||||
void PS4ControllerSim::SetShareButton(bool value) {
|
||||
SetRawButton(PS4Controller::Button::kShare, value);
|
||||
}
|
||||
|
||||
void PS4ControllerSim::SetOptionsButton(bool value) {
|
||||
SetRawButton(PS4Controller::Button::kOptions, value);
|
||||
}
|
||||
|
||||
void PS4ControllerSim::SetL3Button(bool value) {
|
||||
SetRawButton(PS4Controller::Button::kL3, value);
|
||||
}
|
||||
|
||||
void PS4ControllerSim::SetR3Button(bool value) {
|
||||
SetRawButton(PS4Controller::Button::kR3, value);
|
||||
}
|
||||
|
||||
void PS4ControllerSim::SetPSButton(bool value) {
|
||||
SetRawButton(PS4Controller::Button::kPS, value);
|
||||
}
|
||||
|
||||
void PS4ControllerSim::SetTouchpad(bool value) {
|
||||
SetRawButton(PS4Controller::Button::kTouchpad, value);
|
||||
}
|
||||
@@ -20,68 +20,66 @@ XboxControllerSim::XboxControllerSim(int port) : GenericHIDSim{port} {
|
||||
SetButtonCount(10);
|
||||
}
|
||||
|
||||
void XboxControllerSim::SetX(GenericHID::JoystickHand hand, double value) {
|
||||
if (hand == GenericHID::kLeftHand) {
|
||||
SetRawAxis(static_cast<int>(XboxController::Axis::kLeftX), value);
|
||||
} else {
|
||||
SetRawAxis(static_cast<int>(XboxController::Axis::kRightX), value);
|
||||
}
|
||||
void XboxControllerSim::SetLeftX(double value) {
|
||||
SetRawAxis(XboxController::Axis::kLeftX, value);
|
||||
}
|
||||
|
||||
void XboxControllerSim::SetY(GenericHID::JoystickHand hand, double value) {
|
||||
if (hand == GenericHID::kLeftHand) {
|
||||
SetRawAxis(static_cast<int>(XboxController::Axis::kLeftY), value);
|
||||
} else {
|
||||
SetRawAxis(static_cast<int>(XboxController::Axis::kRightY), value);
|
||||
}
|
||||
void XboxControllerSim::SetRightX(double value) {
|
||||
SetRawAxis(XboxController::Axis::kRightX, value);
|
||||
}
|
||||
|
||||
void XboxControllerSim::SetTriggerAxis(GenericHID::JoystickHand hand,
|
||||
double value) {
|
||||
if (hand == GenericHID::kLeftHand) {
|
||||
SetRawAxis(static_cast<int>(XboxController::Axis::kLeftTrigger), value);
|
||||
} else {
|
||||
SetRawAxis(static_cast<int>(XboxController::Axis::kRightTrigger), value);
|
||||
}
|
||||
void XboxControllerSim::SetLeftY(double value) {
|
||||
SetRawAxis(XboxController::Axis::kLeftY, value);
|
||||
}
|
||||
|
||||
void XboxControllerSim::SetBumper(GenericHID::JoystickHand hand, bool state) {
|
||||
if (hand == GenericHID::kLeftHand) {
|
||||
SetRawButton(static_cast<int>(XboxController::Button::kBumperLeft), state);
|
||||
} else {
|
||||
SetRawButton(static_cast<int>(XboxController::Button::kBumperRight), state);
|
||||
}
|
||||
void XboxControllerSim::SetRightY(double value) {
|
||||
SetRawAxis(XboxController::Axis::kRightY, value);
|
||||
}
|
||||
|
||||
void XboxControllerSim::SetStickButton(GenericHID::JoystickHand hand,
|
||||
bool state) {
|
||||
if (hand == GenericHID::kLeftHand) {
|
||||
SetRawButton(static_cast<int>(XboxController::Button::kStickLeft), state);
|
||||
} else {
|
||||
SetRawButton(static_cast<int>(XboxController::Button::kStickRight), state);
|
||||
}
|
||||
void XboxControllerSim::SetLeftTriggerAxis(double value) {
|
||||
SetRawAxis(XboxController::Axis::kLeftTrigger, value);
|
||||
}
|
||||
|
||||
void XboxControllerSim::SetRightTriggerAxis(double value) {
|
||||
SetRawAxis(XboxController::Axis::kRightTrigger, value);
|
||||
}
|
||||
|
||||
void XboxControllerSim::SetLeftBumper(bool state) {
|
||||
SetRawButton(XboxController::Button::kLeftBumper, state);
|
||||
}
|
||||
|
||||
void XboxControllerSim::SetRightBumper(bool state) {
|
||||
SetRawButton(XboxController::Button::kRightBumper, state);
|
||||
}
|
||||
|
||||
void XboxControllerSim::SetLeftStickButton(bool state) {
|
||||
SetRawButton(XboxController::Button::kLeftStick, state);
|
||||
}
|
||||
|
||||
void XboxControllerSim::SetRightStickButton(bool state) {
|
||||
SetRawButton(XboxController::Button::kRightStick, state);
|
||||
}
|
||||
|
||||
void XboxControllerSim::SetAButton(bool state) {
|
||||
SetRawButton(static_cast<int>(XboxController::Button::kA), state);
|
||||
SetRawButton(XboxController::Button::kA, state);
|
||||
}
|
||||
|
||||
void XboxControllerSim::SetBButton(bool state) {
|
||||
SetRawButton(static_cast<int>(XboxController::Button::kB), state);
|
||||
SetRawButton(XboxController::Button::kB, state);
|
||||
}
|
||||
|
||||
void XboxControllerSim::SetXButton(bool state) {
|
||||
SetRawButton(static_cast<int>(XboxController::Button::kX), state);
|
||||
SetRawButton(XboxController::Button::kX, state);
|
||||
}
|
||||
|
||||
void XboxControllerSim::SetYButton(bool state) {
|
||||
SetRawButton(static_cast<int>(XboxController::Button::kY), state);
|
||||
SetRawButton(XboxController::Button::kY, state);
|
||||
}
|
||||
|
||||
void XboxControllerSim::SetBackButton(bool state) {
|
||||
SetRawButton(static_cast<int>(XboxController::Button::kBack), state);
|
||||
SetRawButton(XboxController::Button::kBack, state);
|
||||
}
|
||||
|
||||
void XboxControllerSim::SetStartButton(bool state) {
|
||||
SetRawButton(static_cast<int>(XboxController::Button::kStart), state);
|
||||
SetRawButton(XboxController::Button::kStart, state);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user