1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

pigpiod - only allow send if actually connected.

This commit is contained in:
Dave Conway-Jones 2017-04-19 11:13:57 +01:00
parent a881a5c4af
commit d48644e16a
No known key found for this signature in database
GPG Key ID: 81B04231572A9A2D
2 changed files with 22 additions and 19 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "node-red-node-pi-gpiod", "name": "node-red-node-pi-gpiod",
"version": "0.0.3", "version": "0.0.4",
"description": "A node-red node for PiGPIOd", "description": "A node-red node for PiGPIOd",
"dependencies" : { "dependencies" : {
"js-pigpio": "*" "js-pigpio": "*"

View File

@ -99,6 +99,7 @@ module.exports = function(RED) {
var PiGPIO; var PiGPIO;
function inputlistener(msg) { function inputlistener(msg) {
if (!inerror) {
if (msg.payload === "true") { msg.payload = true; } if (msg.payload === "true") { msg.payload = true; }
if (msg.payload === "false") { msg.payload = false; } if (msg.payload === "false") { msg.payload = false; }
var out = Number(msg.payload); var out = Number(msg.payload);
@ -120,6 +121,7 @@ module.exports = function(RED) {
} }
else { node.warn(RED._("pi-gpiod:errors.invalidinput")+": "+out); } else { node.warn(RED._("pi-gpiod:errors.invalidinput")+": "+out); }
} }
}
if (node.pin !== undefined) { if (node.pin !== undefined) {
PiGPIO = new Pigpio(); PiGPIO = new Pigpio();
@ -132,6 +134,7 @@ module.exports = function(RED) {
node.retry = setTimeout(function() { doit(); }, 5000); node.retry = setTimeout(function() { doit(); }, 5000);
} }
else { else {
inerror = false;
PiGPIO.set_mode(node.pin,PiGPIO.OUTPUT); PiGPIO.set_mode(node.pin,PiGPIO.OUTPUT);
if (node.set) { if (node.set) {
setTimeout(function() { PiGPIO.write(node.pin,node.level); }, 25 ); setTimeout(function() { PiGPIO.write(node.pin,node.level); }, 25 );