mirror of
				https://github.com/node-red/node-red-nodes.git
				synced 2025-03-01 10:37:43 +00:00 
			
		
		
		
	Add neopixel array capability to Blinkstick node
This commit is contained in:
		| @@ -71,7 +71,9 @@ | |||||||
|         <li><b>"random"</b> will generate a random color</li> |         <li><b>"random"</b> will generate a random color</li> | ||||||
|         <li><i><a href="http://www.w3schools.com/html/html_colornames.asp" target="_new">Standard HTML color</a></i> name</li> |         <li><i><a href="http://www.w3schools.com/html/html_colornames.asp" target="_new">Standard HTML color</a></i> name</li> | ||||||
|         <li><b>object</b> can override any of the parameters</li> |         <li><b>object</b> can override any of the parameters</li> | ||||||
|  |         <li><b>array</b> of colours for a neopixel rgb strip - either name,name,... or r,g,b,r,g,b,... where r,g,b are 0 to 255.</li> | ||||||
|     </ul> |     </ul> | ||||||
|  |     <p>If using a neopixel strip it <i>must</i> be wired to the red or R channel of the blinkstick.</p> | ||||||
|     <p>An object payload can override any of the settings on the node. Omitted parameters are left intact. For example:</p> |     <p>An object payload can override any of the settings on the node. Omitted parameters are left intact. For example:</p> | ||||||
| <pre> | <pre> | ||||||
| { 'color': 'blue' } | { 'color': 'blue' } | ||||||
|   | |||||||
| @@ -192,19 +192,54 @@ module.exports = function(RED) { | |||||||
|  |  | ||||||
|         this.on("input", function(msg) { |         this.on("input", function(msg) { | ||||||
|             if (typeof(msg.payload) === 'object' ) { |             if (typeof(msg.payload) === 'object' ) { | ||||||
|                 var data = validatePayloadObject(msg.payload); |                 // if it's an array then hopefully it's r,g,b,r,g,b or name,name,name | ||||||
|  |                 if (Array.isArray(msg.payload)) { | ||||||
|                 if (typeof(data) === 'object') { |                     if (Object.size(node.led) !== 0) { | ||||||
|                     node.task = data.task ? data.task : node.task; |                         node.led.setMode(2); // put it into ws2812B LED mode | ||||||
|                     node.delay = data.delay ? data.delay : node.delay; |                         var data = []; | ||||||
|                     node.repeats = data.repeats ? data.repeats : node.repeats; |                         for (var i = 0; i < msg.payload.length; i++) { | ||||||
|                     node.duration = data.duration ? data.duration : node.duration; |                             if (typeof msg.payload[i] === "string") { // if string then assume must be colour names | ||||||
|                     node.steps = data.steps ? data.steps : node.steps; |                                 var params = node.led.interpretParameters(msg.payload[i]); // lookup colour code from name | ||||||
|                     node.repeat = data.repeat ? data.repeat : node.repeat; |                                 if (params) { | ||||||
|                     node.color = data.color ? data.color : node.color; |                                     data.push(params.green); | ||||||
|                 } else { |                                     data.push(params.red); | ||||||
|                     node.error(data); |                                     data.push(params.blue); | ||||||
|                     return; |                                 } | ||||||
|  |                                 else { node.warn("invalid colour: "+msg.payload[i]); } | ||||||
|  |                             } | ||||||
|  |                             else { // otherwise lets use numbers 0-255 | ||||||
|  |                                 data.push(msg.payload[i+1]); | ||||||
|  |                                 data.push(msg.payload[i]); | ||||||
|  |                                 data.push(msg.payload[i+2]); | ||||||
|  |                                 i += 2; | ||||||
|  |                             } | ||||||
|  |                         } | ||||||
|  |                         if ((data.length % 3) === 0) { // by now length must be a multiple of 3 | ||||||
|  |                             node.led.setColors(0, data, function(err) { | ||||||
|  |                                 if (err) { node.log(err); } | ||||||
|  |                             }); | ||||||
|  |                         } | ||||||
|  |                         else { | ||||||
|  |                             node.warn("Colour array length not / 3"); | ||||||
|  |                         } | ||||||
|  |                         return; | ||||||
|  |                     } // else if no blinkstick let it get caught below | ||||||
|  |                 } | ||||||
|  |                 // not an array - must be the "normal" object.... | ||||||
|  |                 else { | ||||||
|  |                     var data = validatePayloadObject(msg.payload); | ||||||
|  |                     if (typeof(data) === 'object') { | ||||||
|  |                         node.task = data.task ? data.task : node.task; | ||||||
|  |                         node.delay = data.delay ? data.delay : node.delay; | ||||||
|  |                         node.repeats = data.repeats ? data.repeats : node.repeats; | ||||||
|  |                         node.duration = data.duration ? data.duration : node.duration; | ||||||
|  |                         node.steps = data.steps ? data.steps : node.steps; | ||||||
|  |                         node.repeat = data.repeat ? data.repeat : node.repeat; | ||||||
|  |                         node.color = data.color ? data.color : node.color; | ||||||
|  |                     } else { | ||||||
|  |                         node.error(data); | ||||||
|  |                         return; | ||||||
|  |                     } | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|             } else if (p1.test(msg.payload)) { |             } else if (p1.test(msg.payload)) { | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| { | { | ||||||
|     "name"          : "node-red-node-blinkstick", |     "name"          : "node-red-node-blinkstick", | ||||||
|     "version"       : "0.1.2", |     "version"       : "0.1.3", | ||||||
|     "description"   : "A Node-RED node to control a Blinkstick", |     "description"   : "A Node-RED node to control a Blinkstick", | ||||||
|     "dependencies"  : { |     "dependencies"  : { | ||||||
|         "blinkstick"   : "1.1.*" |         "blinkstick"   : "1.1.*" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user