node-red-contrib-boolean-logic-ultimate
Advanced tools
Comparing version 1.0.39 to 1.0.40
@@ -13,2 +13,5 @@ module.exports = function (RED) { | ||
node.restrictinputevaluation = config.restrictinputevaluation === undefined ? false : config.restrictinputevaluation; | ||
node.delayEvaluation = config.delayEvaluation === undefined ? 0 : config.delayEvaluation; // 26/01/2022 Starts evaluating the inputs only after this amount of time is elapsed, after the last msg input or trigger | ||
node.timerDelayEvaluation = null; | ||
node.inputMessage = {}; // 26/01/2022 input message is stored here. | ||
@@ -67,2 +70,9 @@ function setNodeStatus({ fill, shape, text }) { | ||
// Starts the evaluation delay timer, if needed | ||
node.startTimerDelayEvaluation = () => { | ||
if (node.timerDelayEvaluation !== null) clearTimeout(node.timerDelayEvaluation); | ||
node.timerDelayEvaluation = setTimeout(() => { | ||
outputResult(); | ||
}, node.delayEvaluation); | ||
} | ||
@@ -133,17 +143,17 @@ // 14/08/2019 If some inputs are to be initialized, create a dummy items in the array | ||
} | ||
node.inputMessage = msg; // 26/01/2022 Store MSG to be used in the outputResult function. | ||
// Do we have as many inputs as we expect? | ||
var keyCount = Object.keys(node.jSonStates).length; | ||
if (keyCount == node.config.inputCount) { | ||
var resAND = CalculateResult("AND"); | ||
var resOR = CalculateResult("OR"); | ||
var resXOR = CalculateResult("XOR"); | ||
// var resAND = CalculateResult("AND"); | ||
// var resOR = CalculateResult("OR"); | ||
// var resXOR = CalculateResult("XOR"); | ||
if (node.config.filtertrue == "onlytrue") { | ||
if (!resAND) { resAND = null }; | ||
if (!resOR) { resOR = null }; | ||
if (!resXOR) { resXOR = null }; | ||
} | ||
// if (node.config.filtertrue == "onlytrue") { | ||
// if (!resAND) { resAND = null }; | ||
// if (!resOR) { resOR = null }; | ||
// if (!resXOR) { resXOR = null }; | ||
// } | ||
@@ -156,3 +166,8 @@ // Operation mode evaluation | ||
&& node.config.triggertopic === msg.topic) { | ||
SetResult(resAND, resOR, resXOR, node.config.topic, msg); | ||
if (node.delayEvaluation > 0) { | ||
node.startTimerDelayEvaluation(); | ||
setNodeStatus({ fill: "blue", shape: "ring", text: "Delay Eval " + node.delayEvaluation + "ms" }); | ||
} else { | ||
outputResult(); | ||
} | ||
} else { | ||
@@ -162,3 +177,8 @@ setNodeStatus({ fill: "grey", shape: "ring", text: "Saved (" + (msg.hasOwnProperty("topic") ? msg.topic : "empty input topic") + ") " + value }); | ||
} else { | ||
SetResult(resAND, resOR, resXOR, node.config.topic, msg); | ||
if (node.delayEvaluation > 0) { | ||
node.startTimerDelayEvaluation(); | ||
setNodeStatus({ fill: "blue", shape: "ring", text: "Delay Eval " + node.delayEvaluation + "ms" }); | ||
} else { | ||
outputResult(); | ||
} | ||
} | ||
@@ -288,26 +308,37 @@ } | ||
function SetResult(_valueAND, _valueOR, _valueXOR, optionalTopic, _msg) { | ||
setNodeStatus({ fill: "green", shape: "dot", text: "(AND)" + (_valueAND !== null ? _valueAND : "---") + " (OR)" + (_valueOR !== null ? _valueOR : "---") + " (XOR)" + (_valueXOR !== null ? _valueXOR : "---") }); | ||
function outputResult() { | ||
let optionalTopic = node.config.topic; | ||
let calculatedValueAND = CalculateResult("AND"); | ||
let calculatedValueOR = CalculateResult("OR"); | ||
let calculatedValueXOR = CalculateResult("XOR"); | ||
if (node.config.filtertrue == "onlytrue") { | ||
if (!calculatedValueAND) { calculatedValueAND = null }; | ||
if (!calculatedValueOR) { calculatedValueOR = null }; | ||
if (!calculatedValueXOR) { calculatedValueXOR = null }; | ||
} | ||
setNodeStatus({ fill: "green", shape: "dot", text: "(AND)" + (calculatedValueAND !== null ? calculatedValueAND : "---") + " (OR)" + (calculatedValueOR !== null ? calculatedValueOR : "---") + " (XOR)" + (calculatedValueXOR !== null ? calculatedValueXOR : "---") }); | ||
var msgAND = null; | ||
if (_valueAND != null) { | ||
msgAND = RED.util.cloneMessage(_msg); | ||
if (calculatedValueAND != null) { | ||
msgAND = RED.util.cloneMessage(node.inputMessage); | ||
msgAND.topic = optionalTopic === undefined ? "result" : optionalTopic; | ||
msgAND.operation = "AND"; | ||
msgAND.payload = _valueAND; | ||
msgAND.payload = calculatedValueAND; | ||
} | ||
var msgOR = null; | ||
if (_valueOR != null) { | ||
msgOR = RED.util.cloneMessage(_msg); | ||
if (calculatedValueOR != null) { | ||
msgOR = RED.util.cloneMessage(node.inputMessage); | ||
msgOR.topic = optionalTopic === undefined ? "result" : optionalTopic; | ||
msgOR.operation = "OR"; | ||
msgOR.payload = _valueOR; | ||
msgOR.payload = calculatedValueOR; | ||
} | ||
var msgXOR = null; | ||
if (_valueXOR != null) { | ||
msgXOR = RED.util.cloneMessage(_msg); | ||
if (calculatedValueXOR != null) { | ||
msgXOR = RED.util.cloneMessage(node.inputMessage); | ||
msgXOR.topic = optionalTopic === undefined ? "result" : optionalTopic; | ||
msgXOR.operation = "XOR"; | ||
msgXOR.payload = _valueXOR; | ||
msgXOR.payload = calculatedValueXOR; | ||
} | ||
@@ -314,0 +345,0 @@ node.send([msgAND, msgOR, msgXOR]); |
@@ -5,2 +5,6 @@ # node-red-contrib-boolean-logic-ultimate | ||
<p> | ||
<b>Version 1.0.40</b> Januart 2022<br/> | ||
- NEW: Boolean Logic Ultimate: Delay option added. See the readme on gitHub.</br> | ||
</p> | ||
<p> | ||
<b>Version 1.0.39</b> November 2021<br/> | ||
@@ -7,0 +11,0 @@ - FIX a possible issue when msg.payload is numeric.</br> |
{ | ||
"name": "node-red-contrib-boolean-logic-ultimate", | ||
"version": "1.0.39", | ||
"version": "1.0.40", | ||
"description": "A set of Node-RED enhanced boolean logic node, flow interruption node, blinker node, invert node, filter node, with persisten values after reboot and more.", | ||
@@ -5,0 +5,0 @@ "author": "Supergiovane (https://github.com/Supergiovane)", |
@@ -18,5 +18,11 @@ # node-red-contrib-boolean-logic-ultimate | ||
<br/> | ||
<br/> | ||
## CHANGELOG | ||
* See <a href="https://github.com/Supergiovane/node-red-contrib-boolean-logic-ultimate/blob/master/CHANGELOG.md">here the changelog</a> | ||
<br/> | ||
<br/> | ||
# BOOLEAN LOGIC | ||
@@ -92,3 +98,9 @@ | ||
**Delay evaluation (msec)** | ||
Delays the evaluation until this time (in milliseconds) is elapsed. Each time a message or "topic trigger message" (see **Trigger mode**) arrives, the delay is restarted.<br/> | ||
This option is useful for debouncing pourposes or simply for adding some delay.<br/> | ||
For example, you can turn on a light if the room is occupied for a long time, allowing people to fast transit repeatedly, without the need of turning the light on.<br/> | ||
Another example, if you have many sensors changing state rapidly, you can wait until these sensor reach a quiet state, then evaluate the inputs.<br/> | ||
**INPUT MSG TO THE NODE** | ||
@@ -95,0 +107,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
703562
35
791
300