How do I choose (and why) between ..._CLICK_SHORT & ..._SAVED_CLICK_SHORT?

Hi guys,

When writing a prop, how do I choose between (and why):

  • EVENT_SECOND_CLICK_SHORT
  • EVENT_SECOND_SAVED_CLICK_SHORT

Or the ONE, THREE & FOUR variation ?

They react to the same button press (2 short clicks) so they can’t be used with the same button in the same mode.

I am also wondering why we have both, I am guessing backward compatibility ?
Or is there something that one can do (or be combined with) and the other one can’t?

Thank you for enlightening me.

MTFBWY

EVENT_SECOND_SAVED_CLICK_SHORT has a delay.
This delay is used to check if there is an additional, third (and fourth) click or not.
EVENT_SECOND_CLICK_SHORT does not have a delay, but is also triggered for 3-clicks and 4-clicks.

So;
If your prop doesn’t use any 3-clicks or 4-clicks, then you can use EVENT_SECOND_CLICK_SHORT to avoid having a delay before the action takes effect. A prop should generally not use both EVENT_SECOND_CLICK_SHORT and EVENT_SECOND_SAVED_CLICK_SHORT.

Thanks, that makes lot more sense now.
I finally understand why I get two things happening at the same time (on my jetpack mainly).

EVENT_SECOND_CLICK_SHORT
&
EVENT_THIRD_CLICK_SHORT
both would be triggered almost at the “same time”. Is there a case where this can be a desired option ?

One more difference if you don’t mind?
Between:

EVENT_PRESSED,
EVENT_RELEASED,
EVENT_HELD,
EVENT_HELD_MEDIUM,
EVENT_HELD_LONG,
EVENT_CLICK_SHORT,
EVENT_SAVED_CLICK_SHORT,
EVENT_CLICK_LONG,

and

EVENT_FIRST_PRESSED,
EVENT_FIRST_RELEASED,
EVENT_FIRST_HELD,
EVENT_FIRST_HELD_MEDIUM,
EVENT_FIRST_HELD_LONG,
EVENT_FIRST_CLICK_SHORT,
EVENT_FIRST_SAVED_CLICK_SHORT,
EVENT_FIRST_CLICK_LONG,

As far as the user pressing buttons point of view, it’s the same actions in both lists (EVENT_PRESSED and EVENT_FIRST_PRESSED for example), right ? Do they “behave” differently software-wise ?

If you do a double-click, you get EVENT_FIRST_* for the first click and EVENT_SECOND_* for the second click. However, both clicks also generates EVENT_* events.

Using EVENT_* instead of EVENT_FIRST_* might make sense for something like a fire button, which might have rapid clicks, but you don’t want them to be interpreted like double-clicks.

If I understand correctly, if I do 2 short clicks followed by one long held for 3 seconds and released, these are the events that will be generated in order of “appearance”: (& means “at the same time”)

  • EVENT_PRESSED & EVENT_FIRST_PRESSED will be generated
  • EVENT_RELEASED & EVENT_FIRST_RELEASED & EVENT_CLICK_SHORT & EVENT_FIRST_CLICK_SHORT will be generated
  • these will not be generated because I am still clicking: EVENT_SAVED_CLICK_SHORT & EVENT_FIRST_SAVED_CLICK_SHORT
  • EVENT_PRESSED & EVENT_SECOND_PRESSED will be generated
  • EVENT_RELEASED & EVENT_SECOND_RELEASED & EVENT_SECOND_CLICK_SHORT will be generated
  • this will not be generated because I am still clicking: EVENT_SECOND_SAVED_CLICK_SHORT
  • EVENT_PRESSED & EVENT_THIRD_PRESSED will be generated
  • these will not be generated because I am still holding:
    – EVENT_THIRD_HELD,
    – EVENT_THIRD_HELD_MEDIUM
  • EVENT_THIRD_HELD_LONG will be generated
  • EVENT_RELEASED & EVENT_THIRD_RELEASED will be generated & EVENT_THIRD_CLICK_LONG might be generated even though I was holding 1 second too long ?

Except maybe for the last one, did I get it right ?

Note that the numbered event (FIRST) in this case comes before the non-numbered event, and if the numbered event returns true, the non-numbered event is not generated.

You forgot EVENT_CLICK_SHORT here.

And you forgot EVENT_HELD here. (etc.)

The limit is 2.5 seconds for long clicks.
If you had held it 2 seconds instead of three seconds, you would have gotten an EVENT_THIRD_CLICK_LONG and EVENT_CLICK_LONG events.

I think you have the gist of it, even if you got a few details wrong…

1 Like

Thanks, I will take that as a compliment. I find this part very hard to visualize what it does.

