Skip to content

Commit d48644e

Browse files
author
Dave Conway-Jones
committed
pigpiod - only allow send if actually connected.
1 parent a881a5c commit d48644e

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

hardware/pigpiod/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-red-node-pi-gpiod",
3-
"version": "0.0.3",
3+
"version": "0.0.4",
44
"description": "A node-red node for PiGPIOd",
55
"dependencies" : {
66
"js-pigpio": "*"

hardware/pigpiod/pi-gpiod.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,26 +99,28 @@ module.exports = function(RED) {
9999
var PiGPIO;
100100

101101
function inputlistener(msg) {
102-
if (msg.payload === "true") { msg.payload = true; }
103-
if (msg.payload === "false") { msg.payload = false; }
104-
var out = Number(msg.payload);
105-
var limit = 1;
106-
if (node.out !== "out") { limit = 100; }
107-
if ((out >= 0) && (out <= limit)) {
108-
if (RED.settings.verbose) { node.log("out: "+msg.payload); }
109-
if (node.out === "out") {
110-
PiGPIO.write(node.pin, msg.payload);
111-
}
112-
if (node.out === "pwm") {
113-
PiGPIO.set_PWM_dutycycle(node.pin, parseInt(msg.payload * 2.55));
114-
}
115-
if (node.out === "ser") {
116-
var r = (node.sermax - node.sermin) * 100;
117-
PiGPIO.setServoPulsewidth(node.pin, parseInt(1500 - (r/2) + (msg.payload * r / 100)));
102+
if (!inerror) {
103+
if (msg.payload === "true") { msg.payload = true; }
104+
if (msg.payload === "false") { msg.payload = false; }
105+
var out = Number(msg.payload);
106+
var limit = 1;
107+
if (node.out !== "out") { limit = 100; }
108+
if ((out >= 0) && (out <= limit)) {
109+
if (RED.settings.verbose) { node.log("out: "+msg.payload); }
110+
if (node.out === "out") {
111+
PiGPIO.write(node.pin, msg.payload);
112+
}
113+
if (node.out === "pwm") {
114+
PiGPIO.set_PWM_dutycycle(node.pin, parseInt(msg.payload * 2.55));
115+
}
116+
if (node.out === "ser") {
117+
var r = (node.sermax - node.sermin) * 100;
118+
PiGPIO.setServoPulsewidth(node.pin, parseInt(1500 - (r/2) + (msg.payload * r / 100)));
119+
}
120+
node.status({fill:"green",shape:"dot",text:msg.payload.toString()});
118121
}
119-
node.status({fill:"green",shape:"dot",text:msg.payload.toString()});
122+
else { node.warn(RED._("pi-gpiod:errors.invalidinput")+": "+out); }
120123
}
121-
else { node.warn(RED._("pi-gpiod:errors.invalidinput")+": "+out); }
122124
}
123125

124126
if (node.pin !== undefined) {
@@ -132,6 +134,7 @@ module.exports = function(RED) {
132134
node.retry = setTimeout(function() { doit(); }, 5000);
133135
}
134136
else {
137+
inerror = false;
135138
PiGPIO.set_mode(node.pin,PiGPIO.OUTPUT);
136139
if (node.set) {
137140
setTimeout(function() { PiGPIO.write(node.pin,node.level); }, 25 );

0 commit comments

Comments
 (0)