@mschaeffler/node-red-logic 1.4.7 → 2.0.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/math_falling.html +7 -0
- package/math_falling.js +19 -4
- package/math_hysteresis.html +5 -10
- package/math_hysteresis.js +24 -15
- package/math_rising.html +7 -0
- package/math_rising.js +19 -4
- package/package.json +1 -1
package/math_falling.html
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
property:{value:"payload",required:true},
|
|
8
8
|
propertyType:{value:"msg"},
|
|
9
9
|
threshold:{value:"",required:true,validate:RED.validators.number()},
|
|
10
|
+
consecutive:{value:"1",required:true},
|
|
10
11
|
showState:{value:false}
|
|
11
12
|
},
|
|
12
13
|
inputs:1,
|
|
@@ -45,6 +46,10 @@
|
|
|
45
46
|
<label for="node-input-threshold"><i class="fa fa-chevron-down"></i> Threshold</label>
|
|
46
47
|
<input type="text" id="node-input-threshold">
|
|
47
48
|
</div>
|
|
49
|
+
<div class="form-row">
|
|
50
|
+
<label for="node-input-consecutive"><i class="fa fa-line-chart"></i> Consecutive</label>
|
|
51
|
+
<input type="text" id="node-input-consecutive">
|
|
52
|
+
</div>
|
|
48
53
|
<div class="form-row">
|
|
49
54
|
<label for="node-input-showStatus"><i class="fa fa-star-o"></i> Status</label>
|
|
50
55
|
<input type="checkbox" id="node-input-showState" style="display:inline-block; width:20px; vertical-align:baseline;">
|
|
@@ -79,6 +84,8 @@
|
|
|
79
84
|
<dd> defines the message property to be used as payload.</dd>
|
|
80
85
|
<dt>Threshold <span class="property-type">number</span></dt>
|
|
81
86
|
<dd> threshold value for the edge detection.</dd>
|
|
87
|
+
<dt>Consecutive <span class="property-type">number</span></dt>
|
|
88
|
+
<dd> number of consecutive frames to generate an output.</dd>
|
|
82
89
|
<dt>Status <span class="property-type">boolean</span></dt>
|
|
83
90
|
<dd> shows the actual value as a node status.</dd>
|
|
84
91
|
</dl>
|
package/math_falling.js
CHANGED
|
@@ -8,6 +8,7 @@ module.exports = function(RED) {
|
|
|
8
8
|
this.property = config.property ?? "payload";
|
|
9
9
|
this.propertyType = config.propertyType ?? "msg";
|
|
10
10
|
this.threshold = config.threshold;
|
|
11
|
+
this.consecutive = Number( config.consecutive ?? 1 );
|
|
11
12
|
this.showState = Boolean( config.showState );
|
|
12
13
|
if( this.propertyType === "jsonata" )
|
|
13
14
|
{
|
|
@@ -19,6 +20,7 @@ module.exports = function(RED) {
|
|
|
19
20
|
return;
|
|
20
21
|
}
|
|
21
22
|
}
|
|
23
|
+
node.cntFall = 0;
|
|
22
24
|
node.status( "" );
|
|
23
25
|
|
|
24
26
|
node.on('input', function(msg,send,done) {
|
|
@@ -66,11 +68,24 @@ module.exports = function(RED) {
|
|
|
66
68
|
const last = data[msg.topic] ?? Number.MIN_SAFE_INTEGER;
|
|
67
69
|
if( msg.payload < node.threshold && node.threshold <= last )
|
|
68
70
|
{
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
if( ++node.cntFall >= node.consecutive )
|
|
72
|
+
{
|
|
73
|
+
status.fill = "green";
|
|
74
|
+
msg.edge = "falling";
|
|
75
|
+
send( msg );
|
|
76
|
+
data[msg.topic] = msg.payload;
|
|
77
|
+
node.cntFall = 0;
|
|
78
|
+
}
|
|
79
|
+
else
|
|
80
|
+
{
|
|
81
|
+
status.fill = "yellow";
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
else
|
|
85
|
+
{
|
|
86
|
+
node.cntFall = 0;
|
|
87
|
+
data[msg.topic] = msg.payload;
|
|
72
88
|
}
|
|
73
|
-
data[msg.topic] = msg.payload;
|
|
74
89
|
context.set( "data", data );
|
|
75
90
|
}
|
|
76
91
|
else
|
package/math_hysteresis.html
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
const raise = $("#node-input-threshold_raise").length ? $("#node-input-threshold_raise").val() : this.threshold_raise;
|
|
12
12
|
return v!=='' && !isNaN(v) && Number(v)<raise;}
|
|
13
13
|
},
|
|
14
|
-
|
|
14
|
+
consecutive:{value:"1",required:true},
|
|
15
15
|
showState:{value:false}
|
|
16
16
|
},
|
|
17
17
|
inputs:1,
|
|
@@ -55,13 +55,8 @@
|
|
|
55
55
|
<input type="text" id="node-input-threshold_fall">
|
|
56
56
|
</div>
|
|
57
57
|
<div class="form-row">
|
|
58
|
-
<label for="node-input-
|
|
59
|
-
<
|
|
60
|
-
<option value="none">None</option>
|
|
61
|
-
<option value="rising">Rising</option>
|
|
62
|
-
<option value="falling">Falling</option>
|
|
63
|
-
<option value="any">Any</option>
|
|
64
|
-
</select>
|
|
58
|
+
<label for="node-input-consecutive"><i class="fa fa-line-chart"></i> Consecutive</label>
|
|
59
|
+
<input type="text" id="node-input-consecutive">
|
|
65
60
|
</div>
|
|
66
61
|
<div class="form-row">
|
|
67
62
|
<label for="node-input-showStatus"><i class="fa fa-star-o"></i> Status</label>
|
|
@@ -99,8 +94,8 @@
|
|
|
99
94
|
<dd> threshold value for the rising edge detection.</dd>
|
|
100
95
|
<dt>d(ow)n Threshold <span class="property-type">number</span></dt>
|
|
101
96
|
<dd> threshold value for the falling edge detection.</dd>
|
|
102
|
-
<dt>
|
|
103
|
-
<dd>
|
|
97
|
+
<dt>Consecutive <span class="property-type">number</span></dt>
|
|
98
|
+
<dd> number of consecutive frames to generate an output.</dd>
|
|
104
99
|
<dt>Status <span class="property-type">boolean</span></dt>
|
|
105
100
|
<dd> shows the actual value as a node status.</dd>
|
|
106
101
|
</dl>
|
package/math_hysteresis.js
CHANGED
|
@@ -9,7 +9,7 @@ module.exports = function(RED) {
|
|
|
9
9
|
this.propertyType = config.propertyType ?? "msg";
|
|
10
10
|
this.threshold_rise = config.threshold_raise;
|
|
11
11
|
this.threshold_fall = config.threshold_fall;
|
|
12
|
-
this.
|
|
12
|
+
this.consecutive = Number( config.consecutive ?? 1 );
|
|
13
13
|
this.showState = Boolean( config.showState );
|
|
14
14
|
if( this.propertyType === "jsonata" )
|
|
15
15
|
{
|
|
@@ -21,6 +21,8 @@ module.exports = function(RED) {
|
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
+
node.cntRise = 0;
|
|
25
|
+
node.cntFall = 0;
|
|
24
26
|
node.status( "" );
|
|
25
27
|
|
|
26
28
|
node.on('input', function(msg,send,done) {
|
|
@@ -70,41 +72,48 @@ module.exports = function(RED) {
|
|
|
70
72
|
function sendMsg(edge)
|
|
71
73
|
{
|
|
72
74
|
status.fill = "green";
|
|
73
|
-
data[msg.topic]
|
|
75
|
+
data[msg.topic] = edge;
|
|
76
|
+
context.set( "data", data );
|
|
74
77
|
msg.edge = edge;
|
|
75
78
|
send( msg );
|
|
76
79
|
}
|
|
77
80
|
|
|
78
|
-
if( last )
|
|
81
|
+
if( msg.payload > node.threshold_rise && last != 'rising' )
|
|
79
82
|
{
|
|
80
|
-
if(
|
|
83
|
+
if( ++node.cntRise >= node.consecutive )
|
|
81
84
|
{
|
|
82
85
|
sendMsg( 'rising' );
|
|
86
|
+
node.cntRise = 0;
|
|
83
87
|
}
|
|
84
|
-
else
|
|
88
|
+
else
|
|
85
89
|
{
|
|
86
|
-
|
|
90
|
+
status.fill = "yellow";
|
|
87
91
|
}
|
|
92
|
+
node.cntFall = 0;
|
|
88
93
|
}
|
|
89
|
-
else
|
|
94
|
+
else if( msg.payload < node.threshold_fall && last != 'falling' )
|
|
90
95
|
{
|
|
91
|
-
|
|
92
|
-
if( ['any','rising'].includes(node.initial) && msg.payload > node.threshold_rise )
|
|
96
|
+
if( ++node.cntFall >= node.consecutive )
|
|
93
97
|
{
|
|
94
|
-
sendMsg( '
|
|
98
|
+
sendMsg( 'falling' );
|
|
99
|
+
node.cntFall = 0;
|
|
95
100
|
}
|
|
96
|
-
else
|
|
101
|
+
else
|
|
97
102
|
{
|
|
98
|
-
|
|
103
|
+
status.fill = "yellow";
|
|
99
104
|
}
|
|
105
|
+
node.cntRise = 0;
|
|
106
|
+
}
|
|
107
|
+
else
|
|
108
|
+
{
|
|
109
|
+
node.cntRise = 0;
|
|
110
|
+
node.cntFall = 0;
|
|
100
111
|
}
|
|
101
|
-
data[msg.topic].value = msg.payload;
|
|
102
|
-
context.set( "data", data );
|
|
103
112
|
}
|
|
104
113
|
else
|
|
105
114
|
{
|
|
106
115
|
status.fill = "red";
|
|
107
|
-
|
|
116
|
+
status.text = "not a Number";
|
|
108
117
|
}
|
|
109
118
|
|
|
110
119
|
if( node.showState )
|
package/math_rising.html
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
property:{value:"payload",required:true},
|
|
8
8
|
propertyType:{value:"msg"},
|
|
9
9
|
threshold:{value:"",required:true,validate:RED.validators.number()},
|
|
10
|
+
consecutive:{value:"1",required:true},
|
|
10
11
|
showState:{value:false}
|
|
11
12
|
},
|
|
12
13
|
inputs:1,
|
|
@@ -45,6 +46,10 @@
|
|
|
45
46
|
<label for="node-input-threshold"><i class="fa fa-chevron-up"></i> Threshold</label>
|
|
46
47
|
<input type="text" id="node-input-threshold">
|
|
47
48
|
</div>
|
|
49
|
+
<div class="form-row">
|
|
50
|
+
<label for="node-input-consecutive"><i class="fa fa-line-chart"></i> Consecutive</label>
|
|
51
|
+
<input type="text" id="node-input-consecutive">
|
|
52
|
+
</div>
|
|
48
53
|
<div class="form-row">
|
|
49
54
|
<label for="node-input-showStatus"><i class="fa fa-star-o"></i> Status</label>
|
|
50
55
|
<input type="checkbox" id="node-input-showState" style="display:inline-block; width:20px; vertical-align:baseline;">
|
|
@@ -79,6 +84,8 @@
|
|
|
79
84
|
<dd> defines the message property to be used as payload.</dd>
|
|
80
85
|
<dt>Threshold <span class="property-type">number</span></dt>
|
|
81
86
|
<dd> threshold value for the edge detection.</dd>
|
|
87
|
+
<dt>Consecutive <span class="property-type">number</span></dt>
|
|
88
|
+
<dd> number of consecutive frames to generate an output.</dd>
|
|
82
89
|
<dt>Status <span class="property-type">boolean</span></dt>
|
|
83
90
|
<dd> shows the actual value as a node status.</dd>
|
|
84
91
|
</dl>
|
package/math_rising.js
CHANGED
|
@@ -8,6 +8,7 @@ module.exports = function(RED) {
|
|
|
8
8
|
this.property = config.property ?? "payload";
|
|
9
9
|
this.propertyType = config.propertyType ?? "msg";
|
|
10
10
|
this.threshold = config.threshold;
|
|
11
|
+
this.consecutive = Number( config.consecutive ?? 1 );
|
|
11
12
|
this.showState = Boolean( config.showState );
|
|
12
13
|
if( this.propertyType === "jsonata" )
|
|
13
14
|
{
|
|
@@ -19,6 +20,7 @@ module.exports = function(RED) {
|
|
|
19
20
|
return;
|
|
20
21
|
}
|
|
21
22
|
}
|
|
23
|
+
node.cntRise = 0;
|
|
22
24
|
node.status( "" );
|
|
23
25
|
|
|
24
26
|
node.on('input', function(msg,send,done) {
|
|
@@ -67,11 +69,24 @@ module.exports = function(RED) {
|
|
|
67
69
|
const last = data[msg.topic] ?? Number.MAX_SAFE_INTEGER;
|
|
68
70
|
if( msg.payload > node.threshold && node.threshold >= last )
|
|
69
71
|
{
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
if( ++node.cntRise >= node.consecutive )
|
|
73
|
+
{
|
|
74
|
+
status.fill = "green";
|
|
75
|
+
msg.edge = "rising";
|
|
76
|
+
send( msg );
|
|
77
|
+
data[msg.topic] = msg.payload;
|
|
78
|
+
node.cntRise = 0;
|
|
79
|
+
}
|
|
80
|
+
else
|
|
81
|
+
{
|
|
82
|
+
status.fill = "yellow";
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else
|
|
86
|
+
{
|
|
87
|
+
node.cntRise = 0;
|
|
88
|
+
data[msg.topic] = msg.payload;
|
|
73
89
|
}
|
|
74
|
-
data[msg.topic] = msg.payload;
|
|
75
90
|
context.set( "data", data );
|
|
76
91
|
}
|
|
77
92
|
else
|
package/package.json
CHANGED