mirror of
				https://github.com/node-red/node-red-nodes.git
				synced 2025-03-01 10:37:43 +00:00 
			
		
		
		
	pigpiod - only allow send if actually connected.
This commit is contained in:
		| @@ -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": "*" | ||||||
|   | |||||||
| @@ -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 ); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user