Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

BooleanLogicUltimate.html 5.0KB

pirms 5 gadiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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.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. }
  61. });
  62. </script>
  63. <script type="text/x-red" data-template-name="BooleanLogicUltimate">
  64. <div class="form-row">
  65. <label for="node-input-filtertrue"><i class="icon-tag"></i> Filter output result</label>
  66. <select type="text" id="node-input-filtertrue" placeholder="Filter">
  67. <option value="both">Output both 'true' and 'false' results</option>
  68. <option value="onlytrue">Output only 'true' results</option>
  69. </select>
  70. </div>
  71. <div class="form-row">
  72. <input type="checkbox" id="node-input-persist" style="display:inline-block; width:auto; vertical-align:top;">
  73. <label style="width:auto" for="node-input-persist"> Remember latest input values after reboot</label>
  74. <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>
  75. </div>
  76. <div class="form-row">
  77. <label for="node-input-inputCount"><i class="icon-tag"></i> Number of topics</label>
  78. <input type="text" id="node-input-inputCount" placeholder="Number of topics to consider">
  79. </div>
  80. <div class="form-row">
  81. <label for="node-input-name"><i class="icon-tag"></i> Name</label>
  82. <input type="text" id="node-input-name" placeholder="Name">
  83. </div>
  84. <div class="form-row">
  85. <label for="node-input-topic"><i class="icon-tag"></i> Topic</label>
  86. <input type="text" id="node-input-topic" placeholder="Topic">
  87. </div>
  88. </script>
  89. <script type="text/x-red" data-help-name="BooleanLogicUltimate">
  90. <p>The node performs Boolean logic on the incoming payloads.<br/>
  91. 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/>
  92. - Output "AND": true or false<br/>
  93. - Output "OR": true or false<br/>
  94. - Output "XOR": true or false<br/>
  95. <br/>
  96. 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/>
  97. <br/>
  98. The node expects a fixed number of topics (configured in the settings) on which it will operate. It will only output a value
  99. 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/>
  100. <br/><br/>
  101. <b>Filter output result</b><br />
  102. <ol>
  103. <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>
  104. <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>
  105. </ol>
  106. <br/><br/>
  107. <b>Remember latest input values after reboot</b><br />
  108. 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/>
  109. Every time you modify the node's config, <b>the retained values are cleared</b>.<br/>
  110. <br/>
  111. All incoming msg.payloads are converted into a boolean value according to the following rules (this applies to all boolean logic nodes):
  112. <ol>
  113. <li>Boolean values are taken as-is.</li>
  114. <li>For numbers, 0 evaluates to false, all other numbers evaluates to true.</li>
  115. <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>
  116. </ol>
  117. <br>
  118. The XOR operation operates in a one, and only one mode, i.e. (A ^ B) ^ C ... ^ n
  119. </p>
  120. </script>