@mschaeffler/node-red-logic 2.3.3 → 3.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 CHANGED
@@ -8,6 +8,8 @@
8
8
  propertyType:{value:"msg"},
9
9
  threshold:{value:"",required:true,validate:RED.validators.number()},
10
10
  consecutive:{value:"1",required:true},
11
+ output:{value:true,required:true},
12
+ outputType:{value:"bool"},
11
13
  showState:{value:false}
12
14
  },
13
15
  inputs:1,
@@ -28,6 +30,11 @@
28
30
  types:["msg","jsonata"],
29
31
  typeField: "#node-input-propertyType"
30
32
  })
33
+ $("#node-input-output").typedInput({
34
+ type:"bool",
35
+ types:["str","num","bool","json"],
36
+ typeField: "#node-input-outputType"
37
+ })
31
38
  }
32
39
  });
33
40
  </script>
@@ -38,7 +45,7 @@
38
45
  <input type="text" id="node-input-name" placeholder="Name">
39
46
  </div>
40
47
  <div class="form-row">
41
- <label for="node-input-input"><i class="fa fa-ellipsis-h"></i> Eigenschaft</label>
48
+ <label for="node-input-property"><i class="fa fa-ellipsis-h"></i> Eigenschaft</label>
42
49
  <input type="text" id="node-input-property">
43
50
  <input type="hidden" id="node-input-propertyType">
44
51
  </div>
@@ -50,6 +57,11 @@
50
57
  <label for="node-input-consecutive"><i class="fa fa-line-chart"></i> Consecutive</label>
51
58
  <input type="text" id="node-input-consecutive">
52
59
  </div>
60
+ <div class="form-row">
61
+ <label for="node-input-output"><i class="fa fa-sign-out"></i> Output</label>
62
+ <input type="text" id="node-input-output">
63
+ <input type="hidden" id="node-input-outputType">
64
+ </div>
53
65
  <div class="form-row">
54
66
  <label for="node-input-showStatus"><i class="fa fa-star-o"></i> Status</label>
55
67
  <input type="checkbox" id="node-input-showState" style="display:inline-block; width:20px; vertical-align:baseline;">
@@ -86,6 +98,8 @@
86
98
  <dd> threshold value for the edge detection.</dd>
87
99
  <dt>Consecutive <span class="property-type">number</span></dt>
88
100
  <dd> number of consecutive frames to generate an output.</dd>
101
+ <dt>Output <span class="property-type">multi</span></dt>
102
+ <dd> Value to be sent in case of a falling edge.</dd>
89
103
  <dt>Status <span class="property-type">boolean</span></dt>
90
104
  <dd> shows the actual value as a node status.</dd>
91
105
  </dl>
