Skip to content

Fix masks to make press/release/up/down consistent#3

Open
davidc wants to merge 4 commits intobrooksbUWO:mainfrom
davidc:dev_fixes
Open

Fix masks to make press/release/up/down consistent#3
davidc wants to merge 4 commits intobrooksbUWO:mainfrom
davidc:dev_fixes

Conversation

@davidc
Copy link
Copy Markdown

@davidc davidc commented Feb 28, 2026

#2 will need merging first.

Fixes part of #1

The second issue, press and release being sent simultaneously, was due to the masks being all wrong.

You're masking off only the latest 6 bits, but we actually care about both the oldest (highest) bits and the newest (lowest) bits, with some "don't cares" in the middle, as referenced in the Hackaday article. I've adjusted the masks to suit

However, in the case of PATTERN_DOWN/PATTERN_UP, we do want to be looking at only those last 6 bits, so it changes state as quickly as a press/release event does. Otherwise if you're waiting for all 16 bits, you could be in a situation where a button is pressed, a press event is generated, but isUp/isDown is out of sync until an additional 10 cycles have passed! In this case we need an additional mask, which I've added.

I'm sending a pull request, I've kept the masks as pure binary as then they're much more human readable, there's no risk of them getting out of sync with the comments, and there's no performance penalty to doing so. I've also updated the documentation to match.

… pattern matches the article with don't-cares in the middle. Fix isUp/isDown to react as quickly as press/release and reflect the same state.
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.

1 participant