mirror of
				https://github.com/node-red/node-red-nodes.git
				synced 2025-03-01 10:37:43 +00:00 
			
		
		
		
	Update BBB nodes to support Jessie
Fix to close #156 Now mandates octalbonescript so a minor version bump.
This commit is contained in:
		
							
								
								
									
										46
									
								
								hardware/BBB/145-BBB-hardware.js
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							
							
						
						
									
										46
									
								
								hardware/BBB/145-BBB-hardware.js
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							| @@ -25,7 +25,6 @@ module.exports = function (RED) { | |||||||
|     var usrLEDs = ["USR0", "USR1", "USR2", "USR3"]; |     var usrLEDs = ["USR0", "USR1", "USR2", "USR3"]; | ||||||
|     // Load the hardware library and set up polymorphic functions to suit it. Prefer |     // Load the hardware library and set up polymorphic functions to suit it. Prefer | ||||||
|     // octalbonescript (faster & less buggy) but drop back to bonescript if not available |     // octalbonescript (faster & less buggy) but drop back to bonescript if not available | ||||||
|     try { |  | ||||||
| 	bonescript = require("octalbonescript"); | 	bonescript = require("octalbonescript"); | ||||||
| 	adjustName = function (pin) { | 	adjustName = function (pin) { | ||||||
| 		if (pin === "P8_7") { | 		if (pin === "P8_7") { | ||||||
| @@ -40,19 +39,6 @@ module.exports = function (RED) { | |||||||
| 	setPinMode = function (pin, direction, callback) { | 	setPinMode = function (pin, direction, callback) { | ||||||
| 		bonescript.pinMode(pin, direction, callback); | 		bonescript.pinMode(pin, direction, callback); | ||||||
| 	} | 	} | ||||||
|     } catch (e) { |  | ||||||
|         try { |  | ||||||
|             bonescript = require("bonescript"); |  | ||||||
|             adjustName = function (pin) { |  | ||||||
|                 return pin; |  | ||||||
|             }; |  | ||||||
|             setPinMode = function (pin, direction, callback) { |  | ||||||
|                 bonescript.pinMode(pin, direction, undefined, undefined, undefined, callback); |  | ||||||
|             } |  | ||||||
|         } catch (er) { |  | ||||||
|             throw "Info : Ignoring Beaglebone specific node."; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     // Node constructor for bbb-analogue-in |     // Node constructor for bbb-analogue-in | ||||||
|     function AnalogueInputNode(n) { |     function AnalogueInputNode(n) { | ||||||
| @@ -78,7 +64,7 @@ module.exports = function (RED) { | |||||||
|         // The callback function for analogRead. Accumulates the required number of |         // The callback function for analogRead. Accumulates the required number of | ||||||
|         // measurements, then divides the total number, applies output scaling and |         // measurements, then divides the total number, applies output scaling and | ||||||
|         // sends the result |         // sends the result | ||||||
|         var analogReadCallback = function (x) { |         var analogReadCallback = function (err, x) { | ||||||
|             sum = sum + x.value; |             sum = sum + x.value; | ||||||
|             count = count - 1; |             count = count - 1; | ||||||
|             if (count > 0) { |             if (count > 0) { | ||||||
| @@ -153,7 +139,7 @@ module.exports = function (RED) { | |||||||
|         // schedule a re-read of the input pin in 7ms time, and set the debouncing flag |         // schedule a re-read of the input pin in 7ms time, and set the debouncing flag | ||||||
|         // Note: if x has an 'attached' field and no 'value' field, the callback is reporting |         // Note: if x has an 'attached' field and no 'value' field, the callback is reporting | ||||||
|         // the success or failure of attaching the interrupt - we must handle this |         // the success or failure of attaching the interrupt - we must handle this | ||||||
|         var interruptCallback = function (x) { |         var interruptCallback = function (err, x) { | ||||||
|             if (x.value === undefined) { |             if (x.value === undefined) { | ||||||
|                 if (x.attached === true) { |                 if (x.attached === true) { | ||||||
|                     node.interruptAttached = true; |                     node.interruptAttached = true; | ||||||
| @@ -179,7 +165,7 @@ module.exports = function (RED) { | |||||||
|         // This function is called approx 7ms after a potential change-of-state which is |         // This function is called approx 7ms after a potential change-of-state which is | ||||||
|         // being debounced. Terminate the debounce, and send a message if the state has |         // being debounced. Terminate the debounce, and send a message if the state has | ||||||
|         // actually changed |         // actually changed | ||||||
|         var debounceCallback = function (x) { |         var debounceCallback = function (err, x) { | ||||||
|             node.debounceTimer = null; |             node.debounceTimer = null; | ||||||
|             node.debouncing = false; |             node.debouncing = false; | ||||||
|             if (x.value !== undefined && node.currentState !== Number(x.value)) { |             if (x.value !== undefined && node.currentState !== Number(x.value)) { | ||||||
| @@ -261,7 +247,7 @@ module.exports = function (RED) { | |||||||
|             process.nextTick(function () { |             process.nextTick(function () { | ||||||
|                 setPinMode(node._pin, bonescript.INPUT, function (response, pin) { |                 setPinMode(node._pin, bonescript.INPUT, function (response, pin) { | ||||||
|                     if (response.value === true) { |                     if (response.value === true) { | ||||||
|                         bonescript.digitalRead(node._pin, function (x) { |                         bonescript.digitalRead(node._pin, function (err, x) { | ||||||
|                             // Initialise the currentState and lastActiveTime variables based on the value read |                             // Initialise the currentState and lastActiveTime variables based on the value read | ||||||
|                             node.currentState = Number(x.value); |                             node.currentState = Number(x.value); | ||||||
|                             if (node.currentState === node.activeState) { |                             if (node.currentState === node.activeState) { | ||||||
| @@ -357,7 +343,7 @@ module.exports = function (RED) { | |||||||
|             process.nextTick(function () { |             process.nextTick(function () { | ||||||
|                 setPinMode(node._pin, bonescript.INPUT, function (response, pin) { |                 setPinMode(node._pin, bonescript.INPUT, function (response, pin) { | ||||||
|                     if (response.value === true) { |                     if (response.value === true) { | ||||||
|                         bonescript.digitalRead(node._pin, function (x) { |                         bonescript.digitalRead(node._pin, function (err, x) { | ||||||
|                             // Initialise the currentState based on the value read |                             // Initialise the currentState based on the value read | ||||||
|                             node.currentState = Number(x.value); |                             node.currentState = Number(x.value); | ||||||
|                             // Attempt to attach an interrupt handler to the pin. If we succeed, |                             // Attempt to attach an interrupt handler to the pin. If we succeed, | ||||||
| @@ -417,24 +403,25 @@ module.exports = function (RED) { | |||||||
|                     newState = !newState; |                     newState = !newState; | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             bonescript.digitalWrite(node._pin, newState ? 1 : 0); |             bonescript.digitalWrite(node._pin, newState ? 1 : 0, function() { | ||||||
| 				node.send({topic: node.topic, payload: newState}); | 				node.send({topic: node.topic, payload: newState}); | ||||||
| 				node.currentState = newState; | 				node.currentState = newState; | ||||||
|  | 			}); | ||||||
|         }; |         }; | ||||||
|  |  | ||||||
|         // If we have a valid pin, set it as an output and set the default state |         // If we have a valid pin, set it as an output and set the default state | ||||||
|         if (gpioPins.concat(usrLEDs).indexOf(node.pin) >= 0) { |         if (gpioPins.concat(usrLEDs).indexOf(node.pin) >= 0) { | ||||||
|             // Don't set up interrupts & intervals until after the close event handler has been installed |             // Don't set up interrupts & intervals until after the close event handler has been installed | ||||||
|             bonescript.detachInterrupt(node._pin); |             if (node._pin) { bonescript.detachInterrupt(node._pin); } | ||||||
|             process.nextTick(function () { |             process.nextTick(function () { | ||||||
|                 setPinMode(node._pin, bonescript.OUTPUT, function (response, pin) { |                 setPinMode(node._pin, bonescript.OUTPUT, function (response, pin) { | ||||||
|                     if (response.value === true) { |                     if (response) { | ||||||
|  | 						node.error("Unable to set " + pin + " as output: " + response.err); | ||||||
|  |                     } else { | ||||||
|                         node.on("input", inputCallback); |                         node.on("input", inputCallback); | ||||||
|                         setTimeout(function () { |                         setTimeout(function () { | ||||||
|                             bonescript.digitalWrite(node._pin, node.defaultState); |                             bonescript.digitalWrite(node._pin, node.defaultState, function() {}); | ||||||
|                         }, 50); |                         }, 50); | ||||||
|                     } else { |  | ||||||
|                         node.error("Unable to set " + pin + " as output: " + response.err); |  | ||||||
|                     } |                     } | ||||||
|                 }); |                 }); | ||||||
|             }); |             }); | ||||||
| @@ -477,15 +464,17 @@ module.exports = function (RED) { | |||||||
|                 if (node.retriggerable === false) { |                 if (node.retriggerable === false) { | ||||||
|                     if (node.pulseTimer === null) { |                     if (node.pulseTimer === null) { | ||||||
|                         node.pulseTimer = setTimeout(endPulseCallback, time); |                         node.pulseTimer = setTimeout(endPulseCallback, time); | ||||||
|                         bonescript.digitalWrite(node._pin, node.pulseState); |                         bonescript.digitalWrite(node._pin, node.pulseState, function() { | ||||||
| 							node.send({topic: node.topic, payload: node.pulseState}); | 							node.send({topic: node.topic, payload: node.pulseState}); | ||||||
|  | 						}); | ||||||
|                     } |                     } | ||||||
|                 } else { |                 } else { | ||||||
|                     if (node.pulseTimer !== null) { |                     if (node.pulseTimer !== null) { | ||||||
|                         clearTimeout(node.pulseTimer); |                         clearTimeout(node.pulseTimer); | ||||||
|                     } else { |                     } else { | ||||||
|                         bonescript.digitalWrite(node._pin, node.pulseState); |                         bonescript.digitalWrite(node._pin, node.pulseState, function() { | ||||||
| 							node.send({topic: node.topic, payload: node.pulseState}); | 							node.send({topic: node.topic, payload: node.pulseState}); | ||||||
|  |                         }); | ||||||
|                     } |                     } | ||||||
|                     node.pulseTimer = setTimeout(endPulseCallback, time); |                     node.pulseTimer = setTimeout(endPulseCallback, time); | ||||||
|                 } |                 } | ||||||
| @@ -495,8 +484,9 @@ module.exports = function (RED) { | |||||||
|         // At the end of the pulse, restore the default state and set the timer to null |         // At the end of the pulse, restore the default state and set the timer to null | ||||||
|         var endPulseCallback = function () { |         var endPulseCallback = function () { | ||||||
|             node.pulseTimer = null; |             node.pulseTimer = null; | ||||||
|             bonescript.digitalWrite(node._pin, node.defaultState); |             bonescript.digitalWrite(node._pin, node.defaultState, function() { | ||||||
| 				node.send({topic: node.topic, payload: node.defaultState}); | 				node.send({topic: node.topic, payload: node.defaultState}); | ||||||
|  |             }); | ||||||
|         }; |         }; | ||||||
|  |  | ||||||
|         // If we have a valid pin, set it as an output and set the default state |         // If we have a valid pin, set it as an output and set the default state | ||||||
|   | |||||||
| @@ -1,22 +1,27 @@ | |||||||
| node-red-node-beaglebone | node-red-node-beaglebone | ||||||
| ======================== | ======================== | ||||||
| A set of <a href="http://nodered.org" target="_new">Node-RED</a> nodes to interface with the GPIO pins of a <a href="http://http://beagleboard.org/black/" target="_new">Beaglebone Black</a>. | A set of <a href="http://nodered.org" target="_new">Node-RED</a> nodes to | ||||||
|  | interface with the GPIO pins of a <a href="http://http://beagleboard.org/black/" target="_new">Beaglebone Black</a>. | ||||||
|  |  | ||||||
| Pre-requisites | Pre-requisites | ||||||
| -------------- | -------------- | ||||||
|  |  | ||||||
| Only of use on a BeagleboneBlack board. Should ideally be running the <a href="http://beagleboard.org/latest-images/" target="_new"> latest Debian</a> image - as that has node.js v0.10.x and the bonescript npm preinstalled. | Only of use on a BeagleboneBlack board. Should ideally be running the | ||||||
| it does also need <b>bonescript</b> - but this is also pre-installed so no need to mark as a dependency... | <a href="http://beagleboard.org/latest-images/" target="_new"> latest Debian</a> | ||||||
|  | images - as they have node.js v0.10.x preinstalled. | ||||||
|  |  | ||||||
| Install | Install | ||||||
| ------- | ------- | ||||||
|  |  | ||||||
| Run the following command in the root directory of your Node-RED install | For Debian **Jessie** with kernel 4.1 run the following command in the root | ||||||
|  | directory of your Node-RED install. This is usually `~/.node-red` | ||||||
|  |  | ||||||
|     npm install node-red-node-beaglebone |     npm install node-red-node-beaglebone | ||||||
|  |  | ||||||
| v0.4 now also supports <a href="http://octalbonejs.com/" target="_new">OctaBoneScript</a> if installed. | For previous versions of Debian, for example **Wheezy** - use the older version | ||||||
|  | of this node. | ||||||
|  |  | ||||||
|  |     npm install node-red-node-beaglebone@0.0.8 | ||||||
|  |  | ||||||
| Usage | Usage | ||||||
| ----- | ----- | ||||||
| @@ -74,11 +79,9 @@ payloads > 0.5 are 'high' (1), payloads <= 0.5 are 'low' (0). Other payloads whi | |||||||
| evaluate to true are 'high', if not then 'low'. Selecting the Inverting checkbox will | evaluate to true are 'high', if not then 'low'. Selecting the Inverting checkbox will | ||||||
| switch the sense of the pin output. | switch the sense of the pin output. | ||||||
|  |  | ||||||
|  |  | ||||||
| If the Toggle state checkbox is checked, the message content is ignored: successive | If the Toggle state checkbox is checked, the message content is ignored: successive | ||||||
| messages cause the pin to toggle between 0 and 1. | messages cause the pin to toggle between 0 and 1. | ||||||
|  |  | ||||||
|  |  | ||||||
| The pin will be initially set to the given Startup state until the first message arrives: | The pin will be initially set to the given Startup state until the first message arrives: | ||||||
| the Inverting property is not applied to this value. | the Inverting property is not applied to this value. | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,15 +1,16 @@ | |||||||
| { | { | ||||||
|     "name"          : "node-red-node-beaglebone", |     "name"          : "node-red-node-beaglebone", | ||||||
|     "version"       : "0.0.8", |     "version"       : "0.1.0", | ||||||
|     "description"   : "A set of Node-RED nodes to interface to the GPIO pins of a Beaglebone Black board", |     "description"   : "A set of Node-RED nodes to interface to the GPIO pins of a Beaglebone Black board", | ||||||
|     "dependencies"  : { |     "dependencies"  : { | ||||||
|  |         "octalbonescript":"^1.1.*" | ||||||
|     }, |     }, | ||||||
|     "repository" : { |     "repository" : { | ||||||
|         "type":"git", |         "type":"git", | ||||||
|         "url":"https://github.com/node-red/node-red-nodes/tree/master/hardware/BBB" |         "url":"https://github.com/node-red/node-red-nodes/tree/master/hardware/BBB" | ||||||
|     }, |     }, | ||||||
|     "license": "Apache-2.0", |     "license": "Apache-2.0", | ||||||
|     "keywords": [ "node-red", "beagleboneblack", "beaglebone", "bbb" ], |     "keywords": [ "node-red", "beagleboneblack", "beaglebone", "bbb", "octalbonescript" ], | ||||||
|     "node-red"      : { |     "node-red"      : { | ||||||
|         "nodes"     : { |         "nodes"     : { | ||||||
|             "bbb": "145-BBB-hardware.js" |             "bbb": "145-BBB-hardware.js" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user