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

Let unicorn node handle block sized sprites

This commit is contained in:
Dave Conway-Jones 2016-03-26 17:34:07 +00:00
parent 0651f6fdc0
commit 6627d020ae
3 changed files with 54 additions and 47 deletions

View File

@ -1,6 +1,6 @@
{ {
"name" : "node-red-node-pi-unicorn-hat", "name" : "node-red-node-pi-unicorn-hat",
"version" : "0.0.8", "version" : "0.0.9",
"description" : "A Node-RED node to output to a Raspberry Pi Unicorn HAT from Pimorini.", "description" : "A Node-RED node to output to a Raspberry Pi Unicorn HAT from Pimorini.",
"dependencies" : { "dependencies" : {
"pngjs": "2.2.*" "pngjs": "2.2.*"

View File

@ -41,8 +41,8 @@
<p>Any msg with a <code>topic</code> identifies a 'sprite', which can then <p>Any msg with a <code>topic</code> identifies a 'sprite', which can then
be moved independently. A 'sprite' can be a single pixel or a group of pixels.</p> be moved independently. A 'sprite' can be a single pixel or a group of pixels.</p>
<p>Setting <code>payload</code> to <code>0</code> will delete the sprite from the list.</p> <p>Setting <code>payload</code> to <code>0</code> will delete the sprite from the list.</p>
<p>Setting <code>payload</code> to <code>CLS</code> will clear the display to off and delete any sprites.</p> <p>Setting <code>payload</code> to <code>CLEAR</code> will clear the display to off, and delete any sprites.</p>
<p>Setting <code>payload</code> to <ode>DEL</ode> will delete any sprites, and leave the background.</p> <p>Setting <code>payload</code> to <ode>DELETE</ode> will delete any sprites, and leave the background.</p>
<p>The brightness may be set by setting <code>payload</code> to <code>brightness,nn</code> where nn is 0 to 100.</p> <p>The brightness may be set by setting <code>payload</code> to <code>brightness,nn</code> where nn is 0 to 100.</p>
<p>The rotation may be set by setting <code>payload</code> to <code>rotate,rr</code> where rr is 0, 90, 180 or 270.</p> <p>The rotation may be set by setting <code>payload</code> to <code>rotate,rr</code> where rr is 0, 90, 180 or 270.</p>
</script> </script>

View File

@ -98,12 +98,12 @@ module.exports = function(RED) {
var s = msg.payload.toUpperCase().split(","); var s = msg.payload.toUpperCase().split(",");
var doDraw = true; var doDraw = true;
if (s.length === 1) { if (s.length === 1) {
if (s[0] == "CLS") { if ((s[0] == "CLS") || (s[0] == "CLR") || (s[0] == "CLEAR")) {
//console.log("CLEAR") //console.log("CLEAR")
pic.fill(0); pic.fill(0);
node.items = {}; node.items = {};
} }
if (s[0] == "DEL") { if ((s[0] == "DEL") || (s[0] == "DELETE")) {
//console.log("DELETE") //console.log("DELETE")
node.items = {}; node.items = {};
} }
@ -130,39 +130,40 @@ module.exports = function(RED) {
else if (s.length % 5 === 0) { // handles pixel updates else if (s.length % 5 === 0) { // handles pixel updates
if (msg.topic) { if (msg.topic) {
node.items[msg.topic] = msg.payload; node.items[msg.topic] = msg.payload;
console.log("ITEMS",node.items);
} }
else { else {
node.child.stdin.write('P'+msg.payload+'\n'); node.child.stdin.write('P'+msg.payload+'\n');
doDraw = false; doDraw = false;
var x = [];
var y = [];
for (a = 0; a < s.length; a++) { for (a = 0; a < s.length; a++) {
//console.log("PIXELS",a); //console.log("PIXELS",a);
if ((s[a] === "*") && (s[a+1] === "*")) { if (s[a] === "*") {
for (c=0; c<192; c++) { x[0] = 0;
pic[c] = s[a+2]; x[1] = 7;
pic[c+1] = s[a+3]; }
pic[c+2] = s[a+4]; else if (s[a].indexOf("-") !== -1) {
c += 2; x = s[a].split("-").sort();
}
else { x[0] = x[1] = s[a]; }
if (s[a+1] === "*") {
y[0] = 0;
y[1] = 7;
}
else if (s[a+1].indexOf("-") !== -1) {
y = s[a+1].split("-").sort();
}
else { y[0] = y[1] = s[a+1]; }
for (var j = y[0]; j <= y[1]; j++) {
for (var i = x[0]; i <= x[1]; i++) {
pic[i*3+j*24] = s[a+2];
pic[i*3+j*24+1] = s[a+3];
pic[i*3+j*24+2] = s[a+4];
} }
} }
else if (s[a] === "*") {
for (d=0; d<8; d++) {
pic[d*3+s[1]*24] = s[a+2];
pic[d*3+s[1]*24+1] = s[a+3];
pic[d*3+s[1]*24+2] = s[a+4];
}
}
else if (s[a+1] === "*") {
for (e=0; e<8; e++) {
pic[s[a]*3+e*24] = s[a+2];
pic[s[a]*3+e*24+1] = s[a+3];
pic[s[a]*3+e*24+2] = s[a+4];
}
}
else {
pic[s[a]*3+s[a+1]*24] = s[a+2];
pic[s[a]*3+s[a+1]*24+1] = s[a+3];
pic[s[a]*3+s[a+1]*24+2] = s[a+4];
}
a += 4; a += 4;
} }
} }
@ -185,25 +186,31 @@ module.exports = function(RED) {
for (var p in node.items) { for (var p in node.items) {
if (node.items.hasOwnProperty(p)) { if (node.items.hasOwnProperty(p)) {
b = node.items[p].split(","); b = node.items[p].split(",");
var x = [];
var y = [];
for (a = 0; a < b.length; a++) { for (a = 0; a < b.length; a++) {
if (b[a] === "*") { if (b[a] === "*") {
for (d=0; d<8; d++) { x[0] = 0;
pixels[d*3+b[a+1]*24] = b[a+2]; x[1] = 7;
pixels[d*3+b[a+1]*24+1] = b[a+3];
pixels[d*3+b[a+1]*24+2] = b[a+4];
} }
else if (b[a].indexOf("-") !== -1) {
x = b[a].split("-").sort();
} }
else if (b[a+1] === "*") { else { x[0] = x[1] = b[a]; }
for (e=0; e<8; e++) { if (b[a+1] === "*") {
pixels[b[a]*3+e*24] = b[a+2]; y[0] = 0;
pixels[b[a]*3+e*24+1] = b[a+3]; y[1] = 7;
pixels[b[a]*3+e*24+2] = b[a+4];
} }
else if (b[a+1].indexOf("-") !== -1) {
y = b[a+1].split("-").sort();
}
else { y[0] = y[1] = b[a+1]; }
for (var j = y[0]; j <= y[1]; j++) {
for (var i = x[0]; i <= x[1]; i++) {
pixels[i*3+j*24] = b[a+2];
pixels[i*3+j*24+1] = b[a+3];
pixels[i*3+j*24+2] = b[a+4];
} }
else {
pixels[b[a]*3+b[a+1]*24] = b[a+2];
pixels[b[a]*3+b[a+1]*24+1] = b[a+3];
pixels[b[a]*3+b[a+1]*24+2] = b[a+4];
} }
a += 4; a += 4;
} }