Fix OneShot premature timeout

OneShot keys were failing to activate on the first press because of how the timeout was
implemented. Most of the time, at the end of a cycle, `should_cancel_` was being set to
`true` because the current time was being compared to the last time a OneShot key was
activated, regardless of whether or not a OneShot key was active. As a result, OneShot
keys that were pressed for the first time in a while would fail to register as OneShots.

This change prevents checking the timeout unless there is an active OneShot key.

Fixes #603.

Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
pull/605/head
Michael Richters 6 years ago
parent efe113041a
commit 445d50a931
No known key found for this signature in database
GPG Key ID: C40C181A55000EF6

@ -173,7 +173,14 @@ EventHandlerResult OneShot::beforeReportingState() {
} }
EventHandlerResult OneShot::afterEachCycle() { EventHandlerResult OneShot::afterEachCycle() {
if (hasTimedOut()) bool oneshot_active = false;
for (uint8_t i = 0; i < ONESHOT_KEY_COUNT; i++) {
if (state_[i].active) {
oneshot_active = true;
break;
}
}
if (oneshot_active && hasTimedOut())
cancel(); cancel();
bool is_cancelled = false; bool is_cancelled = false;

Loading…
Cancel
Save