mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[commands] Revamp Interruptible (#4192)
This commit is contained in:
@@ -8,8 +8,8 @@ using namespace frc2;
|
||||
|
||||
Button::Button(std::function<bool()> isPressed) : Trigger(isPressed) {}
|
||||
|
||||
Button Button::WhenPressed(Command* command, bool interruptible) {
|
||||
WhenActive(command, interruptible);
|
||||
Button Button::WhenPressed(Command* command) {
|
||||
WhenActive(command);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -25,8 +25,8 @@ Button Button::WhenPressed(std::function<void()> toRun,
|
||||
return *this;
|
||||
}
|
||||
|
||||
Button Button::WhileHeld(Command* command, bool interruptible) {
|
||||
WhileActiveContinous(command, interruptible);
|
||||
Button Button::WhileHeld(Command* command) {
|
||||
WhileActiveContinous(command);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -42,13 +42,13 @@ Button Button::WhileHeld(std::function<void()> toRun,
|
||||
return *this;
|
||||
}
|
||||
|
||||
Button Button::WhenHeld(Command* command, bool interruptible) {
|
||||
WhileActiveOnce(command, interruptible);
|
||||
Button Button::WhenHeld(Command* command) {
|
||||
WhileActiveOnce(command);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Button Button::WhenReleased(Command* command, bool interruptible) {
|
||||
WhenInactive(command, interruptible);
|
||||
Button Button::WhenReleased(Command* command) {
|
||||
WhenInactive(command);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -64,8 +64,8 @@ Button Button::WhenReleased(std::function<void()> toRun,
|
||||
return *this;
|
||||
}
|
||||
|
||||
Button Button::ToggleWhenPressed(Command* command, bool interruptible) {
|
||||
ToggleWhenActive(command, interruptible);
|
||||
Button Button::ToggleWhenPressed(Command* command) {
|
||||
ToggleWhenActive(command);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,9 +13,8 @@ using namespace frc2;
|
||||
|
||||
Trigger::Trigger(const Trigger& other) = default;
|
||||
|
||||
Trigger Trigger::WhenActive(Command* command, bool interruptible) {
|
||||
this->Rising().IfHigh(
|
||||
[command, interruptible] { command->Schedule(interruptible); });
|
||||
Trigger Trigger::WhenActive(Command* command) {
|
||||
this->Rising().IfHigh([command] { command->Schedule(); });
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -30,8 +29,8 @@ Trigger Trigger::WhenActive(std::function<void()> toRun,
|
||||
return WhenActive(InstantCommand(std::move(toRun), requirements));
|
||||
}
|
||||
|
||||
Trigger Trigger::WhileActiveContinous(Command* command, bool interruptible) {
|
||||
this->IfHigh([command, interruptible] { command->Schedule(interruptible); });
|
||||
Trigger Trigger::WhileActiveContinous(Command* command) {
|
||||
this->IfHigh([command] { command->Schedule(); });
|
||||
this->Falling().IfHigh([command] { command->Cancel(); });
|
||||
return *this;
|
||||
}
|
||||
@@ -48,16 +47,14 @@ Trigger Trigger::WhileActiveContinous(
|
||||
return WhileActiveContinous(InstantCommand(std::move(toRun), requirements));
|
||||
}
|
||||
|
||||
Trigger Trigger::WhileActiveOnce(Command* command, bool interruptible) {
|
||||
this->Rising().IfHigh(
|
||||
[command, interruptible] { command->Schedule(interruptible); });
|
||||
Trigger Trigger::WhileActiveOnce(Command* command) {
|
||||
this->Rising().IfHigh([command] { command->Schedule(); });
|
||||
this->Falling().IfHigh([command] { command->Cancel(); });
|
||||
return *this;
|
||||
}
|
||||
|
||||
Trigger Trigger::WhenInactive(Command* command, bool interruptible) {
|
||||
this->Falling().IfHigh(
|
||||
[command, interruptible] { command->Schedule(interruptible); });
|
||||
Trigger Trigger::WhenInactive(Command* command) {
|
||||
this->Falling().IfHigh([command] { command->Schedule(); });
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -72,12 +69,12 @@ Trigger Trigger::WhenInactive(std::function<void()> toRun,
|
||||
return WhenInactive(InstantCommand(std::move(toRun), requirements));
|
||||
}
|
||||
|
||||
Trigger Trigger::ToggleWhenActive(Command* command, bool interruptible) {
|
||||
this->Rising().IfHigh([command, interruptible] {
|
||||
Trigger Trigger::ToggleWhenActive(Command* command) {
|
||||
this->Rising().IfHigh([command] {
|
||||
if (command->IsScheduled()) {
|
||||
command->Cancel();
|
||||
} else {
|
||||
command->Schedule(interruptible);
|
||||
command->Schedule();
|
||||
}
|
||||
});
|
||||
return *this;
|
||||
|
||||
Reference in New Issue
Block a user