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
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::SouthFace(wpi::EventLoop* loop) const {
|
|
|
|
|
return Button(wpi::Gamepad::Button::kSouthFace, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::EastFace(wpi::EventLoop* loop) const {
|
|
|
|
|
return Button(wpi::Gamepad::Button::kEastFace, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::WestFace(wpi::EventLoop* loop) const {
|
|
|
|
|
return Button(wpi::Gamepad::Button::kWestFace, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::NorthFace(wpi::EventLoop* loop) const {
|
|
|
|
|
return Button(wpi::Gamepad::Button::kNorthFace, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::Back(wpi::EventLoop* loop) const {
|
|
|
|
|
return Button(wpi::Gamepad::Button::kBack, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::Guide(wpi::EventLoop* loop) const {
|
|
|
|
|
return Button(wpi::Gamepad::Button::kGuide, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::Start(wpi::EventLoop* loop) const {
|
|
|
|
|
return Button(wpi::Gamepad::Button::kStart, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::LeftStick(wpi::EventLoop* loop) const {
|
|
|
|
|
return Button(wpi::Gamepad::Button::kLeftStick, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::RightStick(wpi::EventLoop* loop) const {
|
|
|
|
|
return Button(wpi::Gamepad::Button::kRightStick, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2026-02-07 10:39:22 -08:00
|
|
|
Trigger CommandGamepad::LeftBumper(wpi::EventLoop* loop) const {
|
|
|
|
|
return Button(wpi::Gamepad::Button::kLeftBumper, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2026-02-07 10:39:22 -08:00
|
|
|
Trigger CommandGamepad::RightBumper(wpi::EventLoop* loop) const {
|
|
|
|
|
return Button(wpi::Gamepad::Button::kRightBumper, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::DpadUp(wpi::EventLoop* loop) const {
|
|
|
|
|
return Button(wpi::Gamepad::Button::kDpadUp, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::DpadDown(wpi::EventLoop* loop) const {
|
|
|
|
|
return Button(wpi::Gamepad::Button::kDpadDown, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::DpadLeft(wpi::EventLoop* loop) const {
|
|
|
|
|
return Button(wpi::Gamepad::Button::kDpadLeft, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::DpadRight(wpi::EventLoop* loop) const {
|
|
|
|
|
return Button(wpi::Gamepad::Button::kDpadRight, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::Misc1(wpi::EventLoop* loop) const {
|
|
|
|
|
return Button(wpi::Gamepad::Button::kMisc1, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::RightPaddle1(wpi::EventLoop* loop) const {
|
|
|
|
|
return Button(wpi::Gamepad::Button::kRightPaddle1, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::LeftPaddle1(wpi::EventLoop* loop) const {
|
|
|
|
|
return Button(wpi::Gamepad::Button::kLeftPaddle1, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::RightPaddle2(wpi::EventLoop* loop) const {
|
|
|
|
|
return Button(wpi::Gamepad::Button::kRightPaddle2, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::LeftPaddle2(wpi::EventLoop* loop) const {
|
|
|
|
|
return Button(wpi::Gamepad::Button::kLeftPaddle2, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::Touchpad(wpi::EventLoop* loop) const {
|
|
|
|
|
return Button(wpi::Gamepad::Button::kTouchpad, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::Misc2(wpi::EventLoop* loop) const {
|
|
|
|
|
return Button(wpi::Gamepad::Button::kMisc2, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::Misc3(wpi::EventLoop* loop) const {
|
|
|
|
|
return Button(wpi::Gamepad::Button::kMisc3, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::Misc4(wpi::EventLoop* loop) const {
|
|
|
|
|
return Button(wpi::Gamepad::Button::kMisc4, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::Misc5(wpi::EventLoop* loop) const {
|
|
|
|
|
return Button(wpi::Gamepad::Button::kMisc5, loop);
|
2025-10-25 23:03:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
Trigger CommandGamepad::Misc6(wpi::EventLoop* loop) const {
|
|
|
|
|
return Button(wpi::Gamepad::Button::kMisc6, 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;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|