[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:
Starlight220
2022-11-28 23:48:48 +02:00
committed by GitHub
parent 15561338d5
commit cb38bacfe8
14 changed files with 555 additions and 243 deletions

View File

@@ -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!() {

View File

@@ -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();
}
}