[wpilib] Synchronize C++ and Java versions of BooleanEvent (#6776)

This commit is contained in:
Christopher Mahoney
2024-07-19 00:08:28 -04:00
committed by GitHub
parent 8d857cdb78
commit 45823abe86
3 changed files with 92 additions and 97 deletions

View File

@@ -7,21 +7,21 @@
using namespace frc;
BooleanEvent::BooleanEvent(EventLoop* loop, std::function<bool()> condition)
: m_loop(loop), m_condition(std::move(condition)) {
m_state = std::make_shared<bool>(m_condition());
: m_loop(loop), m_signal(std::move(condition)) {
m_state = std::make_shared<bool>(m_signal());
m_loop->Bind(
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)
[condition = m_condition, state = m_state] { *state = condition(); });
}
BooleanEvent::operator std::function<bool()>() {
return [state = m_state] { return *state; };
[condition = m_signal, state = m_state] { *state = condition(); });
}
bool BooleanEvent::GetAsBoolean() const {
return *m_state;
}
BooleanEvent::operator std::function<bool()>() {
return [state = m_state] { return *state; };
}
void BooleanEvent::IfHigh(std::function<void()> action) {
m_loop->Bind([state = m_state, action = std::move(action)] {
if (*state) {