Long Press, Double Tap, Single Click

1336 views
Skip to first unread message

Dmitry Novikov

unread,
Oct 26, 2017, 4:09:13 AM10/26/17
to Node-RED
Hi how can i get these event when pressing a button. For example pressed is 1, released is 0. Any ideas?

Julian Knight

unread,
Oct 27, 2017, 7:48:50 AM10/27/17
to Node-RED
What kind of button? Where? How is it connected?

Dmitry Novikov

unread,
Oct 29, 2017, 5:53:48 AM10/29/17
to Node-RED
Let it be just Inject "0" for release or inject "1" for press. For my case is KNX button press events.

пятница, 27 октября 2017 г., 14:48:50 UTC+3 пользователь Julian Knight написал:

Dave C-J

unread,
Oct 29, 2017, 6:07:39 AM10/29/17
to node...@googlegroups.com
I think we are struggling with what you mean by button...
the physical button on the wall ? - KNX button on the wall ? a button connected to a raspberry pi GPIO pin ?
a software button ? button in the Node-RED editor ? button in the Node-RED dashboard ?
They all generate events and are all buttons...
For KNX specifically there are two nodes in http://flows.nodered.org that may help - but ...

Dmitry Novikov

unread,
Oct 29, 2017, 8:46:36 AM10/29/17
to Node-RED
When user presses KNX switch i get JSON:
{"dstgad":"0/0/1","value":1}
when user releases button i get 
{"dstgad":"0/0/1","value":0}

So my purpose is to detect what kind of event happened, single, double or long press.

воскресенье, 29 октября 2017 г., 13:07:39 UTC+3 пользователь Dave C-J написал:

Neil Cherry

unread,
Oct 29, 2017, 9:46:34 AM10/29/17
to Node-RED
On Sunday, October 29, 2017 at 8:46:36 AM UTC-4, Dmitry Novikov wrote:
When user presses KNX switch i get JSON:
{"dstgad":"0/0/1","value":1}
when user releases button i get 
{"dstgad":"0/0/1","value":0}

So my purpose is to detect what kind of event happened, single, double or long press.

Dmitry this sounds like a tough one. You'll need timers and you'll need to monitor the press time (for long press) and release time and then multiple press/release cycles. I'm not sure how to exactly attach such a problem. I haven't given it that much thought.
 

Neil Cherry

unread,
Oct 29, 2017, 9:46:57 AM10/29/17
to Node-RED

On Sunday, October 29, 2017 at 6:07:39 AM UTC-4, Dave C-J wrote:
I think we are struggling with what you mean by button...
the physical button on the wall ? - KNX button on the wall ? a button connected to a raspberry pi GPIO pin ?
a software button ? button in the Node-RED editor ? button in the Node-RED dashboard ?

Sounds like Dimtry has physical KNX buttons. So a user would press/release/press/release for a double tap and generally this should occur in x  amount of time. The general logic needs to occur in node red.

Francois Vander Linden

unread,
Oct 29, 2017, 10:49:17 AM10/29/17
to Node-RED
Dmitry, you really should use the abilities of your KNX module: most of the KNX buttons have the ability to detect short and long press and this should be programmed/configured on the ETS/KNX side, it will be much more precise ...

If you want to time press/release events, simply use a function and store the time ... once you have two times, use the difference... something along those lines ...

