-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[BackLite] Add button release check #4005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice find, thanks! Just a couple of little things
Co-authored-by: Rob Pilling <robpilling@gmail.com>
|
This doesn't work, and if you press, release, and then press quickly, it still checks for the button and lights up the screen, even with the checks in place. @bobrippling do you have any idea why that could be? |
| longPressTimer=setTimeout(() => { | ||
| if (digitalRead(BTN1)) { | ||
| //set brightness until. locked. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't work, and if you press, release, and then press quickly, it still checks for the button and lights up the screen, even with the checks in place. @bobrippling do you have any idea why that could be?
I don't think my below suggestion is right unless there's a race between 'clearTimeout()` and the invocation of the timeout func.
If you add debug logs to both the timeout function (each arm of the if) and the setWatch callback, what gets printed?
| longPressTimer=setTimeout(() => { | |
| if (digitalRead(BTN1)) { | |
| //set brightness until. locked. | |
| longPressTimer=setTimeout(() => { | |
| if (longPressTimer == null) { | |
| // cancelled, ignore | |
| return; | |
| } | |
| if (digitalRead(BTN1)) { | |
| //set brightness until. locked. |
Just checks if the button is released, then cancel the check for long press, to avoid users pressing once, then once more and the screen turns on.