@mschaeffler/node-red-logic 1.4.6 → 1.5.0
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_bool.js +1 -0
- package/logic_not.js +1 -0
- package/math_falling.js +1 -0
- package/math_hysteresis.html +7 -0
- package/math_hysteresis.js +36 -8
- package/math_mean.html +8 -1
- package/math_mean.js +10 -0
- package/math_minus.js +1 -0
- package/math_number.js +1 -0
- package/math_rising.js +1 -0
- package/math_statistics.js +4 -3
- package/package.json +4 -1
package/logic_bool.js
CHANGED
package/logic_not.js
CHANGED
package/math_falling.js
CHANGED
package/math_hysteresis.html
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
return v!=='' && !isNaN(v) && Number(v)<raise;}
|
|
13
13
|
},
|
|
14
14
|
initial:{value:"none"},
|
|
15
|
+
consecutive:{value:"1",required:true},
|
|
15
16
|
showState:{value:false}
|
|
16
17
|
},
|
|
17
18
|
inputs:1,
|
|
@@ -63,6 +64,10 @@
|
|
|
63
64
|
<option value="any">Any</option>
|
|
64
65
|
</select>
|
|
65
66
|
</div>
|
|
67
|
+
<div class="form-row">
|
|
68
|
+
<label for="node-input-consecutive"><i class="fa fa-line-chart"></i> Consecutive</label>
|
|
69
|
+
<input type="text" id="node-input-consecutive">
|
|
70
|
+
</div>
|
|
66
71
|
<div class="form-row">
|
|
67
72
|
<label for="node-input-showStatus"><i class="fa fa-star-o"></i> Status</label>
|
|
68
73
|
<input type="checkbox" id="node-input-showState" style="display:inline-block; width:20px; vertical-align:baseline;">
|
|
@@ -101,6 +106,8 @@
|
|
|
101
106
|
<dd> threshold value for the falling edge detection.</dd>
|
|
102
107
|
<dt>1st message <span class="property-type">string</span></dt>
|
|
103
108
|
<dd> initial behaviour (None, Rising, Falling, Any).</dd>
|
|
109
|
+
<dt>Consecutive <span class="property-type">number</span></dt>
|
|
110
|
+
<dd> number of consecutive frames to generate an output.</dd>
|
|
104
111
|
<dt>Status <span class="property-type">boolean</span></dt>
|
|
105
112
|
<dd> shows the actual value as a node status.</dd>
|
|
106
113
|
</dl>
|
package/math_hysteresis.js
CHANGED
|
@@ -10,6 +10,7 @@ module.exports = function(RED) {
|
|
|
10
10
|
this.threshold_rise = config.threshold_raise;
|
|
11
11
|
this.threshold_fall = config.threshold_fall;
|
|
12
12
|
this.initial = config.initial ?? "none";
|
|
13
|
+
this.consecutive = Number( config.consecutive ?? 1 );
|
|
13
14
|
this.showState = Boolean( config.showState );
|
|
14
15
|
if( this.propertyType === "jsonata" )
|
|
15
16
|
{
|
|
@@ -21,6 +22,9 @@ module.exports = function(RED) {
|
|
|
21
22
|
return;
|
|
22
23
|
}
|
|
23
24
|
}
|
|
25
|
+
node.cntRise = 0;
|
|
26
|
+
node.cntFall = 0;
|
|
27
|
+
node.status( "" );
|
|
24
28
|
|
|
25
29
|
node.on('input', function(msg,send,done) {
|
|
26
30
|
if( msg.invalid )
|
|
@@ -69,25 +73,50 @@ module.exports = function(RED) {
|
|
|
69
73
|
function sendMsg(edge)
|
|
70
74
|
{
|
|
71
75
|
status.fill = "green";
|
|
72
|
-
data[msg.topic].edge
|
|
76
|
+
data[msg.topic].edge = edge;
|
|
77
|
+
data[msg.topic].value = msg.payload;
|
|
73
78
|
msg.edge = edge;
|
|
74
79
|
send( msg );
|
|
75
80
|
}
|
|
76
81
|
|
|
77
82
|
if( last )
|
|
78
83
|
{
|
|
79
|
-
if( msg.payload > node.threshold_rise && node.threshold_rise >= last.value && last.edge != 'rising')
|
|
84
|
+
if( msg.payload > node.threshold_rise && node.threshold_rise >= last.value && last.edge != 'rising' )
|
|
80
85
|
{
|
|
81
|
-
|
|
86
|
+
if( ++node.cntRise >= node.consecutive )
|
|
87
|
+
{
|
|
88
|
+
sendMsg( 'rising' );
|
|
89
|
+
node.cntRise = 0;
|
|
90
|
+
}
|
|
91
|
+
else
|
|
92
|
+
{
|
|
93
|
+
status.fill = "yellow";
|
|
94
|
+
}
|
|
95
|
+
node.cntFall = 0;
|
|
82
96
|
}
|
|
83
|
-
else if( msg.payload < node.threshold_fall && node.threshold_fall <= last.value && last.edge != 'falling')
|
|
97
|
+
else if( msg.payload < node.threshold_fall && node.threshold_fall <= last.value && last.edge != 'falling' )
|
|
84
98
|
{
|
|
85
|
-
|
|
99
|
+
if( ++node.cntFall >= node.consecutive )
|
|
100
|
+
{
|
|
101
|
+
sendMsg( 'falling' );
|
|
102
|
+
node.cntFall = 0;
|
|
103
|
+
}
|
|
104
|
+
else
|
|
105
|
+
{
|
|
106
|
+
status.fill = "yellow";
|
|
107
|
+
}
|
|
108
|
+
node.cntRise = 0;
|
|
109
|
+
}
|
|
110
|
+
else
|
|
111
|
+
{
|
|
112
|
+
node.cntRise = 0;
|
|
113
|
+
node.cntFall = 0;
|
|
114
|
+
data[msg.topic].value = msg.payload;
|
|
86
115
|
}
|
|
87
116
|
}
|
|
88
117
|
else
|
|
89
118
|
{
|
|
90
|
-
data[msg.topic] = {};
|
|
119
|
+
data[msg.topic] = { value: msg.payload };
|
|
91
120
|
if( ['any','rising'].includes(node.initial) && msg.payload > node.threshold_rise )
|
|
92
121
|
{
|
|
93
122
|
sendMsg( 'rising' );
|
|
@@ -97,13 +126,12 @@ module.exports = function(RED) {
|
|
|
97
126
|
sendMsg( 'falling' );
|
|
98
127
|
}
|
|
99
128
|
}
|
|
100
|
-
data[msg.topic].value = msg.payload;
|
|
101
129
|
context.set( "data", data );
|
|
102
130
|
}
|
|
103
131
|
else
|
|
104
132
|
{
|
|
105
133
|
status.fill = "red";
|
|
106
|
-
|
|
134
|
+
status.text = "not a Number";
|
|
107
135
|
}
|
|
108
136
|
|
|
109
137
|
if( node.showState )
|
package/math_mean.html
CHANGED
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
return v!=='' && !isNaN(v) && Number(v)>0;}
|
|
14
14
|
},
|
|
15
15
|
filter:{value:"0", validate:RED.validators.number()},
|
|
16
|
-
zeroIsZero:{value:false}
|
|
16
|
+
zeroIsZero:{value:false},
|
|
17
|
+
showState:{value:false}
|
|
17
18
|
},
|
|
18
19
|
inputs:1,
|
|
19
20
|
outputs:1,
|
|
@@ -62,6 +63,10 @@
|
|
|
62
63
|
<label for="node-input-zeroIsZero"><i class="fa fa-exclamation-circle"></i> Null ist Null</label>
|
|
63
64
|
<input type="checkbox" id="node-input-zeroIsZero" style="display:inline-block; width:20px; vertical-align:baseline;">
|
|
64
65
|
</div>
|
|
66
|
+
<div class="form-row">
|
|
67
|
+
<label for="node-input-showStatus"><i class="fa fa-star-o"></i> Status</label>
|
|
68
|
+
<input type="checkbox" id="node-input-showState" style="display:inline-block; width:20px; vertical-align:baseline;">
|
|
69
|
+
</div>
|
|
65
70
|
</script>
|
|
66
71
|
|
|
67
72
|
<script type="text/html" data-help-name="mean">
|
|
@@ -101,5 +106,7 @@
|
|
|
101
106
|
<dd> send output only after this time.</dd>
|
|
102
107
|
<dt>Null ist NUll <span class="property-type">boolean</span></dt>
|
|
103
108
|
<dd> If 0 is received, 0 is send immediately.</dd>
|
|
109
|
+
<dt>Status <span class="property-type">boolean</span></dt>
|
|
110
|
+
<dd> shows the actual value as a node status.</dd>
|
|
104
111
|
</dl>
|
|
105
112
|
</script>
|
package/math_mean.js
CHANGED
|
@@ -11,6 +11,7 @@ module.exports = function(RED) {
|
|
|
11
11
|
this.minData = Number( config.minData ?? 1 );
|
|
12
12
|
this.filter = Number( config.filter ?? 0 )*1000;
|
|
13
13
|
this.zeroIsZero = Boolean( config.zeroIsZero );
|
|
14
|
+
this.showState = Boolean( config.showState );
|
|
14
15
|
if( this.propertyType === "jsonata" )
|
|
15
16
|
{
|
|
16
17
|
try {
|
|
@@ -21,6 +22,15 @@ module.exports = function(RED) {
|
|
|
21
22
|
return;
|
|
22
23
|
}
|
|
23
24
|
}
|
|
25
|
+
this.oldStatus = this.status;
|
|
26
|
+
this.status = function(state)
|
|
27
|
+
{
|
|
28
|
+
if( node.showState )
|
|
29
|
+
{
|
|
30
|
+
node.oldStatus( state );
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
node.oldStatus( "" );
|
|
24
34
|
|
|
25
35
|
node.on('input', function(msg,send,done) {
|
|
26
36
|
if( msg.invalid )
|
package/math_minus.js
CHANGED
package/math_number.js
CHANGED
package/math_rising.js
CHANGED
package/math_statistics.js
CHANGED
|
@@ -7,8 +7,8 @@ module.exports = function(RED) {
|
|
|
7
7
|
var context = this.context();
|
|
8
8
|
this.property = config.property || "payload";
|
|
9
9
|
this.propertyType = config.propertyType ?? "msg";
|
|
10
|
-
this.deltaTime = Number( config.deltaTime )*1000;
|
|
11
|
-
this.minData = Number( config.minData );
|
|
10
|
+
this.deltaTime = Number( config.deltaTime ?? 60 )*1000;
|
|
11
|
+
this.minData = Number( config.minData ?? 1 );
|
|
12
12
|
if( this.propertyType === "jsonata" )
|
|
13
13
|
{
|
|
14
14
|
try {
|
|
@@ -33,7 +33,6 @@ module.exports = function(RED) {
|
|
|
33
33
|
}
|
|
34
34
|
else
|
|
35
35
|
{
|
|
36
|
-
const now = Date.now();
|
|
37
36
|
function getPayload(callback)
|
|
38
37
|
{
|
|
39
38
|
if( node.propertyPrepared )
|
|
@@ -57,6 +56,7 @@ module.exports = function(RED) {
|
|
|
57
56
|
}
|
|
58
57
|
getPayload( function(value)
|
|
59
58
|
{
|
|
59
|
+
const now = Date.now();
|
|
60
60
|
const payload = Number( value );
|
|
61
61
|
if( ! isNaN( payload ) )
|
|
62
62
|
{
|
|
@@ -73,6 +73,7 @@ module.exports = function(RED) {
|
|
|
73
73
|
if( item.length >= node.minData )
|
|
74
74
|
{
|
|
75
75
|
msg.stat = {
|
|
76
|
+
value: payload,
|
|
76
77
|
count: item.length,
|
|
77
78
|
min: Number.MAX_SAFE_INTEGER,
|
|
78
79
|
max: Number.MIN_SAFE_INTEGER };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mschaeffler/node-red-logic",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "nodes for simple operations.",
|
|
5
5
|
"license": "LGPL-2.1",
|
|
6
6
|
"homepage": "https://github.com/m-schaeffler/node-red-my-nodes/tree/main/node-red-logic",
|
|
@@ -35,5 +35,8 @@
|
|
|
35
35
|
"author": {
|
|
36
36
|
"name": "Mathias Schäffler",
|
|
37
37
|
"url": "https://github.com/m-schaeffler"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"test": "mocha \"test/*_spec.js\""
|
|
38
41
|
}
|
|
39
42
|
}
|