Skip to content

Commit

Permalink
Changed close function to be async and to clear all channels before c…
Browse files Browse the repository at this point in the history
…losing
  • Loading branch information
sudsy committed Nov 26, 2014
1 parent c4bee4e commit 4705c09
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/sendSimple.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ context.fillRect(0,0,10,10);


// connect the canvas to the sender with mapping
var output = new CanvastoE131(canvas, {host: "10.1.1.5"});
var output = new CanvastoE131(canvas, {host: "10.1.1.21"});


output.send();
Expand Down
31 changes: 25 additions & 6 deletions examples/simpleAnimation.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,46 @@
var Canvas = require("canvas");
var CanvastoE131 = require("../");

var canvas = new Canvas(16,16);

var canvas = new Canvas(48,48);

function mappingFunction(x, y){
var mapResult;

if(x % 3 === 0){
mapResult = {universe: Math.floor(x / 3) + 1, channel : y*3 + 1};
}
if(x % 3 === 1){

mapResult = {universe: Math.floor(x / 3) + 1, channel : (51 + 47 - y)*3 + 1};
}
if(x % 3 === 2){
mapResult = {universe: Math.floor(x / 3) + 1, channel : (y + 102)* 3 + 1};
}

// if(y > 46) {
// console.log(x + " - " + y )
// console.log(mapResult) } ;
return mapResult;
}

var output = new CanvastoE131(canvas, {host: "10.1.1.5"});
var output = new CanvastoE131(canvas, {host: "10.1.1.21"}, mappingFunction);



function draw(x, y) {
var context = canvas.getContext('2d');
context.save();
// Each time before drawing the Rectangle in a new position the previous one was deleted
context.clearRect(0, 0, 16, 16);
context.clearRect(0, 0, 48, 48);
context.fillStyle = "white";
context.fillRect(0, 0, 16, 16);
context.fillRect(0, 0, 48, 48);

context.fillStyle = "black";
//We will create an rectangle whose X cordinate we will change in a loop .
context.fillRect(x, 5, 5, 5);

x++;
if(x > 15) { x = 0;}
if(x > 48) { x = 0;}

// Uncomment the following to see snaps of the canvas
// var fs = require('fs'),
Expand Down
13 changes: 11 additions & 2 deletions lib/E131Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,19 @@ E131Controller.prototype.send = function(){
});
};

E131Controller.prototype.close = function(){
E131Controller.prototype.close = function(callback){
this.universeControllers.forEach(function(controller){
controller.close();
for(var i = 0; i < 512; i++){
controller.dmxdata[i] = 0;
}
controller.send(controller.dmxdata);
setTimeout(function(){
controller.close();
}, 100);

});

setTimeout(callback, 2000);
};


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "canvastoe131",
"version": "0.0.1",
"version": "0.0.2",
"description": "Send an image or animation from a canvas to a pixel array over streaming ACN E1.31",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 4705c09

Please sign in to comment.