2025-10-25 23:03:50 -07: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.
|
|
|
|
|
|
2025-11-07 19:56:21 -05:00
|
|
|
#include "wpi/commands2/button/CommandGamepad.hpp"
|
2025-10-25 23:03:50 -07:00
|
|
|
|
2026-03-17 17:19:58 -07:00
|
|
|
#include "wpi/commands2/button/CommandGenericHID.hpp"
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
using namespace wpi::cmd;
|
2025-10-25 23:03:50 -07:00
|
|
|
|
|
|
|
|
CommandGamepad::CommandGamepad(int port)
|
2025-11-07 20:00:05 -05:00
|
|
|
: CommandGenericHID(port), m_hid{wpi::Gamepad(port)} {}
|
2025-10-25 23:03:50 -07:00
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::Gamepad& CommandGamepad::GetHID() {
|
2025-10-25 23:03:50 -07:00
|
|
|
return m_hid;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-17 17:19:58 -07:00
|
|
|
Trigger CommandGamepad::Button(enum wpi::Gamepad::Button button,
|
|
|
|
|
wpi::EventLoop* loop) const {
|
|
|
|
|
return CommandGenericHID::Button(static_cast<int>(button), loop);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-14 22:08:57 -07:00
|
|
|
Trigger CommandGamepad::FaceDown(wpi::EventLoop* loop) const {
|
2026-05-26 21:55:07 -07:00
|
|
|
return Button(wpi::Gamepad::Button::FACE_DOWN, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2026-05-14 22:08:57 -07:00
|
|
|
Trigger CommandGamepad::FaceRight(wpi::EventLoop* loop) const {
|
2026-05-26 21:55:07 -07:00
|
|
|
return Button(wpi::Gamepad::Button::FACE_RIGHT, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2026-05-14 22:08:57 -07:00
|
|
|
Trigger CommandGamepad::FaceLeft(wpi::EventLoop* loop) const {
|
2026-05-26 21:55:07 -07:00
|
|
|
return Button(wpi::Gamepad::Button::FACE_LEFT, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2026-05-14 22:08:57 -07:00
|
|
|
Trigger CommandGamepad::FaceUp(wpi::EventLoop* loop) const {
|
2026-05-26 21:55:07 -07:00
|
|
|
return Button(wpi::Gamepad::Button::FACE_UP, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::Back(wpi::EventLoop* loop) const {
|
2026-03-17 17:19:58 -07:00
|
|
|
return Button(wpi::Gamepad::Button::BACK, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::Guide(wpi::EventLoop* loop) const {
|
2026-03-17 17:19:58 -07:00
|
|
|
return Button(wpi::Gamepad::Button::GUIDE, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::Start(wpi::EventLoop* loop) const {
|
2026-03-17 17:19:58 -07:00
|
|
|
return Button(wpi::Gamepad::Button::START, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::LeftStick(wpi::EventLoop* loop) const {
|
2026-03-17 17:19:58 -07:00
|
|
|
return Button(wpi::Gamepad::Button::LEFT_STICK, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::RightStick(wpi::EventLoop* loop) const {
|
2026-03-17 17:19:58 -07:00
|
|
|
return Button(wpi::Gamepad::Button::RIGHT_STICK, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2026-02-07 10:39:22 -08:00
|
|
|
Trigger CommandGamepad::LeftBumper(wpi::EventLoop* loop) const {
|
2026-03-17 17:19:58 -07:00
|
|
|
return Button(wpi::Gamepad::Button::LEFT_BUMPER, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2026-02-07 10:39:22 -08:00
|
|
|
Trigger CommandGamepad::RightBumper(wpi::EventLoop* loop) const {
|
2026-03-17 17:19:58 -07:00
|
|
|
return Button(wpi::Gamepad::Button::RIGHT_BUMPER, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::DpadUp(wpi::EventLoop* loop) const {
|
2026-03-17 17:19:58 -07:00
|
|
|
return Button(wpi::Gamepad::Button::DPAD_UP, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::DpadDown(wpi::EventLoop* loop) const {
|
2026-03-17 17:19:58 -07:00
|
|
|
return Button(wpi::Gamepad::Button::DPAD_DOWN, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::DpadLeft(wpi::EventLoop* loop) const {
|
2026-03-17 17:19:58 -07:00
|
|
|
return Button(wpi::Gamepad::Button::DPAD_LEFT, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::DpadRight(wpi::EventLoop* loop) const {
|
2026-03-17 17:19:58 -07:00
|
|
|
return Button(wpi::Gamepad::Button::DPAD_RIGHT, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::Misc1(wpi::EventLoop* loop) const {
|
2026-03-17 17:19:58 -07:00
|
|
|
return Button(wpi::Gamepad::Button::MISC_1, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::RightPaddle1(wpi::EventLoop* loop) const {
|
2026-03-17 17:19:58 -07:00
|
|
|
return Button(wpi::Gamepad::Button::RIGHT_PADDLE_1, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::LeftPaddle1(wpi::EventLoop* loop) const {
|
2026-03-17 17:19:58 -07:00
|
|
|
return Button(wpi::Gamepad::Button::LEFT_PADDLE_1, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::RightPaddle2(wpi::EventLoop* loop) const {
|
2026-03-17 17:19:58 -07:00
|
|
|
return Button(wpi::Gamepad::Button::RIGHT_PADDLE_2, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::LeftPaddle2(wpi::EventLoop* loop) const {
|
2026-03-17 17:19:58 -07:00
|
|
|
return Button(wpi::Gamepad::Button::LEFT_PADDLE_2, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::Touchpad(wpi::EventLoop* loop) const {
|
2026-03-17 17:19:58 -07:00
|
|
|
return Button(wpi::Gamepad::Button::TOUCHPAD, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::Misc2(wpi::EventLoop* loop) const {
|
2026-03-17 17:19:58 -07:00
|
|
|
return Button(wpi::Gamepad::Button::MISC_2, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::Misc3(wpi::EventLoop* loop) const {
|
2026-03-17 17:19:58 -07:00
|
|
|
return Button(wpi::Gamepad::Button::MISC_3, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::Misc4(wpi::EventLoop* loop) const {
|
2026-03-17 17:19:58 -07:00
|
|
|
return Button(wpi::Gamepad::Button::MISC_4, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::Misc5(wpi::EventLoop* loop) const {
|
2026-03-17 17:19:58 -07:00
|
|
|
return Button(wpi::Gamepad::Button::MISC_5, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::Misc6(wpi::EventLoop* loop) const {
|
2026-03-17 17:19:58 -07:00
|
|
|
return Button(wpi::Gamepad::Button::MISC_6, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Trigger CommandGamepad::LeftTrigger(double threshold,
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::EventLoop* loop) const {
|
2025-10-25 23:03:50 -07:00
|
|
|
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 {
|
2025-10-25 23:03:50 -07:00
|
|
|
return Trigger(loop, [this, threshold] {
|
|
|
|
|
return m_hid.GetRightTriggerAxis() > threshold;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-17 17:19:58 -07:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-25 23:03:50 -07:00
|
|
|
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();
|
|
|
|
|
}
|