Clean up edge detection logic in ButtonScheduler subclasses (#1340)

This also changes the behavior of whileActive to call start once on the starting edge
instead of every loop iteration.
This commit is contained in:
Tyler Veness
2018-09-26 22:55:34 -07:00
committed by Peter Johnson
parent 6171856020
commit a732854866
8 changed files with 70 additions and 88 deletions

View File

@@ -17,13 +17,13 @@ HeldButtonScheduler::HeldButtonScheduler(bool last, Trigger* button,
: ButtonScheduler(last, button, orders) {}
void HeldButtonScheduler::Execute() {
if (m_button->Grab()) {
m_pressedLast = true;
bool pressed = m_button->Grab();
if (!m_pressedLast && pressed) {
m_command->Start();
} else {
if (m_pressedLast) {
m_pressedLast = false;
m_command->Cancel();
}
} else if (m_pressedLast && !pressed) {
m_command->Cancel();
}
m_pressedLast = pressed;
}