2014-02-02 04:16:30 +00:00
|
|
|
"use strict"
|
|
|
|
|
|
|
|
var FTDI = require('ftdi')
|
|
|
|
|
2014-04-24 17:53:07 +00:00
|
|
|
function EnttecOpenUsbDMX(locationId, cb) {
|
2014-04-19 21:49:17 +00:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
cb = cb || function() {}
|
2014-04-24 17:53:07 +00:00
|
|
|
self.universe = Array(513);
|
|
|
|
self.universe[0] = 0;
|
|
|
|
self.updateAll(0);
|
|
|
|
self.sleepTime = 24;
|
2014-04-19 21:49:17 +00:00
|
|
|
self.timeout;
|
2014-04-24 17:53:07 +00:00
|
|
|
self.dev = new FTDI.FtdiDevice(locationId)
|
2014-04-19 21:49:17 +00:00
|
|
|
self.dev.open({
|
|
|
|
'baudrate': 115200 / 2,
|
|
|
|
'databits': 8,
|
|
|
|
'stopbits': 2,
|
|
|
|
'parity': 'none'
|
|
|
|
}, function(err) {
|
2014-04-24 17:53:07 +00:00
|
|
|
cb(err, locationId)
|
2014-04-19 21:49:17 +00:00
|
|
|
if(!err) {
|
|
|
|
self.loopUniverse()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
EnttecOpenUsbDMX.prototype.loopUniverse = function(){
|
|
|
|
var self = this;
|
2014-04-24 17:53:07 +00:00
|
|
|
clearTimeout(self.timeout);
|
2014-04-19 21:49:17 +00:00
|
|
|
|
|
|
|
self.dev.write(self.universe);
|
2014-04-24 17:53:07 +00:00
|
|
|
|
2014-04-19 21:49:17 +00:00
|
|
|
self.timeout = setTimeout(function(){
|
|
|
|
self.loopUniverse();
|
|
|
|
}, self.sleepTime)
|
|
|
|
}
|
|
|
|
|
|
|
|
EnttecOpenUsbDMX.prototype.pause = function(){
|
2014-04-24 17:53:07 +00:00
|
|
|
var self = this;
|
|
|
|
|
2014-04-19 21:49:17 +00:00
|
|
|
clearTimeout(self.timeout);
|
2014-02-02 04:16:30 +00:00
|
|
|
}
|
|
|
|
|
2014-04-19 21:49:17 +00:00
|
|
|
EnttecOpenUsbDMX.prototype.close = function(cb){
|
2014-04-24 17:53:07 +00:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
self.pause();
|
2014-04-19 21:49:17 +00:00
|
|
|
self.dev.close(function(err){
|
|
|
|
cb(err)
|
|
|
|
})
|
2014-02-02 04:16:30 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 23:32:46 +00:00
|
|
|
EnttecOpenUsbDMX.prototype.update = function(u) {
|
2014-04-19 21:49:17 +00:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
for(var c in u) {
|
2014-04-24 17:53:07 +00:00
|
|
|
self.universe[(c + 1)] = u[c];
|
2014-04-19 21:49:17 +00:00
|
|
|
}
|
2014-02-02 04:16:30 +00:00
|
|
|
}
|
|
|
|
|
2014-04-24 17:53:07 +00:00
|
|
|
EnttecOpenUsbDMX.prototype.updateAll = function(v) {
|
2014-04-19 21:49:17 +00:00
|
|
|
var self = this;
|
|
|
|
|
2014-04-24 17:53:07 +00:00
|
|
|
var i = 1;
|
|
|
|
while(i < self.universe.length){
|
|
|
|
self.universe[i] = v;
|
|
|
|
i++;
|
|
|
|
}
|
2014-04-19 21:49:17 +00:00
|
|
|
}
|
|
|
|
|
2014-04-24 17:53:07 +00:00
|
|
|
EnttecOpenUsbDMX.prototype.get = function(c) {
|
2014-04-19 21:49:17 +00:00
|
|
|
var self = this;
|
|
|
|
|
2014-04-24 17:53:07 +00:00
|
|
|
return self.universe[(c + 1)];
|
2014-02-02 04:16:30 +00:00
|
|
|
}
|
|
|
|
|
2014-04-19 21:49:17 +00:00
|
|
|
module.exports = EnttecOpenUsbDMX
|