package/math_falling.js CHANGED
@@ -1,4 +1,5 @@
1
1
  module.exports = function(RED) {
2
+ var tools = require('./tools.js');
2
3
 
3
4
  function FallingEdgeNode(config) {
4
5
  RED.nodes.createNode(this,config);
@@ -7,8 +8,9 @@ module.exports = function(RED) {
7
8
  var context = this.context();
8
9
  this.property = config.property ?? "payload";
9
10
  this.propertyType = config.propertyType ?? "msg";
10
- this.threshold = config.threshold;
11
+ this.threshold = Number( config.threshold );
11
12
  this.consecutive = Number( config.consecutive ?? 1 );
13
+ this.output = tools.convertTypedInput( config.output ?? "true", config.outputType ?? "bool" );
12
14
  this.showState = Boolean( config.showState );
13
15
  if( this.propertyType === "jsonata" )
14
16
  {
@@ -59,21 +61,22 @@ module.exports = function(RED) {
59
61
  }
60
62
  getPayload( function(value)
61
63
  {
62
- msg.payload = Number( value );
63
- let status = { fill:"gray", shape:"dot", text:msg.payload };
64
+ msg.value = Number( value );
65
+ let status = { fill:"gray", shape:"dot", text:msg.value };
64
66
 
65
- if( ! isNaN( msg.payload ) )
67
+ if( ! isNaN( msg.value ) )
66
68
  {
67
69
  let data = context.get( "data" ) ?? {};
68
70
  const last = data[msg.topic] ?? Number.MIN_SAFE_INTEGER;
69
- if( msg.payload < node.threshold && node.threshold <= last )
71
+ if( msg.value < node.threshold && node.threshold <= last )
70
72
  {
71
73
  if( ++node.cntFall >= node.consecutive )
72
74
  {
73
75
  status.fill = "green";
74
- msg.edge = "falling";
76
+ msg.payload = node.output;
77
+ msg.edge = "falling";
75
78
  send( msg );
76
- data[msg.topic] = msg.payload;
79
+ data[msg.topic] = msg.value;
77
80
  node.cntFall = 0;
78
81
  }
79
82
  else
@@ -84,7 +87,7 @@ module.exports = function(RED) {
84
87
  else
85
88
  {
86
89
  node.cntFall = 0;
87
- data[msg.topic] = msg.payload;
90
+ data[msg.topic] = msg.value;
88
91
  }
89
92
  context.set( "data", data );
90
93
  }
@@ -12,6 +12,10 @@
12
12
  return v!=='' && !isNaN(v) && Number(v)<raise;}
13
13
  },
14
14
  consecutive:{value:"1",required:true},
15
+ outputRise:{value:true,required:true},
16
+ outputRiseType:{value:"bool"},
17
+ outputFall:{value:false,required:true},
18
+ outputFallType:{value:"bool"},
15
19
  showState:{value:false}
16
20
  },
17
21
  inputs:1,
@@ -32,6 +36,16 @@
32
36
  types:["msg","jsonata"],
33
37
  typeField: "#node-input-propertyType"
34
38
  })
39
+ $("#node-input-outputRise").typedInput({
40
+ type:"bool",
41
+ types:["str","num","bool","json"],
42
+ typeField: "#node-input-outputRiseType"
43
+ })
44
+ $("#node-input-outputFall").typedInput({
45
+ type:"bool",
46
+ types:["str","num","bool","json"],
47
+ typeField: "#node-input-outputFallType"
48
+ })
35
49
  }
36
50
  });
37
51
  </script>
@@ -58,6 +72,16 @@
58
72
  <label for="node-input-consecutive"><i class="fa fa-line-chart"></i> Consecutive</label>
59
73
  <input type="text" id="node-input-consecutive">
60
74
  </div>
75
+ <div class="form-row">
76
+ <label for="node-input-outputRise"><i class="fa fa-sign-out"></i> rise Output</label>
77
+ <input type="text" id="node-input-outputRise">
78
+ <input type="hidden" id="node-input-outputRiseType">
79
+ </div>
80
+ <div class="form-row">
81
+ <label for="node-input-outputFall"><i class="fa fa-sign-out"></i> fall Output</label>
82
+ <input type="text" id="node-input-outputFall">
83
+ <input type="hidden" id="node-input-outputFallType">
84
+ </div>
61
85
  <div class="form-row">
62
86
  <label for="node-input-showStatus"><i class="fa fa-star-o"></i> Status</label>
63
87
  <input type="checkbox" id="node-input-showState" style="display:inline-block; width:20px; vertical-align:baseline;">
@@ -96,6 +120,10 @@
96
120
  <dd> threshold value for the falling edge detection.</dd>
97
121
  <dt>Consecutive <span class="property-type">number</span></dt>
98
122
  <dd> number of consecutive frames to generate an output.</dd>
123
+ <dt>rise Output <span class="property-type">multi</span></dt>
124
+ <dd> Value to be sent in case of a rising edge.</dd>
125
+ <dt>fall Output <span class="property-type">multi</span></dt>
126
+ <dd> Value to be sent in case of a falling edge.</dd>
99
127
  <dt>Status <span class="property-type">boolean</span></dt>
100
128
  <dd> shows the actual value as a node status.</dd>
101
129
  </dl>
