diff --git a/hardware/blinkstick/76-blinkstick.html b/hardware/blinkstick/76-blinkstick.html index 959bfb75..66e947f6 100644 --- a/hardware/blinkstick/76-blinkstick.html +++ b/hardware/blinkstick/76-blinkstick.html @@ -71,7 +71,9 @@
  • "random" will generate a random color
  • Standard HTML color name
  • object can override any of the parameters
  • +
  • array 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.
  • +

    If using a neopixel strip it must be wired to the red or R channel of the blinkstick.

    An object payload can override any of the settings on the node. Omitted parameters are left intact. For example:

     { 'color': 'blue' }
    diff --git a/hardware/blinkstick/76-blinkstick.js b/hardware/blinkstick/76-blinkstick.js
    index dbc7e67b..dc0aa21b 100644
    --- a/hardware/blinkstick/76-blinkstick.js
    +++ b/hardware/blinkstick/76-blinkstick.js
    @@ -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)) {
    diff --git a/hardware/blinkstick/package.json b/hardware/blinkstick/package.json
    index d06f9585..e1073fa3 100644
    --- a/hardware/blinkstick/package.json
    +++ b/hardware/blinkstick/package.json
    @@ -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.*"