mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
[wpilib] Make BooleanEvent more consistent (#5436)
Co-authored-by: Tyler Veness <calcmogul@gmail.com> Co-authored-by: Joseph Eng <91924258+KangarooKoala@users.noreply.github.com>
This commit is contained in:
@@ -40,9 +40,10 @@ class BooleanEvent {
|
||||
BooleanEvent(EventLoop* loop, std::function<bool()> condition);
|
||||
|
||||
/**
|
||||
* Check whether this event is active or not.
|
||||
* Check whether this event is active or not as of the last loop poll.
|
||||
*
|
||||
* @return true if active.
|
||||
* @return true if active, false if not active. If the event was never polled,
|
||||
* it returns the state at event construction.
|
||||
*/
|
||||
bool GetAsBoolean() const;
|
||||
|
||||
@@ -69,7 +70,7 @@ class BooleanEvent {
|
||||
[](EventLoop* loop, std::function<bool()> condition) {
|
||||
return T(loop, condition);
|
||||
}) {
|
||||
return ctor(m_loop, m_condition);
|
||||
return ctor(m_loop, [state = m_state] { return *state; });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,7 +85,8 @@ class BooleanEvent {
|
||||
* Composes this event with another event, returning a new event that is
|
||||
* active when both events are active.
|
||||
*
|
||||
* <p>The new event will use this event's polling loop.
|
||||
* <p>The events must use the same event loop. If the events use different
|
||||
* event loops, the composed signal won't update until both loops are polled.
|
||||
*
|
||||
* @param rhs the event to compose with
|
||||
* @return the event that is active when both events are active
|
||||
@@ -95,7 +97,8 @@ class BooleanEvent {
|
||||
* Composes this event with another event, returning a new event that is
|
||||
* active when either event is active.
|
||||
*
|
||||
* <p>The new event will use this event's polling loop.
|
||||
* <p>The events must use the same event loop. If the events use different
|
||||
* event loops, the composed signal won't update until both loops are polled.
|
||||
*
|
||||
* @param rhs the event to compose with
|
||||
* @return the event that is active when either event is active
|
||||
@@ -131,5 +134,6 @@ class BooleanEvent {
|
||||
private:
|
||||
EventLoop* m_loop;
|
||||
std::function<bool()> m_condition;
|
||||
std::shared_ptr<bool> m_state; // A programmer's worst nightmare.
|
||||
};
|
||||
} // namespace frc
|
||||
|
||||
Reference in New Issue
Block a user