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 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})

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)
}
DMX.prototype.updateAll = function(universe, value) {
this.universes[universe].updateAll(value)
this.emit('updateAll', universe, value)
}
module.exports = DMX

View file

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

View file

@ -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]
}

View file

@ -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]
}