mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	Let Blinkstick accept upper case colours
This commit is contained in:
		| @@ -23,27 +23,28 @@ | |||||||
| </script> | </script> | ||||||
|  |  | ||||||
| <script type="text/x-red" data-help-name="blinkstick"> | <script type="text/x-red" data-help-name="blinkstick"> | ||||||
| 	<p>BlinkStick output node. Expects a <b>msg.payload</b> with either a hex string #rrggbb triple or red,green,blue as three 0-255 values.</p> |     <p>BlinkStick output node. Expects a <b>msg.payload</b> with either a hex string #rrggbb triple or red,green,blue as three 0-255 values. | ||||||
| 	<p><b>NOTE:</b> currently only works with a single BlinkStick. (As it uses the findFirst() function to attach).</p> |     It can also accept <i><a href="http://www.w3schools.com/html/html_colornames.asp" target="_new">standard HTML colour</a></i> names</p> | ||||||
| 	<p>For more info see the <i><a href="http://blinkstick.com/" target="_new">BlinkStick website</a></i> or the <i><a href="https://github.com/arvydas/blinkstick-node" target="_new">node module</a></i> documentation.</p> |     <p><b>NOTE:</b> currently only works with a single BlinkStick. (As it uses the findFirst() function to attach).</p> | ||||||
|  |     <p>For more info see the <i><a href="http://blinkstick.com/" target="_new">BlinkStick website</a></i> or the <i><a href="https://github.com/arvydas/blinkstick-node" target="_new">node module</a></i> documentation.</p> | ||||||
| </script> | </script> | ||||||
|  |  | ||||||
| <script type="text/javascript"> | <script type="text/javascript"> | ||||||
| 	RED.nodes.registerType('blinkstick',{ |     RED.nodes.registerType('blinkstick',{ | ||||||
| 		category: 'output', |         category: 'output', | ||||||
| 		color:"GoldenRod", |         color:"GoldenRod", | ||||||
| 		defaults: { |         defaults: { | ||||||
| 			name: {value:""} |             name: {value:""} | ||||||
| 		}, |         }, | ||||||
| 		inputs:1, |         inputs:1, | ||||||
| 		outputs:0, |         outputs:0, | ||||||
| 		icon: "light.png", |         icon: "light.png", | ||||||
| 		align: "right", |         align: "right", | ||||||
| 		label: function() { |         label: function() { | ||||||
| 			return this.name||"blinkstick"; |             return this.name||"blinkstick"; | ||||||
| 		}, |         }, | ||||||
| 		labelStyle: function() { |         labelStyle: function() { | ||||||
| 			return this.name?"node_label_italic":""; |             return this.name?"node_label_italic":""; | ||||||
| 		} |         } | ||||||
| 	}); |     }); | ||||||
| </script> | </script> | ||||||
|   | |||||||
| @@ -18,44 +18,44 @@ var RED = require("../../red/red"); | |||||||
| var blinkstick = require("blinkstick"); | var blinkstick = require("blinkstick"); | ||||||
|  |  | ||||||
| Object.size = function(obj) { | Object.size = function(obj) { | ||||||
| 	var size = 0, key; |     var size = 0, key; | ||||||
| 	for (key in obj) { if (obj.hasOwnProperty(key)) size++; } |     for (key in obj) { if (obj.hasOwnProperty(key)) size++; } | ||||||
| 	return size; |     return size; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| function BlinkStick(n) { | function BlinkStick(n) { | ||||||
| 	RED.nodes.createNode(this,n); |     RED.nodes.createNode(this,n); | ||||||
| 	var p1 = /^\#[A-Fa-f0-9]{6}$/ |     var p1 = /^\#[A-Fa-f0-9]{6}$/ | ||||||
| 	var p2 = /[0-9]+,[0-9]+,[0-9]+/ |     var p2 = /[0-9]+,[0-9]+,[0-9]+/ | ||||||
| 	this.led = blinkstick.findFirst(); // maybe try findAll() (one day) |     this.led = blinkstick.findFirst(); // maybe try findAll() (one day) | ||||||
| 	var node = this; |     var node = this; | ||||||
|  |  | ||||||
| 	this.on("input", function(msg) { |     this.on("input", function(msg) { | ||||||
| 		if (msg != null) { |         if (msg != null) { | ||||||
| 			if (Object.size(node.led) !== 0) { |             if (Object.size(node.led) !== 0) { | ||||||
| 				try { |                 try { | ||||||
| 					if (p2.test(msg.payload)) { |                     if (p2.test(msg.payload)) { | ||||||
| 						var rgb = msg.payload.split(","); |                         var rgb = msg.payload.split(","); | ||||||
| 						node.led.setColor(parseInt(rgb[0])&255, parseInt(rgb[1])&255, parseInt(rgb[2])&255); |                         node.led.setColor(parseInt(rgb[0])&255, parseInt(rgb[1])&255, parseInt(rgb[2])&255); | ||||||
| 					} |                     } | ||||||
| 					else { |                     else { | ||||||
| 						node.led.setColor(msg.payload); |                         node.led.setColor(msg.payload.toLowerCase().replace(/\s+/g,'')); | ||||||
| 					} |                     } | ||||||
| 				} |                 } | ||||||
| 				catch (err) { |                 catch (err) { | ||||||
| 					node.warn("BlinkStick missing ?"); |                     node.warn("BlinkStick missing ?"); | ||||||
| 					node.led = blinkstick.findFirst(); |                     node.led = blinkstick.findFirst(); | ||||||
| 				} |                 } | ||||||
| 			} |             } | ||||||
| 			else { |             else { | ||||||
| 				//node.warn("No BlinkStick found"); |                 //node.warn("No BlinkStick found"); | ||||||
| 				node.led = blinkstick.findFirst(); |                 node.led = blinkstick.findFirst(); | ||||||
| 			} |             } | ||||||
| 		} |         } | ||||||
| 	}); |     }); | ||||||
| 	if (Object.size(node.led) === 0) { |     if (Object.size(node.led) === 0) { | ||||||
| 		node.error("No BlinkStick found"); |         node.error("No BlinkStick found"); | ||||||
| 	} |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user