mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-28 02:11:43 +00:00
[commands] Revert to original Trigger implementation (#4673)
Trigger was refactored to use BooleanEvent when it was introduced in #4104. This reverts to the original implementation until edge-based BooleanEvents can be fixed.
This commit is contained in:
@@ -17,8 +17,12 @@ bool BooleanEvent::GetAsBoolean() const {
|
||||
return m_condition();
|
||||
}
|
||||
|
||||
void BooleanEvent::IfHigh(wpi::unique_function<void()> action) {
|
||||
m_loop->Bind(m_condition, std::move(action));
|
||||
void BooleanEvent::IfHigh(std::function<void()> action) {
|
||||
m_loop->Bind([condition = m_condition, action = std::move(action)] {
|
||||
if (condition()) {
|
||||
action();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
BooleanEvent BooleanEvent::operator!() {
|
||||
|
||||
@@ -8,20 +8,13 @@ using namespace frc;
|
||||
|
||||
EventLoop::EventLoop() {}
|
||||
|
||||
void EventLoop::Binding::Poll() {
|
||||
if (condition()) {
|
||||
action();
|
||||
}
|
||||
}
|
||||
|
||||
void EventLoop::Bind(std::function<bool()> condition,
|
||||
wpi::unique_function<void()> action) {
|
||||
m_bindings.emplace_back(Binding{condition, std::move(action)});
|
||||
void EventLoop::Bind(wpi::unique_function<void()> action) {
|
||||
m_bindings.emplace_back(std::move(action));
|
||||
}
|
||||
|
||||
void EventLoop::Poll() {
|
||||
for (Binding& binding : m_bindings) {
|
||||
binding.Poll();
|
||||
for (wpi::unique_function<void()>& action : m_bindings) {
|
||||
action();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace frc {
|
||||
/**
|
||||
* This class provides an easy way to link actions to inputs. Each object
|
||||
* represents a boolean condition to which callback actions can be bound using
|
||||
* {@link #IfHigh(wpi::unique_function<void()>)}.
|
||||
* {@link #IfHigh(std::function<void()>)}.
|
||||
*
|
||||
* <p>These events can easily be composed using factories such as {@link
|
||||
* #operator!},
|
||||
@@ -51,7 +51,7 @@ class BooleanEvent {
|
||||
*
|
||||
* @param action the action to run if this event is active.
|
||||
*/
|
||||
void IfHigh(wpi::unique_function<void()> action);
|
||||
void IfHigh(std::function<void()> action);
|
||||
|
||||
operator std::function<bool()>(); // NOLINT
|
||||
|
||||
|
||||
@@ -20,13 +20,11 @@ class EventLoop {
|
||||
EventLoop& operator=(const EventLoop&) = delete;
|
||||
|
||||
/**
|
||||
* Bind a new action to run whenever the condition is true.
|
||||
* Bind a new action to run.
|
||||
*
|
||||
* @param condition the condition to listen to.
|
||||
* @param action the action to run.
|
||||
*/
|
||||
void Bind(std::function<bool()> condition,
|
||||
wpi::unique_function<void()> action);
|
||||
void Bind(wpi::unique_function<void()> action);
|
||||
|
||||
/**
|
||||
* Poll all bindings.
|
||||
@@ -39,12 +37,6 @@ class EventLoop {
|
||||
void Clear();
|
||||
|
||||
private:
|
||||
struct Binding {
|
||||
std::function<bool()> condition;
|
||||
wpi::unique_function<void()> action;
|
||||
|
||||
void Poll();
|
||||
};
|
||||
std::vector<Binding> m_bindings;
|
||||
std::vector<wpi::unique_function<void()>> m_bindings;
|
||||
};
|
||||
} // namespace frc
|
||||
|
||||
Reference in New Issue
Block a user