SenseHat: Add clock example and support for x0-x1 ranges

This commit is contained in:
Nick O'Leary
2016-03-28 22:53:28 +01:00
parent 73e84c7ff9
commit a4daf91a30
6 changed files with 50 additions and 20 deletions

View File

@@ -286,8 +286,7 @@ module.exports = function(RED) {
var lines = msg.payload.split("\n");
lines.forEach(function(line) {
command = null;
col = colours.getRGB(line);
if ( /^(([0-7]|\*),([0-7]|\*),(\d{1,3},\d{1,3},\d{1,3}|#[a-f0-9]{3,6}|[a-z]+))(,([0-7]|\*),([0-7]|\*),(\d{1,3},\d{1,3},\d{1,3}|#[a-f0-9]{3,6}|[a-z]+))*$/i.test(line)) {
if ( /^(([0-7]|\*|[0-7]-[0-7]),([0-7]|\*|[0-7]-[0-7]),(\d{1,3},\d{1,3},\d{1,3}|#[a-f0-9]{3,6}|[a-z]+))(,([0-7]|\*|[0-7]-[0-7]),([0-7]|\*|[0-7]-[0-7]),(\d{1,3},\d{1,3},\d{1,3}|#[a-f0-9]{3,6}|[a-z]+))*$/i.test(line)) {
parts = line.split(",");
var expanded = [];
var i=0;
@@ -305,22 +304,46 @@ module.exports = function(RED) {
} else {
col += ","+parts[i++]+","+parts[i++];
}
if (x!=='*' && y!=='*') {
expanded.push([x,y,col]);
} else if (x == '*' && y == '*') {
for (j=0;j<8;j++) {
for (var k=0;k<8;k++) {
expanded.push([j,k,col]);
}
if (x === '*') {
x = "0-7";
}
if (y === '*') {
y = "0-7";
}
var x0,x1;
var y0,y1;
if (x.indexOf("-") === -1) {
x0 = x1 = parseInt(x);
} else {
var px = x.split("-");
x0 = parseInt(px[0]);
x1 = parseInt(px[1]);
if (x1<x0) {
j = x1;
x1 = x0;
x0 = j;
}
} else if (x == '*') {
for (j=0;j<8;j++) {
expanded.push([j,y,col]);
}
if (y.indexOf("-") === -1) {
y0 = y1 = parseInt(y);
} else {
var py = y.split("-");
y0 = parseInt(py[0]);
y1 = parseInt(py[1]);
if (y1<y0) {
j = y1;
y1 = y0;
y0 = j;
}
} else if (y == '*') {
for (j=0;j<8;j++) {
expanded.push([x,j,col]);
}
x = x0;
while(x<=x1) {
y = y0;
while(y<=y1) {
expanded.push([x,y,col]);
y++;
}
x++;
}
}
if (expanded.length > 0) {