[commands] Extract common trigger binding logic (#7550)

This makes the logic clearer in the actual binding methods and will hopefully make it less annoying to make changes such as allowing control over initial edges.

Also changes Java to use previous and current to match C++.
This commit is contained in:
Joseph Eng
2024-12-14 23:13:41 -08:00
committed by GitHub
parent 564c1f2de2
commit 70f36cce7e
3 changed files with 128 additions and 209 deletions

View File

@@ -11,6 +11,7 @@
#include <frc/event/EventLoop.h>
#include <frc/filter/Debouncer.h>
#include <units/time.h>
#include <wpi/FunctionExtras.h>
#include "frc2/command/Command.h"
#include "frc2/command/CommandScheduler.h"
@@ -291,6 +292,13 @@ class Trigger {
bool Get() const;
private:
/**
* Adds a binding to the EventLoop.
*
* @param body The body of the binding to add.
*/
void AddBinding(wpi::unique_function<void(bool, bool)>&& body);
frc::EventLoop* m_loop;
std::function<bool()> m_condition;
};