Skip to content
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

release callack #57

Open
alikanarya opened this issue Oct 14, 2024 · 4 comments
Open

release callack #57

alikanarya opened this issue Oct 14, 2024 · 4 comments
Assignees
Labels
question Further information is requested

Comments

@alikanarya
Copy link

Hi, firstly I thank for your library.
I want to simulate tm1638 buttons as push puttons.
I coded and worked.
I attached release and click callback functions.
However, release fn is called before click fn.
And this makes some awkward behaviour in my scenerio.
Could you please guide me how to call release callback fn after click fn?
Thanks

example monitor output when I pressed and released button 1:
relased button: 1
pressed button: 1

@maxint-rd maxint-rd self-assigned this Oct 14, 2024
@maxint-rd maxint-rd added the question Further information is requested label Oct 14, 2024
@maxint-rd
Copy link
Owner

Hello, the behavior you describe is by design. Currently there is no callback for a button being pressed. Only after a button is released we can determine if it was a click, a double click or a long click.

The main goal for having a release callback is for fast actions when no click or double click needs to be detected while allowing checking if other buttons are still being pressed (think of a shift key).

The normal usage of what I think you intend to do is only have a click callback, which is indeed called right after the button was released.

FYI: in case of a double-click the sequence is like this:

Button 2 release.
Button 2 release.
Button 2 doubleclick.

If you still want to act before the release is done (e.g. to give visual indication of a button being pressed), you could use the return value of tick(). The 32-bit return value indicates if buttons are pressed (value != 0) and which buttons are pressed (bit at button position is set). Is this explanation helpful?

@alikanarya
Copy link
Author

Thanks you very much for your rapid response and explanation.
But these two sentences dont match in my mind;
"Only after a button is released we can determine if it was a click,"
"The 32-bit return value indicates if buttons are pressed"
if you decide if a button is pressed or not by release action, how can return value of tick() knows the pressed state?

@maxint-rd
Copy link
Owner

I think in your mind you need to distinguish press from click. A click is press+release. A long click has long duration between press and release. A double click is two clicks within a short time.

Normally you call the tick() method numerous times at the top of your running loop(). The tick() method implements a state engine to determine the state of each possible button. Only once released tick() can tell if a button was clicked once, twice or long. If you print millis() in the callbacks you can see the time between the various events.

Each time you call tick, it returns a 32-bit value containing the on/off value of 32 buttons maximum. Before returning it sets timers, updates the state engine and does callbacks. However when just pressing, tick() currently returns without doing a callback. Whether and when a specific button is pressed is stored in the state engine. Eventually tick() returns the current on/off value of all possible buttons. Does this clarify things?

@alikanarya
Copy link
Author

Thank for your support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants