dmx-flok/drivers/enttec-open-usb-dmx.js

79 lines
1.4 KiB
JavaScript
Raw Normal View History

2014-02-02 04:16:30 +00:00
"use strict"
var FTDI = require('ftdi')
function EnttecOpenUsbDMX(locationId, cb) {
2014-04-19 21:49:17 +00:00
var self = this;
cb = cb || function() {}
self.universe = Array(513);
self.universe[0] = 0;
self.updateAll(0);
self.sleepTime = 24;
2014-04-19 21:49:17 +00:00
self.timeout;
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) {
cb(err, locationId)
2014-04-19 21:49:17 +00:00
if(!err) {
self.loopUniverse()
}
})
}
EnttecOpenUsbDMX.prototype.loopUniverse = function(){
var self = this;
clearTimeout(self.timeout);
2014-04-19 21:49:17 +00:00
self.dev.write(self.universe);
2014-04-19 21:49:17 +00:00
self.timeout = setTimeout(function(){
self.loopUniverse();
}, self.sleepTime)
}
EnttecOpenUsbDMX.prototype.pause = function(){
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){
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) {
self.universe[(c + 1)] = u[c];
2014-04-19 21:49:17 +00:00
}
2014-02-02 04:16:30 +00:00
}
EnttecOpenUsbDMX.prototype.updateAll = function(v) {
2014-04-19 21:49:17 +00:00
var self = this;
var i = 1;
while(i < self.universe.length){
self.universe[i] = v;
i++;
}
2014-04-19 21:49:17 +00:00
}
EnttecOpenUsbDMX.prototype.get = function(c) {
2014-04-19 21:49:17 +00:00
var self = this;
return self.universe[(c + 1)];
2014-02-02 04:16:30 +00:00
}
2014-04-19 21:49:17 +00:00
module.exports = EnttecOpenUsbDMX