Skip to content

Fix isLongPressed() during longPressStart callback - #166

Open
r3wretrhy wants to merge 1 commit into
mathertel:masterfrom
r3wretrhy:fix/longpress-start-state-165
Open

r3wretrhy wants to merge 1 commit into
mathertel:masterfrom
r3wretrhy:fix/longpress-start-state-165

Conversation

@r3wretrhy

Copy link
Copy Markdown

Fixes #165.

attachLongPressStart callbacks ran while the FSM was still in OCS_DOWN, so isLongPressed() returned false inside the callback even though a long press had just been recognized. This enters OCS_PRESS before invoking the callback. OneButtonTiny gets the same ordering.

Testing

Host harness (stubbed Arduino.h, driving tick(bool) with a fake clock), no board:

  1. Hold the button active past setPressMs(100).
  2. Inside the attachLongPressStart callback, check isLongPressed().
  • Before (master 9489276): isLongPressed() is false inside the callback.
  • After: isLongPressed() is true inside the callback.

Enter OCS_PRESS before invoking longPressStart so isLongPressed()
returns true inside the callback. Same ordering in OneButtonTiny.

Fixes mathertel#165
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The OneButton::_fsm() function incorrectly changes state after the callback for a long press start event

1 participant