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

Fixed regex for LEDs to look for 0-9a-fA-F

This commit is contained in:
Dave C-J 2013-09-16 17:55:49 +01:00
parent 5a5a4644db
commit 939178720a
3 changed files with 15 additions and 13 deletions

View File

@ -25,7 +25,7 @@ Object.size = function(obj) {
function BlinkStick(n) {
RED.nodes.createNode(this,n);
var p1 = /^\#[A-Za-z0-9]{6}$/
var p1 = /^\#[A-Fa-f0-9]{6}$/
var p2 = /[0-9]+,[0-9]+,[0-9]+/
this.led = blinkstick.findFirst(); // maybe try findAll() (one day)
var node = this;
@ -33,21 +33,23 @@ function BlinkStick(n) {
this.on("input", function(msg) {
if (msg != null) {
if (Object.size(node.led) !== 0) {
if (p2.test(msg.payload)) {
var rgb = msg.payload.split(",");
node.led.setColor(parseInt(rgb[0])&255, parseInt(rgb[1])&255, parseInt(rgb[2])&255);
}
else {
try {
try {
if (p2.test(msg.payload)) {
var rgb = msg.payload.split(",");
node.led.setColor(parseInt(rgb[0])&255, parseInt(rgb[1])&255, parseInt(rgb[2])&255);
}
else {
node.led.setColor(msg.payload);
}
catch (err) {
node.warn("Incorrect format: "+msg.payload);
}
}
catch (err) {
node.warn("BlinkStick missing ?");
node.led = blinkstick.findFirst();
}
}
else {
node.warn("No BlinkStick found");
node.led = blinkstick.findFirst();
}
}
});

View File

@ -23,7 +23,7 @@ function Blink1Node(n) {
var node = this;
try {
var p1 = /^\#[A-Za-z0-9]{6}$/
var p1 = /^\#[A-Fa-f0-9]{6}$/
var p2 = /[0-9]+,[0-9]+,[0-9]+/
this.on("input", function(msg) {
if (blink1) {
@ -53,7 +53,7 @@ function Blink1Node(n) {
var blink1 = new Blink1.Blink1();
}
catch(e) {
node.error("no Blink1 found");
node.error("No Blink1 found");
}
}

View File

@ -25,7 +25,7 @@ catch (err) { util.log("[77-ledborg.js] Error: PiBorg hardware : LedBorg not fou
function LedBorgNode(n) {
RED.nodes.createNode(this,n);
var p1 = /[0-2][0-2][0-2]/
var p2 = /^\#[A-Za-z0-9]{6}$/
var p2 = /^\#[A-Fa-f0-9]{6}$/
var node = this;
this.on("input", function(msg) {