diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandGenericHID.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandGenericHID.cpp index ea5696ed62..b7f1d5a28a 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandGenericHID.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandGenericHID.cpp @@ -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(); + return m_hid.Button(button, loop).CastTo(); } 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; }); } diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandJoystick.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandJoystick.cpp index 9b8ec76511..03cb6d89d2 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandJoystick.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandJoystick.cpp @@ -6,14 +6,25 @@ using namespace frc2; -Trigger CommandJoystick::Button(int button, frc::EventLoop* loop) const { - return GenericHID::Button(button, loop).CastTo(); +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(); + return m_hid.Trigger(loop).CastTo(); } Trigger CommandJoystick::Top(frc::EventLoop* loop) const { - return Joystick::Top(loop).CastTo(); + return m_hid.Top(loop).CastTo(); +} + +double CommandJoystick::GetMagnitude() const { + return m_hid.GetMagnitude(); +} + +units::radian_t CommandJoystick::GetDirection() const { + return m_hid.GetDirection(); } diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandPS4Controller.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandPS4Controller.cpp index d04ab66d5e..8388682f8b 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandPS4Controller.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandPS4Controller.cpp @@ -6,58 +6,85 @@ using namespace frc2; -Trigger CommandPS4Controller::Button(int button, frc::EventLoop* loop) const { - return GenericHID::Button(button, loop).CastTo(); +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(); + return m_hid.Square(loop).CastTo(); } Trigger CommandPS4Controller::Cross(frc::EventLoop* loop) const { - return PS4Controller::Cross(loop).CastTo(); + return m_hid.Cross(loop).CastTo(); } Trigger CommandPS4Controller::Circle(frc::EventLoop* loop) const { - return PS4Controller::Circle(loop).CastTo(); + return m_hid.Circle(loop).CastTo(); } Trigger CommandPS4Controller::Triangle(frc::EventLoop* loop) const { - return PS4Controller::Triangle(loop).CastTo(); + return m_hid.Triangle(loop).CastTo(); } Trigger CommandPS4Controller::L1(frc::EventLoop* loop) const { - return PS4Controller::L1(loop).CastTo(); + return m_hid.L1(loop).CastTo(); } Trigger CommandPS4Controller::R1(frc::EventLoop* loop) const { - return PS4Controller::R1(loop).CastTo(); + return m_hid.R1(loop).CastTo(); } Trigger CommandPS4Controller::L2(frc::EventLoop* loop) const { - return PS4Controller::L2(loop).CastTo(); + return m_hid.L2(loop).CastTo(); } Trigger CommandPS4Controller::R2(frc::EventLoop* loop) const { - return PS4Controller::R2(loop).CastTo(); + return m_hid.R2(loop).CastTo(); } Trigger CommandPS4Controller::Options(frc::EventLoop* loop) const { - return PS4Controller::Options(loop).CastTo(); + return m_hid.Options(loop).CastTo(); } Trigger CommandPS4Controller::L3(frc::EventLoop* loop) const { - return PS4Controller::L3(loop).CastTo(); + return m_hid.L3(loop).CastTo(); } Trigger CommandPS4Controller::R3(frc::EventLoop* loop) const { - return PS4Controller::R3(loop).CastTo(); + return m_hid.R3(loop).CastTo(); } Trigger CommandPS4Controller::PS(frc::EventLoop* loop) const { - return PS4Controller::PS(loop).CastTo(); + return m_hid.PS(loop).CastTo(); } Trigger CommandPS4Controller::Touchpad(frc::EventLoop* loop) const { - return PS4Controller::Touchpad(loop).CastTo(); + return m_hid.Touchpad(loop).CastTo(); +} + +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(); } diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandPS5Controller.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandPS5Controller.cpp index 399a771ddc..d98cc23780 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandPS5Controller.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandPS5Controller.cpp @@ -6,58 +6,85 @@ using namespace frc2; -Trigger CommandPS5Controller::Button(int button, frc::EventLoop* loop) const { - return GenericHID::Button(button, loop).CastTo(); +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(); + return m_hid.Square(loop).CastTo(); } Trigger CommandPS5Controller::Cross(frc::EventLoop* loop) const { - return PS5Controller::Cross(loop).CastTo(); + return m_hid.Cross(loop).CastTo(); } Trigger CommandPS5Controller::Circle(frc::EventLoop* loop) const { - return PS5Controller::Circle(loop).CastTo(); + return m_hid.Circle(loop).CastTo(); } Trigger CommandPS5Controller::Triangle(frc::EventLoop* loop) const { - return PS5Controller::Triangle(loop).CastTo(); + return m_hid.Triangle(loop).CastTo(); } Trigger CommandPS5Controller::L1(frc::EventLoop* loop) const { - return PS5Controller::L1(loop).CastTo(); + return m_hid.L1(loop).CastTo(); } Trigger CommandPS5Controller::R1(frc::EventLoop* loop) const { - return PS5Controller::R1(loop).CastTo(); + return m_hid.R1(loop).CastTo(); } Trigger CommandPS5Controller::L2(frc::EventLoop* loop) const { - return PS5Controller::L2(loop).CastTo(); + return m_hid.L2(loop).CastTo(); } Trigger CommandPS5Controller::R2(frc::EventLoop* loop) const { - return PS5Controller::R2(loop).CastTo(); + return m_hid.R2(loop).CastTo(); } Trigger CommandPS5Controller::Options(frc::EventLoop* loop) const { - return PS5Controller::Options(loop).CastTo(); + return m_hid.Options(loop).CastTo(); } Trigger CommandPS5Controller::L3(frc::EventLoop* loop) const { - return PS5Controller::L3(loop).CastTo(); + return m_hid.L3(loop).CastTo(); } Trigger CommandPS5Controller::R3(frc::EventLoop* loop) const { - return PS5Controller::R3(loop).CastTo(); + return m_hid.R3(loop).CastTo(); } Trigger CommandPS5Controller::PS(frc::EventLoop* loop) const { - return PS5Controller::PS(loop).CastTo(); + return m_hid.PS(loop).CastTo(); } Trigger CommandPS5Controller::Touchpad(frc::EventLoop* loop) const { - return PS5Controller::Touchpad(loop).CastTo(); + return m_hid.Touchpad(loop).CastTo(); +} + +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(); } diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandStadiaController.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandStadiaController.cpp index 86c34bad21..6568b8253f 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandStadiaController.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandStadiaController.cpp @@ -6,67 +6,85 @@ using namespace frc2; -Trigger CommandStadiaController::Button(int button, - frc::EventLoop* loop) const { - return GenericHID::Button(button, loop).CastTo(); +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(); + return m_hid.LeftBumper(loop).CastTo(); } Trigger CommandStadiaController::RightBumper(frc::EventLoop* loop) const { - return StadiaController::RightBumper(loop).CastTo(); + return m_hid.RightBumper(loop).CastTo(); } Trigger CommandStadiaController::LeftStick(frc::EventLoop* loop) const { - return StadiaController::LeftStick(loop).CastTo(); + return m_hid.LeftStick(loop).CastTo(); } Trigger CommandStadiaController::RightStick(frc::EventLoop* loop) const { - return StadiaController::RightStick(loop).CastTo(); + return m_hid.RightStick(loop).CastTo(); } Trigger CommandStadiaController::A(frc::EventLoop* loop) const { - return StadiaController::A(loop).CastTo(); + return m_hid.A(loop).CastTo(); } Trigger CommandStadiaController::B(frc::EventLoop* loop) const { - return StadiaController::B(loop).CastTo(); + return m_hid.B(loop).CastTo(); } Trigger CommandStadiaController::X(frc::EventLoop* loop) const { - return StadiaController::X(loop).CastTo(); + return m_hid.X(loop).CastTo(); } Trigger CommandStadiaController::Y(frc::EventLoop* loop) const { - return StadiaController::Y(loop).CastTo(); + return m_hid.Y(loop).CastTo(); } Trigger CommandStadiaController::Ellipses(frc::EventLoop* loop) const { - return StadiaController::Ellipses(loop).CastTo(); + return m_hid.Ellipses(loop).CastTo(); } Trigger CommandStadiaController::Hamburger(frc::EventLoop* loop) const { - return StadiaController::Hamburger(loop).CastTo(); + return m_hid.Hamburger(loop).CastTo(); } Trigger CommandStadiaController::Stadia(frc::EventLoop* loop) const { - return StadiaController::Stadia(loop).CastTo(); + return m_hid.Stadia(loop).CastTo(); } Trigger CommandStadiaController::Google(frc::EventLoop* loop) const { - return StadiaController::Google(loop).CastTo(); + return m_hid.Google(loop).CastTo(); } Trigger CommandStadiaController::Frame(frc::EventLoop* loop) const { - return StadiaController::Frame(loop).CastTo(); + return m_hid.Frame(loop).CastTo(); } Trigger CommandStadiaController::LeftTrigger(frc::EventLoop* loop) const { - return StadiaController::LeftTrigger(loop).CastTo(); + return m_hid.LeftTrigger(loop).CastTo(); } Trigger CommandStadiaController::RightTrigger(frc::EventLoop* loop) const { - return StadiaController::RightTrigger(loop).CastTo(); + return m_hid.RightTrigger(loop).CastTo(); +} + +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(); } diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandXboxController.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandXboxController.cpp index 8c4eba0fd2..2e366d27e2 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandXboxController.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandXboxController.cpp @@ -6,56 +6,83 @@ using namespace frc2; -Trigger CommandXboxController::Button(int button, frc::EventLoop* loop) const { - return GenericHID::Button(button, loop).CastTo(); +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(); + return m_hid.LeftBumper(loop).CastTo(); } Trigger CommandXboxController::RightBumper(frc::EventLoop* loop) const { - return XboxController::RightBumper(loop).CastTo(); + return m_hid.RightBumper(loop).CastTo(); } Trigger CommandXboxController::LeftStick(frc::EventLoop* loop) const { - return XboxController::LeftStick(loop).CastTo(); + return m_hid.LeftStick(loop).CastTo(); } Trigger CommandXboxController::RightStick(frc::EventLoop* loop) const { - return XboxController::RightStick(loop).CastTo(); + return m_hid.RightStick(loop).CastTo(); } Trigger CommandXboxController::A(frc::EventLoop* loop) const { - return XboxController::A(loop).CastTo(); + return m_hid.A(loop).CastTo(); } Trigger CommandXboxController::B(frc::EventLoop* loop) const { - return XboxController::B(loop).CastTo(); + return m_hid.B(loop).CastTo(); } Trigger CommandXboxController::X(frc::EventLoop* loop) const { - return XboxController::X(loop).CastTo(); + return m_hid.X(loop).CastTo(); } Trigger CommandXboxController::Y(frc::EventLoop* loop) const { - return XboxController::Y(loop).CastTo(); + return m_hid.Y(loop).CastTo(); } Trigger CommandXboxController::Back(frc::EventLoop* loop) const { - return XboxController::Back(loop).CastTo(); + return m_hid.Back(loop).CastTo(); } Trigger CommandXboxController::Start(frc::EventLoop* loop) const { - return XboxController::Start(loop).CastTo(); + return m_hid.Start(loop).CastTo(); } Trigger CommandXboxController::LeftTrigger(double threshold, frc::EventLoop* loop) const { - return XboxController::LeftTrigger(threshold, loop).CastTo(); + return m_hid.LeftTrigger(threshold, loop).CastTo(); } Trigger CommandXboxController::RightTrigger(double threshold, frc::EventLoop* loop) const { - return XboxController::RightTrigger(threshold, loop).CastTo(); + return m_hid.RightTrigger(threshold, loop).CastTo(); +} + +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(); } diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandGenericHID.h b/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandGenericHID.h index 5c986dde2b..56fb377f1d 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandGenericHID.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandGenericHID.h @@ -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 diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandJoystick.h b/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandJoystick.h index 5b51e86604..d1eeadfc2c 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandJoystick.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandJoystick.h @@ -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 diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandPS4Controller.h b/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandPS4Controller.h index 22c54ad22e..476828d26f 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandPS4Controller.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandPS4Controller.h @@ -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 diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandPS5Controller.h b/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandPS5Controller.h index d86d38388b..badf55cd50 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandPS5Controller.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandPS5Controller.h @@ -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 diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandStadiaController.h b/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandStadiaController.h index 7a1b54934c..17e57a2dc2 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandStadiaController.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandStadiaController.h @@ -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 diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandXboxController.h b/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandXboxController.h index 94a3c2c505..f22681440b 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandXboxController.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandXboxController.h @@ -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