diff --git a/hardware/neopixel/colours.js b/hardware/neopixel/colours.js
index 6f60c26e..43e09951 100644
--- a/hardware/neopixel/colours.js
+++ b/hardware/neopixel/colours.js
@@ -169,15 +169,22 @@ var colours = {
var p1 = /^\#[A-Fa-f0-9]{6}$/
-module.exports.getRGB = function(col) {
+module.exports.getRGB = function(col,rgb) {
col = col.toString().toLowerCase();
if (col in colours) {
col = colours[col];
}
if (p1.test(col)) {
- r = parseInt(col.slice(1,3),16);
- g = parseInt(col.slice(3,5),16);
- b = parseInt(col.slice(5),16);
+ if (rgb === "grb") {
+ g = parseInt(col.slice(1,3),16);
+ r = parseInt(col.slice(3,5),16);
+ b = parseInt(col.slice(5),16);
+ }
+ else {
+ r = parseInt(col.slice(1,3),16);
+ g = parseInt(col.slice(3,5),16);
+ b = parseInt(col.slice(5),16);
+ }
return r+","+g+","+b;
}
else {
diff --git a/hardware/neopixel/neopixel.html b/hardware/neopixel/neopixel.html
index 4b8591ba..9e4f7779 100644
--- a/hardware/neopixel/neopixel.html
+++ b/hardware/neopixel/neopixel.html
@@ -40,7 +40,11 @@
- mS
+ mS Pixel order
+
@@ -80,7 +84,8 @@
bgnd: { value:"" },
fgnd: { value:"" },
wipe: { value:"40", required:true, validate:RED.validators.number() },
- mode: { value:"pcent" }
+ mode: { value:"pcent" },
+ rgb: { value:"rgb" }
},
inputs:1,
outputs:0,
diff --git a/hardware/neopixel/neopixel.js b/hardware/neopixel/neopixel.js
index 7336e16a..d87c82ad 100644
--- a/hardware/neopixel/neopixel.js
+++ b/hardware/neopixel/neopixel.js
@@ -17,7 +17,7 @@
module.exports = function(RED) {
"use strict";
var spawn = require('child_process').spawn;
- var fs = require('fs');
+ var fs = require('fs');
var colors = require('./colours.js');
var piCommand = __dirname+'/neopix';
@@ -46,6 +46,7 @@ module.exports = function(RED) {
this.bgnd = n.bgnd || "0,0,0";
this.fgnd = n.fgnd || "128,128,128";
this.mode = n.mode || "pcent";
+ this.rgb = n.rgb || "rgb";
this.wipe = Number(n.wipe || 40);
if (this.wipe < 0) { this.wipe = 0; }
var node = this;
@@ -62,25 +63,24 @@ module.exports = function(RED) {
if (parts.length <= 2) {
if (parts.length === 2) { // it's a colour and length
if (isNaN(parseInt(parts[1]))) { parts = parts.reverse(); }
- if (colors.getRGB(parts[0])) {
+ if (colors.getRGB(parts[0],node.rgb)) {
var l = parts[1];
if (node.mode.indexOf("pcent") >= 0) { l = parseInt(l / 100 * node.pixels + 0.5); }
l = l - 1;
if (node.mode.indexOf("need") >= 0) {
- needle = colors.getRGB(parts[0]);
+ needle = colors.getRGB(parts[0],node.rgb);
pay = "0,"+(l-1)+","+node.fgnd+"\n"+l+","+needle+"\n"+(l+1)+","+(node.pixels-1)+","+node.bgnd;
} else {
- node.fgnd = colors.getRGB(parts[0]);
+ node.fgnd = colors.getRGB(parts[0],node.rgb);
pay = "0,"+l+","+node.fgnd+"\n"+(l+1)+","+(node.pixels-1)+","+node.bgnd;
}
- console.log(pay);
}
- else { node.warn("Invalid payload : "+pay); return; }
+ else { node.warn("Invalid colour : "+pay); return; }
}
else {
if (isNaN(pay)) { // it's a single colour word so set background
- if (colors.getRGB(pay)) {
- node.bgnd = colors.getRGB(pay);
+ if (colors.getRGB(pay,node.rgb)) {
+ node.bgnd = colors.getRGB(pay,node.rgb);
pay = node.bgnd;
}
else { node.warn("Invalid payload : "+pay); return; }
@@ -96,10 +96,17 @@ module.exports = function(RED) {
}
}
}
+ node.child.stdin.write(pay+"\n");
+ return;
}
- if ((parts.length <= 2) || p2.test(pay) || p3.test(pay) || p4.test(pay) ) {
- if (parts.length === 3) { node.bgnd = pay; }
- node.child.stdin.write(pay+"\n"); // handle 3 parts, 4 part and 5 parts in the python
+ if ( p2.test(pay) || p3.test(pay) || p4.test(pay) ) {
+ if ((parts.length > 2) && (node.rgb === "grb")) { // swap r and g values
+ var tmp = parts[parts.length-3];
+ parts[parts.length-3] = parts[parts.length-2];
+ parts[parts.length-2] = tmp;
+ }
+ if (parts.length === 3) { node.bgnd = parts.join(","); }
+ node.child.stdin.write(parts.join(",")+"\n"); // handle 3 parts, 4 part and 5 parts in the python
}
else { node.warn("Invalid payload : "+pay); }
}
@@ -145,7 +152,7 @@ module.exports = function(RED) {
if (node.bgnd) {
if (node.bgnd.split(',').length === 1) {
- node.bgnd = colors.getRGB(node.bgnd);
+ node.bgnd = colors.getRGB(node.bgnd,node.rgb);
}
if (node.mode.indexOf("shift") === -1) {
node.child.stdin.write(node.bgnd+"\n");
@@ -154,7 +161,7 @@ module.exports = function(RED) {
if (node.fgnd) {
if (node.fgnd.split(',').length === 1) {
- node.fgnd = colors.getRGB(node.fgnd);
+ node.fgnd = colors.getRGB(node.fgnd,node.rgb);
}
}
}
diff --git a/hardware/neopixel/package.json b/hardware/neopixel/package.json
index 900fec9b..f00ba726 100644
--- a/hardware/neopixel/package.json
+++ b/hardware/neopixel/package.json
@@ -1,6 +1,6 @@
{
"name" : "node-red-node-pi-neopixel",
- "version" : "0.0.6",
+ "version" : "0.0.7",
"description" : "A Node-RED node to output to a neopixel (ws2812) string of LEDS from a Raspberry Pi.",
"dependencies" : {
},