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:
@@ -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