Skip to content

Commit

Permalink
Let gpiod turn off output in servo mode by sending null or ""
Browse files Browse the repository at this point in the history
to close #543
  • Loading branch information
Dave Conway-Jones committed May 26, 2019
1 parent af4eefa commit b74aacd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
2 changes: 1 addition & 1 deletion hardware/pigpiod/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-node-pi-gpiod",
"version": "0.0.11",
"version": "0.0.12",
"description": "A node-red node for PiGPIOd",
"dependencies" : {
"js-pigpio": "*"
Expand Down
1 change: 1 addition & 0 deletions hardware/pigpiod/pi-gpiod.html
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@
and will set the selected physical pin high or low depending on the value passed in.</p>
<p>The initial value of the pin at deploy time can also be set to 0 or 1.</p>
<p>When using PWM and Servo modes, the input value should be a number 0 - 100, and can be floating point.</p>
<p>In Servo mode you can stop the output by sending a <code>msg.payload</code> of <code>null</code> or <code>""</code>.</p>
<p>If using with Docker on Pi then the default Host IP should be <code>172.17.0.1</code>. You will also need to run <code>sudo pigpiod</code> on the host.</p>
<p><b>Note</b>: the pin numbers refer the physical pin numbers on connector P1 as they are easier to locate.</p>
</script>
Expand Down
51 changes: 30 additions & 21 deletions hardware/pigpiod/pi-gpiod.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,32 +99,41 @@ module.exports = function(RED) {
var PiGPIO;

function inputlistener(msg) {
if (msg.payload === "true") { msg.payload = true; }
if (msg.payload === "false") { msg.payload = false; }
var out = Number(msg.payload);
var limit = 1;
if (node.out !== "out") { limit = 100; }
var pre = "";
if ((out >= 0) && (out <= limit)) {
if (RED.settings.verbose) { node.log("out: "+msg.payload); }
if (node.out === "ser" && (msg.payload === null || msg.payload === "")) {
if (!inerror) {
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));
PiGPIO.setServoPulsewidth(node.pin, 0);
node.status({fill:"green",shape:"dot",text:""});
}
else { node.status({fill:"grey",shape:"ring",text:"N/C: " + msg.payload.toString()}); }
}
else {
if (msg.payload === "true") { msg.payload = true; }
if (msg.payload === "false") { msg.payload = false; }
var out = Number(msg.payload);
var limit = 1;
if (node.out !== "out") { limit = 100; }
var pre = "";
if ((out >= 0) && (out <= limit)) {
if (RED.settings.verbose) { node.log("out: "+msg.payload); }
if (!inerror) {
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 === "ser") {
var r = (node.sermax - node.sermin) * 100;
PiGPIO.setServoPulsewidth(node.pin, parseInt(1500 - (r/2) + (msg.payload * r / 100)));
else {
node.status({fill:"grey",shape:"ring",text:"N/C: " + msg.payload.toString()});
}
node.status({fill:"green",shape:"dot",text:msg.payload.toString()});
}
else {
node.status({fill:"grey",shape:"ring",text:"N/C: " + msg.payload.toString()});
}
else { node.warn(RED._("pi-gpiod:errors.invalidinput")+": "+out); }
}
else { node.warn(RED._("pi-gpiod:errors.invalidinput")+": "+out); }
}

if (node.pin !== undefined) {
Expand Down

0 comments on commit b74aacd

Please sign in to comment.