@@ -44,18 +44,15 @@ function Blink1Node(n) {
4444 else {
4545 // you can add fancy colours by name here if you want...
4646 // these are the @cheerlight ones.
47- var result = msg . payload . toLowerCase ( ) . match ( / r e d | g r e e n | b l u e | c y a n | w h i t e | w a r m w h i t e | p u r p l e | m a g e n t a | y e l l o w | o r a n g e | b l a c k / g) ;
4847 var colors = { "red" :"#FF0000" , "green" :"#008000" , "blue" :"#0000FF" , "cyan" :"#00FFFF" , "white" :"#FFFFFF" ,
4948 "warmwhite" :"#FDF5E6" , "purple" :"#800080" , "magenta" :"#FF00FF" , "yellow" :"#FFFF00" , "orange" :"#FFA500" , "black" :"#000000" }
50- if ( result != null ) {
51- for ( var colour in result ) {
52- var c = colors [ result [ colour ] ] ;
53- var r = parseInt ( c . slice ( 1 , 3 ) , 16 ) ;
54- var g = parseInt ( c . slice ( 3 , 5 ) , 16 ) ;
55- var b = parseInt ( c . slice ( 5 ) , 16 ) ;
56- if ( node . fade == 0 ) { blink1 . setRGB ( r , g , b ) ; }
57- else { blink1 . fadeToRGB ( node . fade , r , g , b ) ; }
58- }
49+ if ( msg . payload . toLowerCase ( ) in colors ) {
50+ var c = colors [ msg . payload . toLowerCase ( ) ] ;
51+ var r = parseInt ( c . slice ( 1 , 3 ) , 16 ) ;
52+ var g = parseInt ( c . slice ( 3 , 5 ) , 16 ) ;
53+ var b = parseInt ( c . slice ( 5 ) , 16 ) ;
54+ if ( node . fade == 0 ) { blink1 . setRGB ( r , g , b ) ; }
55+ else { blink1 . fadeToRGB ( node . fade , r , g , b ) ; }
5956 }
6057 else {
6158 node . warn ( "Blink1 : invalid msg : " + msg . payload ) ;
@@ -66,11 +63,12 @@ function Blink1Node(n) {
6663 node . warn ( "No Blink1 found" ) ;
6764 }
6865 } ) ;
69- this . on ( "close" , function ( ) {
70- if ( blink1 && typeof blink1 . close == "function" ) {
71- blink1 . close ( ) ;
72- }
73- } ) ;
66+ // This ought to work but seems to cause more hangs on closing than not...
67+ //this.on("close", function() {
68+ //if (blink1 && typeof blink1.close == "function") {
69+ //blink1.close();
70+ //}
71+ //});
7472 var blink1 = new Blink1 . Blink1 ( ) ;
7573 }
7674 catch ( e ) {
0 commit comments