|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- <script type="text/javascript">
- RED.nodes.registerType('BooleanLogicUltimate',{
- category: 'boolean logic ultimate',
- color: '#ff8080',
- defaults: {
- name: {
- value: ""
- },
- filtertrue: {value:"both"},
- persist: {value:true},
- sInitializeWith: {value:"WaitForPayload"},
- triggertopic: {
- value: "trigger",
- required: false
- },
- outputtriggeredby:{
- value:"all",
- required: false},
- inputCount: {
- value: 2,
- required: true,
- validate:
- function(v) {
- return !isNaN( parseInt( v ) ) && parseInt( v ) >= 2;
- }
- },
- topic: {
- value: "result",
- required: true,
- validate:
- function(v) {
- return v !== undefined && v.length > 0;
- }
- }
- },
- inputs:1,
- outputs:3,
- outputLabels: function(i) {
- var ret="";
- switch (i) {
- case 0:
- return "AND";
- break;
- case 1:
- return "OR";
- break;
- case 2
- :
- return "XOR";
- break;
- default:
- break;
- }
- },
- icon: "serial.png",
- label:
- function() {
- let label = "";
- let filtered=this.filtertrue=="both" ? "" : "f" ;
- let trigger="";
- if(typeof this.outputtriggeredby !== "undefined") trigger=this.outputtriggeredby=="all" ? "" : "t (" + this.triggertopic+")";
- label= this.inputCount + ((filtered+trigger)==""?" Boolean Logic":(filtered+trigger));
- if( this.name !== undefined && this.name.length > 0 ) {
- label += " (" + this.name + ")";
- }
- return label;
- },
- paletteLabel: function() {
- return "BooleanLogicUltimate";
- },
- oneditprepare: function () {
- // Add write and response as default for existing nodes like was default before
- if (this.outputtriggeredby === 'all') {
- $("#triggertopic").hide()
- }else
- {
- $("#triggertopic").show()
- }
-
- $("#node-input-outputtriggeredby").on('change',function() {
- if ($("#node-input-outputtriggeredby").val()==="all") {
- $("#triggertopic").hide()
- }else{
- $("#triggertopic").show()
- }
- })
-
- // default
- if(typeof this.outputtriggeredby === "undefined")
- {
- $("#node-input-outputtriggeredby").val("all");
- this.outputtriggeredby="all";
- }
-
- // default
- if(typeof this.sInitializeWith === "undefined")
- {
- $("#node-input-sInitializeWith").val("WaitForPayload");
- this.sInitializeWith="WaitForPayload";
- }
-
- },
- oneditsave: function () {
- // Delete persistent state file
- $.get( "stateoperation_delete?nodeid=" +this.id, function( data ) {});
- }
- });
-
-
- </script>
-
- <script type="text/x-red" data-template-name="BooleanLogicUltimate">
- <div class="form-row">
- <label for="node-input-inputCount"><i class="fa fa-indent"></i> Number of different topics to evaluate</label>
- <input type="text" id="node-input-inputCount" placeholder="Number of different topics to consider">
- </div>
- <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-topic"><i class="fa fa-tasks"></i> Node topic</label>
- <input type="text" id="node-input-topic" placeholder="Node's own topic">
- </div>
- <div class="form-row">
- <label for="node-input-filtertrue"><i class="fa fa-filter"></i> Filter output result</label>
- <select type="text" id="node-input-filtertrue" placeholder="Filter">
- <option value="both">Output both 'true' and 'false' results</option>
- <option value="onlytrue">Output only 'true' results</option>
- </select>
- </div>
- <div class="form-row">
- <label for="node-input-outputtriggeredby"><i class="fa fa-filter"></i> Trigger mode</label>
- <select type="text" id="node-input-outputtriggeredby" placeholder="Event">
- <option value="all">All topics</option>
- <option value="onlyonetopic">Single topic</option>
- </select>
- </div>
- <div class="form-row" id="triggertopic">
- <label for="node-input-triggertopic"><i class="fa fa-tasks"></i> Topic that start boolean logic evaluation</label>
- <input type="text" id="node-input-triggertopic" placeholder="Input topic">
- </div>
- <div class="form-row">
- <i class="fa fa-floppy-o"></i>
- <label style="width:auto" for="node-input-persist"> Remember latest input values after reboot</label> <input type="checkbox" id="node-input-persist" style="display:inline-block; width:auto; vertical-align:top;">
- <div id="helpallga"><i> If checked, the input values are retained <br /> after a node-red reboot.<br/>If you reboot your node-red, <br />you don't need to wait all inputs <br />to arrive and initialize the node, <br />before the node can output a payload.</div>
- </div>
- <div class="form-row">
- <label for="node-input-sInitializeWith"><i class="fa fa-home"></i> If input states are undefined</label>
- <select type="text" id="node-input-sInitializeWith" placeholder="">
- <option value="WaitForPayload">Leave undefined</option>
- <option value="false">Initialize all with False</option>
- <option value="true">Initialize all with True</option>
- </select>
- </div>
-
- </script>
-
- <script type="text/x-red" data-help-name="BooleanLogicUltimate">
- <p>
- <a href="https://www.paypal.me/techtoday" target="_blank"><img src='https://img.shields.io/badge/Donate-PayPal-blue.svg?style=flat-square' width='30%'></a>
- and
- <a href="http://eepurl.com/gJm095" target="_blank">Subscribe to my channel</a> for news about my nodes.
- </p>
-
- <p>The node performs Boolean logic on the incoming payloads.<br/>
- <a href="https://www.paypal.me/techtoday" target="_blank"><img src='https://img.shields.io/badge/Donate-PayPal-blue.svg?style=flat-square' width='30%'></a>
- <br/><br/>
- The node performs 3 checks (<b>AND,OR,XOR</b>) on the incoming boolean payloads and outputs the result at the same time, as follow:<br/>
- - Output "AND": true or false<br/>
- - Output "OR": true or false<br/>
- - Output "XOR": true or false<br/>
-
- <b>Number of different topics to evaluate</b><br />
- Set the number of different topics to be evaluated. The node will output a message to the flow, after this number of different topics arrives.<br/>
- <b> Remember: each input topic must be different. For example, if you set this field to 3, the node expects 3 different topics.</b><br/>
-
- <br/>
- Changing the topic is usually only needed when chaining multiple boolean nodes after each other becuse the topics will then all be the same when delivered to the nodes further down the chain.<br/>
- <br/>
- The node expects a fixed number of topics (configured in the settings) on which it will operate. It will only output a value
- when it has seen the expected number of topics. If it ever sees more than the configured number of topics it will log a message then reset its state and start over.<br/>
- <b> Remember: each input topic must be different. For example, if you set "Number of different topics to evaluate" to 3, the node expects 3 different topics.</b><br/>
- <br/><br/>
- <b>Filter output result</b><br />
- <ol>
- <li>Output both 'true' and 'false' results: Standard behaviour, the node will output <b>true</b> and <b>false</b> whenever it receives an input and calculate the boolean logics as output.</li>
- <li>Output only 'true' results: whenever the node receives an input, it outputs a payload <b>true</b> only if the result of the logic is true. <b>False</b> results are filtered out.</li>
- </ol>
- <b>filtered</b>: shown on label, means that the node will pass out only <code>true</code> values (Output only 'true' results). <br/>
- <br/><br/>
-
- <b>Trigger mode</b><br />
- The node can acts ad a standard boolean logic or as single topic triggered boolean logic.<br/>
- As single topic triggered boolean logic, the node will evaluate the inputs (and thus will output a payload) only if a specified topic input arrives.<br/>
- In a coding perspectives, it acts as follows:<br/>
- <code>
- if (msg.topic == specified topic)<br/>
- {<br/>
- If (all other inputs are true) -> outputs true otherwise false<br/>
- }<br/>
- </code>
- <ol>
- <li>All topics: standard behaviour, the node will output <b>true</b> and <b>false</b> by evaluating all inputs. Each input change will trigger the node output.</li>
- <li>Single topic + only eval others: <u>only whenever the node receives a msg input with the <b>specified topic</b> (having payload = true)</u>, it starts the evaluation of all other inputs as well and outputs the evaluated payload. If the node receives a msg input other than the <b>specified topic</b>), it only retains it's value for the boolean evaluation.</li>
- </ol>
- Example of trigger mode = Single topic + eval other inputs: <b>SEE THE README FOR AN EXAMPLE</b>
- <br/><br/>
-
- <b>Remember latest input values after reboot</b><br />
- If checked, the input values are retained after a node-red reboot. That means, that if you reboot your node-red, you don't need to wait all inputs to arrive and initialize the node, before the node can output a payload.<br/>
- Every time you modify the node's config, <b>the retained values are cleared</b>.<br/>
- <br/>
-
- <b> If input states are undefined</b><br />
- Every time you create a node or modify the node, all inputs are set to undefined. This means that the node will wait the arrive of all topics (for example 3 topics, if you've selected 3 topics in the option), before it can output a payload. This can be a problem if your logic must be operative as soon as you deploy the flow. To overcome this problem, you can "initialize" all the undefined inputs with True or False.
- <ol>
- <li>Leave undefined: Standard behaviour, the node will wait all the "undefined" topics to arrive, then starts a flow with the result.</li>
- <li>True or False: The node is immediately operative, by force the initialization of the "undefined" inputs with "true" or "false".</li>
- </ol>
- <br/>
-
- <i> How inputs are handled:</i><br />
- All incoming msg.payloads are converted into a boolean value according to the following rules (this applies to all boolean logic nodes):
- <ol>
- <li>Boolean values are taken as-is.</li>
- <li>For numbers, 0 evaluates to false, all other numbers evaluates to true.</li>
- <li>Strings are converted to numbers if they match the format of a decimal value, then the same rule as for numbers are applied. If it does not match, it evaluates to false. Also, the string "true" evaluates to true.</li>
- </ol>
- <br>
- The XOR operation operates in a one, and only one mode, i.e. (A ^ B) ^ C ... ^ n
-
- </p>
- </script>
|