2020-12-26 14:12:05 -08: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.
|
2019-08-25 23:55:59 -04:00
|
|
|
|
|
|
|
|
#include "frc2/command/button/Button.h"
|
|
|
|
|
|
|
|
|
|
using namespace frc2;
|
|
|
|
|
|
|
|
|
|
Button::Button(std::function<bool()> isPressed) : Trigger(isPressed) {}
|
|
|
|
|
|
2022-08-30 07:53:47 +03:00
|
|
|
Button Button::WhenPressed(Command* command) {
|
|
|
|
|
WhenActive(command);
|
2019-08-25 23:55:59 -04:00
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-08 21:30:30 -05:00
|
|
|
Button Button::WhenPressed(std::function<void()> toRun,
|
|
|
|
|
std::initializer_list<Subsystem*> requirements) {
|
|
|
|
|
WhenActive(std::move(toRun), requirements);
|
2019-08-25 23:55:59 -04:00
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-01 20:09:17 -08:00
|
|
|
Button Button::WhenPressed(std::function<void()> toRun,
|
2021-06-06 19:51:14 -07:00
|
|
|
wpi::span<Subsystem* const> requirements) {
|
2020-01-01 20:09:17 -08:00
|
|
|
WhenActive(std::move(toRun), requirements);
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-30 07:53:47 +03:00
|
|
|
Button Button::WhileHeld(Command* command) {
|
|
|
|
|
WhileActiveContinous(command);
|
2019-08-25 23:55:59 -04:00
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-08 21:30:30 -05:00
|
|
|
Button Button::WhileHeld(std::function<void()> toRun,
|
|
|
|
|
std::initializer_list<Subsystem*> requirements) {
|
|
|
|
|
WhileActiveContinous(std::move(toRun), requirements);
|
2019-08-25 23:55:59 -04:00
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-01 20:09:17 -08:00
|
|
|
Button Button::WhileHeld(std::function<void()> toRun,
|
2021-06-06 19:51:14 -07:00
|
|
|
wpi::span<Subsystem* const> requirements) {
|
2020-01-01 20:09:17 -08:00
|
|
|
WhileActiveContinous(std::move(toRun), requirements);
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-30 07:53:47 +03:00
|
|
|
Button Button::WhenHeld(Command* command) {
|
|
|
|
|
WhileActiveOnce(command);
|
2019-08-25 23:55:59 -04:00
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-30 07:53:47 +03:00
|
|
|
Button Button::WhenReleased(Command* command) {
|
|
|
|
|
WhenInactive(command);
|
2019-08-25 23:55:59 -04:00
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-08 21:30:30 -05:00
|
|
|
Button Button::WhenReleased(std::function<void()> toRun,
|
|
|
|
|
std::initializer_list<Subsystem*> requirements) {
|
|
|
|
|
WhenInactive(std::move(toRun), requirements);
|
2019-08-25 23:55:59 -04:00
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-01 20:09:17 -08:00
|
|
|
Button Button::WhenReleased(std::function<void()> toRun,
|
2021-06-06 19:51:14 -07:00
|
|
|
wpi::span<Subsystem* const> requirements) {
|
2020-01-01 20:09:17 -08:00
|
|
|
WhenInactive(std::move(toRun), requirements);
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-30 07:53:47 +03:00
|
|
|
Button Button::ToggleWhenPressed(Command* command) {
|
|
|
|
|
ToggleWhenActive(command);
|
2019-08-25 23:55:59 -04:00
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Button Button::CancelWhenPressed(Command* command) {
|
|
|
|
|
CancelWhenActive(command);
|
|
|
|
|
return *this;
|
|
|
|
|
}
|