EasyButton icon indicating copy to clipboard operation
EasyButton copied to clipboard

Multiple onPressedFor

Open FraOre opened this issue 3 years ago • 4 comments

Hi, I would like to do something like this with the same button:

button.onPressedFor(1000, showIP); button.onPressedFor(3000, restartDevice);

so execute two different callback based on the pressing duration. It doesn't work for me. Just the last function is called. Any idea?

Thank you so much, Francesco

FraOre avatar Oct 01 '21 15:10 FraOre

I am trying to do the same thing, and having the same problems.

TylerTotally avatar Jan 27 '22 20:01 TylerTotally

Hi @FraOre and @TylerTotally, I will take a look at this.

evert-arias avatar Mar 12 '22 18:03 evert-arias

Basically, it is the last defined OnPressedFor that is stamped in the EasyButtonBase class's members. WIhich is to say that all the previous calls to OnPressedFor are overwritten by the last one. So in the initial message, the 3000 callback it the winning one, but if they were declared 3000 THEN 1000, only the 1000 one will be used (and triggered)

So I believe that an array (or a chained list of events) should be set in place in order to hold the different OnPressedFor callbacks. Of course, _checkPressedTime should then loop that structure until found proper callback. I'll see how to setup something decently behaving :)

JFClaeys avatar Mar 31 '22 12:03 JFClaeys

This would be a useful addition to the library

fastbike avatar Sep 22 '22 02:09 fastbike