mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-27 02:01:42 +00:00
[commands] GenericHIDController: use composition in C++ (#6296)
This commit is contained in:
@@ -6,8 +6,14 @@
|
||||
|
||||
using namespace frc2;
|
||||
|
||||
CommandGenericHID::CommandGenericHID(int port) : m_hid{port} {}
|
||||
|
||||
frc::GenericHID& CommandGenericHID::GetHID() {
|
||||
return m_hid;
|
||||
}
|
||||
|
||||
Trigger CommandGenericHID::Button(int button, frc::EventLoop* loop) const {
|
||||
return GenericHID::Button(button, loop).CastTo<Trigger>();
|
||||
return m_hid.Button(button, loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandGenericHID::POV(int angle, frc::EventLoop* loop) const {
|
||||
@@ -16,7 +22,7 @@ Trigger CommandGenericHID::POV(int angle, frc::EventLoop* loop) const {
|
||||
|
||||
Trigger CommandGenericHID::POV(int pov, int angle, frc::EventLoop* loop) const {
|
||||
return Trigger(loop,
|
||||
[this, pov, angle] { return this->GetPOV(pov) == angle; });
|
||||
[this, pov, angle] { return m_hid.GetPOV(pov) == angle; });
|
||||
}
|
||||
|
||||
Trigger CommandGenericHID::POVUp(frc::EventLoop* loop) const {
|
||||
@@ -58,13 +64,13 @@ Trigger CommandGenericHID::POVCenter(frc::EventLoop* loop) const {
|
||||
Trigger CommandGenericHID::AxisLessThan(int axis, double threshold,
|
||||
frc::EventLoop* loop) const {
|
||||
return Trigger(loop, [this, axis, threshold]() {
|
||||
return this->GetRawAxis(axis) < threshold;
|
||||
return m_hid.GetRawAxis(axis) < threshold;
|
||||
});
|
||||
}
|
||||
|
||||
Trigger CommandGenericHID::AxisGreaterThan(int axis, double threshold,
|
||||
frc::EventLoop* loop) const {
|
||||
return Trigger(loop, [this, axis, threshold]() {
|
||||
return this->GetRawAxis(axis) > threshold;
|
||||
return m_hid.GetRawAxis(axis) > threshold;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -6,14 +6,25 @@
|
||||
|
||||
using namespace frc2;
|
||||
|
||||
Trigger CommandJoystick::Button(int button, frc::EventLoop* loop) const {
|
||||
return GenericHID::Button(button, loop).CastTo<class Trigger>();
|
||||
CommandJoystick::CommandJoystick(int port)
|
||||
: CommandGenericHID(port), m_hid{frc::Joystick(port)} {}
|
||||
|
||||
frc::Joystick& CommandJoystick::GetHID() {
|
||||
return m_hid;
|
||||
}
|
||||
|
||||
Trigger CommandJoystick::Trigger(frc::EventLoop* loop) const {
|
||||
return Joystick::Trigger(loop).CastTo<class Trigger>();
|
||||
return m_hid.Trigger(loop).CastTo<class Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandJoystick::Top(frc::EventLoop* loop) const {
|
||||
return Joystick::Top(loop).CastTo<class Trigger>();
|
||||
return m_hid.Top(loop).CastTo<class Trigger>();
|
||||
}
|
||||
|
||||
double CommandJoystick::GetMagnitude() const {
|
||||
return m_hid.GetMagnitude();
|
||||
}
|
||||
|
||||
units::radian_t CommandJoystick::GetDirection() const {
|
||||
return m_hid.GetDirection();
|
||||
}
|
||||
|
||||
@@ -6,58 +6,85 @@
|
||||
|
||||
using namespace frc2;
|
||||
|
||||
Trigger CommandPS4Controller::Button(int button, frc::EventLoop* loop) const {
|
||||
return GenericHID::Button(button, loop).CastTo<Trigger>();
|
||||
CommandPS4Controller::CommandPS4Controller(int port)
|
||||
: CommandGenericHID(port), m_hid{frc::PS4Controller(port)} {}
|
||||
|
||||
frc::PS4Controller& CommandPS4Controller::GetHID() {
|
||||
return m_hid;
|
||||
}
|
||||
|
||||
Trigger CommandPS4Controller::Square(frc::EventLoop* loop) const {
|
||||
return PS4Controller::Square(loop).CastTo<Trigger>();
|
||||
return m_hid.Square(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS4Controller::Cross(frc::EventLoop* loop) const {
|
||||
return PS4Controller::Cross(loop).CastTo<Trigger>();
|
||||
return m_hid.Cross(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS4Controller::Circle(frc::EventLoop* loop) const {
|
||||
return PS4Controller::Circle(loop).CastTo<Trigger>();
|
||||
return m_hid.Circle(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS4Controller::Triangle(frc::EventLoop* loop) const {
|
||||
return PS4Controller::Triangle(loop).CastTo<Trigger>();
|
||||
return m_hid.Triangle(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS4Controller::L1(frc::EventLoop* loop) const {
|
||||
return PS4Controller::L1(loop).CastTo<Trigger>();
|
||||
return m_hid.L1(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS4Controller::R1(frc::EventLoop* loop) const {
|
||||
return PS4Controller::R1(loop).CastTo<Trigger>();
|
||||
return m_hid.R1(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS4Controller::L2(frc::EventLoop* loop) const {
|
||||
return PS4Controller::L2(loop).CastTo<Trigger>();
|
||||
return m_hid.L2(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS4Controller::R2(frc::EventLoop* loop) const {
|
||||
return PS4Controller::R2(loop).CastTo<Trigger>();
|
||||
return m_hid.R2(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS4Controller::Options(frc::EventLoop* loop) const {
|
||||
return PS4Controller::Options(loop).CastTo<Trigger>();
|
||||
return m_hid.Options(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS4Controller::L3(frc::EventLoop* loop) const {
|
||||
return PS4Controller::L3(loop).CastTo<Trigger>();
|
||||
return m_hid.L3(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS4Controller::R3(frc::EventLoop* loop) const {
|
||||
return PS4Controller::R3(loop).CastTo<Trigger>();
|
||||
return m_hid.R3(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS4Controller::PS(frc::EventLoop* loop) const {
|
||||
return PS4Controller::PS(loop).CastTo<Trigger>();
|
||||
return m_hid.PS(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS4Controller::Touchpad(frc::EventLoop* loop) const {
|
||||
return PS4Controller::Touchpad(loop).CastTo<Trigger>();
|
||||
return m_hid.Touchpad(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
double CommandPS4Controller::GetR2Axis() {
|
||||
return m_hid.GetR2Axis();
|
||||
}
|
||||
|
||||
double CommandPS4Controller::GetL2Axis() {
|
||||
return m_hid.GetL2Axis();
|
||||
}
|
||||
|
||||
double CommandPS4Controller::GetRightY() {
|
||||
return m_hid.GetRightY();
|
||||
}
|
||||
|
||||
double CommandPS4Controller::GetLeftY() {
|
||||
return m_hid.GetLeftY();
|
||||
}
|
||||
|
||||
double CommandPS4Controller::GetRightX() {
|
||||
return m_hid.GetRightX();
|
||||
}
|
||||
|
||||
double CommandPS4Controller::GetLeftX() {
|
||||
return m_hid.GetLeftX();
|
||||
}
|
||||
|
||||
@@ -6,58 +6,85 @@
|
||||
|
||||
using namespace frc2;
|
||||
|
||||
Trigger CommandPS5Controller::Button(int button, frc::EventLoop* loop) const {
|
||||
return GenericHID::Button(button, loop).CastTo<Trigger>();
|
||||
CommandPS5Controller::CommandPS5Controller(int port)
|
||||
: CommandGenericHID(port), m_hid{frc::PS5Controller(port)} {}
|
||||
|
||||
frc::PS5Controller& CommandPS5Controller::GetHID() {
|
||||
return m_hid;
|
||||
}
|
||||
|
||||
Trigger CommandPS5Controller::Square(frc::EventLoop* loop) const {
|
||||
return PS5Controller::Square(loop).CastTo<Trigger>();
|
||||
return m_hid.Square(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS5Controller::Cross(frc::EventLoop* loop) const {
|
||||
return PS5Controller::Cross(loop).CastTo<Trigger>();
|
||||
return m_hid.Cross(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS5Controller::Circle(frc::EventLoop* loop) const {
|
||||
return PS5Controller::Circle(loop).CastTo<Trigger>();
|
||||
return m_hid.Circle(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS5Controller::Triangle(frc::EventLoop* loop) const {
|
||||
return PS5Controller::Triangle(loop).CastTo<Trigger>();
|
||||
return m_hid.Triangle(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS5Controller::L1(frc::EventLoop* loop) const {
|
||||
return PS5Controller::L1(loop).CastTo<Trigger>();
|
||||
return m_hid.L1(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS5Controller::R1(frc::EventLoop* loop) const {
|
||||
return PS5Controller::R1(loop).CastTo<Trigger>();
|
||||
return m_hid.R1(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS5Controller::L2(frc::EventLoop* loop) const {
|
||||
return PS5Controller::L2(loop).CastTo<Trigger>();
|
||||
return m_hid.L2(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS5Controller::R2(frc::EventLoop* loop) const {
|
||||
return PS5Controller::R2(loop).CastTo<Trigger>();
|
||||
return m_hid.R2(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS5Controller::Options(frc::EventLoop* loop) const {
|
||||
return PS5Controller::Options(loop).CastTo<Trigger>();
|
||||
return m_hid.Options(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS5Controller::L3(frc::EventLoop* loop) const {
|
||||
return PS5Controller::L3(loop).CastTo<Trigger>();
|
||||
return m_hid.L3(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS5Controller::R3(frc::EventLoop* loop) const {
|
||||
return PS5Controller::R3(loop).CastTo<Trigger>();
|
||||
return m_hid.R3(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS5Controller::PS(frc::EventLoop* loop) const {
|
||||
return PS5Controller::PS(loop).CastTo<Trigger>();
|
||||
return m_hid.PS(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS5Controller::Touchpad(frc::EventLoop* loop) const {
|
||||
return PS5Controller::Touchpad(loop).CastTo<Trigger>();
|
||||
return m_hid.Touchpad(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
double CommandPS5Controller::GetR2Axis() {
|
||||
return m_hid.GetR2Axis();
|
||||
}
|
||||
|
||||
double CommandPS5Controller::GetL2Axis() {
|
||||
return m_hid.GetL2Axis();
|
||||
}
|
||||
|
||||
double CommandPS5Controller::GetRightY() {
|
||||
return m_hid.GetRightY();
|
||||
}
|
||||
|
||||
double CommandPS5Controller::GetLeftY() {
|
||||
return m_hid.GetLeftY();
|
||||
}
|
||||
|
||||
double CommandPS5Controller::GetRightX() {
|
||||
return m_hid.GetRightX();
|
||||
}
|
||||
|
||||
double CommandPS5Controller::GetLeftX() {
|
||||
return m_hid.GetLeftX();
|
||||
}
|
||||
|
||||
@@ -6,67 +6,85 @@
|
||||
|
||||
using namespace frc2;
|
||||
|
||||
Trigger CommandStadiaController::Button(int button,
|
||||
frc::EventLoop* loop) const {
|
||||
return GenericHID::Button(button, loop).CastTo<Trigger>();
|
||||
CommandStadiaController::CommandStadiaController(int port)
|
||||
: CommandGenericHID(port), m_hid{frc::StadiaController(port)} {}
|
||||
|
||||
frc::StadiaController& CommandStadiaController::GetHID() {
|
||||
return m_hid;
|
||||
}
|
||||
|
||||
Trigger CommandStadiaController::LeftBumper(frc::EventLoop* loop) const {
|
||||
return StadiaController::LeftBumper(loop).CastTo<Trigger>();
|
||||
return m_hid.LeftBumper(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandStadiaController::RightBumper(frc::EventLoop* loop) const {
|
||||
return StadiaController::RightBumper(loop).CastTo<Trigger>();
|
||||
return m_hid.RightBumper(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandStadiaController::LeftStick(frc::EventLoop* loop) const {
|
||||
return StadiaController::LeftStick(loop).CastTo<Trigger>();
|
||||
return m_hid.LeftStick(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandStadiaController::RightStick(frc::EventLoop* loop) const {
|
||||
return StadiaController::RightStick(loop).CastTo<Trigger>();
|
||||
return m_hid.RightStick(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandStadiaController::A(frc::EventLoop* loop) const {
|
||||
return StadiaController::A(loop).CastTo<Trigger>();
|
||||
return m_hid.A(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandStadiaController::B(frc::EventLoop* loop) const {
|
||||
return StadiaController::B(loop).CastTo<Trigger>();
|
||||
return m_hid.B(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandStadiaController::X(frc::EventLoop* loop) const {
|
||||
return StadiaController::X(loop).CastTo<Trigger>();
|
||||
return m_hid.X(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandStadiaController::Y(frc::EventLoop* loop) const {
|
||||
return StadiaController::Y(loop).CastTo<Trigger>();
|
||||
return m_hid.Y(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandStadiaController::Ellipses(frc::EventLoop* loop) const {
|
||||
return StadiaController::Ellipses(loop).CastTo<Trigger>();
|
||||
return m_hid.Ellipses(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandStadiaController::Hamburger(frc::EventLoop* loop) const {
|
||||
return StadiaController::Hamburger(loop).CastTo<Trigger>();
|
||||
return m_hid.Hamburger(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandStadiaController::Stadia(frc::EventLoop* loop) const {
|
||||
return StadiaController::Stadia(loop).CastTo<Trigger>();
|
||||
return m_hid.Stadia(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandStadiaController::Google(frc::EventLoop* loop) const {
|
||||
return StadiaController::Google(loop).CastTo<Trigger>();
|
||||
return m_hid.Google(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandStadiaController::Frame(frc::EventLoop* loop) const {
|
||||
return StadiaController::Frame(loop).CastTo<Trigger>();
|
||||
return m_hid.Frame(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandStadiaController::LeftTrigger(frc::EventLoop* loop) const {
|
||||
return StadiaController::LeftTrigger(loop).CastTo<Trigger>();
|
||||
return m_hid.LeftTrigger(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandStadiaController::RightTrigger(frc::EventLoop* loop) const {
|
||||
return StadiaController::RightTrigger(loop).CastTo<Trigger>();
|
||||
return m_hid.RightTrigger(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
double CommandStadiaController::GetLeftX() const {
|
||||
return m_hid.GetLeftX();
|
||||
}
|
||||
|
||||
double CommandStadiaController::GetRightX() const {
|
||||
return m_hid.GetRightX();
|
||||
}
|
||||
|
||||
double CommandStadiaController::GetLeftY() const {
|
||||
return m_hid.GetLeftY();
|
||||
}
|
||||
|
||||
double CommandStadiaController::GetRightY() const {
|
||||
return m_hid.GetRightY();
|
||||
}
|
||||
|
||||
@@ -6,56 +6,83 @@
|
||||
|
||||
using namespace frc2;
|
||||
|
||||
Trigger CommandXboxController::Button(int button, frc::EventLoop* loop) const {
|
||||
return GenericHID::Button(button, loop).CastTo<Trigger>();
|
||||
CommandXboxController::CommandXboxController(int port)
|
||||
: CommandGenericHID(port), m_hid{frc::XboxController(port)} {}
|
||||
|
||||
frc::XboxController& CommandXboxController::GetHID() {
|
||||
return m_hid;
|
||||
}
|
||||
|
||||
Trigger CommandXboxController::LeftBumper(frc::EventLoop* loop) const {
|
||||
return XboxController::LeftBumper(loop).CastTo<Trigger>();
|
||||
return m_hid.LeftBumper(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandXboxController::RightBumper(frc::EventLoop* loop) const {
|
||||
return XboxController::RightBumper(loop).CastTo<Trigger>();
|
||||
return m_hid.RightBumper(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandXboxController::LeftStick(frc::EventLoop* loop) const {
|
||||
return XboxController::LeftStick(loop).CastTo<Trigger>();
|
||||
return m_hid.LeftStick(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandXboxController::RightStick(frc::EventLoop* loop) const {
|
||||
return XboxController::RightStick(loop).CastTo<Trigger>();
|
||||
return m_hid.RightStick(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandXboxController::A(frc::EventLoop* loop) const {
|
||||
return XboxController::A(loop).CastTo<Trigger>();
|
||||
return m_hid.A(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandXboxController::B(frc::EventLoop* loop) const {
|
||||
return XboxController::B(loop).CastTo<Trigger>();
|
||||
return m_hid.B(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandXboxController::X(frc::EventLoop* loop) const {
|
||||
return XboxController::X(loop).CastTo<Trigger>();
|
||||
return m_hid.X(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandXboxController::Y(frc::EventLoop* loop) const {
|
||||
return XboxController::Y(loop).CastTo<Trigger>();
|
||||
return m_hid.Y(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandXboxController::Back(frc::EventLoop* loop) const {
|
||||
return XboxController::Back(loop).CastTo<Trigger>();
|
||||
return m_hid.Back(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandXboxController::Start(frc::EventLoop* loop) const {
|
||||
return XboxController::Start(loop).CastTo<Trigger>();
|
||||
return m_hid.Start(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandXboxController::LeftTrigger(double threshold,
|
||||
frc::EventLoop* loop) const {
|
||||
return XboxController::LeftTrigger(threshold, loop).CastTo<Trigger>();
|
||||
return m_hid.LeftTrigger(threshold, loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandXboxController::RightTrigger(double threshold,
|
||||
frc::EventLoop* loop) const {
|
||||
return XboxController::RightTrigger(threshold, loop).CastTo<Trigger>();
|
||||
return m_hid.RightTrigger(threshold, loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
double CommandXboxController::GetRightTriggerAxis() {
|
||||
return m_hid.GetRightTriggerAxis();
|
||||
}
|
||||
|
||||
double CommandXboxController::GetLeftTriggerAxis() {
|
||||
return m_hid.GetLeftTriggerAxis();
|
||||
}
|
||||
|
||||
double CommandXboxController::GetRightY() {
|
||||
return m_hid.GetRightY();
|
||||
}
|
||||
|
||||
double CommandXboxController::GetLeftY() {
|
||||
return m_hid.GetLeftY();
|
||||
}
|
||||
|
||||
double CommandXboxController::GetRightX() {
|
||||
return m_hid.GetRightX();
|
||||
}
|
||||
|
||||
double CommandXboxController::GetLeftX() {
|
||||
return m_hid.GetLeftX();
|
||||
}
|
||||
|
||||
@@ -9,15 +9,29 @@
|
||||
#include "frc2/command/CommandScheduler.h"
|
||||
|
||||
namespace frc2 {
|
||||
|
||||
/**
|
||||
* A subclass of {@link GenericHID} with {@link Trigger} factories for
|
||||
* A version of {@link frc::GenericHID} with {@link Trigger} factories for
|
||||
* command-based.
|
||||
*
|
||||
* @see GenericHID
|
||||
*/
|
||||
class CommandGenericHID : public frc::GenericHID {
|
||||
class CommandGenericHID {
|
||||
public:
|
||||
using GenericHID::GenericHID;
|
||||
/**
|
||||
* Construct an instance of a device.
|
||||
*
|
||||
* @param port The port index on the Driver Station that the device is plugged
|
||||
* into.
|
||||
*/
|
||||
explicit CommandGenericHID(int port);
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
*/
|
||||
frc::GenericHID& GetHID();
|
||||
|
||||
/**
|
||||
* Constructs an event instance around this button's digital signal.
|
||||
@@ -215,5 +229,8 @@ class CommandGenericHID : public frc::GenericHID {
|
||||
int axis, double threshold,
|
||||
frc::EventLoop* loop =
|
||||
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
|
||||
|
||||
private:
|
||||
frc::GenericHID m_hid;
|
||||
};
|
||||
} // namespace frc2
|
||||
|
||||
@@ -7,30 +7,31 @@
|
||||
|
||||
#include "Trigger.h"
|
||||
#include "frc2/command/CommandScheduler.h"
|
||||
#include "frc2/command/button/CommandGenericHID.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
* A version of {@link Joystick} with {@link Trigger} factories for
|
||||
* A version of {@link frc::Joystick} with {@link Trigger} factories for
|
||||
* command-based.
|
||||
*
|
||||
* @see Joystick
|
||||
* @see frc::Joystick
|
||||
*/
|
||||
class CommandJoystick : public frc::Joystick {
|
||||
class CommandJoystick : public CommandGenericHID {
|
||||
public:
|
||||
using Joystick::Joystick;
|
||||
/**
|
||||
* Construct an instance of a controller.
|
||||
*
|
||||
* @param port The port index on the Driver Station that the controller is
|
||||
* plugged into.
|
||||
*/
|
||||
explicit CommandJoystick(int port);
|
||||
|
||||
/**
|
||||
* Constructs an event instance around this button's digital signal.
|
||||
* Get the underlying GenericHID object.
|
||||
*
|
||||
* @param button the button index
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return an event instance representing the button's digital signal attached
|
||||
* to the given loop.
|
||||
* @return the wrapped GenericHID object
|
||||
*/
|
||||
class Trigger Button(
|
||||
int button, frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
frc::Joystick& GetHID();
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the trigger button's digital signal.
|
||||
@@ -54,5 +55,22 @@ class CommandJoystick : public frc::Joystick {
|
||||
*/
|
||||
class Trigger Top(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
/**
|
||||
* Get the magnitude of the direction vector formed by the joystick's
|
||||
* current position relative to its origin.
|
||||
*
|
||||
* @return The magnitude of the direction vector
|
||||
*/
|
||||
double GetMagnitude() const;
|
||||
|
||||
/**
|
||||
* Get the direction of the vector formed by the joystick and its origin.
|
||||
*
|
||||
* @return The direction of the vector.
|
||||
*/
|
||||
units::radian_t GetDirection() const;
|
||||
|
||||
private:
|
||||
frc::Joystick m_hid;
|
||||
};
|
||||
} // namespace frc2
|
||||
|
||||
@@ -7,17 +7,31 @@
|
||||
|
||||
#include "Trigger.h"
|
||||
#include "frc2/command/CommandScheduler.h"
|
||||
#include "frc2/command/button/CommandGenericHID.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
* A version of {@link PS4Controller} with {@link Trigger} factories for
|
||||
* A version of {@link frc::PS4Controller} with {@link Trigger} factories for
|
||||
* command-based.
|
||||
*
|
||||
* @see PS4Controller
|
||||
* @see frc::PS4Controller
|
||||
*/
|
||||
class CommandPS4Controller : public frc::PS4Controller {
|
||||
class CommandPS4Controller : public frc2::CommandGenericHID {
|
||||
public:
|
||||
using PS4Controller::PS4Controller;
|
||||
/**
|
||||
* Construct an instance of a device.
|
||||
*
|
||||
* @param port The port index on the Driver Station that the device is plugged
|
||||
* into.
|
||||
*/
|
||||
explicit CommandPS4Controller(int port);
|
||||
|
||||
/**
|
||||
* Get the underlying GenericHID object.
|
||||
*
|
||||
* @return the wrapped GenericHID object
|
||||
*/
|
||||
frc::PS4Controller& GetHID();
|
||||
|
||||
/**
|
||||
* Constructs an event instance around this button's digital signal.
|
||||
@@ -174,5 +188,52 @@ class CommandPS4Controller : public frc::PS4Controller {
|
||||
*/
|
||||
Trigger Touchpad(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Get the R2 axis value of the controller. Note that this axis is bound to
|
||||
* the range of [0, 1] as opposed to the usual [-1, 1].
|
||||
*
|
||||
* @return the axis value.
|
||||
*/
|
||||
double GetR2Axis();
|
||||
|
||||
/**
|
||||
* Get the L2 axis value of the controller. Note that this axis is bound to
|
||||
* the range of [0, 1] as opposed to the usual [-1, 1].
|
||||
*
|
||||
* @return the axis value.
|
||||
*/
|
||||
double GetL2Axis();
|
||||
|
||||
/**
|
||||
* Get the Y axis value of right side of the controller.
|
||||
*
|
||||
* @return the axis value.
|
||||
*/
|
||||
double GetRightY();
|
||||
|
||||
/**
|
||||
* Get the Y axis value of left side of the controller.
|
||||
*
|
||||
* @return the axis value.
|
||||
*/
|
||||
double GetLeftY();
|
||||
|
||||
/**
|
||||
* Get the X axis value of right side of the controller.
|
||||
*
|
||||
* @return the axis value.
|
||||
*/
|
||||
double GetRightX();
|
||||
|
||||
/**
|
||||
* Get the X axis value of left side of the controller.
|
||||
*
|
||||
* @return the axis value.
|
||||
*/
|
||||
double GetLeftX();
|
||||
|
||||
private:
|
||||
frc::PS4Controller m_hid;
|
||||
};
|
||||
} // namespace frc2
|
||||
|
||||
@@ -7,30 +7,31 @@
|
||||
|
||||
#include "Trigger.h"
|
||||
#include "frc2/command/CommandScheduler.h"
|
||||
#include "frc2/command/button/CommandGenericHID.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
* A version of {@link PS5Controller} with {@link Trigger} factories for
|
||||
* A version of {@link frc::PS5Controller} with {@link Trigger} factories for
|
||||
* command-based.
|
||||
*
|
||||
* @see PS5Controller
|
||||
* @see frc::PS5Controller
|
||||
*/
|
||||
class CommandPS5Controller : public frc::PS5Controller {
|
||||
class CommandPS5Controller : public CommandGenericHID {
|
||||
public:
|
||||
using PS5Controller::PS5Controller;
|
||||
/**
|
||||
* Construct an instance of a device.
|
||||
*
|
||||
* @param port The port index on the Driver Station that the device is plugged
|
||||
* into.
|
||||
*/
|
||||
explicit CommandPS5Controller(int port);
|
||||
|
||||
/**
|
||||
* Constructs an event instance around this button's digital signal.
|
||||
* Get the underlying GenericHID object.
|
||||
*
|
||||
* @param button the button index
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return an event instance representing the button's digital signal attached
|
||||
* to the given loop.
|
||||
* @return the wrapped GenericHID object
|
||||
*/
|
||||
Trigger Button(int button,
|
||||
frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
frc::PS5Controller& GetHID();
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the square button's digital signal.
|
||||
@@ -174,5 +175,52 @@ class CommandPS5Controller : public frc::PS5Controller {
|
||||
*/
|
||||
Trigger Touchpad(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Get the R2 axis value of the controller. Note that this axis is bound to
|
||||
* the range of [0, 1] as opposed to the usual [-1, 1].
|
||||
*
|
||||
* @return the axis value.
|
||||
*/
|
||||
double GetR2Axis();
|
||||
|
||||
/**
|
||||
* Get the L2 axis value of the controller. Note that this axis is bound to
|
||||
* the range of [0, 1] as opposed to the usual [-1, 1].
|
||||
*
|
||||
* @return the axis value.
|
||||
*/
|
||||
double GetL2Axis();
|
||||
|
||||
/**
|
||||
* Get the Y axis value of right side of the controller.
|
||||
*
|
||||
* @return the axis value.
|
||||
*/
|
||||
double GetRightY();
|
||||
|
||||
/**
|
||||
* Get the Y axis value of left side of the controller.
|
||||
*
|
||||
* @return the axis value.
|
||||
*/
|
||||
double GetLeftY();
|
||||
|
||||
/**
|
||||
* Get the X axis value of right side of the controller.
|
||||
*
|
||||
* @return the axis value.
|
||||
*/
|
||||
double GetRightX();
|
||||
|
||||
/**
|
||||
* Get the X axis value of left side of the controller.
|
||||
*
|
||||
* @return the axis value.
|
||||
*/
|
||||
double GetLeftX();
|
||||
|
||||
private:
|
||||
frc::PS5Controller m_hid;
|
||||
};
|
||||
} // namespace frc2
|
||||
|
||||
@@ -7,30 +7,31 @@
|
||||
|
||||
#include "Trigger.h"
|
||||
#include "frc2/command/CommandScheduler.h"
|
||||
#include "frc2/command/button/CommandGenericHID.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
* A version of {@link StadiaController} with {@link Trigger} factories for
|
||||
* A version of {@link frc::StadiaController} with {@link Trigger} factories for
|
||||
* command-based.
|
||||
*
|
||||
* @see StadiaController
|
||||
* @see frc::StadiaController
|
||||
*/
|
||||
class CommandStadiaController : public frc::StadiaController {
|
||||
class CommandStadiaController : public CommandGenericHID {
|
||||
public:
|
||||
using StadiaController::StadiaController;
|
||||
/**
|
||||
* Construct an instance of a controller.
|
||||
*
|
||||
* @param port The port index on the Driver Station that the controller is
|
||||
* plugged into.
|
||||
*/
|
||||
explicit CommandStadiaController(int port);
|
||||
|
||||
/**
|
||||
* Constructs an event instance around this button's digital signal.
|
||||
* Get the underlying GenericHID object.
|
||||
*
|
||||
* @param button the button index
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return an event instance representing the button's digital signal attached
|
||||
* to the given loop.
|
||||
* @return the wrapped GenericHID object
|
||||
*/
|
||||
Trigger Button(int button,
|
||||
frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
frc::StadiaController& GetHID();
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the left bumper's digital signal.
|
||||
@@ -197,5 +198,36 @@ class CommandStadiaController : public frc::StadiaController {
|
||||
Trigger RightTrigger(
|
||||
frc::EventLoop* loop =
|
||||
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Get the X axis value of left side of the controller.
|
||||
*
|
||||
* @return the axis value
|
||||
*/
|
||||
double GetLeftX() const;
|
||||
|
||||
/**
|
||||
* Get the X axis value of right side of the controller.
|
||||
*
|
||||
* @return the axis value
|
||||
*/
|
||||
double GetRightX() const;
|
||||
|
||||
/**
|
||||
* Get the Y axis value of left side of the controller.
|
||||
*
|
||||
* @return the axis value
|
||||
*/
|
||||
double GetLeftY() const;
|
||||
|
||||
/**
|
||||
* Get the Y axis value of right side of the controller.
|
||||
*
|
||||
* @return the axis value
|
||||
*/
|
||||
double GetRightY() const;
|
||||
|
||||
private:
|
||||
frc::StadiaController m_hid;
|
||||
};
|
||||
} // namespace frc2
|
||||
|
||||
@@ -7,30 +7,31 @@
|
||||
|
||||
#include "Trigger.h"
|
||||
#include "frc2/command/CommandScheduler.h"
|
||||
#include "frc2/command/button/CommandGenericHID.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
* A version of {@link XboxController} with {@link Trigger} factories for
|
||||
* A version of {@link frc::XboxController} with {@link Trigger} factories for
|
||||
* command-based.
|
||||
*
|
||||
* @see XboxController
|
||||
* @see frc::XboxController
|
||||
*/
|
||||
class CommandXboxController : public frc::XboxController {
|
||||
class CommandXboxController : CommandGenericHID {
|
||||
public:
|
||||
using XboxController::XboxController;
|
||||
/**
|
||||
* Construct an instance of a controller.
|
||||
*
|
||||
* @param port The port index on the Driver Station that the controller is
|
||||
* plugged into.
|
||||
*/
|
||||
explicit CommandXboxController(int port);
|
||||
|
||||
/**
|
||||
* Constructs an event instance around this button's digital signal.
|
||||
* Get the underlying GenericHID object.
|
||||
*
|
||||
* @param button the button index
|
||||
* @param loop the event loop instance to attach the event to. Defaults to the
|
||||
* CommandScheduler's default loop.
|
||||
* @return an event instance representing the button's digital signal attached
|
||||
* to the given loop.
|
||||
* @return the wrapped GenericHID object
|
||||
*/
|
||||
Trigger Button(int button,
|
||||
frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
frc::XboxController& GetHID();
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the left bumper's digital signal.
|
||||
@@ -176,5 +177,52 @@ class CommandXboxController : public frc::XboxController {
|
||||
double threshold = 0.5,
|
||||
frc::EventLoop* loop =
|
||||
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Get the right trigger (RT) axis value of the controller. Note that this
|
||||
* axis is bound to the range of [0, 1] as opposed to the usual [-1, 1].
|
||||
*
|
||||
* @return The axis value.
|
||||
*/
|
||||
double GetRightTriggerAxis();
|
||||
|
||||
/**
|
||||
* Get the left trigger (LT) axis value of the controller. Note that this axis
|
||||
* is bound to the range of [0, 1] as opposed to the usual [-1, 1].
|
||||
*
|
||||
* @return The axis value.
|
||||
*/
|
||||
double GetLeftTriggerAxis();
|
||||
|
||||
/**
|
||||
* Get the Y axis value of right side of the controller.
|
||||
*
|
||||
* @return The axis value.
|
||||
*/
|
||||
double GetRightY();
|
||||
|
||||
/**
|
||||
* Get the Y axis value of left side of the controller.
|
||||
*
|
||||
* @return The axis value.
|
||||
*/
|
||||
double GetLeftY();
|
||||
|
||||
/**
|
||||
* Get the X axis value of right side of the controller.
|
||||
*
|
||||
* @return The axis value.
|
||||
*/
|
||||
double GetRightX();
|
||||
|
||||
/**
|
||||
* Get the X axis value of left side of the controller.
|
||||
*
|
||||
* @return The axis value.
|
||||
*/
|
||||
double GetLeftX();
|
||||
|
||||
private:
|
||||
frc::XboxController m_hid;
|
||||
};
|
||||
} // namespace frc2
|
||||
|
||||
Reference in New Issue
Block a user