@@ -1,4 +1,5 @@
1
1
  module.exports = function(RED) {
2
+ var tools = require('./tools.js');
2
3
 
3
4
  function HysteresisEdgeNode(config) {
4
5
  RED.nodes.createNode(this,config);
@@ -7,9 +8,11 @@ module.exports = function(RED) {
7
8
  var context = this.context();
8
9
  this.property = config.property ?? "payload";
9
10
  this.propertyType = config.propertyType ?? "msg";
10
- this.threshold_rise = config.threshold_raise;
11
- this.threshold_fall = config.threshold_fall;
11
+ this.threshold_rise = Number( config.threshold_raise );
12
+ this.threshold_fall = Number( config.threshold_fall );
12
13
  this.consecutive = Number( config.consecutive ?? 1 );
14
+ this.outputRise = tools.convertTypedInput( config.outputRise ?? "true", config.outputRiseType ?? "bool" );
15
+ this.outputFall = tools.convertTypedInput( config.outputFall ?? "false",config.outputFallType ?? "bool" );
13
16
  this.showState = Boolean( config.showState );
14
17
  if( this.propertyType === "jsonata" )
15
18
  {
@@ -61,28 +64,29 @@ module.exports = function(RED) {
61
64
  }
62
65
  getPayload( function(value)
63
66
  {
64
- msg.payload = Number( value );
65
- let status = { fill:"gray", shape:"dot", text:msg.payload.toPrecision(4) };
67
+ msg.value = Number( value );
68
+ let data = context.get( "data" ) ?? {};
69
+ let status = { fill:data[msg.topic]?.status??"gray", shape:"dot", text:msg.value.toPrecision(4) };
66
70
 
67
- if( ! isNaN( msg.payload ) )
71
+ if( ! isNaN( msg.value ) )
68
72
  {
69
- let data = context.get( "data" ) ?? {};
70
- const last = data[msg.topic];
73
+ const last = data[msg.topic]?.edge;
71
74
 
72
75
  function sendMsg(edge)
73
76
  {
74
- status.fill = "green";
75
- data[msg.topic] = edge;
77
+ status.fill = edge ? "green" : "gray";
78
+ data[msg.topic] = { edge:edge, status:status.fill };
76
79
  context.set( "data", data );
77
- msg.edge = edge;
80
+ msg.payload = edge ? node.outputRise : node.outputFall;
81
+ msg.edge = edge ? "rising" : 'falling';
78
82
  send( msg );
79
83
  }
80
84
 
81
- if( msg.payload > node.threshold_rise && last != 'rising' )
85
+ if( msg.value > node.threshold_rise && last !== true )
82
86
  {
83
87
  if( ++node.cntRise >= node.consecutive )
84
88
  {
85
- sendMsg( 'rising' );
89
+ sendMsg( true );
86
90
  node.cntRise = 0;
87
91
  }
88
92
  else
@@ -91,11 +95,11 @@ module.exports = function(RED) {
91
95
  }
92
96
  node.cntFall = 0;
93
97
  }
94
- else if( msg.payload < node.threshold_fall && last != 'falling' )
98
+ else if( msg.value < node.threshold_fall && last !== false )
95
99
  {
96
100
  if( ++node.cntFall >= node.consecutive )
97
101
  {
98
- sendMsg( 'falling' );
102
+ sendMsg( false );
99
103
  node.cntFall = 0;
100
104
  }
101
105
  else
package/math_rising.html CHANGED
@@ -8,6 +8,8 @@
8
8
  propertyType:{value:"msg"},
9
9
  threshold:{value:"",required:true,validate:RED.validators.number()},
10
10
  consecutive:{value:"1",required:true},
11
+ output:{value:true,required:true},
12
+ outputType:{value:"bool"},
11
13
  showState:{value:false}
12
14
  },
13
15
  inputs:1,
@@ -28,6 +30,11 @@
28
30
  types:["msg","jsonata"],
29
31
  typeField: "#node-input-propertyType"
30
32
  })
33
+ $("#node-input-output").typedInput({
34
+ type:"bool",
35
+ types:["str","num","bool","json"],
36
+ typeField: "#node-input-outputType"
37
+ })
31
38
  }
32
39
  });
33
40
  </script>
@@ -38,7 +45,7 @@
38
45
  <input type="text" id="node-input-name" placeholder="Name">
39
46
  </div>
40
47
  <div class="form-row">
41
- <label for="node-input-input"><i class="fa fa-ellipsis-h"></i> Eigenschaft</label>
48
+ <label for="node-input-property"><i class="fa fa-ellipsis-h"></i> Eigenschaft</label>
42
49
  <input type="text" id="node-input-property">
43
50
  <input type="hidden" id="node-input-propertyType">
44
51
  </div>
@@ -50,6 +57,11 @@
50
57
  <label for="node-input-consecutive"><i class="fa fa-line-chart"></i> Consecutive</label>
51
58
  <input type="text" id="node-input-consecutive">
52
59
  </div>
60
+ <div class="form-row">
61
+ <label for="node-input-output"><i class="fa fa-sign-out"></i> Output</label>
62
+ <input type="text" id="node-input-output">
63
+ <input type="hidden" id="node-input-outputType">
64
+ </div>
53
65
  <div class="form-row">
54
66
  <label for="node-input-showStatus"><i class="fa fa-star-o"></i> Status</label>
55
67
  <input type="checkbox" id="node-input-showState" style="display:inline-block; width:20px; vertical-align:baseline;">
@@ -86,6 +98,8 @@
86
98
  <dd> threshold value for the edge detection.</dd>
87
99
  <dt>Consecutive <span class="property-type">number</span></dt>
88
100
  <dd> number of consecutive frames to generate an output.</dd>
101
+ <dt>Output <span class="property-type">multi</span></dt>
102
+ <dd> Value to be sent in case of a rising edge.</dd>
89
103
  <dt>Status <span class="property-type">boolean</span></dt>
90
104
  <dd> shows the actual value as a node status.</dd>
91
105
  </dl>
package/math_rising.js CHANGED
@@ -1,4 +1,5 @@
1
1
  module.exports = function(RED) {
2
+ var tools = require('./tools.js');
2
3
 
3
4
  function RaisingEdgeNode(config) {
4
5
  RED.nodes.createNode(this,config);
@@ -7,8 +8,9 @@ module.exports = function(RED) {
7
8
  var context = this.context();
8
9
  this.property = config.property ?? "payload";
9
10
  this.propertyType = config.propertyType ?? "msg";
10
- this.threshold = config.threshold;
11
+ this.threshold = Number( config.threshold );
11
12
  this.consecutive = Number( config.consecutive ?? 1 );
13
+ this.output = tools.convertTypedInput( config.output ?? "true", config.outputType ?? "bool" );
12
14
  this.showState = Boolean( config.showState );
13
15
  if( this.propertyType === "jsonata" )
14
16
  {
@@ -60,21 +62,22 @@ module.exports = function(RED) {
60
62
  }
61
63
  getPayload( function(value)
62
64
  {
63
- msg.payload = Number( value );
64
- let status = { fill:"gray", shape:"dot", text:msg.payload };
65
+ msg.value = Number( value );
66
+ let status = { fill:"gray", shape:"dot", text:msg.value };
65
67
 
66
- if( ! isNaN( msg.payload ) )
68
+ if( ! isNaN( msg.value ) )
67
69
  {
68
70
  let data = context.get( "data" ) ?? {};
69
71
  const last = data[msg.topic] ?? Number.MAX_SAFE_INTEGER;
70
- if( msg.payload > node.threshold && node.threshold >= last )
72
+ if( msg.value > node.threshold && node.threshold >= last )
71
73
  {
72
74
  if( ++node.cntRise >= node.consecutive )
73
75
  {
74
76
  status.fill = "green";
75
- msg.edge = "rising";
77
+ msg.payload = node.output;
78
+ msg.edge = "rising";
76
79
  send( msg );
77
- data[msg.topic] = msg.payload;
80
+ data[msg.topic] = msg.value;
78
81
  node.cntRise = 0;
79
82
  }
80
83
  else
@@ -85,7 +88,7 @@ module.exports = function(RED) {
85
88
  else
86
89
  {
87
90
  node.cntRise = 0;
88
- data[msg.topic] = msg.payload;
91
+ data[msg.topic] = msg.value;
89
92
  }
90
93
  context.set( "data", data );
91
94
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mschaeffler/node-red-logic",
3
- "version": "2.3.3",
3
+ "version": "3.0.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",
package/tools.js CHANGED
@@ -58,6 +58,21 @@ exports.getPayload = function(node,msg,callback)
58
58
  }
59
59
  }
60
60
 
61
+ exports.convertTypedInput = function(value,type)
62
+ {
63
+ switch( type )
64
+ {
65
+ case "num":
66
+ return Number( value );
67
+ case "bool":
68
+ return exports.property2boolean( value );
69
+ case "json":
70
+ return JSON.parse( value );
71
+ default:
72
+ return value;
73
+ }
74
+ }
75
+
61
76
  exports.distance = function(a,b)
62
77
  {
63
78
  return a>b ? a-b : b-a;