mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-30 02:31:44 +00:00
[commands] Replace Command HID inheritance with delegation (#4470)
This commit is contained in:
@@ -9,3 +9,48 @@ using namespace frc2;
|
||||
Trigger CommandGenericHID::Button(int button, frc::EventLoop* loop) const {
|
||||
return GenericHID::Button(button, loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandGenericHID::POV(int angle, frc::EventLoop* loop) const {
|
||||
return POV(0, angle, loop);
|
||||
}
|
||||
|
||||
Trigger CommandGenericHID::POV(int pov, int angle, frc::EventLoop* loop) const {
|
||||
return Trigger(loop,
|
||||
[this, pov, angle] { return this->GetPOV(pov) == angle; });
|
||||
}
|
||||
|
||||
Trigger CommandGenericHID::POVUp(frc::EventLoop* loop) const {
|
||||
return POV(0, loop);
|
||||
}
|
||||
|
||||
Trigger CommandGenericHID::POVUpRight(frc::EventLoop* loop) const {
|
||||
return POV(45, loop);
|
||||
}
|
||||
|
||||
Trigger CommandGenericHID::POVRight(frc::EventLoop* loop) const {
|
||||
return POV(90, loop);
|
||||
}
|
||||
|
||||
Trigger CommandGenericHID::POVDownRight(frc::EventLoop* loop) const {
|
||||
return POV(135, loop);
|
||||
}
|
||||
|
||||
Trigger CommandGenericHID::POVDown(frc::EventLoop* loop) const {
|
||||
return POV(180, loop);
|
||||
}
|
||||
|
||||
Trigger CommandGenericHID::POVDownLeft(frc::EventLoop* loop) const {
|
||||
return POV(225, loop);
|
||||
}
|
||||
|
||||
Trigger CommandGenericHID::POVLeft(frc::EventLoop* loop) const {
|
||||
return POV(270, loop);
|
||||
}
|
||||
|
||||
Trigger CommandGenericHID::POVUpLeft(frc::EventLoop* loop) const {
|
||||
return POV(315, loop);
|
||||
}
|
||||
|
||||
Trigger CommandGenericHID::POVCenter(frc::EventLoop* loop) const {
|
||||
return POV(360, loop);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,10 @@
|
||||
|
||||
using namespace frc2;
|
||||
|
||||
Trigger CommandPS4Controller::Button(int button, frc::EventLoop* loop) const {
|
||||
return GenericHID::Button(button, loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandPS4Controller::Square(frc::EventLoop* loop) const {
|
||||
return PS4Controller::Square(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,10 @@
|
||||
|
||||
using namespace frc2;
|
||||
|
||||
Trigger CommandXboxController::Button(int button, frc::EventLoop* loop) const {
|
||||
return GenericHID::Button(button, loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
Trigger CommandXboxController::LeftBumper(frc::EventLoop* loop) const {
|
||||
return XboxController::LeftBumper(loop).CastTo<Trigger>();
|
||||
}
|
||||
|
||||
@@ -31,5 +31,153 @@ class CommandGenericHID : public frc::GenericHID {
|
||||
Trigger Button(int button,
|
||||
frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance based around this angle of a POV on the HID.
|
||||
*
|
||||
* <p>The POV angles start at 0 in the up direction, and increase clockwise
|
||||
* (eg right is 90, upper-left is 315).
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to
|
||||
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
|
||||
* scheduler button loop}.
|
||||
* @param angle POV angle in degrees, or -1 for the center / not pressed.
|
||||
* @return a Trigger instance based around this angle of a POV on the HID.
|
||||
*/
|
||||
Trigger POV(int angle,
|
||||
frc::EventLoop* loop =
|
||||
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance based around this angle of a POV on the HID.
|
||||
*
|
||||
* <p>The POV angles start at 0 in the up direction, and increase clockwise
|
||||
* (eg right is 90, upper-left is 315).
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to
|
||||
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
|
||||
* scheduler button loop}.
|
||||
* @param pov index of the POV to read (starting at 0). Defaults to 0.
|
||||
* @param angle POV angle in degrees, or -1 for the center / not pressed.
|
||||
* @return a Trigger instance based around this angle of a POV on the HID.
|
||||
*/
|
||||
Trigger POV(int pov, int angle,
|
||||
frc::EventLoop* loop =
|
||||
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance based around the 0-degree angle (up) of the
|
||||
* default (index 0) POV on the HID.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to
|
||||
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
|
||||
* scheduler button loop}.
|
||||
* @return a Trigger instance based around the 90-degree angle of a POV on the
|
||||
* HID.
|
||||
*/
|
||||
Trigger POVUp(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance based around the 45-degree angle (right up)
|
||||
* of the default (index 0) POV on the HID.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to
|
||||
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
|
||||
* scheduler button loop}.
|
||||
* @return a Trigger instance based around the 90-degree angle of a POV on the
|
||||
* HID.
|
||||
*/
|
||||
Trigger POVUpRight(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance based around the 90-degree angle (right) of
|
||||
* the default (index 0) POV on the HID.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to
|
||||
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
|
||||
* scheduler button loop}.
|
||||
* @return a Trigger instance based around the 90-degree angle of a POV on the
|
||||
* HID.
|
||||
*/
|
||||
Trigger POVRight(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance based around the 135-degree angle (right
|
||||
* down) of the default (index 0) POV on the HID.
|
||||
*
|
||||
* @return a Trigger instance based around the 135-degree angle of a POV on
|
||||
* the HID.
|
||||
*/
|
||||
Trigger POVDownRight(
|
||||
frc::EventLoop* loop =
|
||||
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance based around the 180-degree angle (down) of
|
||||
* the default (index 0) POV on the HID.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to
|
||||
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
|
||||
* scheduler button loop}.
|
||||
* @return a Trigger instance based around the 90-degree angle of a POV on the
|
||||
* HID.
|
||||
*/
|
||||
Trigger POVDown(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance based around the 225-degree angle (down left)
|
||||
* of the default (index 0) POV on the HID.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to
|
||||
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
|
||||
* scheduler button loop}.
|
||||
* @return a Trigger instance based around the 90-degree angle of a POV on the
|
||||
* HID.
|
||||
*/
|
||||
Trigger POVDownLeft(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance based around the 270-degree angle (left) of
|
||||
* the default (index 0) POV on the HID.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to
|
||||
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
|
||||
* scheduler button loop}.
|
||||
* @return a Trigger instance based around the 90-degree angle of a POV on the
|
||||
* HID.
|
||||
*/
|
||||
Trigger POVLeft(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance based around the 315-degree angle (left up)
|
||||
* of the default (index 0) POV on the HID.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to
|
||||
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
|
||||
* scheduler button loop}.
|
||||
* @return a Trigger instance based around the 90-degree angle of a POV on the
|
||||
* HID.
|
||||
*/
|
||||
Trigger POVUpLeft(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs a Trigger instance based around the center (not pressed) of the
|
||||
* default (index 0) POV on the HID.
|
||||
*
|
||||
* @param loop the event loop instance to attach the event to. Defaults to
|
||||
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
|
||||
* scheduler button loop}.
|
||||
* @return a Trigger instance based around the 90-degree angle of a POV on the
|
||||
* HID.
|
||||
*/
|
||||
Trigger POVCenter(frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
};
|
||||
} // namespace frc2
|
||||
|
||||
@@ -19,6 +19,19 @@ class CommandPS4Controller : public frc::PS4Controller {
|
||||
public:
|
||||
using PS4Controller::PS4Controller;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around this button's digital signal.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
Trigger Button(int button,
|
||||
frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the square button's digital signal.
|
||||
*
|
||||
|
||||
@@ -19,6 +19,19 @@ class CommandXboxController : public frc::XboxController {
|
||||
public:
|
||||
using XboxController::XboxController;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around this button's digital signal.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
Trigger Button(int button,
|
||||
frc::EventLoop* loop = CommandScheduler::GetInstance()
|
||||
.GetDefaultButtonLoop()) const;
|
||||
|
||||
/**
|
||||
* Constructs an event instance around the left bumper's digital signal.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user