Merge pull request #4 from evantahler/master

Update enttec-open-usb-dmx.js
This commit is contained in:
Sebastian Wiedenroth 2014-04-25 12:22:39 +02:00
commit 6c837ccfc5
6 changed files with 97 additions and 44 deletions

View file

@ -6,6 +6,7 @@ var A = DMX.Animation
var dmx = new DMX() var dmx = new DMX()
// var universe = dmx.addUniverse('demo', 'enttec-usb-dmx-pro', 0) // 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') var universe = dmx.addUniverse('demo', 'null')
universe.update({0: 1, 1: 0}) universe.update({0: 1, 1: 0})

21
demo_simple.js Normal file
View file

@ -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);

5
dmx.js
View file

@ -30,4 +30,9 @@ DMX.prototype.update = function(universe, channels) {
this.emit('update', 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 module.exports = DMX

View file

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

View file

@ -53,6 +53,10 @@ EnttecUSBDMXPRO.prototype.update = function(u) {
this.send_universe() this.send_universe()
} }
EnttecUSBDMXPRO.prototype.updateAll = function(v){
// TODO
}
EnttecUSBDMXPRO.prototype.get = function(c) { EnttecUSBDMXPRO.prototype.get = function(c) {
return this.universe[c] return this.universe[c]
} }

View file

@ -14,6 +14,10 @@ Null.prototype.update = function(u) {
console.log(this.universe) console.log(this.universe)
} }
Null.prototype.updateAll = function(v){
// TODO
}
Null.prototype.get = function(c) { Null.prototype.get = function(c) {
return this.universe[c] return this.universe[c]
} }