1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

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
This commit is contained in:
Dennis Gaida 2021-06-22 13:39:22 +02:00 committed by GitHub
parent 799eee3873
commit eb8bae6782
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 114 additions and 12 deletions

View File

@ -1,5 +1,8 @@
<script type="text/x-red" data-template-name="blink1">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-serial"><i class="fa fa-random"></i> Device ID</label>
<input type="text" id="node-input-serial" placeholder="defaults to first found" style="width:60%">
@ -9,10 +12,6 @@
<label for="node-input-fade"><i class="fa fa-signal"></i> Fade (mS)</label>
<input type="text" id="node-input-fade" placeholder="between 0 and 60,000 mS (1 min)">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<script type="text/x-red" data-help-name="blink1">
@ -26,8 +25,9 @@
<script type="text/javascript">
RED.nodes.registerType('blink1',{
category: 'output',
category: "blink1",
color:"GoldenRod",
paletteLabel: "blink1 out",
defaults: {
serial: {value:""},
fade: {value:"500",required:true,validate:RED.validators.number()},
@ -38,7 +38,58 @@
icon: "light.png",
align: "right",
label: function() {
return this.name||"blink1";
return this.name||"blink1 out";
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
oneditprepare: function() {
$("#node-lookup-serial").click(function() {
$.getJSON('blink1list',function(data) {
$("#node-input-serial").autocomplete({
source:data,
minLength:0,
close: function( event, ui ) {
$("#node-input-serial").autocomplete( "destroy" );
}
}).autocomplete("search","");
});
});
}
});
</script>
<script type="text/x-red" data-template-name="blink1 in">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-serial"><i class="fa fa-random"></i> Device ID</label>
<input type="text" id="node-input-serial" placeholder="defaults to first found" style="width:60%">
<a id="node-lookup-serial" class="btn"><i id="node-lookup-serial-icon" class="fa fa-search"></i></a>
</div>
</script>
<script type="text/x-red" data-help-name="blink1 in">
<p>ThingM Blink1 input node.</p>
<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>
</script>
<script type="text/javascript">
RED.nodes.registerType('blink1 in',{
category: 'blink1',
color:"GoldenRod",
paletteLabel:"blink1 in",
defaults: {
serial: {value:""}
},
inputs:1,
outputs:1,
icon: "light.png",
align: "left",
label: function() {
return this.name||"blink1 in";
},
labelStyle: function() {
return this.name?"node_label_italic":"";

View File

@ -4,7 +4,7 @@ module.exports = function(RED) {
var Blink1 = require("node-blink1");
var blink1 = {};
function Blink1Node(n) {
function Blink1OutNode(n) {
RED.nodes.createNode(this,n);
this.serial = n.serial;
if (!this.serial) { delete this.serial; }
@ -83,7 +83,52 @@ module.exports = function(RED) {
node.error("No Blink1 found (" + e + ")");
}
}
RED.nodes.registerType("blink1",Blink1Node);
RED.nodes.registerType("blink1",Blink1OutNode);
function Blink1InNode(n) {
RED.nodes.createNode(this,n);
this.serial = n.serial;
if (!this.serial) { delete this.serial; }
var node = this;
try {
this.on("input", function(msg) {
try {
blink1[node.serial||"one"] = blink1[node.serial||"one"] || new Blink1.Blink1(node.serial);
node.status({text:node.serial});
if (blink1[node.serial||"one"]) {
var that = this;
var returnRgb = function (r,g,b){
var rgb = [r,g,b];
var payload = rgb.every(el => el === 0) ? "off" : rgb;
msg.payload = payload;
that.send(msg);
};
try {
var device = blink1[node.serial||"one"];
device.rgb(returnRgb);
}
catch (e) { node.error("Blink1 : error | " + e); blink1[node.serial||"one"] = null; }
}
else { node.warn("Blink1 : not found"); }
}
catch (e) { node.error("Blink1 : device not found"); blink1[node.serial||"one"] = null; }
});
this.on("close", function(done) {
if (blink1[node.serial||"one"] && typeof blink1[node.serial||"one"].close === "function") {
blink1[node.serial||"one"].close(function() { done() });
}
else { done(); }
blink1[node.serial||"one"] = null;
});
}
catch(e) {
node.error("No Blink1 found (" + e + ")");
}
}
RED.nodes.registerType("blink1 in",Blink1InNode);
RED.httpAdmin.get("/blink1list", RED.auth.needsPermission('blink1.read'), function(req,res) {
res.json(Blink1.devices());

View File

@ -29,10 +29,16 @@ Run the following command in your Node-RED user directory - typically `~/.node-r
Usage
-----
__Out__
Sends the `msg.payload` to a Thingm Blink(1) LED device. The payload can be any of the following:
- a three part csv string of r,g,b - e.g. red is 255,0,0
- a hex colour #rrggbb - e.g. green is #00FF00
- a three part csv string of r,g,b - e.g. red is 255,0,0
- a hex colour #rrggbb - e.g. green is #00FF00
- a <a href="http://www.cheerlights.com/control-cheerlights">@cheerlights</a> colour name - e.g. blue
The colours it accepts are - red, amber, green, blue, cyan, magenta, yellow, orange, pink, purple, white, warmwhite (or oldlace), black, (and off)
__In__
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].
If the Blink(1) is off the device returns 0,0,0. Instead of [0,0,0] the node returns "off".

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-blink1",
"version" : "0.0.18",
"version" : "0.1.0",
"description" : "A Node-RED node to control a Thingm Blink(1)",
"dependencies" : {
"node-blink1" : "0.5.1"