if (msg.value==1) t0 = Date.now();  // press
if (msg.value==0) { // release ...
   t1 = Date.now();
   tdiff = t1-t0;         // milliseconds between two events ...
   if (tdiff>longpress_time)  { // do stuff related to long press }
   else //short press

Colin Law

unread,
Oct 29, 2017, 10:55:06 AM10/29/17
to node...@googlegroups.com
You would need to save the times in the node context so that they are
available when the next message comes in. However if the KNX module
can do the timing for you that would be much better.

Colin

On 29 October 2017 at 14:49, Francois Vander Linden
> --
> http://nodered.org
>
> Join us on Slack to continue the conversation: http://nodered.org/slack
> ---
> You received this message because you are subscribed to the Google Groups
> "Node-RED" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to node-red+u...@googlegroups.com.
> To post to this group, send email to node...@googlegroups.com.
> Visit this group at https://groups.google.com/group/node-red.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/node-red/d6e630d0-e4a9-4851-a874-67a1ddb48d66%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

Francois Vander Linden

unread,
Oct 29, 2017, 10:56:54 AM10/29/17
to Node-RED
you're right, store the values of t0 & t1 in the global or flow context ...

Dave C-J

unread,
Oct 29, 2017, 11:04:40 AM10/29/17
to node...@googlegroups.com
No. Just save them in the local function node context. No need to spread any further. 
--
Sent from phone.

Dmitry Novikov

unread,
Oct 30, 2017, 2:42:05 AM10/30/17
to Node-RED
Thanks for help, check this out:

Введите код...[{"id":"a9c55fd4.82672","type":"timed-counter","z":"d89be59e.ba1768","name":"","timelimit":"350","withhold":true,"fixedtimeout":false,"x":720,"y":100,"wires":[["237fbd8d.65fc62"]]},{"id":"85d0c07d.15e0a","type":"switch","z":"d89be59e.ba1768","name":"","property":"payload.value","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"0","vt":"str"}],"checkall":"false","outputs":2,"x":570,"y":120,"wires":[["a9c55fd4.82672"],["18e0387b.ea2578"]]},{"id":"237fbd8d.65fc62","type":"function","z":"d89be59e.ba1768","name":"Single/Double/Long","func":"if (msg.count >= 2 && msg.payload.value == '1')\n{\n    msg.payload = \"double\";\n    context.set('pressTime',null);\n    context.set('releaseTime',null);\n    return msg;\n}\nif (msg.count == 1){\n    if (msg.payload.value == '1') {   //Pressed\n        var pressTime = Date.now(); \n        //node.send({payload:{pressTime}});\n        context.set('pressTime',pressTime);\n    }\n    var pressTime = context.get('pressTime');\n    //node.send({payload:{pressTime}});\n    if (msg.payload.value === '0' && pressTime !== null) {  //Released\n        releaseTime = Date.now(); \n        \n        var timeDiff = releaseTime-pressTime;\n        //node.send({payload:{timeDiff}});\n        if (releaseTime-pressTime>350)  {msg.payload = \"long\";}\n        else {msg.payload = \"single\";}\n        context.set('pressTime',null);\n        context.set('releaseTime',null);\n        return msg;\n    }\n}","outputs":1,"noerr":0,"x":920,"y":120,"wires":[["1443e91e.a865f7"]]},{"id":"1443e91e.a865f7","type":"debug","z":"d89be59e.ba1768","name":"","active":true,"console":"false","complete":"payload","x":1116.250015258789,"y":120.00000190734863,"wires":[]},{"id":"18e0387b.ea2578","type":"timed-counter","z":"d89be59e.ba1768","name":"","timelimit":"350","withhold":true,"fixedtimeout":false,"x":720,"y":140,"wires":[["237fbd8d.65fc62"]]},{"id":"1a9a8e65.6b1be2","type":"delay","z":"d89be59e.ba1768","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"8","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":410,"y":80,"wires":[["85d0c07d.15e0a"]]},{"id":"b9b30572.fcccc8","type":"function","z":"d89be59e.ba1768","name":"Double","func":"node.send({ payload:    {\"value\":\"1\"}   });\nnode.send({ payload:    {\"value\":\"0\"}   });\nnode.send({ payload:    {\"value\":\"1\"}   });\nnode.send({ payload:    {\"value\":\"0\"}   });","outputs":1,"noerr":0,"x":260,"y":80,"wires":[["1a9a8e65.6b1be2"]]},{"id":"c070a0c4.511e2","type":"function","z":"d89be59e.ba1768","name":"Single","func":"node.send({ payload:    {\"value\":\"1\"}   });\nnode.send({ payload:    {\"value\":\"0\"}   });","outputs":1,"noerr":0,"x":250,"y":120,"wires":[["8c72414c.45415"]]},{"id":"188314e7.76f2cb","type":"function","z":"d89be59e.ba1768","name":"Long","func":"node.send({ payload:    {\"value\":\"1\"}   });\nnode.send({ payload:    {\"value\":\"0\"}   });","outputs":1,"noerr":0,"x":250,"y":160,"wires":[["fbb67950.2b6248"]]},{"id":"fbb67950.2b6248","type":"delay","z":"d89be59e.ba1768","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":410,"y":160,"wires":[["85d0c07d.15e0a"]]},{"id":"c9b9fb0.db1da08","type":"inject","z":"d89be59e.ba1768","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":120,"y":80,"wires":[["b9b30572.fcccc8"]]},{"id":"fc31dc2c.6a786","type":"inject","z":"d89be59e.ba1768","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":120,"y":120,"wires":[["c070a0c4.511e2"]]},{"id":"cf82dabb.70e798","type":"inject","z":"d89be59e.ba1768","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":120,"y":160,"wires":[["188314e7.76f2cb"]]},{"id":"8c72414c.45415","type":"delay","z":"d89be59e.ba1768","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"4","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":410,"y":120,"wires":[["85d0c07d.15e0a"]]},{"id":"dba1821f.4756c","type":"comment","z":"d89be59e.ba1768","name":"Emulation of press/release events","info":"","x":340,"y":40,"wires":[]}]



воскресенье, 29 октября 2017 г., 18:04:40 UTC+3 пользователь Dave C-J написал:

Dmitry Novikov

unread,
Oct 30, 2017, 2:54:18 AM10/30/17
to Node-RED
About embedded KNX logic, keypad has a lot of options(dimming, shade control, so on) but in key switch mode does not have parameters for detection short/double/long presses. If somebody knows how to calculate it on KNX side i would be very grateful for an advise !

понедельник, 30 октября 2017 г., 9:42:05 UTC+3 пользователь Dmitry Novikov написал:

Colin Law

unread,
Oct 30, 2017, 3:13:06 AM10/30/17
to node...@googlegroups.com
You have not made it clear whether it is working out whether you are asking for more help.

Colin


--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.

To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

Dmitry Novikov

unread,
Oct 30, 2017, 3:45:26 AM10/30/17
to Node-RED
As for me it works fine, shared it for anyone. Maybe not optimal

понедельник, 30 октября 2017 г., 10:13:06 UTC+3 пользователь Colin Law написал:
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.

To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
Reply all
Reply to author
Forward
0 new messages