Files
allwpilib/commandsv2/src/main/native/cpp/frc2/command/button/CommandGamepad.cpp

184 lines
5.6 KiB
C++
Raw Normal View History

// 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.
2025-11-07 19:56:21 -05:00
#include "wpi/commands2/button/CommandGamepad.hpp"
#include "wpi/commands2/button/CommandGenericHID.hpp"
2025-11-07 20:00:05 -05:00
using namespace wpi::cmd;
CommandGamepad::CommandGamepad(int port)
2025-11-07 20:00:05 -05:00
: CommandGenericHID(port), m_hid{wpi::Gamepad(port)} {}
2025-11-07 20:00:05 -05:00
wpi::Gamepad& CommandGamepad::GetHID() {
return m_hid;
}
Trigger CommandGamepad::Button(enum wpi::Gamepad::Button button,
wpi::EventLoop* loop) const {
return CommandGenericHID::Button(static_cast<int>(button), loop);
}
[wpilib,cmd] Rename gamepad face-button trigger APIs to directional names (faceUp/Down/Left/Right) (#8896) This updates gamepad trigger naming from cardinal-style face buttons (`northFace/southFace/eastFace/westFace` and `NorthFace/SouthFace/EastFace/WestFace`) to directional naming (`faceUp/faceDown/faceRight/faceLeft` and `FaceUp/FaceDown/FaceRight/FaceLeft`) to match the requested API shape. The change is applied across Java and C++ HID/command layers, along with related examples and binding metadata. - **API surface updates (Java)** - Renamed trigger/event methods in: - `wpilibj` `Gamepad` - `commandsv2` `CommandGamepad` - `commandsv3` `CommandGamepad` - Mapping preserved: - `southFace` → `faceDown` - `eastFace` → `faceRight` - `westFace` → `faceLeft` - `northFace` → `faceUp` - **API surface updates (C++)** - Renamed trigger/event methods in: - `wpilibc` `Gamepad` - `commandsv2` `CommandGamepad` - Mapping preserved: - `SouthFace` → `FaceDown` - `EastFace` → `FaceRight` - `WestFace` → `FaceLeft` - `NorthFace` → `FaceUp` - **Python semiwrap updates** - Updated `wpilibc/src/main/python/semiwrap/Gamepad.yml` method mappings to the renamed C++ method names (`FaceDown/FaceRight/FaceLeft/FaceUp`). - **Callsite migration** - Updated Java examples/template code and C++ examples/template code to use the new method names so samples remain aligned with the API rename. - **Docs/comments alignment** - Updated related Javadoc/reference text and example comments to use directional terminology. ```java // Before driverController.southFace().onTrue(command); driverController.eastFace().onTrue(command); // After driverController.faceDown().onTrue(command); driverController.faceRight().onTrue(command); ``` ```cpp // Before driverController.SouthFace().OnTrue(command); driverController.EastFace().OnTrue(command); // After driverController.FaceDown().OnTrue(command); driverController.FaceRight().OnTrue(command); ``` --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ThadHouse <7727148+ThadHouse@users.noreply.github.com>
2026-05-14 22:08:57 -07:00
Trigger CommandGamepad::FaceDown(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::FACE_DOWN, loop);
}
[wpilib,cmd] Rename gamepad face-button trigger APIs to directional names (faceUp/Down/Left/Right) (#8896) This updates gamepad trigger naming from cardinal-style face buttons (`northFace/southFace/eastFace/westFace` and `NorthFace/SouthFace/EastFace/WestFace`) to directional naming (`faceUp/faceDown/faceRight/faceLeft` and `FaceUp/FaceDown/FaceRight/FaceLeft`) to match the requested API shape. The change is applied across Java and C++ HID/command layers, along with related examples and binding metadata. - **API surface updates (Java)** - Renamed trigger/event methods in: - `wpilibj` `Gamepad` - `commandsv2` `CommandGamepad` - `commandsv3` `CommandGamepad` - Mapping preserved: - `southFace` → `faceDown` - `eastFace` → `faceRight` - `westFace` → `faceLeft` - `northFace` → `faceUp` - **API surface updates (C++)** - Renamed trigger/event methods in: - `wpilibc` `Gamepad` - `commandsv2` `CommandGamepad` - Mapping preserved: - `SouthFace` → `FaceDown` - `EastFace` → `FaceRight` - `WestFace` → `FaceLeft` - `NorthFace` → `FaceUp` - **Python semiwrap updates** - Updated `wpilibc/src/main/python/semiwrap/Gamepad.yml` method mappings to the renamed C++ method names (`FaceDown/FaceRight/FaceLeft/FaceUp`). - **Callsite migration** - Updated Java examples/template code and C++ examples/template code to use the new method names so samples remain aligned with the API rename. - **Docs/comments alignment** - Updated related Javadoc/reference text and example comments to use directional terminology. ```java // Before driverController.southFace().onTrue(command); driverController.eastFace().onTrue(command); // After driverController.faceDown().onTrue(command); driverController.faceRight().onTrue(command); ``` ```cpp // Before driverController.SouthFace().OnTrue(command); driverController.EastFace().OnTrue(command); // After driverController.FaceDown().OnTrue(command); driverController.FaceRight().OnTrue(command); ``` --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ThadHouse <7727148+ThadHouse@users.noreply.github.com>
2026-05-14 22:08:57 -07:00
Trigger CommandGamepad::FaceRight(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::FACE_RIGHT, loop);
}
[wpilib,cmd] Rename gamepad face-button trigger APIs to directional names (faceUp/Down/Left/Right) (#8896) This updates gamepad trigger naming from cardinal-style face buttons (`northFace/southFace/eastFace/westFace` and `NorthFace/SouthFace/EastFace/WestFace`) to directional naming (`faceUp/faceDown/faceRight/faceLeft` and `FaceUp/FaceDown/FaceRight/FaceLeft`) to match the requested API shape. The change is applied across Java and C++ HID/command layers, along with related examples and binding metadata. - **API surface updates (Java)** - Renamed trigger/event methods in: - `wpilibj` `Gamepad` - `commandsv2` `CommandGamepad` - `commandsv3` `CommandGamepad` - Mapping preserved: - `southFace` → `faceDown` - `eastFace` → `faceRight` - `westFace` → `faceLeft` - `northFace` → `faceUp` - **API surface updates (C++)** - Renamed trigger/event methods in: - `wpilibc` `Gamepad` - `commandsv2` `CommandGamepad` - Mapping preserved: - `SouthFace` → `FaceDown` - `EastFace` → `FaceRight` - `WestFace` → `FaceLeft` - `NorthFace` → `FaceUp` - **Python semiwrap updates** - Updated `wpilibc/src/main/python/semiwrap/Gamepad.yml` method mappings to the renamed C++ method names (`FaceDown/FaceRight/FaceLeft/FaceUp`). - **Callsite migration** - Updated Java examples/template code and C++ examples/template code to use the new method names so samples remain aligned with the API rename. - **Docs/comments alignment** - Updated related Javadoc/reference text and example comments to use directional terminology. ```java // Before driverController.southFace().onTrue(command); driverController.eastFace().onTrue(command); // After driverController.faceDown().onTrue(command); driverController.faceRight().onTrue(command); ``` ```cpp // Before driverController.SouthFace().OnTrue(command); driverController.EastFace().OnTrue(command); // After driverController.FaceDown().OnTrue(command); driverController.FaceRight().OnTrue(command); ``` --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ThadHouse <7727148+ThadHouse@users.noreply.github.com>
2026-05-14 22:08:57 -07:00
Trigger CommandGamepad::FaceLeft(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::FACE_LEFT, loop);
}
[wpilib,cmd] Rename gamepad face-button trigger APIs to directional names (faceUp/Down/Left/Right) (#8896) This updates gamepad trigger naming from cardinal-style face buttons (`northFace/southFace/eastFace/westFace` and `NorthFace/SouthFace/EastFace/WestFace`) to directional naming (`faceUp/faceDown/faceRight/faceLeft` and `FaceUp/FaceDown/FaceRight/FaceLeft`) to match the requested API shape. The change is applied across Java and C++ HID/command layers, along with related examples and binding metadata. - **API surface updates (Java)** - Renamed trigger/event methods in: - `wpilibj` `Gamepad` - `commandsv2` `CommandGamepad` - `commandsv3` `CommandGamepad` - Mapping preserved: - `southFace` → `faceDown` - `eastFace` → `faceRight` - `westFace` → `faceLeft` - `northFace` → `faceUp` - **API surface updates (C++)** - Renamed trigger/event methods in: - `wpilibc` `Gamepad` - `commandsv2` `CommandGamepad` - Mapping preserved: - `SouthFace` → `FaceDown` - `EastFace` → `FaceRight` - `WestFace` → `FaceLeft` - `NorthFace` → `FaceUp` - **Python semiwrap updates** - Updated `wpilibc/src/main/python/semiwrap/Gamepad.yml` method mappings to the renamed C++ method names (`FaceDown/FaceRight/FaceLeft/FaceUp`). - **Callsite migration** - Updated Java examples/template code and C++ examples/template code to use the new method names so samples remain aligned with the API rename. - **Docs/comments alignment** - Updated related Javadoc/reference text and example comments to use directional terminology. ```java // Before driverController.southFace().onTrue(command); driverController.eastFace().onTrue(command); // After driverController.faceDown().onTrue(command); driverController.faceRight().onTrue(command); ``` ```cpp // Before driverController.SouthFace().OnTrue(command); driverController.EastFace().OnTrue(command); // After driverController.FaceDown().OnTrue(command); driverController.FaceRight().OnTrue(command); ``` --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ThadHouse <7727148+ThadHouse@users.noreply.github.com>
2026-05-14 22:08:57 -07:00
Trigger CommandGamepad::FaceUp(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::FACE_UP, loop);
}
2025-11-07 20:00:05 -05:00
Trigger CommandGamepad::Back(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::BACK, loop);
}
2025-11-07 20:00:05 -05:00
Trigger CommandGamepad::Guide(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::GUIDE, loop);
}
2025-11-07 20:00:05 -05:00
Trigger CommandGamepad::Start(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::START, loop);
}
2025-11-07 20:00:05 -05:00
Trigger CommandGamepad::LeftStick(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::LEFT_STICK, loop);
}
2025-11-07 20:00:05 -05:00
Trigger CommandGamepad::RightStick(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::RIGHT_STICK, loop);
}
Trigger CommandGamepad::LeftBumper(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::LEFT_BUMPER, loop);
}
Trigger CommandGamepad::RightBumper(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::RIGHT_BUMPER, loop);
}
2025-11-07 20:00:05 -05:00
Trigger CommandGamepad::DpadUp(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::DPAD_UP, loop);
}
2025-11-07 20:00:05 -05:00
Trigger CommandGamepad::DpadDown(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::DPAD_DOWN, loop);
}
2025-11-07 20:00:05 -05:00
Trigger CommandGamepad::DpadLeft(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::DPAD_LEFT, loop);
}
2025-11-07 20:00:05 -05:00
Trigger CommandGamepad::DpadRight(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::DPAD_RIGHT, loop);
}
2025-11-07 20:00:05 -05:00
Trigger CommandGamepad::Misc1(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::MISC_1, loop);
}
2025-11-07 20:00:05 -05:00
Trigger CommandGamepad::RightPaddle1(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::RIGHT_PADDLE_1, loop);
}
2025-11-07 20:00:05 -05:00
Trigger CommandGamepad::LeftPaddle1(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::LEFT_PADDLE_1, loop);
}
2025-11-07 20:00:05 -05:00
Trigger CommandGamepad::RightPaddle2(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::RIGHT_PADDLE_2, loop);
}
2025-11-07 20:00:05 -05:00
Trigger CommandGamepad::LeftPaddle2(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::LEFT_PADDLE_2, loop);
}
2025-11-07 20:00:05 -05:00
Trigger CommandGamepad::Touchpad(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::TOUCHPAD, loop);
}
2025-11-07 20:00:05 -05:00
Trigger CommandGamepad::Misc2(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::MISC_2, loop);
}
2025-11-07 20:00:05 -05:00
Trigger CommandGamepad::Misc3(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::MISC_3, loop);
}
2025-11-07 20:00:05 -05:00
Trigger CommandGamepad::Misc4(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::MISC_4, loop);
}
2025-11-07 20:00:05 -05:00
Trigger CommandGamepad::Misc5(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::MISC_5, loop);
}
2025-11-07 20:00:05 -05:00
Trigger CommandGamepad::Misc6(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::MISC_6, loop);
}
Trigger CommandGamepad::LeftTrigger(double threshold,
2025-11-07 20:00:05 -05:00
wpi::EventLoop* loop) const {
return Trigger(loop, [this, threshold] {
return m_hid.GetLeftTriggerAxis() > threshold;
});
}
Trigger CommandGamepad::RightTrigger(double threshold,
2025-11-07 20:00:05 -05:00
wpi::EventLoop* loop) const {
return Trigger(loop, [this, threshold] {
return m_hid.GetRightTriggerAxis() > threshold;
});
}
Trigger CommandGamepad::AxisLessThan(wpi::Gamepad::Axis axis, double threshold,
wpi::EventLoop* loop) const {
return CommandGenericHID::AxisLessThan(static_cast<int>(axis), threshold,
loop);
}
Trigger CommandGamepad::AxisGreaterThan(wpi::Gamepad::Axis axis,
double threshold,
wpi::EventLoop* loop) const {
return CommandGenericHID::AxisGreaterThan(static_cast<int>(axis), threshold,
loop);
}
Trigger CommandGamepad::AxisMagnitudeGreaterThan(wpi::Gamepad::Axis axis,
double threshold,
wpi::EventLoop* loop) const {
return CommandGenericHID::AxisMagnitudeGreaterThan(static_cast<int>(axis),
threshold, loop);
}
double CommandGamepad::GetLeftX() const {
return m_hid.GetLeftX();
}
double CommandGamepad::GetLeftY() const {
return m_hid.GetLeftY();
}
double CommandGamepad::GetRightX() const {
return m_hid.GetRightX();
}
double CommandGamepad::GetRightY() const {
return m_hid.GetRightY();
}
double CommandGamepad::GetLeftTriggerAxis() const {
return m_hid.GetLeftTriggerAxis();
}
double CommandGamepad::GetRightTriggerAxis() const {
return m_hid.GetRightTriggerAxis();
}