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,26 +99,28 @@ module.exports = function(RED) {
var PiGPIO; var PiGPIO;
function inputlistener(msg) { function inputlistener(msg) {
if (msg.payload === "true") { msg.payload = true; } if (!inerror) {
if (msg.payload === "false") { msg.payload = false; } if (msg.payload === "true") { msg.payload = true; }
var out = Number(msg.payload); if (msg.payload === "false") { msg.payload = false; }
var limit = 1; var out = Number(msg.payload);
if (node.out !== "out") { limit = 100; } var limit = 1;
if ((out >= 0) && (out <= limit)) { if (node.out !== "out") { limit = 100; }
if (RED.settings.verbose) { node.log("out: "+msg.payload); } if ((out >= 0) && (out <= limit)) {
if (node.out === "out") { if (RED.settings.verbose) { node.log("out: "+msg.payload); }
PiGPIO.write(node.pin, msg.payload); if (node.out === "out") {
PiGPIO.write(node.pin, msg.payload);
}
if (node.out === "pwm") {
PiGPIO.set_PWM_dutycycle(node.pin, parseInt(msg.payload * 2.55));
}
if (node.out === "ser") {
var r = (node.sermax - node.sermin) * 100;
PiGPIO.setServoPulsewidth(node.pin, parseInt(1500 - (r/2) + (msg.payload * r / 100)));
}
node.status({fill:"green",shape:"dot",text:msg.payload.toString()});
} }
if (node.out === "pwm") { else { node.warn(RED._("pi-gpiod:errors.invalidinput")+": "+out); }
PiGPIO.set_PWM_dutycycle(node.pin, parseInt(msg.payload * 2.55));
}
if (node.out === "ser") {
var r = (node.sermax - node.sermin) * 100;
PiGPIO.setServoPulsewidth(node.pin, parseInt(1500 - (r/2) + (msg.payload * r / 100)));
}
node.status({fill:"green",shape:"dot",text:msg.payload.toString()});
} }
else { node.warn(RED._("pi-gpiod:errors.invalidinput")+": "+out); }
} }
if (node.pin !== undefined) { if (node.pin !== undefined) {
@ -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 );