@mschaeffler/node-red-logic 0.3.0 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/logic_and.js CHANGED
@@ -11,34 +11,42 @@ module.exports = function(RED) {
11
11
  this.minData = Number( config.minData );
12
12
 
13
13
  node.on('input', function(msg,send,done) {
14
- const payload = tools.property2boolean( RED.util.getMessageProperty( msg, node.property ) );
15
-
16
- if( payload !== null )
14
+ if( msg.reset || msg.topic==="init" )
15
+ {
16
+ context.set( "data", {} );
17
+ node.status( "" );
18
+ }
19
+ else
17
20
  {
18
- let data = context.get( "data" ) ?? {};
19
- data[msg.topic] = payload;
20
- context.set( "data", data );
21
+ const payload = tools.property2boolean( RED.util.getMessageProperty( msg, node.property ) );
21
22
 
22
- msg.topic = node.topic;
23
- msg.payload = true;
24
- msg.count = 0;
25
- for( const item in data )
23
+ if( payload !== null )
26
24
  {
27
- msg.count++;
28
- if( ! data[item] )
25
+ let data = context.get( "data" ) ?? {};
26
+ data[msg.topic] = payload;
27
+ context.set( "data", data );
28
+
29
+ msg.topic = node.topic;
30
+ msg.payload = true;
31
+ msg.count = 0;
32
+ for( const item in data )
29
33
  {
30
- msg.payload = false;
34
+ msg.count++;
35
+ if( ! data[item] )
36
+ {
37
+ msg.payload = false;
38
+ }
31
39
  }
32
- }
33
40
 
34
- if( msg.count >= node.minData )
35
- {
36
- node.status( msg.payload );
37
- send( msg );
38
- }
39
- else
40
- {
41
- node.status( "waiting for data" );
41
+ if( msg.count >= node.minData )
42
+ {
43
+ node.status( msg.payload );
44
+ send( msg );
45
+ }
46
+ else
47
+ {
48
+ node.status( "waiting for data" );
49
+ }
42
50
  }
43
51
  }
44
52
 
package/logic_bool.html CHANGED
@@ -37,7 +37,7 @@
37
37
  <input type="hidden" id="node-input-property-type">
38
38
  </div>
39
39
  <div class="form-row">
40
- <label for="node-input-showStatus"><i class="fa-star-o"></i> Status</label>
40
+ <label for="node-input-showStatus"><i class="fa fa-star-o"></i> Status</label>
41
41
  <input type="checkbox" id="node-input-showState" style="display:inline-block; width:20px; vertical-align:baseline;">
42
42
  </div>
43
43
  </script>
package/logic_or.js CHANGED
@@ -11,34 +11,42 @@ module.exports = function(RED) {
11
11
  this.minData = Number( config.minData );
12
12
 
13
13
  node.on('input', function(msg,send,done) {
14
- const payload = tools.property2boolean( RED.util.getMessageProperty( msg, node.property ) );
15
-
16
- if( payload !== null )
14
+ if( msg.reset || msg.topic==="init" )
15
+ {
16
+ context.set( "data", {} );
17
+ node.status( "" );
18
+ }
19
+ else
17
20
  {
18
- let data = context.get( "data" ) ?? {};
19
- data[msg.topic] = payload;
20
- context.set( "data", data );
21
+ const payload = tools.property2boolean( RED.util.getMessageProperty( msg, node.property ) );
21
22
 
22
- msg.topic = node.topic;
23
- msg.payload = false;
24
- msg.count = 0;
25
- for( const item in data )
23
+ if( payload !== null )
26
24
  {
27
- msg.count++;
28
- if( data[item] )
25
+ let data = context.get( "data" ) ?? {};
26
+ data[msg.topic] = payload;
27
+ context.set( "data", data );
28
+
29
+ msg.topic = node.topic;
30
+ msg.payload = false;
31
+ msg.count = 0;
32
+ for( const item in data )
29
33
  {
30
- msg.payload = true;
34
+ msg.count++;
35
+ if( data[item] )
36
+ {
37
+ msg.payload = true;
38
+ }
31
39
  }
32
- }
33
40
 
34
- if( msg.count >= node.minData )
35
- {
36
- node.status( msg.payload );
37
- send( msg );
38
- }
39
- else
40
- {
41
- node.status( "waiting for data" );
41
+ if( msg.count >= node.minData )
42
+ {
43
+ node.status( msg.payload );
44
+ send( msg );
45
+ }
46
+ else
47
+ {
48
+ node.status( "waiting for data" );
49
+ }
42
50
  }
43
51
  }
44
52
 
@@ -0,0 +1,81 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('fallingEdge',{
3
+ category: 'function',
4
+ color: "#C0DEED",
5
+ defaults: {
6
+ name:{value:""},
7
+ property:{value:"payload",required:true},
8
+ threshold:{value:"",required:true,validate:RED.validators.number()},
9
+ showState:{value:false}
10
+ },
11
+ inputs:1,
12
+ outputs:1,
13
+ icon: "falling-edge.png",
14
+ label: function() {
15
+ return this.name||"falling edge";
16
+ },
17
+ paletteLabel: "falling edge",
18
+ inputLabels: 'input',
19
+ outputLabels: 'edge trigger',
20
+ oneditprepare: function() {
21
+ $("#node-input-property").typedInput({
22
+ type:"msg",
23
+ types:["msg"],
24
+ typeField: "#node-input-property-type"
25
+ })
26
+ }
27
+ });
28
+ </script>
29
+
30
+ <script type="text/html" data-template-name="fallingEdge">
31
+ <div class="form-row">
32
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
33
+ <input type="text" id="node-input-name" placeholder="Name">
34
+ </div>
35
+ <div class="form-row">
36
+ <label for="node-input-input"><i class="fa fa-ellipsis-h"></i> Eigenschaft</label>
37
+ <input type="text" id="node-input-property">
38
+ <input type="hidden" id="node-input-property-type">
39
+ </div>
40
+ <div class="form-row">
41
+ <label for="node-input-threshold"><i class="fa fa-chevron-down"></i> Threshold</label>
42
+ <input type="text" id="node-input-threshold">
43
+ </div>
44
+ <div class="form-row">
45
+ <label for="node-input-showStatus"><i class="fa fa-star-o"></i> Status</label>
46
+ <input type="checkbox" id="node-input-showState" style="display:inline-block; width:20px; vertical-align:baseline;">
47
+ </div>
48
+ </script>
49
+
50
+ <script type="text/html" data-help-name="fallingEdge">
51
+
52
+ <p>Message is only forwarded, if the payload falls below a threshold value.</p>
53
+ <p>Each <code>topic</code> is treated seperatly.</p>
54
+
55
+ <h3>Input</h3>
56
+
57
+ <p>The message property to be used as payload can be defined with the <code>Property</code> property.</p>
58
+
59
+ <dl class="message-properties">
60
+ <dt>topic <span class="property-type">string</span></dt>
61
+ <dd> name of the input channel.</dd>
62
+ <dt>payload <span class="property-type"></span></dt>
63
+ <dd> input value for <code>topic</code>.</dd>
64
+ </dl>
65
+
66
+ <h3>Output</h3>
67
+
68
+ <p>Trigger message, in case a falling edge is detected.</p>
69
+
70
+ <h3>Parameter</h3>
71
+
72
+ <dl class="message-properties">
73
+ <dt>Property <span class="property-type">string</span></dt>
74
+ <dd> defines the message property to be used as payload.</dd>
75
+ <dt>Threshold <span class="property-type">number</span></dt>
76
+ <dd> threshold value for the edge detection.</dd>
77
+ <dt>Status <span class="property-type">boolean</span></dt>
78
+ <dd> shows the actual value as a node status.</dd>
79
+ </dl>
80
+
81
+ </script>
@@ -0,0 +1,52 @@
1
+ module.exports = function(RED) {
2
+
3
+ function FallingEdgeNode(config) {
4
+ RED.nodes.createNode(this,config);
5
+ //this.config = config;
6
+ var node = this;
7
+ var context = this.context();
8
+ this.property = config.property ?? "payload";
9
+ this.threshold = config.threshold;
10
+ this.showState = config.showState;
11
+
12
+ node.on('input', function(msg,send,done) {
13
+ if( msg.reset || msg.topic==="init" )
14
+ {
15
+ context.set( "data", {} );
16
+ node.status( "" );
17
+ }
18
+ else
19
+ {
20
+ msg.payload = Number( RED.util.getMessageProperty( msg, node.property ) );
21
+ let status = { fill:"gray", shape:"dot", text:msg.payload };
22
+
23
+ if( ! isNaN( msg.payload ) )
24
+ {
25
+ let data = context.get( "data" ) ?? {};
26
+ const last = data[msg.topic] ?? Number.MIN_SAFE_INTEGER;
27
+ if( msg.payload < this.threshold && this.threshold <= last )
28
+ {
29
+ status.fill = "green";
30
+ msg.edge = "falling";
31
+ send( msg );
32
+ }
33
+ data[msg.topic] = msg.payload;
34
+ context.set( "data", data );
35
+ }
36
+ else
37
+ {
38
+ status.fill = "red";
39
+ status.text = "not a Number";
40
+ }
41
+
42
+ if( node.showState )
43
+ {
44
+ node.status( status );
45
+ }
46
+ }
47
+ done();
48
+ });
49
+ }
50
+
51
+ RED.nodes.registerType("fallingEdge",FallingEdgeNode);
52
+ }
@@ -0,0 +1,103 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('hysteresisEdge',{
3
+ category: 'function',
4
+ color: "#C0DEED",
5
+ defaults: {
6
+ name:{value:""},
7
+ property:{value:"payload",required:true},
8
+ threshold_raise:{value:"",required:true,validate:RED.validators.number()},
9
+ threshold_fall:{value:"",required:true,validate:function(v){
10
+ const raise = $("#node-input-threshold_raise").length ? $("#node-input-threshold_raise").val() : this.threshold_raise;
11
+ return v!=='' && !isNaN(v) && Number(v)<raise;}
12
+ },
13
+ initial:{value:"none"},
14
+ showState:{value:false}
15
+ },
16
+ inputs:1,
17
+ outputs:1,
18
+ icon: "hysteresis.png",
19
+ label: function() {
20
+ return this.name||"hysteresis";
21
+ },
22
+ paletteLabel: "hysteresis",
23
+ inputLabels: 'input',
24
+ outputLabels: 'hysteresis trigger',
25
+ oneditprepare: function() {
26
+ $("#node-input-property").typedInput({
27
+ type:"msg",
28
+ types:["msg"],
29
+ typeField: "#node-input-property-type"
30
+ })
31
+ }
32
+ });
33
+ </script>
34
+
35
+ <script type="text/html" data-template-name="hysteresisEdge">
36
+ <div class="form-row">
37
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
38
+ <input type="text" id="node-input-name" placeholder="Name">
39
+ </div>
40
+ <div class="form-row">
41
+ <label for="node-input-input"><i class="fa fa-ellipsis-h"></i> Eigenschaft</label>
42
+ <input type="text" id="node-input-property">
43
+ <input type="hidden" id="node-input-property-type">
44
+ </div>
45
+ <div class="form-row">
46
+ <label for="node-input-threshold_raise"><i class="fa fa-chevron-up"></i> up threshold</label>
47
+ <input type="text" id="node-input-threshold_raise">
48
+ </div>
49
+ <div class="form-row">
50
+ <label for="node-input-threshold_fall"><i class="fa fa-chevron-down"></i> dn threshold</label>
51
+ <input type="text" id="node-input-threshold_fall">
52
+ </div>
53
+ <div class="form-row">
54
+ <label for="node-input-initial"><i class="fa fa-play"></i> 1st message</label>
55
+ <select id="node-input-initial">
56
+ <option value="none">None</option>
57
+ <option value="rising">Rising</option>
58
+ <option value="falling">Falling</option>
59
+ <option value="any">Any</option>
60
+ </select>
61
+ </div>
62
+ <div class="form-row">
63
+ <label for="node-input-showStatus"><i class="fa fa-star-o"></i> Status</label>
64
+ <input type="checkbox" id="node-input-showState" style="display:inline-block; width:20px; vertical-align:baseline;">
65
+ </div>
66
+ </script>
67
+
68
+ <script type="text/html" data-help-name="hysteresisEdge">
69
+
70
+ <p>Message is only forwarded, if the payload raises above an upper limit or falls below a lower limit.</p>
71
+ <p>Each <code>topic</code> is treated seperatly.</p>
72
+
73
+ <h3>Input</h3>
74
+
75
+ <p>The message property to be used as payload can be defined with the <code>Property</code> property.</p>
76
+
77
+ <dl class="message-properties">
78
+ <dt>topic <span class="property-type">string</span></dt>
79
+ <dd> name of the input channel.</dd>
80
+ <dt>payload <span class="property-type"></span></dt>
81
+ <dd> input value for <code>topic</code>.</dd>
82
+ </dl>
83
+
84
+ <h3>Output</h3>
85
+
86
+ <p>Trigger message, in case an edge is detected.</p>
87
+
88
+ <h3>Parameter</h3>
89
+
90
+ <dl class="message-properties">
91
+ <dt>Property <span class="property-type">string</span></dt>
92
+ <dd> defines the message property to be used as payload.</dd>
93
+ <dt>up Threshold <span class="property-type">number</span></dt>
94
+ <dd> threshold value for the raising edge detection.</dd>
95
+ <dt>d(ow)n Threshold <span class="property-type">number</span></dt>
96
+ <dd> threshold value for the falling edge detection.</dd>
97
+ <dt>1st message <span class="property-type">string</span></dt>
98
+ <dd> initial behaviour (None, Rising, Falling, Any).</dd>
99
+ <dt>Status <span class="property-type">boolean</span></dt>
100
+ <dd> shows the actual value as a node status.</dd>
101
+ </dl>
102
+
103
+ </script>
@@ -0,0 +1,81 @@
1
+ module.exports = function(RED) {
2
+
3
+ function HysteresisEdgeNode(config) {
4
+ RED.nodes.createNode(this,config);
5
+ //this.config = config;
6
+ var node = this;
7
+ var context = this.context();
8
+ this.property = config.property ?? "payload";
9
+ this.threshold_raise = config.threshold_raise;
10
+ this.threshold_fall = config.threshold_fall;
11
+ this.initial = config.initial;
12
+ this.showState = config.showState;
13
+
14
+ node.on('input', function(msg,send,done) {
15
+
16
+ if( msg.reset || msg.topic==="init" )
17
+ {
18
+ context.set( "data", {} );
19
+ node.status( "" );
20
+ }
21
+ else
22
+ {
23
+ msg.payload = Number( RED.util.getMessageProperty( msg, node.property ) );
24
+ let status = { fill:"gray", shape:"dot", text:msg.payload };
25
+
26
+ if( ! isNaN( msg.payload ) )
27
+ {
28
+ let data = context.get( "data" ) ?? {};
29
+ const last = data[msg.topic];
30
+
31
+ function sendMsg(edge)
32
+ {
33
+ status.fill = "green";
34
+ data[msg.topic].edge = edge;
35
+ msg.edge = edge;
36
+ send( msg );
37
+ }
38
+
39
+ if( last )
40
+ {
41
+ if( msg.payload > this.threshold_raise && this.threshold_raise >= last.value && last.edge != 'rising')
42
+ {
43
+ sendMsg( 'rising' );
44
+ }
45
+ else if( msg.payload < this.threshold_fall && this.threshold_fall <= last.value && last.edge != 'falling')
46
+ {
47
+ sendMsg( 'falling' );
48
+ }
49
+ }
50
+ else
51
+ {
52
+ data[msg.topic] = {};
53
+ if( this.initial in ['any','rising'] && msg.payload > this.threshold_raise )
54
+ {
55
+ sendMsg( 'rising' );
56
+ }
57
+ else if( this.initial in ['any','falling'] && msg.payload < this.threshold_fall )
58
+ {
59
+ sendMsg( 'falling' );
60
+ }
61
+ }
62
+ data[msg.topic].value = msg.payload;
63
+ context.set( "data", data );
64
+ }
65
+ else
66
+ {
67
+ status.fill = "red";
68
+ status.text = "not a Number";
69
+ }
70
+
71
+ if( node.showState )
72
+ {
73
+ node.status( status );
74
+ }
75
+ }
76
+ done();
77
+ });
78
+ }
79
+
80
+ RED.nodes.registerType("hysteresisEdge",HysteresisEdgeNode);
81
+ }
package/math_number.html CHANGED
@@ -37,7 +37,7 @@
37
37
  <input type="hidden" id="node-input-property-type">
38
38
  </div>
39
39
  <div class="form-row">
40
- <label for="node-input-showStatus"><i class="fa-star-o"></i> Status</label>
40
+ <label for="node-input-showStatus"><i class="fa fa-star-o"></i> Status</label>
41
41
  <input type="checkbox" id="node-input-showState" style="display:inline-block; width:20px; vertical-align:baseline;">
42
42
  </div>
43
43
  </script>
@@ -0,0 +1,81 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('raisingEdge',{
3
+ category: 'function',
4
+ color: "#C0DEED",
5
+ defaults: {
6
+ name:{value:""},
7
+ property:{value:"payload",required:true},
8
+ threshold:{value:"",required:true,validate:RED.validators.number()},
9
+ showState:{value:false}
10
+ },
11
+ inputs:1,
12
+ outputs:1,
13
+ icon: "raising-edge.png",
14
+ label: function() {
15
+ return this.name||"raising edge";
16
+ },
17
+ paletteLabel: "raising edge",
18
+ inputLabels: 'input',
19
+ outputLabels: 'edge trigger',
20
+ oneditprepare: function() {
21
+ $("#node-input-property").typedInput({
22
+ type:"msg",
23
+ types:["msg"],
24
+ typeField: "#node-input-property-type"
25
+ })
26
+ }
27
+ });
28
+ </script>
29
+
30
+ <script type="text/html" data-template-name="raisingEdge">
31
+ <div class="form-row">
32
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
33
+ <input type="text" id="node-input-name" placeholder="Name">
34
+ </div>
35
+ <div class="form-row">
36
+ <label for="node-input-input"><i class="fa fa-ellipsis-h"></i> Eigenschaft</label>
37
+ <input type="text" id="node-input-property">
38
+ <input type="hidden" id="node-input-property-type">
39
+ </div>
40
+ <div class="form-row">
41
+ <label for="node-input-threshold"><i class="fa fa-chevron-up"></i> Threshold</label>
42
+ <input type="text" id="node-input-threshold">
43
+ </div>
44
+ <div class="form-row">
45
+ <label for="node-input-showStatus"><i class="fa fa-star-o"></i> Status</label>
46
+ <input type="checkbox" id="node-input-showState" style="display:inline-block; width:20px; vertical-align:baseline;">
47
+ </div>
48
+ </script>
49
+
50
+ <script type="text/html" data-help-name="raisingEdge">
51
+
52
+ <p>Message is only forwarded, if the payload raises above a threshold value.</p>
53
+ <p>Each <code>topic</code> is treated seperatly.</p>
54
+
55
+ <h3>Input</h3>
56
+
57
+ <p>The message property to be used as payload can be defined with the <code>Property</code> property.</p>
58
+
59
+ <dl class="message-properties">
60
+ <dt>topic <span class="property-type">string</span></dt>
61
+ <dd> name of the input channel.</dd>
62
+ <dt>payload <span class="property-type"></span></dt>
63
+ <dd> input value for <code>topic</code>.</dd>
64
+ </dl>
65
+
66
+ <h3>Output</h3>
67
+
68
+ <p>Trigger message, in case a raising edge is detected.</p>
69
+
70
+ <h3>Parameter</h3>
71
+
72
+ <dl class="message-properties">
73
+ <dt>Property <span class="property-type">string</span></dt>
74
+ <dd> defines the message property to be used as payload.</dd>
75
+ <dt>Threshold <span class="property-type">number</span></dt>
76
+ <dd> threshold value for the edge detection.</dd>
77
+ <dt>Status <span class="property-type">boolean</span></dt>
78
+ <dd> shows the actual value as a node status.</dd>
79
+ </dl>
80
+
81
+ </script>
@@ -0,0 +1,52 @@
1
+ module.exports = function(RED) {
2
+
3
+ function RaisingEdgeNode(config) {
4
+ RED.nodes.createNode(this,config);
5
+ //this.config = config;
6
+ var node = this;
7
+ var context = this.context();
8
+ this.property = config.property ?? "payload";
9
+ this.threshold = config.threshold;
10
+ this.showState = config.showState;
11
+
12
+ node.on('input', function(msg,send,done) {
13
+ if( msg.reset || msg.topic==="init" )
14
+ {
15
+ context.set( "data", {} );
16
+ node.status( "" );
17
+ }
18
+ else
19
+ {
20
+ msg.payload = Number( RED.util.getMessageProperty( msg, node.property ) );
21
+ let status = { fill:"gray", shape:"dot", text:msg.payload };
22
+
23
+ if( ! isNaN( msg.payload ) )
24
+ {
25
+ let data = context.get( "data" ) ?? {};
26
+ const last = data[msg.topic] ?? Number.MAX_SAFE_INTEGER;
27
+ if( msg.payload > this.threshold && this.threshold >= last )
28
+ {
29
+ status.fill = "green";
30
+ msg.edge = "raising";
31
+ send( msg );
32
+ }
33
+ data[msg.topic] = msg.payload;
34
+ context.set( "data", data );
35
+ }
36
+ else
37
+ {
38
+ status.fill = "red";
39
+ status.text = "not a Number";
40
+ }
41
+
42
+ if( node.showState )
43
+ {
44
+ node.status( status );
45
+ }
46
+ }
47
+ done();
48
+ });
49
+ }
50
+
51
+ RED.nodes.registerType("raisingEdge",RaisingEdgeNode);
52
+ }
package/math_reduce.html CHANGED
@@ -42,6 +42,7 @@
42
42
  types:["msg"],
43
43
  typeField: "#node-input-property-type"
44
44
  });
45
+ /*
45
46
  $("#node-input-algo").typedInput({
46
47
  types:[{
47
48
  value:"algo",
@@ -53,7 +54,7 @@
53
54
  { value: "max", label: "Maximum" }
54
55
  ]
55
56
  }]
56
- })
57
+ })*/
57
58
  }
58
59
  });
59
60
  </script>
@@ -86,7 +87,13 @@
86
87
  </div>
87
88
  <div class="form-row">
88
89
  <label for="node-input-algo"><i class="fa fa-flask"></i> Algorithm</label>
89
- <input type="text" id="node-input-algo">
90
+ <select type="text" id="node-input-algo">
91
+ <option value="add">Adition</option>
92
+ <option value="mean">Mean Value</option>
93
+ <option value="prod">Product</option>
94
+ <option value="min">Minimum</option>
95
+ <option value="max">Maximum</option>
96
+ </select>
90
97
  </div>
91
98
  </script>
92
99
 
@@ -135,4 +142,14 @@
135
142
 
136
143
  <h3>Algorithms</h3>
137
144
 
145
+ <dl class="message-properties">
146
+ <table>
147
+ <tr><th>algorithm</th><th>description</th></tr>
148
+ <tr><td>add</td><td>ads up the <code>topic</code> channels</td></tr>
149
+ <tr><td>mean</td><td>averages the <code>topic</code> channels</td></tr>
150
+ <tr><td>prod</td><td>multiplies the <code>topic</code> channels</td></tr>
151
+ <tr><td>min</td><td>gets the minimal value of the <code>topic</code> channels</td></tr>
152
+ <tr><td>max</td><td>gets the maximal value of the <code>topic</code> channels</td></tr>
153
+ </table>
154
+
138
155
  </script>