mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Make fade work properly for Blink1,
And add some colour name support for @cheerlights
This commit is contained in:
parent
57d5db945d
commit
83965a91af
@ -23,11 +23,11 @@
|
||||
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
</div>
|
||||
<div class="form-tips">Expects a msg.payload with three part csv string of r,g,b.</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="blink1">
|
||||
<p>ThingM Blink1 output node. Expects a msg.payload with a three part csv string of r,g,b.</p>
|
||||
<p>ThingM Blink1 output node.</p>
|
||||
<p>Expects a msg.payload with either a three part csv string of r,g,b or a hex colour #rrggbb</p>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
@ -19,7 +19,7 @@ var Blink1 = require("node-blink1");
|
||||
|
||||
function Blink1Node(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
this.fade = n.fade||0;
|
||||
this.fade = Number(n.fade) || 0;
|
||||
var node = this;
|
||||
|
||||
try {
|
||||
@ -43,14 +43,31 @@ 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 ); }
|
||||
}
|
||||
}
|
||||
else {
|
||||
node.warn("Blink1 : invalid msg : "+msg.payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
node.warn("No Blink1 found");
|
||||
}
|
||||
});
|
||||
this.on("close", function() {
|
||||
console.log(typeof blink1.close);
|
||||
if (blink1 && typeof blink1.close == "function") {
|
||||
blink1.close();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user