[CCSDK-28] populated the seed code for dgbuilder
[ccsdk/distribution.git] / dgbuilder / core_nodes / core / 89-trigger.html
1 <!--
2   Copyright 2014 IBM Corp.
3
4   Licensed under the Apache License, Version 2.0 (the "License");
5   you may not use this file except in compliance with the License.
6   You may obtain a copy of the License at
7
8   http://www.apache.org/licenses/LICENSE-2.0
9
10   Unless required by applicable law or agreed to in writing, software
11   distributed under the License is distributed on an "AS IS" BASIS,
12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   See the License for the specific language governing permissions and
14   limitations under the License.
15 -->
16
17 <script type="text/x-red" data-template-name="trigger">
18     <div class="form-row">
19         <label for="node-input-op1type"><i class="fa fa-arrow-up"></i> Output</label>
20         <select id="node-input-op1type" style="width:73% !important">
21             <option value="val">the value below</option>
22             <option value="pay">the existing payload</option>
23             <option value="nul">nothing (no output)</option>
24         </select>
25     </div>
26     <div class="form-row" id="node-op1">
27         <label for="node-input-op1">&nbsp;</label>
28         <input type="text" id="node-input-op1">
29     </div>
30     <div class="form-row">
31         <label for="node-input-duration"><i class="fa fa-clock-o"></i> then wait</label>
32         <input type="text" id="node-input-duration" placeholder="250" style="direction:rtl; width:70px !important">
33         <select id="node-input-units" style="width:140px !important">
34             <option value="ms">Milliseconds</option>
35             <option value="s">Seconds</option>
36             <option value="min">Minutes</option>
37             <option value="hr">Hours</option>
38         </select>
39     </div>
40     <div class="form-row">
41         <label for="node-input-op2type"><i class="fa fa-arrow-down"></i> output</label>
42         <select id="node-input-op2type" style="width:73% !important">
43             <option value="val">the value below</option>
44             <option value="pay">the existing payload</option>
45             <option value="nul">nothing (no output)</option>
46         </select>
47     </div>
48     <div class="form-row" id="node-op2">
49         <label for="node-input-op2">&nbsp;</label>
50         <input type="text" id="node-input-op2">
51     </div>
52     <div class="form-row">
53         <label for="node-input-extend"><i class="fa fa-repeat"></i> and</label>
54         <select id="node-input-extend" style="width:73% !important">
55             <option value="false">don't extend the timer if retriggered</option>
56             <option value="true">extend the timer if retriggered</option>
57         </select>
58     </div>
59     <div class="form-row">
60         <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
61         <input type="text" id="node-input-name" placeholder="Name">
62     </div>
63     <!-- <div class="form-tips">Tip: Outputs can be values, null, {{templated}} or msg.payload<br/> -->
64     <div class="form-tips">Setting the timeout to 0 sets an infinite timeout = single shot.</div>
65     <script>
66     {
67         $("#node-input-op1type").change(function() {
68             if ($("#node-input-op1type").val() == "val") { $("#node-op1").show(); }
69             else { $("#node-op1").hide(); }
70         });
71         $("#node-input-op2type").change(function() {
72             if ($("#node-input-op2type").val() == "val") { $("#node-op2").show(); }
73             else { $("#node-op2").hide(); }
74         });
75     }
76     </script>
77 </script>
78
79 <script type="text/x-red" data-help-name="trigger">
80     <p>Creates two messages on the output separated by a timeout whenever ANY <b>msg</b> arrives on the input.</p>
81     <p>For example, this can be used to toggle a Raspberry PI GPIO pin on and off.</p>
82     <p>The two output states can be specified as can the duration of the timer.
83     Either output can be set to a value, or templated from the inbound
84     <b>msg</b> using mustache syntax. <pre>The payload is {{payload}}</pre></p>
85     <p>If the payload is an object then setting the output to <i>existing payload</i> will pass the complete payload object through.</p>
86     <p>Optionally the timer can be extended by being retriggered... or not.</p>
87     <p>By setting the first output to <i>nothing</i>, and selecting extend timer - a watchdog timer can be created.
88     No output will happen as long as repeated inputs occur within the timeout period.</p>
89     <p>Setting the timer to 0 creates an "infinite" timeout - the first output will happen but the second
90     never will, and neither can the first be retriggered - so a true one shot.</p>
91     <p>If a <b>msg.reset</b> property is present any timeout currently in progress
92     will be cleared and the second output will not happen.</p>
93 </script>
94
95 <script type="text/javascript">
96     RED.nodes.registerType('trigger',{
97         category: 'function',
98         color:"#E6E0F8",
99         defaults: {
100             op1: {value:"1"},
101             op2: {value:"0"},
102             op1type: {value:""},
103             op2type: {value:""},
104             duration: {value:"250",required:true,validate:RED.validators.number()},
105             extend: {value:"false"},
106             units: {value: "ms"},
107             name: {value:""}
108         },
109         inputs:1,
110         outputs:1,
111         icon: "trigger.png",
112         label: function() {
113             if (this.duration > 0) {
114                 return this.name||"trigger "+this.duration+this.units;
115             }
116             else {
117                 return this.name||"trigger once &infin;";
118             }
119         },
120         labelStyle: function() {
121             return this.name?"node_label_italic":"";
122         },
123         oneditprepare: function() {
124             $( "#node-input-duration" ).spinner({
125                 min:1,
126                 increment:25
127             });
128         }
129     });
130 </script>