enttec opendmx actually works; simple demo

This commit is contained in:
Evan Tahler 2014-04-24 10:53:07 -07:00
parent 9de02a0240
commit 0c88e55225
6 changed files with 60 additions and 17 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,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

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