Allow Smooth node to be reset by msg.reset

to close #273
This commit is contained in:
Dave Conway-Jones
2017-02-07 21:41:18 +00:00
parent 7e421db642
commit 93c85ca7cd
5 changed files with 35 additions and 2 deletions

View File

@@ -32,7 +32,10 @@
<script type="text/x-red" data-help-name="smooth">
<p>A simple node to provide various functions across several previous values, including max, min, mean, high and low pass filters.</p>
<p>Max, Min and Mean work over a specified number of previous values.</p>
<p>The High and Low pass filters use a smoothing factor. The higher the number the more the smoothing. E.g. a value of 10 is similar to an &alpha; of 0.1. It is analagous to an RC time constant - but there is no time component to this as the time is based on events arriving.</p>
<p>The High and Low pass filters use a smoothing factor. The higher the number the more the smoothing. E.g. a value of 10 is
similar to an &alpha; of 0.1. It is analagous to an RC time constant - but there is no time component to this as the
time is based on events arriving.</p>
<p>If <code>msg.reset</code> is received (with any value), all the counters and intermediate values are reset to an initial state.</p>
<p><b>Note:</b> This only operates on <b>numbers</b>. Anything else will try to be made into a number and rejected if that fails.</p>
</script>

View File

@@ -16,6 +16,13 @@ module.exports = function(RED) {
var old = null;
this.on('input', function (msg) {
if (msg.hasOwnProperty("reset")) {
a = [];
tot = 0;
tot2 = 0;
pop = 0;
old = null;
}
if (msg.hasOwnProperty("payload")) {
var n = Number(msg.payload);
if (!isNaN(n)) {

View File

@@ -33,5 +33,7 @@ the more the smoothing. E.g. a value of 10 is similar to an &alpha; of 0.1.
It is analogous to an RC time constant - but there is no time component to
this as the code is based on events arriving.
If `msg.reset` is received (with any value), all the counters and intermediate values are reset to an initial state.
**Note:** This node only operates on **numbers**. Anything else will try to be
made into a number and rejected if that fails.

View File

@@ -1,6 +1,6 @@
{
"name" : "node-red-node-smooth",
"version" : "0.0.9",
"version" : "0.0.10",
"description" : "A Node-RED node that provides several simple smoothing algorithms for incoming data values.",
"dependencies" : {
},