Switch input - Push button on longpress

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
iz8mbw
Normal user
Posts: 35
Joined: 14 Apr 2023, 08:43
Location: Napoli, Italy

Switch input - Push button on longpress

#1 Post by iz8mbw » 27 Oct 2023, 19:15

Hello.
I have notices the Switch input - Push button on longpress does not work as I expect.

What I notices is EVENT 10 (the long press event) is always generated also if the press duration of push button is less than what is configured in "Longpress min. interval (ms)".
Example I have Long press interval set to 600 ms but if I press very fast I have two EVENTs, first one is "1" and just after I have "10".
So, why EVENT 10 is generated if I press for less than 600 ms?

See log, dont' know if it can help:

Code: Select all

88822278: SW : GPIO=34 State=0 Output value=1
88822319: EVENT: swdown#State=1
88822327: ACT : taskvalueset,dummyswdown,state,1
88822335: ACT : taskrun,dummyswdown
88822340: Dummy: value 1: 1
88822345: EVENT: dummyswdown#State=1
88822382: ACT : Publish,espeasy_1/pushdown,0
88822388: ACT : Let,8,0
88822948: SW : LongPress: GPIO= 34 State=0 Output value=10
88822962: EVENT: swdown#State=10
88822971: ACT : taskvalueset,dummyswdown,state,10
88822978: ACT : taskrun,dummyswdown
88822983: Dummy: value 1: 10
88822996: EVENT: dummyswdown#State=10

bidrohini
Normal user
Posts: 105
Joined: 03 Nov 2022, 16:24

Re: Switch input - Push button on longpress

#2 Post by bidrohini » 28 Oct 2023, 15:01

Here are some old threads in this forum about long press switch input. You can check these.
viewtopic.php?t=5636
viewtopic.php?t=9236
And in case if you ever want to create a ESPeasy compatible PCB for your system, you can see this design.
https://www.pcbway.com/project/sharepro ... S_PCB.html

iz8mbw
Normal user
Posts: 35
Joined: 14 Apr 2023, 08:43
Location: Napoli, Italy

Re: Switch input - Push button on longpress

#3 Post by iz8mbw » 29 Oct 2023, 10:43

Thank you for the link provided.
Anyway I have the issue that the "EVENT10" (Logpress) is generated also if I press for a very very short time the push button, and this is a problem.

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Switch input - Push button on longpress

#4 Post by chromo23 » 29 Oct 2023, 12:04

Even if i don't know you exact configuration.
Try this:

Set the "Longpress event:" to "Active only on LOW"

and use this code:

Code: Select all

On button#state Do
 If %eventvalue1% = 1
  Let,1,0
 Elseif %eventvalue1% = 0 And [var#23] = 0
  LogEntry,'short-press'
  //Put your code for short-press-event in here
 Elseif %eventvalue1% =11
  LogEntry,'long-press'
  Let,1,1
   //Put your code for long-press-event in here
 Endif
Endon
Without any extra code a short-press event will always precede a long-press event!

Edit:

Just saw you are using the input as a push button.. therefore you must use this differently... one second...
For pushbutton setup:

Keep or change the "Switch Button Type:" to "Normal Switch"

and use this code instead:

Code: Select all

On button#state Do
 If %eventvalue1% = 1
  Let,1,0
 Elseif %eventvalue1% = 0 And [var#23] = 0
  LogEntry,'short-press'
  GPIOToggle,<GPIO>  //toggles a specific GPIO 
  //Put your code for short-press-event in here
 Elseif %eventvalue1% =11
  LogEntry,'long-press'
  Let,1,1
   //Put your code for long-press-event in here
 Endif
Endon
Edit2:
This confusion about firing the initial short-press event on a long-press happens very often.
Maybe we should change that behavior in the plugin?

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Switch input - Push button on longpress

#5 Post by chromo23 » 29 Oct 2023, 12:22

Ubbs.. forgot the most important part in the code.. just updated it

iz8mbw
Normal user
Posts: 35
Joined: 14 Apr 2023, 08:43
Location: Napoli, Italy

Re: Switch input - Push button on longpress

#6 Post by iz8mbw » 29 Oct 2023, 15:00

@chromo23 I suppose we should change that behavior in the plugin.
EVENT 0 (or 1) should NOT be sent if EVENT 10 (or 11) is generated, so IF Logpress THEN no EVENT1 (or 0).
Now both EVENT 0 (or 1) AND EVENT 10 (or 11) are generated.

A longpress IS NOT a short press.

iz8mbw
Normal user
Posts: 35
Joined: 14 Apr 2023, 08:43
Location: Napoli, Italy

Re: Switch input - Push button on longpress

#7 Post by iz8mbw » 29 Oct 2023, 15:12


User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Switch input - Push button on longpress

#8 Post by chromo23 » 29 Oct 2023, 19:11

Since you still have problems with the longpress i´ll write you here instead of github.

Can you post a screenshot of your switch plugin?

iz8mbw
Normal user
Posts: 35
Joined: 14 Apr 2023, 08:43
Location: Napoli, Italy

Re: Switch input - Push button on longpress

#9 Post by iz8mbw » 29 Oct 2023, 19:42

Here my Switch Input config:
switch_input.JPG
switch_input.JPG (59.52 KiB) Viewed 1855 times

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Switch input - Push button on longpress

#10 Post by chromo23 » 29 Oct 2023, 20:11

Testet it with your settings... everything works as expected

With the settings in the screenshot your button input gets low when releasing it.
Since "Longpress event" is set to "active low" it will trigger a longpress event (10) because it stays low after releasing the button.

use "active on high" and the the longpress event will only get triggered when the button is pressed (high).
The event as written in the selection field is then 11 ! (swdown#State = 11)

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Switch input - Push button on longpress

#11 Post by chromo23 » 29 Oct 2023, 20:21

I made an mistake (its all a bit confusing)..
I didn´t set the switch type to "push button active low" :o

You are right.. this seems to be bug indeed. It does create a longpress event when longpress event is set to "active on low". (every time you release the button there will be a longpress as it is supposed to be)

The combination "switch type" = "push button active low" & "longpress event " = "active on high" does not work at all.

edit:
As long as this is not working change switch type to "normal switch" and use the aforementioned rule:

Code: Select all

On button#state Do
 If %eventvalue1% = 1
  Let,1,0
 Elseif %eventvalue1% = 0 And [var#23] = 0
  LogEntry,'short-press'
  GPIOToggle,<GPIO>  //toggles a specific GPIO 
  //Put your code for short-press-event in here
 Elseif %eventvalue1% =11
  LogEntry,'long-press'
  Let,1,1
   //Put your code for long-press-event in here
 Endif
Endon

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Switch input - Push button on longpress

#12 Post by chromo23 » 29 Oct 2023, 20:48

Also here i post what i wrote on github:

Did some testing.
Yeah it is confusing but in a way it makes sense.

The longpress event is triggered only if the button type and the longpress event type are matching.

eg. button type: Push Button Active High & Longpress event = Active on High -> works
button type: Push Button Active High & Longpress event = Active on LOW -> doesn´t

Which makes sense.. who needs a longpress event when the button is released.

Edit: Which also begs the question.. do we need the longpress event selection? It could be kind of set automatically regarding the switch type leaving it a en/disable option only

iz8mbw
Normal user
Posts: 35
Joined: 14 Apr 2023, 08:43
Location: Napoli, Italy

Re: Switch input - Push button on longpress

#13 Post by iz8mbw » 29 Oct 2023, 21:38

since it's a bug, please I'll prefer to talk about it on GitHub.
Thanks!

Post Reply

Who is online

Users browsing this forum: No registered users and 38 guests