UNPKG

@redplc/node-red-gpio

Version:

Node-RED nodes for Raspberry Pi gpio using with redPlc nodes

143 lines (134 loc) 6.09 kB
<!-- Copyright 2024 Derya Y. (iot.redplc@gmail.com). Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <script type="text/javascript"> RED.nodes.registerType('redplc-gpio-out', { category: 'redPlc modules', color: 'Orange', paletteLabel: 'gpio-out', defaults: { address: { value: 0, required: true, validate: function (v) { return RED.validators.number(v) && (v >= 0) && (v <= 999); } }, tupdate: { value: 20, required: true, validate: function(v) { return RED.validators.number(v) && (v >= 5) && (v <= 10000); } }, gpioinit: { value: [] }, gpioactv: { value: [] }, }, inputs: 1, outputs: 1, icon:"font-awesome/fa-microchip", inputLabels: "boolean", outputLabels: ["boolean"], label: "gpio-out", oneditprepare: function () { function makefield(idx) { var pin = idx + 2; var prelabel = (pin < 10) ? "GPIO0" + pin : "GPIO" + pin; $("#div-gpiolist").append('<label for=init' + idx + '>' + prelabel + '</label>'); $("#div-gpiolist").append('<select id=init' + idx + ' title="Mode" value=0 style="width: auto;">'); $("#init" + idx).append('<option value=0>------</option>'); $("#init" + idx).append('<option value=1>output</option>'); $("#init" + idx).append('<option value=2>output source</option>'); $("#init" + idx).append('<option value=2>output sink</option>'); $("#div-gpiolist").append('</select>'); $("#div-gpiolist").append('&nbsp;&nbsp; Init &nbsp;&nbsp;'); $("#div-gpiolist").append('<select id=activate' + idx + ' title="Activate" value=0 style="width: auto;">'); $("#activate" + idx).append('<option value=0>deactivate</option>'); $("#activate" + idx).append('<option value=1>activate</option>'); $("#div-gpiolist").append('</select>'); } for (var idx = 0; idx <= 25; idx++) { $("#div-gpiolist").append('<div class="form-row">'); makefield(idx); $("#div-gpiolist").append('</div>'); } if (this.gpioinit.length > 0) { for (var idx = 0; idx <= 25; idx++) { $("#init" + idx).val(this.gpioinit[idx]); $("#activate" + idx).val(this.gpioactv[idx]); } } }, oneditsave: function () { this.gpioinit = []; this.gpioactv = []; for (var idx = 0; idx <= 25; idx++) { this.gpioinit.push($("#init" + idx).val()); this.gpioactv.push($("#activate" + idx).val()); } } }); </script> <script type="text/html" data-template-name="redplc-gpio-out"> <div class="form-row"> <label style="width:100%; border-bottom: 2px solid rgb(0, 0, 0);"><b>redPlc Raspberry Pi GPIO digital output</b></label> </div> <div class="form-row"> <label>Variable</label> <label style="width: auto;"><b>Q</b></label> <input id="node-input-address" title="Address" value=0 input type="number" min="0" max="999" required style="width: auto;"> </div> <div class="form-row"> <label for="node-input-tupdate">Update-Cycle</label> <input id="node-input-tupdate" input type="number" min="5" max="10000" required style="width: auto;"> <label for="node-input-tupdate"> ms</label> </div> <div id="div-gpiolist" class="form-row"> </div> </script> <script type="text/html" data-help-name="redplc-gpio-out"> <p>Sets Raspberry Pi GPIO digital outputs<br> from boolean array.</p> <h3><b>Input:</b></h3> <dl class="message-properties"> <dt>payload <span class="property-type">boolean</span></dt> <dd><b>True</b> triggers update.<dd> </dl> <h3><b>Output:</b></h3> <dl class="message-properties"> <dt>payload <span class="property-type">boolean</span></dt> <dd>Same as input payload.</dd> </dl> <h3><b>Variable (Outputs):</b></h3> <dl class="message-properties"> <dt><b>Q </b> Digital-Outputs<span class="property-type">boolean array</span></dt> </dl> <h3><b>Usage:</b></h3> <p> Output is updated on input message True,<br> and <b>Update-Cycle</b> is done,<br> and variable data is changed.<br> Variable is created and must unique.<br> Array index is equal GPIO pin.<br> For example Q0[7] is GPIO7.<br> Valid index is 2..27.<br> Not selected pins are undefined in array.<br> <br> <b>GPIO output modes:</b><br> <ul> <li><b>------</b> Output not selected.</li> <li><b>output</b> Sets pin to output.</li> <li><b>output source</b> Sets pin to output source.</li> <li><b>output sink</b> Sets pin to output sink.</li> </ul> <b>GPIO init modes on startup:</b><br> <ul> <li><b>deactivate</b> Deactivate output (false).</li> <li><b>activate</b> Activate output (true).</li> </ul> On output modes <b>output source</b> and<br> <b>output sink</b> output level is Hi-Z<br> on <b>deactivate</b>.<br> This node works on Raspberry Pi<br> with 32bit or 64bit OS.<br> Check with <b>raspi-config</b> for<br> alternate functions on GPIO.<br> </p> </script>