Node-Red configuration
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

BooleanLogic.html 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <!--
  2. Licensed under the MIT license, see LICENSE file.
  3. Author: Per Malmberg (https://github.com/PerMalmberg)
  4. -->
  5. <script type="text/javascript">
  6. RED.nodes.registerType('BooleanLogic',{
  7. category: 'boolean logic',
  8. color: '#C0DEED',
  9. defaults: {
  10. name: {
  11. value: ""
  12. },
  13. operation: {
  14. value: "AND",
  15. required: true,
  16. validate:
  17. function(v) {
  18. return v !== undefined && v.length > 0;
  19. }
  20. },
  21. inputCount: {
  22. value: 2,
  23. required: true,
  24. validate:
  25. function(v) {
  26. return !isNaN( parseInt( v ) ) && parseInt( v ) >= 2;
  27. }
  28. },
  29. topic: {
  30. value: "result",
  31. required: true,
  32. validate:
  33. function(v) {
  34. return v !== undefined && v.length > 0;
  35. }
  36. }
  37. },
  38. inputs:1,
  39. outputs:1,
  40. icon: "serial.png",
  41. label:
  42. function() {
  43. var label = this.operation + " [" + this.inputCount + "]";
  44. if( this.name !== undefined && this.name.length > 0 ) {
  45. label = label + " (" + this.name + ")";
  46. }
  47. return label;
  48. },
  49. paletteLabel: function() {
  50. return "Boolean logic";
  51. }
  52. });
  53. </script>
  54. <script type="text/x-red" data-template-name="BooleanLogic">
  55. <div class="form-row">
  56. <label for="node-input-operation"><i class="icon-tag"></i> Operation</label>
  57. <select type="text" id="node-input-operation" placeholder="Operation">
  58. <option value="AND">And</option>
  59. <option value="OR">Or</option>
  60. <option value="XOR">Exclusive Or</option>
  61. </select>
  62. </div>
  63. <div class="form-row">
  64. <label for="node-input-inputCount"><i class="icon-tag"></i> Number of topics</label>
  65. <input type="text" id="node-input-inputCount" placeholder="Number of topics to consider">
  66. </div>
  67. <div class="form-row">
  68. <label for="node-input-name"><i class="icon-tag"></i> Name</label>
  69. <input type="text" id="node-input-name" placeholder="Name">
  70. </div>
  71. <div class="form-row">
  72. <label for="node-input-topic"><i class="icon-tag"></i> Topic</label>
  73. <input type="text" id="node-input-topic" placeholder="Topic">
  74. </div>
  75. </script>
  76. <script type="text/x-red" data-help-name="BooleanLogic">
  77. <p>A node that performs Boolean logic on the incoming payloads.<br/>
  78. Select the operation in the settings.<br/>
  79. 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/>
  80. <br/>
  81. The node expects a fixed number of topics (configured in the settings) on which it will operate. It will only output a value
  82. 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/>
  83. <br/>
  84. Example:<br/>
  85. The node has been configured for two topics, with the operation OR.
  86. <br/>
  87. <ol>
  88. <li>Topic 'A' with value false arrives - only one topic seen so no output.</li>
  89. <li>Topic 'B' with value true arrives - two topics seen so the node evaluates the received topics and outputs true.</li>
  90. <li>Topic 'C' arrives. This is the third topic which is one more than the configured number so the node resets and will not output another value until
  91. two new topics have been received. Note that when resetting it does not output any value.</li>
  92. </ol>
  93. <br/>
  94. All incoming msg.payloads are converted into a boolean value according to the following rules (this applies to all boolean logic nodes):
  95. <ol>
  96. <li>Boolean values are taken as-is.</li>
  97. <li>For numbers, 0 evaluates to false, all other numbers evaluates to true.</li>
  98. <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>
  99. </ol>
  100. <br>
  101. The XOR operation operates in a one, and only one mode, i.e. (A ^ B) ^ C ... ^ n
  102. </p>
  103. </script>