You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BooleanLogicUltimate.html 5.2KB

преди 5 години
преди 5 години
преди 5 години
преди 5 години
преди 5 години
преди 5 години
преди 5 години
преди 5 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <script type="text/javascript">
  2. RED.nodes.registerType('BooleanLogicUltimate',{
  3. category: 'boolean logic ultimate',
  4. color: '#ff8080',
  5. defaults: {
  6. name: {
  7. value: ""
  8. },
  9. filtertrue: {value:"both"},
  10. persist: {value:true},
  11. inputCount: {
  12. value: 2,
  13. required: true,
  14. validate:
  15. function(v) {
  16. return !isNaN( parseInt( v ) ) && parseInt( v ) >= 2;
  17. }
  18. },
  19. topic: {
  20. value: "result",
  21. required: true,
  22. validate:
  23. function(v) {
  24. return v !== undefined && v.length > 0;
  25. }
  26. }
  27. },
  28. inputs:1,
  29. outputs:3,
  30. outputLabels: function(i) {
  31. var ret="";
  32. switch (i) {
  33. case 0:
  34. return "AND";
  35. break;
  36. case 1:
  37. return "OR";
  38. break;
  39. case 2
  40. :
  41. return "XOR";
  42. break;
  43. default:
  44. break;
  45. }
  46. },
  47. icon: "serial.png",
  48. label:
  49. function() {
  50. var label = "Logic" + (this.filtertrue=="both" ? "" : " filtered" ) + " [" + this.inputCount + "]";
  51. if( this.name !== undefined && this.name.length > 0 ) {
  52. label = label + " (" + this.name + ")";
  53. }
  54. return label;
  55. },
  56. paletteLabel: function() {
  57. return "Boolean Logic Ultimate";
  58. },
  59. oneditsave: function () {
  60. // Delete persistent state file
  61. $.get( "stateoperation_delete?nodeid=" +this.id, function( data ) {});
  62. }
  63. });
  64. </script>
  65. <script type="text/x-red" data-template-name="BooleanLogicUltimate">
  66. <div class="form-row">
  67. <label for="node-input-filtertrue"><i class="icon-tag"></i> Filter output result</label>
  68. <select type="text" id="node-input-filtertrue" placeholder="Filter">
  69. <option value="both">Output both 'true' and 'false' results</option>
  70. <option value="onlytrue">Output only 'true' results</option>
  71. </select>
  72. </div>
  73. <div class="form-row">
  74. <input type="checkbox" id="node-input-persist" style="display:inline-block; width:auto; vertical-align:top;">
  75. <label style="width:auto" for="node-input-persist"> Remember latest input values after reboot</label>
  76. <div id="helpallga"><i> 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.</div>
  77. </div>
  78. <div class="form-row">
  79. <label for="node-input-inputCount"><i class="icon-tag"></i> Number of topics</label>
  80. <input type="text" id="node-input-inputCount" placeholder="Number of topics to consider">
  81. </div>
  82. <div class="form-row">
  83. <label for="node-input-name"><i class="icon-tag"></i> Name</label>
  84. <input type="text" id="node-input-name" placeholder="Name">
  85. </div>
  86. <div class="form-row">
  87. <label for="node-input-topic"><i class="icon-tag"></i> Topic</label>
  88. <input type="text" id="node-input-topic" placeholder="Topic">
  89. </div>
  90. </script>
  91. <script type="text/x-red" data-help-name="BooleanLogicUltimate">
  92. <p>The node performs Boolean logic on the incoming payloads.<br/>
  93. 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/>
  94. - Output "AND": true or false<br/>
  95. - Output "OR": true or false<br/>
  96. - Output "XOR": true or false<br/>
  97. <br/>
  98. 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/>
  99. <br/>
  100. The node expects a fixed number of topics (configured in the settings) on which it will operate. It will only output a value
  101. 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/>
  102. <br/><br/>
  103. <b>Filter output result</b><br />
  104. <ol>
  105. <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>
  106. <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>
  107. </ol>
  108. <b>filtered</b>: shown on label, means that the node will pass out only <code>true</code> values (Output only 'true' results). <br/>
  109. <br/><br/>
  110. <b>Remember latest input values after reboot</b><br />
  111. 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/>
  112. Every time you modify the node's config, <b>the retained values are cleared</b>.<br/>
  113. <br/>
  114. All incoming msg.payloads are converted into a boolean value according to the following rules (this applies to all boolean logic nodes):
  115. <ol>
  116. <li>Boolean values are taken as-is.</li>
  117. <li>For numbers, 0 evaluates to false, all other numbers evaluates to true.</li>
  118. <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>
  119. </ol>
  120. <br>
  121. The XOR operation operates in a one, and only one mode, i.e. (A ^ B) ^ C ... ^ n
  122. </p>
  123. </script>