Long press button delay

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
trojan-tj1
New user
Posts: 7
Joined: 03 Apr 2018, 14:18

Long press button delay

#1 Post by trojan-tj1 » 03 Apr 2018, 20:35

Hello! I'm new to using EspEasy. I've been trying to figure it out for a few days, but I can not do anything. My task is simple. There is 1 switch. With this switch I want to operate 2 relays. By means of short and long pressing of the button. Switch is a simple press button. I can do it with the help of this rule:

on sw1#value1 do
if [sw1#value1] = 0
timerSet, 1, 1
endon

on rules#timer=1 do
if [sw1#value1] = 1
...
else
...
endif
endon

But there is a problem - too long delay with a short press. A whole second. And it's very inconvenient. I have read that for timerSet you can not use a value of less than 1 second. I read about the delay function. I'm trying to use it instead of timerSet, but nothing happens. Maybe someone can help me?

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Long press button delay

#2 Post by grovkillen » 03 Apr 2018, 20:46

Delay will not work since it's essentially pausing the unit until the delay time is up.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

Martinus

Re: Long press button delay

#3 Post by Martinus » 03 Apr 2018, 21:09

Maybe use the new way to directly read gpio :
[Plugin#GPIO#Pinstate#13]
After 250 mS delay?

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: Long press button delay

#4 Post by toffel969 » 05 Apr 2018, 09:45

Martinus wrote: 03 Apr 2018, 21:09 Maybe use the new way to directly read gpio :
[Plugin#GPIO#Pinstate#13]
After 250 mS delay?
Hi martinus

Is there doc/info available on that new feature, so that we can update the wiki ( couldn't find a PR on github)? Does this also work on mcp/pcf gpio? Since when is it part of the nightlies?

regards
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8

Martinus

Re: Long press button delay

#5 Post by Martinus » 05 Apr 2018, 12:46

toffel969 wrote: 05 Apr 2018, 09:45Hi martinus

Is there doc/info available on that new feature, so that we can update the wiki ( couldn't find a PR on github)? Does this also work on mcp/pcf gpio? Since when is it part of the nightlies?

regards
I think that Wiki should reflect the current stable to avoid confusion. This feature was added on Dev branch on March 7th. It's preliminary work on build-in GPIO only.
Waiting to be evaluated by it's requester on issue:
https://github.com/letscontrolit/ESPEasy/issues/1018

trojan-tj1
New user
Posts: 7
Joined: 03 Apr 2018, 14:18

Re: Long press button delay

#6 Post by trojan-tj1 » 15 Apr 2018, 13:12

Does anyone have more detailed information on the use of the new way to directly read gpio? For example, [Plugin#GPIO#Pinstate#13]

trojan-tj1
New user
Posts: 7
Joined: 03 Apr 2018, 14:18

Re: Long press button delay

#7 Post by trojan-tj1 » 15 Apr 2018, 19:44

At last I managed to realize what I wanted. Nowhere in the forums did not find a solution. Through trial and error, I made this rule. I turn to the experts. What can you say about this rule?

on System#Boot do
TaskValueSet 2,1,1 //dummy variable for long press
TaskValueSet 2,2,1 //dummy variable for short press
endon

on sw1#value1 do //my button
delay 250
if [Plugin#GPIO#Pinstate#12]=0
event,longpush
else
event,shortpush
endif
endon

on longpush do
if [counter#longcount]=1
gpio,14,0
TaskValueSet 2,1,0
else
gpio,14,1
TaskValueSet 2,1,1
endon

on shortpush do
if [counter#shortcount]=1
gpio,16,0
TaskValueSet 2,2,0
else
gpio,16,1
TaskValueSet 2,2,1
endon

TD-er
Core team member
Posts: 8729
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Long press button delay

#8 Post by TD-er » 16 Apr 2018, 00:28

My first reaction is, don't use GPIO 16.
Please have a look at the usable pins here: https://www.esp8266.com/wiki/doku.php?i ... llocations

Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests