@redplc/node-red-gpio
Version:
Node-RED nodes for Raspberry Pi gpio using with redPlc nodes
136 lines (127 loc) • 5.78 kB
HTML
<!--
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-in', {
category: 'redPlc modules',
color: 'Orange',
paletteLabel: 'gpio-in',
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: [] },
gpiodeb: { value: [] },
},
inputs: 1,
outputs: 1,
icon:"font-awesome/fa-microchip",
inputLabels: "boolean",
outputLabels: ["boolean"],
label: "gpio-in",
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>nopull</option>');
$("#init" + idx).append('<option value=2>pulldown</option>');
$("#init" + idx).append('<option value=3>pullup</option>');
$("#div-gpiolist").append('</select>');
$("#div-gpiolist").append(' Debounce ');
$("#div-gpiolist").append('<input id=debounce' + idx + ' title="Debounce ms" value=25 input type="number" min="0" max="500" required style="width: auto;">');
$("#div-gpiolist").append('<label style="width: auto;">ms</label>');
}
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]);
$("#debounce" + idx).val(this.gpiodeb[idx]);
}
}
},
oneditsave: function () {
this.gpioinit = [];
this.gpiodeb = [];
for (var idx = 0; idx <= 25; idx++) {
this.gpioinit.push($("#init" + idx).val());
this.gpiodeb.push(parseInt($("#debounce" + idx).val()));
}
}
});
</script>
<script type="text/html" data-template-name="redplc-gpio-in">
<div class="form-row">
<label style="width:100%; border-bottom: 2px solid rgb(0, 0, 0);"><b>redPlc GPIO digital input</b></label>
</div>
<div class="form-row">
<label>Variable</label>
<label style="width: auto;"><b>I</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-in">
<p>Gets GPIO digital inputs<br>
and stores in 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 (Inputs):</b></h3>
<dl class="message-properties">
<dt><b>I </b> Digital-Inputs<span class="property-type">boolean array</span></dt>
</dl>
<h3><b>Usage:</b></h3>
<p>
Variable is updated on input message True,<br>
and <b>Update-Cycle</b> is done.<br>
Variable is created and must unique.<br>
Array index is equal GPIO pin.<br>
For example I0[7] is GPIO7.<br>
Valid index is 2..27.<br>
Not selected pins are undefined in array.<br>
<br>
<b>GPIO input modes:</b><br>
<ul>
<li><b>------</b> Input not selected.</li>
<li><b>nopull</b> Input with no pull resistor.<br>
Floating input.</li>
<li><b>pulldown</b> Input with pulldown.<br>
True if connected to <b>+3.3V</b>.</li>
<li><b>pullup</b> Input with pullup.<br>
True if connected to <b>ground</b>.</li>
</ul>
Debounce time of 0ms disables debounce.<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>