mirror of
				https://github.com/node-red/node-red-nodes.git
				synced 2025-03-01 10:37:43 +00:00 
			
		
		
		
	| @@ -1,7 +1,8 @@ | |||||||
| #!/bin/bash | #!/bin/bash | ||||||
|  |  | ||||||
| python_cmd='python3' | python_cmd='python3' | ||||||
| # Fallback to Python 2, if Python 3 is not available | # Fallback to Python 2, if Python 3 is not available | ||||||
| command -v python3 > /dev/null || python_cmd='python' | command -v python3 > /dev/null || python_cmd='python' | ||||||
|  |  | ||||||
| BASEDIR=$(dirname $0) | BASEDIR=$(dirname $0) | ||||||
| exec $python_cmd -u $BASEDIR/nrsrf.py $@ | $python_cmd -u $BASEDIR/nrsrf.py $@ | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| { | { | ||||||
|     "name"          : "node-red-node-pisrf", |     "name"          : "node-red-node-pisrf", | ||||||
|     "version"       : "0.3.0", |     "version"       : "0.4.0", | ||||||
|     "description"   : "A Node-RED node for a Raspberry Pi to use a SRF04 or SRF05 range finder", |     "description"   : "A Node-RED node for a Raspberry Pi to use a SRF04 or SRF05 range finder", | ||||||
|     "dependencies"  : { |     "dependencies"  : { | ||||||
|     }, |     }, | ||||||
| @@ -18,7 +18,7 @@ | |||||||
|     }, |     }, | ||||||
|     "author": { |     "author": { | ||||||
|         "name": "Dave Conway-Jones", |         "name": "Dave Conway-Jones", | ||||||
|         "email": "ceejay@vnet.ibm.com", |         "email": "dceejay@gmail.com", | ||||||
|         "url": "http://nodered.org" |         "url": "http://nodered.org" | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,33 +1,41 @@ | |||||||
|  |  | ||||||
| module.exports = function(RED) { | module.exports = function(RED) { | ||||||
|     "use strict"; |     "use strict"; | ||||||
|     var util = require("util"); |  | ||||||
|     var spawn = require('child_process').spawn; |     var spawn = require('child_process').spawn; | ||||||
|     var fs = require('fs'); |     var execSync = require('child_process').execSync; | ||||||
|  |     //var fs = require('fs'); | ||||||
|  |  | ||||||
|  |     var testCommand = __dirname + '/testgpio'; | ||||||
|     var gpioCommand = __dirname + '/nrsrf'; |     var gpioCommand = __dirname + '/nrsrf'; | ||||||
|     var allOK = true; |     var allOK = true; | ||||||
|  |  | ||||||
|     try { |     try { | ||||||
|         var cpuinfo = fs.readFileSync("/proc/cpuinfo").toString(); |         execSync(testCommand); | ||||||
|         if (cpuinfo.indexOf(": BCM") === -1 && cpuinfo.indexOf(": Raspberry Pi") === -1) { |     } catch(err) { | ||||||
|             RED.log.warn("rpi-srf : "+RED._("node-red:rpi-gpio.errors.ignorenode")); |  | ||||||
|             allOK = false; |  | ||||||
|         } |  | ||||||
|         else if (!fs.existsSync("/usr/share/doc/python-rpi.gpio") && !fs.existsSync("/usr/share/doc/python3-rpi.gpio")) { |  | ||||||
|             RED.log.warn("rpi-srf : "+RED._("node-red:rpi-gpio.errors.libnotfound")); |  | ||||||
|             allOK = false; |  | ||||||
|         } |  | ||||||
|         else if (!(1 & parseInt ((fs.statSync(gpioCommand).mode & parseInt ("777", 8)).toString (8)[0]))) { |  | ||||||
|             RED.log.warn("rpi-srf : "+RED._("node-red:rpi-gpio.errors.needtobeexecutable",{command:gpioCommand})); |  | ||||||
|             allOK = false; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|     catch(err) { |  | ||||||
|         RED.log.warn("rpi-srf : "+RED._("node-red:rpi-gpio.errors.ignorenode")); |  | ||||||
|         allOK = false; |         allOK = false; | ||||||
|  |         RED.log.warn("rpi-srf : "+RED._("rpi-gpio.errors.ignorenode")); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     // try { | ||||||
|  |     //     var cpuinfo = fs.readFileSync("/proc/cpuinfo").toString(); | ||||||
|  |     //     if (cpuinfo.indexOf(": Raspberry Pi") === -1) { | ||||||
|  |     //         RED.log.warn("rpi-srf : "+RED._("node-red:rpi-gpio.errors.ignorenode")); | ||||||
|  |     //         allOK = false; | ||||||
|  |     //     } | ||||||
|  |     //     else if (!fs.existsSync("/usr/share/doc/python-rpi.gpio") && !fs.existsSync("/usr/share/doc/python3-rpi.gpio")) { | ||||||
|  |     //         RED.log.warn("rpi-srf : "+RED._("node-red:rpi-gpio.errors.libnotfound")); | ||||||
|  |     //         allOK = false; | ||||||
|  |     //     } | ||||||
|  |     //     else if (!(1 & parseInt ((fs.statSync(gpioCommand).mode & parseInt ("777", 8)).toString (8)[0]))) { | ||||||
|  |     //         RED.log.warn("rpi-srf : "+RED._("node-red:rpi-gpio.errors.needtobeexecutable",{command:gpioCommand})); | ||||||
|  |     //         allOK = false; | ||||||
|  |     //     } | ||||||
|  |     // } | ||||||
|  |     // catch(err) { | ||||||
|  |     //     RED.log.warn("rpi-srf : "+RED._("node-red:rpi-gpio.errors.ignorenode")); | ||||||
|  |     //     allOK = false; | ||||||
|  |     // } | ||||||
|  |  | ||||||
|     function PiSrfNode(n) { |     function PiSrfNode(n) { | ||||||
|         RED.nodes.createNode(this, n); |         RED.nodes.createNode(this, n); | ||||||
|         this.topic = n.topic; |         this.topic = n.topic; | ||||||
| @@ -83,6 +91,7 @@ module.exports = function(RED) { | |||||||
|             node.on("close", function(done) { |             node.on("close", function(done) { | ||||||
|                 if (node.child != null) { |                 if (node.child != null) { | ||||||
|                     node.child.kill('SIGKILL'); |                     node.child.kill('SIGKILL'); | ||||||
|  |                     setTimeout(function() { if (done) { done(); } }, 50); | ||||||
|                 } |                 } | ||||||
|                 wfi(done); |                 wfi(done); | ||||||
|             }); |             }); | ||||||
|   | |||||||
							
								
								
									
										8
									
								
								hardware/PiSrf/testgpio
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										8
									
								
								hardware/PiSrf/testgpio
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,8 @@ | |||||||
|  | #!/bin/bash | ||||||
|  |  | ||||||
|  | python_cmd='python3' | ||||||
|  | # Fallback to Python 2, if Python 3 is not available | ||||||
|  | command -v python3 > /dev/null || python_cmd='python' | ||||||
|  |  | ||||||
|  | BASEDIR=$(dirname $0) | ||||||
|  | $python_cmd -u $BASEDIR/testgpio.py $@ | ||||||
							
								
								
									
										6
									
								
								hardware/PiSrf/testgpio.py
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										6
									
								
								hardware/PiSrf/testgpio.py
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,6 @@ | |||||||
|  | import sys | ||||||
|  | try: | ||||||
|  |     import RPi.GPIO as GPIO | ||||||
|  |     sys.exit(0) | ||||||
|  | except ImportError: | ||||||
|  |     sys.exit(1) | ||||||
		Reference in New Issue
	
	Block a user