mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Add neopixel array capability to Blinkstick node
This commit is contained in:
parent
4742e19202
commit
cba50b74a2
@ -71,7 +71,9 @@
|
||||
<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><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>
|
||||
<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>
|
||||
<pre>
|
||||
{ 'color': 'blue' }
|
||||
|
@ -192,19 +192,54 @@ module.exports = function(RED) {
|
||||
|
||||
this.on("input", function(msg) {
|
||||
if (typeof(msg.payload) === 'object' ) {
|
||||
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;
|
||||
// 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 (Object.size(node.led) !== 0) {
|
||||
node.led.setMode(2); // put it into ws2812B LED mode
|
||||
var data = [];
|
||||
for (var i = 0; i < msg.payload.length; i++) {
|
||||
if (typeof msg.payload[i] === "string") { // if string then assume must be colour names
|
||||
var params = node.led.interpretParameters(msg.payload[i]); // lookup colour code from name
|
||||
if (params) {
|
||||
data.push(params.green);
|
||||
data.push(params.red);
|
||||
data.push(params.blue);
|
||||
}
|
||||
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)) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name" : "node-red-node-blinkstick",
|
||||
"version" : "0.1.2",
|
||||
"version" : "0.1.3",
|
||||
"description" : "A Node-RED node to control a Blinkstick",
|
||||
"dependencies" : {
|
||||
"blinkstick" : "1.1.*"
|
||||
|
Loading…
Reference in New Issue
Block a user