@mschaeffler/node-red-logic 1.4.7 → 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.
@@ -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>
@@ -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,8 @@ module.exports = function(RED) {
21
22
  return;
22
23
  }
23
24
  }
25
+ node.cntRise = 0;
26
+ node.cntFall = 0;
24
27
  node.status( "" );
25
28
 
26
29
  node.on('input', function(msg,send,done) {
@@ -70,25 +73,50 @@ module.exports = function(RED) {
70
73
  function sendMsg(edge)
71
74
  {
72
75
  status.fill = "green";
73
- data[msg.topic].edge = edge;
76
+ data[msg.topic].edge = edge;
77
+ data[msg.topic].value = msg.payload;
74
78
  msg.edge = edge;
75
79
  send( msg );
76
80
  }
77
81
 
78
82
  if( last )
79
83
  {
80
- 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' )
81
85
  {
82
- sendMsg( 'rising' );
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;
83
96
  }
84
- 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' )
85
98
  {
86
- sendMsg( 'falling' );
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;
87
115
  }
88
116
  }
89
117
  else
90
118
  {
91
- data[msg.topic] = {};
119
+ data[msg.topic] = { value: msg.payload };
92
120
  if( ['any','rising'].includes(node.initial) && msg.payload > node.threshold_rise )
93
121
  {
94
122
  sendMsg( 'rising' );
@@ -98,13 +126,12 @@ module.exports = function(RED) {
98
126
  sendMsg( 'falling' );
99
127
  }
100
128
  }
101
- data[msg.topic].value = msg.payload;
102
129
  context.set( "data", data );
103
130
  }
104
131
  else
105
132
  {
106
133
  status.fill = "red";
107
- status.text = "not a Number";
134
+ status.text = "not a Number";
108
135
  }
109
136
 
110
137
  if( node.showState )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mschaeffler/node-red-logic",
3
- "version": "1.4.7",
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",