diff --git a/hardware/blink/77-blink1.js b/hardware/blink/77-blink1.js index a07c6e52c..5c5b41ee0 100644 --- a/hardware/blink/77-blink1.js +++ b/hardware/blink/77-blink1.js @@ -44,18 +44,15 @@ function Blink1Node(n) { else { // you can add fancy colours by name here if you want... // these are the @cheerlight ones. - var result = msg.payload.toLowerCase().match(/red|green|blue|cyan|white|warmwhite|purple|magenta|yellow|orange|black/g); var colors = {"red":"#FF0000","green":"#008000","blue":"#0000FF","cyan":"#00FFFF","white":"#FFFFFF", "warmwhite":"#FDF5E6","purple":"#800080","magenta":"#FF00FF","yellow":"#FFFF00","orange":"#FFA500","black":"#000000"} - if (result != null) { - for (var colour in result) { - var c = colors[result[colour]]; - var r = parseInt(c.slice(1,3),16); - var g = parseInt(c.slice(3,5),16); - var b = parseInt(c.slice(5),16); - if (node.fade == 0) { blink1.setRGB( r, g, b ); } - else { blink1.fadeToRGB(node.fade, r, g, b ); } - } + if (msg.payload.toLowerCase() in colors) { + var c = colors[msg.payload.toLowerCase()]; + var r = parseInt(c.slice(1,3),16); + var g = parseInt(c.slice(3,5),16); + var b = parseInt(c.slice(5),16); + if (node.fade == 0) { blink1.setRGB( r, g, b ); } + else { blink1.fadeToRGB(node.fade, r, g, b ); } } else { node.warn("Blink1 : invalid msg : "+msg.payload); @@ -66,11 +63,12 @@ function Blink1Node(n) { node.warn("No Blink1 found"); } }); - this.on("close", function() { - if (blink1 && typeof blink1.close == "function") { - blink1.close(); - } - }); + // This ought to work but seems to cause more hangs on closing than not... + //this.on("close", function() { + //if (blink1 && typeof blink1.close == "function") { + //blink1.close(); + //} + //}); var blink1 = new Blink1.Blink1(); } catch(e) {