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 dd482c0..4e59985 100644 --- a/drivers/enttec-open-usb-dmx.js +++ b/drivers/enttec-open-usb-dmx.js @@ -2,59 +2,77 @@ var FTDI = require('ftdi') -var ENTTEC_PRO_DMX_STARTCODE = 0x00 - , ENTTEC_PRO_START_OF_MSG = 0x7e - , ENTTEC_PRO_END_OF_MSG = 0xe7 - , ENTTEC_PRO_SEND_DMX_RQ = 0x06 - ; +function EnttecOpenUsbDMX(locationId, cb) { + var self = this; -function EnttecOpenUsbDMX(device_id, cb) { - var self = this - cb = cb || function() {} - this.universe = new Buffer(512) - this.universe.fill(0) - - this.dev = new FTDI.FtdiDevice(device_id) - this.dev.open({ - 'baudrate': 115200, - 'databits': 8, - 'stopbits': 2, - 'parity': 'none' - }, function(err) { - cb(err, device_id) - if(!err) { - self.send_universe() - } - }) + cb = cb || function() {} + self.universe = Array(513); + self.universe[0] = 0; + self.updateAll(0); + self.sleepTime = 24; + self.timeout; + self.dev = new FTDI.FtdiDevice(locationId) + self.dev.open({ + 'baudrate': 115200 / 2, + 'databits': 8, + 'stopbits': 2, + 'parity': 'none' + }, function(err) { + cb(err, locationId) + if(!err) { + self.loopUniverse() + } + }) } -EnttecOpenUsbDMX.prototype.send_universe = function() { - var hdr = Buffer([ - ENTTEC_PRO_START_OF_MSG, - ENTTEC_PRO_SEND_DMX_RQ, - // (this.universe.length + 1) & 0xff, - ((this.universe.length + 1) >> 0) & 0xff, - ((this.universe.length + 1) >> 8) & 0xff, - ENTTEC_PRO_DMX_STARTCODE - ]) +EnttecOpenUsbDMX.prototype.loopUniverse = function(){ + var self = this; + clearTimeout(self.timeout); - var msg = Buffer.concat([ - hdr, - this.universe, - Buffer([ENTTEC_PRO_END_OF_MSG]) - ]) - this.dev.write(msg) + 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) + }) } EnttecOpenUsbDMX.prototype.update = function(u) { - for(var c in u) { - this.universe[c] = u[c] - } - this.send_universe() + var self = this; + + for(var c in u) { + 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++; + } } EnttecOpenUsbDMX.prototype.get = function(c) { - return this.universe[c] + var self = this; + + return self.universe[(c + 1)]; } -module.exports = EnttecOpenUsbDMX \ No newline at end of file +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] }