Skip to content

Commit eb8bae6

Browse files
authored
blink1: added "blink1 in" node (#812)
* Added "blink1 in" node * sets msg.payload to current RGB value or "off" if RGB = 0,0,0 * can also be used to pipe msg.payload to blink1 out * blink1 category created * blink1 label set to "blink1 out" * Bumped version to 0.1.0 * Modified readme
1 parent 799eee3 commit eb8bae6

File tree

4 files changed

+114
-12
lines changed

4 files changed

+114
-12
lines changed

hardware/blink1/77-blink1.html

+58-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
21
<script type="text/x-red" data-template-name="blink1">
2+
<div class="form-row">
3+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
4+
<input type="text" id="node-input-name" placeholder="Name">
5+
</div>
36
<div class="form-row">
47
<label for="node-input-serial"><i class="fa fa-random"></i> Device ID</label>
58
<input type="text" id="node-input-serial" placeholder="defaults to first found" style="width:60%">
@@ -9,10 +12,6 @@
912
<label for="node-input-fade"><i class="fa fa-signal"></i> Fade (mS)</label>
1013
<input type="text" id="node-input-fade" placeholder="between 0 and 60,000 mS (1 min)">
1114
</div>
12-
<div class="form-row">
13-
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
14-
<input type="text" id="node-input-name" placeholder="Name">
15-
</div>
1615
</script>
1716

1817
<script type="text/x-red" data-help-name="blink1">
@@ -26,8 +25,9 @@
2625

2726
<script type="text/javascript">
2827
RED.nodes.registerType('blink1',{
29-
category: 'output',
28+
category: "blink1",
3029
color:"GoldenRod",
30+
paletteLabel: "blink1 out",
3131
defaults: {
3232
serial: {value:""},
3333
fade: {value:"500",required:true,validate:RED.validators.number()},
@@ -38,7 +38,58 @@
3838
icon: "light.png",
3939
align: "right",
4040
label: function() {
41-
return this.name||"blink1";
41+
return this.name||"blink1 out";
42+
},
43+
labelStyle: function() {
44+
return this.name?"node_label_italic":"";
45+
},
46+
oneditprepare: function() {
47+
$("#node-lookup-serial").click(function() {
48+
$.getJSON('blink1list',function(data) {
49+
$("#node-input-serial").autocomplete({
50+
source:data,
51+
minLength:0,
52+
close: function( event, ui ) {
53+
$("#node-input-serial").autocomplete( "destroy" );
54+
}
55+
}).autocomplete("search","");
56+
});
57+
});
58+
}
59+
});
60+
</script>
61+
62+
<script type="text/x-red" data-template-name="blink1 in">
63+
<div class="form-row">
64+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
65+
<input type="text" id="node-input-name" placeholder="Name">
66+
</div>
67+
<div class="form-row">
68+
<label for="node-input-serial"><i class="fa fa-random"></i> Device ID</label>
69+
<input type="text" id="node-input-serial" placeholder="defaults to first found" style="width:60%">
70+
<a id="node-lookup-serial" class="btn"><i id="node-lookup-serial-icon" class="fa fa-search"></i></a>
71+
</div>
72+
</script>
73+
74+
<script type="text/x-red" data-help-name="blink1 in">
75+
<p>ThingM Blink1 input node.</p>
76+
<p>Outputs the current RGB value as array <code>[r,g,b]</code> or "off" as string if RGB is 0,0,0 to <code>msg.payload</code>.</p>
77+
</script>
78+
79+
<script type="text/javascript">
80+
RED.nodes.registerType('blink1 in',{
81+
category: 'blink1',
82+
color:"GoldenRod",
83+
paletteLabel:"blink1 in",
84+
defaults: {
85+
serial: {value:""}
86+
},
87+
inputs:1,
88+
outputs:1,
89+
icon: "light.png",
90+
align: "left",
91+
label: function() {
92+
return this.name||"blink1 in";
4293
},
4394
labelStyle: function() {
4495
return this.name?"node_label_italic":"";

hardware/blink1/77-blink1.js

+47-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports = function(RED) {
44
var Blink1 = require("node-blink1");
55
var blink1 = {};
66

7-
function Blink1Node(n) {
7+
function Blink1OutNode(n) {
88
RED.nodes.createNode(this,n);
99
this.serial = n.serial;
1010
if (!this.serial) { delete this.serial; }
@@ -83,7 +83,52 @@ module.exports = function(RED) {
8383
node.error("No Blink1 found (" + e + ")");
8484
}
8585
}
86-
RED.nodes.registerType("blink1",Blink1Node);
86+
RED.nodes.registerType("blink1",Blink1OutNode);
87+
88+
function Blink1InNode(n) {
89+
RED.nodes.createNode(this,n);
90+
this.serial = n.serial;
91+
if (!this.serial) { delete this.serial; }
92+
var node = this;
93+
94+
try {
95+
this.on("input", function(msg) {
96+
try {
97+
blink1[node.serial||"one"] = blink1[node.serial||"one"] || new Blink1.Blink1(node.serial);
98+
node.status({text:node.serial});
99+
if (blink1[node.serial||"one"]) {
100+
var that = this;
101+
102+
var returnRgb = function (r,g,b){
103+
var rgb = [r,g,b];
104+
var payload = rgb.every(el => el === 0) ? "off" : rgb;
105+
msg.payload = payload;
106+
that.send(msg);
107+
};
108+
109+
try {
110+
var device = blink1[node.serial||"one"];
111+
device.rgb(returnRgb);
112+
}
113+
catch (e) { node.error("Blink1 : error | " + e); blink1[node.serial||"one"] = null; }
114+
}
115+
else { node.warn("Blink1 : not found"); }
116+
}
117+
catch (e) { node.error("Blink1 : device not found"); blink1[node.serial||"one"] = null; }
118+
});
119+
this.on("close", function(done) {
120+
if (blink1[node.serial||"one"] && typeof blink1[node.serial||"one"].close === "function") {
121+
blink1[node.serial||"one"].close(function() { done() });
122+
}
123+
else { done(); }
124+
blink1[node.serial||"one"] = null;
125+
});
126+
}
127+
catch(e) {
128+
node.error("No Blink1 found (" + e + ")");
129+
}
130+
}
131+
RED.nodes.registerType("blink1 in",Blink1InNode);
87132

88133
RED.httpAdmin.get("/blink1list", RED.auth.needsPermission('blink1.read'), function(req,res) {
89134
res.json(Blink1.devices());

hardware/blink1/README.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,16 @@ Run the following command in your Node-RED user directory - typically `~/.node-r
2929
Usage
3030
-----
3131

32+
__Out__
3233
Sends the `msg.payload` to a Thingm Blink(1) LED device. The payload can be any of the following:
3334

34-
- a three part csv string of r,g,b - e.g. red is 255,0,0
35-
- a hex colour #rrggbb - e.g. green is #00FF00
35+
- a three part csv string of r,g,b - e.g. red is 255,0,0
36+
- a hex colour #rrggbb - e.g. green is #00FF00
3637
- a <a href="http://www.cheerlights.com/control-cheerlights">@cheerlights</a> colour name - e.g. blue
3738

3839
The colours it accepts are - red, amber, green, blue, cyan, magenta, yellow, orange, pink, purple, white, warmwhite (or oldlace), black, (and off)
40+
41+
__In__
42+
Outputs the current color value of the Blink(1) LED device in the `msg.payload` with the r,g,b values as an array e.g. [255,0,0].
43+
44+
If the Blink(1) is off the device returns 0,0,0. Instead of [0,0,0] the node returns "off".

hardware/blink1/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name" : "node-red-node-blink1",
3-
"version" : "0.0.18",
3+
"version" : "0.1.0",
44
"description" : "A Node-RED node to control a Thingm Blink(1)",
55
"dependencies" : {
66
"node-blink1" : "0.5.1"

0 commit comments

Comments
 (0)