@mschaeffler/node-red-logic 1.5.0 → 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 +0 -12
- package/math_hysteresis.js +19 -37
- 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,6 @@
|
|
|
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
|
-
initial:{value:"none"},
|
|
15
14
|
consecutive:{value:"1",required:true},
|
|
16
15
|
showState:{value:false}
|
|
17
16
|
},
|
|
@@ -55,15 +54,6 @@
|
|
|
55
54
|
<label for="node-input-threshold_fall"><i class="fa fa-chevron-down"></i> dn threshold</label>
|
|
56
55
|
<input type="text" id="node-input-threshold_fall">
|
|
57
56
|
</div>
|
|
58
|
-
<div class="form-row">
|
|
59
|
-
<label for="node-input-initial"><i class="fa fa-play"></i> 1st message</label>
|
|
60
|
-
<select id="node-input-initial">
|
|
61
|
-
<option value="none">None</option>
|
|
62
|
-
<option value="rising">Rising</option>
|
|
63
|
-
<option value="falling">Falling</option>
|
|
64
|
-
<option value="any">Any</option>
|
|
65
|
-
</select>
|
|
66
|
-
</div>
|
|
67
57
|
<div class="form-row">
|
|
68
58
|
<label for="node-input-consecutive"><i class="fa fa-line-chart"></i> Consecutive</label>
|
|
69
59
|
<input type="text" id="node-input-consecutive">
|
|
@@ -104,8 +94,6 @@
|
|
|
104
94
|
<dd> threshold value for the rising edge detection.</dd>
|
|
105
95
|
<dt>d(ow)n Threshold <span class="property-type">number</span></dt>
|
|
106
96
|
<dd> threshold value for the falling edge detection.</dd>
|
|
107
|
-
<dt>1st message <span class="property-type">string</span></dt>
|
|
108
|
-
<dd> initial behaviour (None, Rising, Falling, Any).</dd>
|
|
109
97
|
<dt>Consecutive <span class="property-type">number</span></dt>
|
|
110
98
|
<dd> number of consecutive frames to generate an output.</dd>
|
|
111
99
|
<dt>Status <span class="property-type">boolean</span></dt>
|
package/math_hysteresis.js
CHANGED
|
@@ -9,7 +9,6 @@ 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.initial = config.initial ?? "none";
|
|
13
12
|
this.consecutive = Number( config.consecutive ?? 1 );
|
|
14
13
|
this.showState = Boolean( config.showState );
|
|
15
14
|
if( this.propertyType === "jsonata" )
|
|
@@ -73,60 +72,43 @@ module.exports = function(RED) {
|
|
|
73
72
|
function sendMsg(edge)
|
|
74
73
|
{
|
|
75
74
|
status.fill = "green";
|
|
76
|
-
data[msg.topic]
|
|
77
|
-
|
|
75
|
+
data[msg.topic] = edge;
|
|
76
|
+
context.set( "data", data );
|
|
78
77
|
msg.edge = edge;
|
|
79
78
|
send( msg );
|
|
80
79
|
}
|
|
81
80
|
|
|
82
|
-
if( last )
|
|
81
|
+
if( msg.payload > node.threshold_rise && last != 'rising' )
|
|
83
82
|
{
|
|
84
|
-
if(
|
|
83
|
+
if( ++node.cntRise >= node.consecutive )
|
|
85
84
|
{
|
|
86
|
-
|
|
87
|
-
{
|
|
88
|
-
sendMsg( 'rising' );
|
|
89
|
-
node.cntRise = 0;
|
|
90
|
-
}
|
|
91
|
-
else
|
|
92
|
-
{
|
|
93
|
-
status.fill = "yellow";
|
|
94
|
-
}
|
|
95
|
-
node.cntFall = 0;
|
|
96
|
-
}
|
|
97
|
-
else if( msg.payload < node.threshold_fall && node.threshold_fall <= last.value && last.edge != 'falling' )
|
|
98
|
-
{
|
|
99
|
-
if( ++node.cntFall >= node.consecutive )
|
|
100
|
-
{
|
|
101
|
-
sendMsg( 'falling' );
|
|
102
|
-
node.cntFall = 0;
|
|
103
|
-
}
|
|
104
|
-
else
|
|
105
|
-
{
|
|
106
|
-
status.fill = "yellow";
|
|
107
|
-
}
|
|
85
|
+
sendMsg( 'rising' );
|
|
108
86
|
node.cntRise = 0;
|
|
109
87
|
}
|
|
110
88
|
else
|
|
111
89
|
{
|
|
112
|
-
|
|
113
|
-
node.cntFall = 0;
|
|
114
|
-
data[msg.topic].value = msg.payload;
|
|
90
|
+
status.fill = "yellow";
|
|
115
91
|
}
|
|
92
|
+
node.cntFall = 0;
|
|
116
93
|
}
|
|
117
|
-
else
|
|
94
|
+
else if( msg.payload < node.threshold_fall && last != 'falling' )
|
|
118
95
|
{
|
|
119
|
-
|
|
120
|
-
if( ['any','rising'].includes(node.initial) && msg.payload > node.threshold_rise )
|
|
96
|
+
if( ++node.cntFall >= node.consecutive )
|
|
121
97
|
{
|
|
122
|
-
sendMsg( '
|
|
98
|
+
sendMsg( 'falling' );
|
|
99
|
+
node.cntFall = 0;
|
|
123
100
|
}
|
|
124
|
-
else
|
|
101
|
+
else
|
|
125
102
|
{
|
|
126
|
-
|
|
103
|
+
status.fill = "yellow";
|
|
127
104
|
}
|
|
105
|
+
node.cntRise = 0;
|
|
106
|
+
}
|
|
107
|
+
else
|
|
108
|
+
{
|
|
109
|
+
node.cntRise = 0;
|
|
110
|
+
node.cntFall = 0;
|
|
128
111
|
}
|
|
129
|
-
context.set( "data", data );
|
|
130
112
|
}
|
|
131
113
|
else
|
|
132
114
|
{
|
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