That is a bit of a bummer for me. I have (or I should say “had”, because I will need to change them) my:

  • HELD was set to 1 second
  • HELD_MED set to 2 seconds
  • HELD_LONG set to 3 seconds
    because it is easier to count seconds rather than try and guess part of a second.

I know where the 2.5sec is in the code (button_base.h end of line 112) but why is that a “set in stone” limit ?

No particular reason really.
It could be changed into a define with a default value of 2500.

Generally there is no need for guessing with “HELD” events since they trigger before you release the button.

Let’s say the saber turns off after HELD_LONG… you just hold the button until the saber starts to turn off, then you can release.

HELD_LONG is easy but I do need to “guesstimate” for HELD & HELD_MEDIUM

Like this:

#ifndef BUTTON_LONG_CLICK_TIMEOUT
#define BUTTON_LONG_CLICK_TIMEOUT 2500
#endif

&

        } else if (millis() - push_millis_ < BUTTON_LONG_CLICK_TIMEOUT) {
instead of
        } else if (millis() - push_millis_ < 2500) {

Would this be acceptable ?

Why?
They also do things immediately.
Also, if you have HELD_MEDIUM, you can’t really have a HELD_LONG, so it doesn’t hurt if you hold it longer…

Yep, that seems reasonable.

Now I understand how it works, I hope!
Pfffffff !
I was trying to use held, held medium and held long on the same button and same mode for my one button jetpack option because I was running out of pissibilities. I will be changing it to a two button prop only. I will cancel the PR on Github and re-submit when it is ready!

Reasonable enough for a PR ?

You’ll want saved double/triple/quad-clicks instead. (Combined with long clicks if you need more options.)

certainly

1 Like

So these are events that are not going to “interfere” with each other:

EVENT_FIRST_SAVED_CLICK_SHORT
EVENT_SECOND_SAVED_CLICK_SHORT
EVENT_THIRD_SAVED_CLICK_SHORT
EVENT_FOURTH_SAVED_CLICK_SHORT
EVENT_FIRST_CLICK_LONG
EVENT_SECOND_CLICK_LONG
EVENT_THIRD_CLICK_LONG
EVENT_FOURTH_CLICK_LONG

or

EVENT_FIRST_SAVED_CLICK_SHORT
EVENT_SECOND_SAVED_CLICK_SHORT
EVENT_THIRD_SAVED_CLICK_SHORT
EVENT_FOURTH_SAVED_CLICK_SHORT
EVENT_FIRST_HELD* (but only one of the 3)
EVENT_SECOND_HELD* (but only one of the 3)
EVENT_THIRD_HELD* (but only one of the 3)
EVENT_FOURTH_HELD* (but only of the 3)

So the maximum amount of “button events” that can be assigned to one button in the same mode is 8, unless I choose “while holding another button” (witch is not helpful for a one button setup). Is this correct ?

You can do 12 usable events per button before needing to combo with another button or gesture.

For clicks 1-4:
Click.
Click long.
Held.

Keep in mind, you can multiply that by 3 if you assign angle to each. (Pointing up, pointing down, not pointing up or down.)

So 36 .

In theory we could also do saved long clicks, which would mean that you could have short-long-short-held as a event…

I guess you mean saved click(s) ?

Isn’t held going to be released before click long thus rendering click long unusable if booth are assigned ?

It’s for a jetpack that will be an “on my back” kind of prop (not in my hand) and I am really the opposite of flexible and/or athletic. I am more like a John Favreau - Paz Vizla (except taller and much fatter) than a Pedro Pascal - Din Djarin (who probably doesn’t do front/back/side flips like animated Ahsoka without ropes, pulleys and stunt-double either) so I would like to not have to use motion or angles if possible?

But it’s not coded yet, right?

And what about this:
// Long clicks cannot be "saved", so just emit immediately. (button_base.h, line 113)
'cannot be “saved” ’ because it is not coded yet or because it can’t be coded ?

I only use HELD_MEDIUM or HELD_LONG. Also custom timings


#ifndef BUTTON_DOUBLE_CLICK_TIMEOUT
#define BUTTON_DOUBLE_CLICK_TIMEOUT 300
#endif

#ifndef BUTTON_SHORT_CLICK_TIMEOUT
#define BUTTON_SHORT_CLICK_TIMEOUT 300
#endif

#ifndef BUTTON_HELD_TIMEOUT
#define BUTTON_HELD_TIMEOUT 300
#endif

#ifndef BUTTON_HELD_MEDIUM_TIMEOUT
#define BUTTON_HELD_MEDIUM_TIMEOUT 800
#endif

#ifndef BUTTON_HELD_LONG_TIMEOUT
#define BUTTON_HELD_LONG_TIMEOUT 2000
#endif

correct

It can be coded.
It would make 31 buttons combinations, not counting combos or blade angles.

1 Like