15#include "wpi/units/time.hpp"
40 explicit Trigger(std::function<
bool()> condition)
42 std::move(condition)} {}
51 : m_loop{
loop}, m_condition{
std::move(condition)} {}
226 return Trigger(m_loop, [condition = m_condition, rhs = std::move(rhs)] {
227 return condition() && rhs();
237 return Trigger(m_loop, [condition = m_condition, rhs] {
238 return condition() && rhs.m_condition();
248 return Trigger(m_loop, [condition = m_condition, rhs = std::move(rhs)] {
249 return condition() || rhs();
259 return Trigger(m_loop, [condition = m_condition, rhs] {
260 return condition() || rhs.m_condition();
271 return Trigger(m_loop, [condition = m_condition] {
return !condition(); });
318 std::function<bool()> m_condition;
A declarative way to bind a set of actions to a loop and execute them when the loop is polled.
Definition EventLoop.hpp:15
A state machine representing a complete action to be performed by the robot.
Definition Command.hpp:41
A wrapper around std::unique_ptr<Command> so commands have move-only semantics.
Definition CommandPtr.hpp:28
The scheduler responsible for running Commands.
Definition CommandScheduler.hpp:39
Trigger ToggleOnTrue(Command *command)
Toggles a command when the condition changes from false to true.
Trigger ToggleOnFalse(CommandPtr &&command)
Toggles a command when the condition changes from true to false.
Trigger MultiPress(int requiredPresses, units::second_t windowTime)
Creates a new multi-press trigger from this trigger - it will become active when this trigger has bee...
Trigger ToggleOnTrue(CommandPtr &&command)
Toggles a command when the condition changes from false to true.
Trigger OnChange(Command *command)
Starts the command when the condition changes.
Trigger operator&&(Trigger rhs)
Composes two triggers with logical AND.
Definition Trigger.hpp:236
Trigger WhileFalse(Command *command)
Starts the given command when the condition changes to false and cancels it when the condition change...
Trigger(const Trigger &other)
Trigger operator&&(std::function< bool()> rhs)
Composes two triggers with logical AND.
Definition Trigger.hpp:225
Trigger(wpi::EventLoop *loop, std::function< bool()> condition)
Creates a new trigger based on the given condition.
Definition Trigger.hpp:50
Trigger operator||(Trigger rhs)
Composes two triggers with logical OR.
Definition Trigger.hpp:258
Trigger WhileTrue(Command *command)
Starts the given command when the condition changes to true and cancels it when the condition changes...
bool Get() const
Returns the current state of this trigger.
Trigger ToggleOnFalse(Command *command)
Toggles a command when the condition changes from true to the low state.
Trigger()
Create a new trigger that is always false.
Definition Trigger.hpp:56
Trigger(std::function< bool()> condition)
Creates a new trigger based on the given condition.
Definition Trigger.hpp:40
Trigger OnTrue(Command *command)
Starts the given command whenever the condition changes from false to true.
Trigger operator!()
Composes a trigger with logical NOT.
Definition Trigger.hpp:270
Trigger OnFalse(Command *command)
Starts the given command whenever the condition changes from true to false.
Trigger Debounce(wpi::units::second_t debounceTime, wpi::math::Debouncer::DebounceType type=wpi::math::Debouncer::DebounceType::kRising)
Creates a new debounced trigger from this trigger - it will become active when this trigger has been ...
Trigger operator||(std::function< bool()> rhs)
Composes two triggers with logical OR.
Definition Trigger.hpp:247
Trigger OnFalse(CommandPtr &&command)
Starts the given command whenever the condition changes from true to false.
Trigger OnChange(CommandPtr &&command)
Starts the command when the condition changes.
Trigger WhileTrue(CommandPtr &&command)
Starts the given command when the condition changes to true and cancels it when the condition changes...
Trigger WhileFalse(CommandPtr &&command)
Starts the given command when the condition changes to false and cancels it when the condition change...
Trigger OnTrue(CommandPtr &&command)
Starts the given command whenever the condition changes from false to true.
DebounceType
Type of debouncing to perform.
Definition Debouncer.hpp:21
@ kRising
Rising edge.
Definition Debouncer.hpp:23
unique_function is a type-erasing functor similar to std::function.
Definition FunctionExtras.hpp:57
Definition StringMap.hpp:773
Definition CommandNiDsStadiaController.hpp:15