add ignore first message option to rue node

This commit is contained in:
Dave Conway-Jones
2017-05-24 13:14:55 +01:00
parent 8799b1e85b
commit 76e33acae5
5 changed files with 51 additions and 6 deletions

View File

@@ -2,6 +2,7 @@
"rbe": {
"label": {
"func": "Mode",
"init": "Send initial value",
"start": "Start value",
"name": "Name"
},
@@ -11,6 +12,7 @@
},
"opts": {
"rbe": "block unless value changes",
"rbei": "block unless value changes (ignore initial value)",
"deadband": "block unless value change is greater than",
"deadbandEq": "block unless value change is greater or equal to",
"narrowband": "block if value change is greater than",

View File

@@ -1,6 +1,6 @@
{
"name" : "node-red-node-rbe",
"version" : "0.1.8",
"version" : "0.1.9",
"description" : "A Node-RED node that provides report-by-exception (RBE) and deadband capability.",
"dependencies" : {
},

View File

@@ -4,6 +4,7 @@
<label for="node-input-func"><i class="fa fa-wrench"></i> <span data-i18n="rbe.label.func"></span></label>
<select type="text" id="node-input-func" style="width:74%;">
<option value="rbe" data-i18n="rbe.opts.rbe"></option>
<option value="rbei" data-i18n="rbe.opts.rbei"></option>
<option value="deadbandEq" data-i18n="rbe.opts.deadbandEq"></option>
<option value="deadband" data-i18n="rbe.opts.deadband"></option>
<option value="narrowbandEq" data-i18n="rbe.opts.narrowbandEq"></option>
@@ -78,7 +79,7 @@
outputs:1,
icon: "rbe.png",
label: function() {
var ll = (this.func||"").replace("Eq","")||"rbe";
var ll = (this.func||"").replace("Eq","").replace("rbei","rbe")||"rbe";
return this.name||ll||"rbe";
},
labelStyle: function() {
@@ -90,7 +91,7 @@
$("#node-input-inout").val("out");
}
$("#node-input-func").on("change",function() {
if ($("#node-input-func").val() === "rbe") {
if (($("#node-input-func").val() === "rbe")||($("#node-input-func").val() === "rbei")) {
$("#node-bandgap").hide();
} else {
$("#node-bandgap").show();

View File

@@ -13,24 +13,26 @@ module.exports = function(RED) {
this.gap = parseFloat(this.gap);
}
this.g = this.gap;
var node = this;
node.previous = {};
this.on("input",function(msg) {
if (msg.hasOwnProperty("payload")) {
var t = msg.topic || "_no_topic";
if (this.func === "rbe") {
if ((this.func === "rbe") || (this.func === "rbei")) {
var doSend = (this.func !== "rbei") || (node.previous.hasOwnProperty(t)) || false;
if (typeof(msg.payload) === "object") {
if (typeof(node.previous[t]) !== "object") { node.previous[t] = {}; }
if (!RED.util.compareObjects(msg.payload, node.previous[t])) {
node.previous[t] = msg.payload;
node.send(msg);
if (doSend) { node.send(msg); }
}
}
else {
if (msg.payload !== node.previous[t]) {
node.previous[t] = msg.payload;
node.send(msg);
if (doSend) { node.send(msg); }
}
}
}