forked from dkern/node-red-counter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcounter.html
99 lines (97 loc) · 4.49 KB
/
counter.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<script type="text/x-red" data-template-name="counter">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-init"><i class="fa fa-cog"></i> Initial Count</label>
<input type="text" id="node-input-init" placeholder="0">
</div>
<div class="form-row">
<label for="node-input-step"><i class="fa fa-forward"></i> Default Step</label>
<input type="text" id="node-input-step" placeholder="1">
</div>
<div class="form-row">
<label for="node-input-lower"><i class="fa fa-arrow-down"></i> Lower Limit</label>
<input type="text" id="node-input-lower" placeholder="unlimited">
</div>
<div class="form-row">
<label for="node-input-upper"><i class="fa fa-arrow-up"></i> Upper Limit</label>
<input type="text" id="node-input-upper" placeholder="unlimited">
</div>
<div class="form-row">
<label for="node-input-mode"><i class="fa fa-tasks"></i> Mode</label>
<select id="node-input-mode">
<option value="increment">increment</option>
<option value="decrement">decrement</option>
</select>
</div>
<div class="form-row">
<label for="node-input-outputs"><i class="fa fa-random"></i> Outputs</label>
<select id="node-input-outputs">
<option value="1">single (1)</option>
<option value="2">split (2)</option>
</select>
</div>
</script>
<script type="text/x-red" data-help-name="counter">
<p>A simple node to create a counter with messages.</p>
<p>By default the counter will be incremented for every inbound message and append the current count to <code>msg.count</code>.</p>
<p><strong>Configuration</strong><br/>
<ul>
<li><code>Initial Count</code>: The initial count can be set in the configuration. By default it will be <strong>zero</strong> at start.</li>
<li><code>Default Step</code>: Default amount that will be incremented or decremented on every incoming message.</li>
<li><code>Lower Limit</code>: Optional limitation of the lower count limit. Will add <code>countLowerLimitReached</code> to <code>msg</code> if reached.</li>
<li><code>Upper Limit</code>: Optional limitation of the upper count limit. Will add <code>countUpperLimitReached</code> to <code>msg</code> if reached.</li>
<li><code>Mode</code>: Determine if count value should be incremented or decremented on every incoming message.</li>
<li><code>Outputs</code>: Selects the output format of the counter. For more info read below.</li>
</ul>
</p>
<p><strong>Output</strong><br/>
There are two output options for the counter value:
<ul>
<li><strong>single</strong>: The actual count will be appended to <code>msg.count</code> of the original <code>msg</code>.</li>
<li><strong>split</strong>: The node will become two outputs, first will return the count as <code>msg.payload</code> and possible limitation info, the second returns the untouched original <code>msg</code>.</li>
</ul>
</p>
<p><strong>Control</strong><br/>
It's possible to control the counter with incoming <code>msg</code> properties:
<ul>
<li><code>msg.increment</code>: counter will be incremented by the given value.</li>
<li><code>msg.decrement</code>: counter will be decremented by the given value.</li>
<li><code>msg.reset</code>: resets the counter to it's initial count, or to the given value, when it's a number.</li>
</ul>
</p>
</script>
<script type="text/javascript">
RED.nodes.registerType("counter", {
category: "function",
defaults: {
name: {value:""},
init: {value:"0"},
step: {value:"1"},
lower: {value:null},
upper: {value:null},
mode: {value:"increment"},
outputs: {value:"1"}
},
color:"#e2d96e",
inputs: 1,
outputs: 1,
icon: "counter.png",
label: function() {
return this.name || "counter";
},
labelStyle: function() {
return this.name ? "node_label_italic" : "";
},
oneditprepare: function() {
this.init = this.init || 0;
this.step = this.step || 1;
this.lower = this.lower || null;
this.upper = this.upper || null;
this.mode = this.mode || "increment";
this.outputs = this.outputs || 1;
}
});
</script>