Massimo před 4 roky
rodič
revize
de40e43a6a
3 změnil soubory, kde provedl 65 přidání a 53 odebrání
  1. +4
    -0
      CHANGELOG.md
  2. +60
    -52
      boolean-logic-ultimate/BooleanLogicUltimate.js
  3. +1
    -1
      package.json

+ 4
- 0
CHANGELOG.md Zobrazit soubor

@@ -3,6 +3,10 @@

<a href="http://eepurl.com/gJm095" target="_blank">Subscribe to my channel.</a> Only news about my nodes, no spam, no ads. I'm a github developer, not a merchant.

<p>
<b>Version 1.0.18</b> August 2020<br/>
- Boolean Logic: warn user if either topic or payload are not set. You must always set a topic and payload.</br>
</p>
<p>
<b>Version 1.0.17</b> June 2020<br/>
- Interruptflowultimete: State save/replay. Msg.play = true sends the current payload See the README on github for an example.</br>

+ 60
- 52
boolean-logic-ultimate/BooleanLogicUltimate.js Zobrazit soubor

@@ -44,78 +44,86 @@ module.exports = function (RED) {

this.on('input', function (msg) {

// 28/08/2020 inform user about undefined topic or payload
if (!msg.hasOwnProperty("topic") || typeof (msg.topic) == "undefined") {
setNodeStatus({ fill: "red", shape: "dot", text: "Received invalid topic!" });
return;
}
// 28/08/2020 inform user about undefined topic or payload
if (!msg.hasOwnProperty("payload") || typeof (msg.payload) == "undefined") {
setNodeStatus({ fill: "red", shape: "dot", text: "Received invalid payload!" });
return;
}
var topic = msg.topic;
var payload = msg.payload;
var value = ToBoolean(payload);

if (topic !== undefined && payload !== undefined) {
var value = ToBoolean(payload);

// 14/08/2019 if inputs are initialized, remove a "dummy" item from the state's array, as soon as new topic arrives
if (node.sInitializeWith !== "WaitForPayload") {
// Search if the current topic is in the state array
if (typeof node.jSonStates[topic] === "undefined") {
// Delete one dummy
for (let index = 0; index < node.config.inputCount; index++) {
if (node.jSonStates.hasOwnProperty("dummy" + index)) {
//RED.log.info(JSON.stringify(node.jSonStates))
delete node.jSonStates["dummy" + index];
//RED.log.info(JSON.stringify(node.jSonStates))
break;
}
// 14/08/2019 if inputs are initialized, remove a "dummy" item from the state's array, as soon as new topic arrives
if (node.sInitializeWith !== "WaitForPayload") {
// Search if the current topic is in the state array
if (typeof node.jSonStates[topic] === "undefined") {
// Delete one dummy
for (let index = 0; index < node.config.inputCount; index++) {
if (node.jSonStates.hasOwnProperty("dummy" + index)) {
//RED.log.info(JSON.stringify(node.jSonStates))
delete node.jSonStates["dummy" + index];
//RED.log.info(JSON.stringify(node.jSonStates))
break;
}
}
}
}

// Add current attribute
node.jSonStates[topic] = value;
// Add current attribute
node.jSonStates[topic] = value;

// Save the state array to a perisistent file
if (node.config.persist == true) {
try {
if (!fs.existsSync("states")) fs.mkdirSync("states");
fs.writeFileSync("states/" + node.id.toString(), JSON.stringify(node.jSonStates));
// Save the state array to a perisistent file
if (node.config.persist == true) {
try {
if (!fs.existsSync("states")) fs.mkdirSync("states");
fs.writeFileSync("states/" + node.id.toString(), JSON.stringify(node.jSonStates));

} catch (error) {
setNodeStatus({ fill: "red", shape: "dot", text: "Node cannot write to filesystem: " + error });
}
} catch (error) {
setNodeStatus({ fill: "red", shape: "dot", text: "Node cannot write to filesystem: " + error });
}
}

// Do we have as many inputs as we expect?
var keyCount = Object.keys(node.jSonStates).length;
// Do we have as many inputs as we expect?
var keyCount = Object.keys(node.jSonStates).length;

if (keyCount == node.config.inputCount) {
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 };
}

// Operation mode evaluation
if (node.config.outputtriggeredby == "onlyonetopic") {
if (typeof node.config.triggertopic !== "undefined"
&& node.config.triggertopic !== ""
&& msg.hasOwnProperty("topic") && msg.topic !== ""
&& node.config.triggertopic === msg.topic) {
SetResult(resAND, resOR, resXOR, node.config.topic, msg);
} else {
setNodeStatus({ fill: "grey", shape: "ring", text: "Saved (" + (msg.hasOwnProperty("topic") ? msg.topic : "empty input topic") + ") " + value });
}
} else {
// Operation mode evaluation
if (node.config.outputtriggeredby == "onlyonetopic") {
if (typeof node.config.triggertopic !== "undefined"
&& node.config.triggertopic !== ""
&& msg.hasOwnProperty("topic") && msg.topic !== ""
&& node.config.triggertopic === msg.topic) {
SetResult(resAND, resOR, resXOR, node.config.topic, msg);
} else {
setNodeStatus({ fill: "grey", shape: "ring", text: "Saved (" + (msg.hasOwnProperty("topic") ? msg.topic : "empty input topic") + ") " + value });
}
}
else if (keyCount > node.config.inputCount) {
setNodeStatus({ fill: "gray", shape: "ring", text: "Reset due to unexpected new topic" });
DeletePersistFile();
} else {
setNodeStatus({ fill: "green", shape: "ring", text: "Arrived topic " + keyCount + " of " + node.config.inputCount });
SetResult(resAND, resOR, resXOR, node.config.topic, msg);
}
}
else if (keyCount > node.config.inputCount) {
setNodeStatus({ fill: "gray", shape: "ring", text: "Reset due to unexpected new topic" });
DeletePersistFile();
} else {
setNodeStatus({ fill: "green", shape: "ring", text: "Arrived topic " + keyCount + " of " + node.config.inputCount });
}

});

this.on('close', function (removed, done) {

+ 1
- 1
package.json Zobrazit soubor

@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-boolean-logic-ultimate",
"version": "1.0.17",
"version": "1.0.18",
"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.",
"author": "Supergiovane (https://github.com/Supergiovane)",
"dependencies": {

Načítá se…
Zrušit
Uložit