node-red-contrib-deglitch
Version:
This node filters out short impulses or erroneous data from sensors.
77 lines (68 loc) • 3.67 kB
HTML
<!--
Copyright JS Foundation and other contributors, http://js.foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<script type="text/x-red" data-template-name="deglitch">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-mode"><i class="fa fa-tasks"></i> Behaviour</label>
<select id="node-input-mode">
<option value=1>Separate messages based on their topic</option>
<option value=2>Don't watch topic</option>
</select>
</div>
<div class="form-row" id="time-details-for">
<label for="node-input-time"><i class="fa fa-clock-o"></i> Time</label>
<input type="text" id="node-input-time" style="text-align:end; width:50px !important">
<select id="node-input-timeUnits" style="width:200px !important">
<option value="milliseconds">Milliseconds</option>
<option value="seconds">Seconds</option>
<option value="minutes">Minutes</option>
<option value="hours">Hours</option>
</select>
</div>
</script>
<script type="text/x-red" data-help-name="deglitch">
<p>Real world sensors and inputs may be imperfect some time. They may have some spurious short invalid data which needs to be filtered out before processing. This node helps removing the unwanted signal transitions from the flow by filtering it based on payload data. <br/>
A very simple example: real-world buttons and on-off switches are bouncing during the transition, creating extra on-off events in the flow. These short glitches have to be removed and this node is intended to do this. Of course, not just boolean payloads are supported but you can have any kind of object and multiple values.<br/>
The node will filter the different topics independently of eachother, however this behaviour can be changed by config.
For further explanation, see the <a href="http://reactivex.io/documentation/operators/debounce.html" target="new">debounce pattern</a><br/>
</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('deglitch',{
category: 'function',
color: '#a6bbcf',
defaults: {
name: {value:""},
mode: {value:1},
time: {value:"5", required:true, validate:RED.validators.number()},
timeUnits: {value:"seconds"},
},
inputs:1,
outputs:1,
icon: "trigger.png",
label: function() {
if (this.timeUnits == 'milliseconds') v = this.time.toString()+' ms';
else if (this.timeUnits == 'seconds') v = this.time.toString()+' s';
else if (this.timeUnits == 'minutes') v = this.time.toString()+' min';
else if (this.timeUnits == 'hours') v = this.time.toString()+' hr';
return this.name||("deglitch "+v);
},
oneditprepare: function() {
var node = this;
$( "#node-input-time" ).spinner({min:1});
}
});
</script>