diff --git a/demo.js b/demo.js index d529200..a8826e1 100644 --- a/demo.js +++ b/demo.js @@ -6,6 +6,7 @@ var A = DMX.Animation var dmx = new DMX() // var universe = dmx.addUniverse('demo', 'enttec-usb-dmx-pro', 0) +// var universe = dmx.addUniverse('demo', 'enttec-open-usb-dmx', 0) var universe = dmx.addUniverse('demo', 'null') universe.update({0: 1, 1: 0}) diff --git a/demo_simple.js b/demo_simple.js new file mode 100644 index 0000000..4a31edd --- /dev/null +++ b/demo_simple.js @@ -0,0 +1,21 @@ +"use strict" + +var DMX = require('./dmx'); +var A = DMX.Animation; + +var dmx = new DMX(); +// var universe = dmx.addUniverse('demo', 'enttec-open-usb-dmx', 0) +var universe = dmx.addUniverse('demo', 'null') + +var on = false; +setInterval(function(){ + if(on){ + on = false; + universe.updateAll(0); + console.log("off"); + }else{ + on = true; + universe.updateAll(250); + console.log("on"); + } +}, 1000); \ No newline at end of file diff --git a/dmx.js b/dmx.js index 235549f..4072f65 100644 --- a/dmx.js +++ b/dmx.js @@ -30,4 +30,9 @@ DMX.prototype.update = function(universe, channels) { this.emit('update', universe, channels) } +DMX.prototype.updateAll = function(universe, value) { + this.universes[universe].updateAll(value) + this.emit('updateAll', universe, value) +} + module.exports = DMX diff --git a/drivers/enttec-open-usb-dmx.js b/drivers/enttec-open-usb-dmx.js index 30b91e9..4e59985 100644 --- a/drivers/enttec-open-usb-dmx.js +++ b/drivers/enttec-open-usb-dmx.js @@ -2,23 +2,23 @@ var FTDI = require('ftdi') -function EnttecOpenUsbDMX(device_id, cb) { +function EnttecOpenUsbDMX(locationId, cb) { var self = this; cb = cb || function() {} - self.universe = new Buffer(513); - self.universe.fill(0); - self.sleepTime = 20; + self.universe = Array(513); + self.universe[0] = 0; + self.updateAll(0); + self.sleepTime = 24; self.timeout; - - self.dev = new FTDI.FtdiDevice(device_id) + self.dev = new FTDI.FtdiDevice(locationId) self.dev.open({ 'baudrate': 115200 / 2, 'databits': 8, 'stopbits': 2, 'parity': 'none' }, function(err) { - cb(err, device_id) + cb(err, locationId) if(!err) { self.loopUniverse() } @@ -27,18 +27,25 @@ function EnttecOpenUsbDMX(device_id, cb) { EnttecOpenUsbDMX.prototype.loopUniverse = function(){ var self = this; + clearTimeout(self.timeout); self.dev.write(self.universe); + self.timeout = setTimeout(function(){ self.loopUniverse(); }, self.sleepTime) } EnttecOpenUsbDMX.prototype.pause = function(){ + var self = this; + clearTimeout(self.timeout); } EnttecOpenUsbDMX.prototype.close = function(cb){ + var self = this; + + self.pause(); self.dev.close(function(err){ cb(err) }) @@ -48,7 +55,17 @@ EnttecOpenUsbDMX.prototype.update = function(u) { var self = this; for(var c in u) { - self.universe[(c + 1)] = u[self.toHex(c)]; + self.universe[(c + 1)] = u[c]; + } +} + +EnttecOpenUsbDMX.prototype.updateAll = function(v) { + var self = this; + + var i = 1; + while(i < self.universe.length){ + self.universe[i] = v; + i++; } } @@ -58,13 +75,4 @@ EnttecOpenUsbDMX.prototype.get = function(c) { return self.universe[(c + 1)]; } -EnttecOpenUsbDMX.prototype.toHex = function(number){ - var self = this; - - var octet = parseInt(number).toString(16); - if(octet.length == 1){ octet = "0" + octet; } - var fullOctet = "0x" + octet; - return eval(fullOctet); // TODO: dangerous! -} - module.exports = EnttecOpenUsbDMX diff --git a/drivers/enttec-usb-dmx-pro.js b/drivers/enttec-usb-dmx-pro.js index 514f1dc..b13d2bd 100644 --- a/drivers/enttec-usb-dmx-pro.js +++ b/drivers/enttec-usb-dmx-pro.js @@ -53,6 +53,10 @@ EnttecUSBDMXPRO.prototype.update = function(u) { this.send_universe() } +EnttecUSBDMXPRO.prototype.updateAll = function(v){ + // TODO +} + EnttecUSBDMXPRO.prototype.get = function(c) { return this.universe[c] } diff --git a/drivers/null.js b/drivers/null.js index c63e4f3..8259b6b 100644 --- a/drivers/null.js +++ b/drivers/null.js @@ -14,6 +14,10 @@ Null.prototype.update = function(u) { console.log(this.universe) } +Null.prototype.updateAll = function(v){ + // TODO +} + Null.prototype.get = function(c) { return this.universe[c] }