2014-02-02 04:16:30 +00:00
|
|
|
"use strict"
|
|
|
|
|
|
|
|
var FTDI = require('ftdi')
|
|
|
|
|
2015-05-15 12:34:24 +00:00
|
|
|
function EnttecOpenUsbDMX(device_id, cb) {
|
|
|
|
var self = this
|
|
|
|
|
|
|
|
cb = cb || function() {}
|
|
|
|
this.universe = new Buffer(512)
|
|
|
|
this.universe.fill(0)
|
|
|
|
|
|
|
|
self.sleepTime = 24
|
|
|
|
self.timeout
|
|
|
|
|
|
|
|
self.dev = new FTDI.FtdiDevice(device_id)
|
|
|
|
self.dev.open({
|
|
|
|
'baudrate': 57600,
|
|
|
|
'databits': 8,
|
|
|
|
'stopbits': 2,
|
|
|
|
'parity': 'none'
|
|
|
|
}, function(err) {
|
|
|
|
cb(err, device_id)
|
|
|
|
if(!err) {
|
|
|
|
self.start()
|
|
|
|
}
|
|
|
|
})
|
2014-04-19 21:49:17 +00:00
|
|
|
}
|
|
|
|
|
2015-05-15 12:34:24 +00:00
|
|
|
EnttecOpenUsbDMX.prototype.send_universe = function() {
|
|
|
|
this.dev.write(this.universe)
|
2014-04-19 21:49:17 +00:00
|
|
|
}
|
|
|
|
|
2015-05-15 12:34:24 +00:00
|
|
|
EnttecOpenUsbDMX.prototype.start = function() {
|
|
|
|
this.timeout = setInterval(this.send_universe.bind(this), this.sleepTime)
|
2014-02-02 04:16:30 +00:00
|
|
|
}
|
|
|
|
|
2015-05-15 12:34:24 +00:00
|
|
|
EnttecOpenUsbDMX.prototype.stop = function() {
|
|
|
|
clearInterval(this.timeout)
|
|
|
|
}
|
2014-04-24 17:53:07 +00:00
|
|
|
|
2015-05-15 12:34:24 +00:00
|
|
|
EnttecOpenUsbDMX.prototype.close = function(cb) {
|
|
|
|
this.stop()
|
|
|
|
this.dev.close(cb)
|
2014-02-02 04:16:30 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 23:32:46 +00:00
|
|
|
EnttecOpenUsbDMX.prototype.update = function(u) {
|
2015-05-15 12:34:24 +00:00
|
|
|
for(var c in u) {
|
|
|
|
this.universe[c] = u[c]
|
|
|
|
}
|
2014-02-02 04:16:30 +00:00
|
|
|
}
|
|
|
|
|
2014-04-24 17:53:07 +00:00
|
|
|
EnttecOpenUsbDMX.prototype.updateAll = function(v) {
|
2015-05-15 12:34:24 +00:00
|
|
|
for(var i = 0; i < 512; i++) {
|
|
|
|
this.universe[i] = v
|
|
|
|
}
|
2014-04-19 21:49:17 +00:00
|
|
|
}
|
|
|
|
|
2014-04-24 17:53:07 +00:00
|
|
|
EnttecOpenUsbDMX.prototype.get = function(c) {
|
2015-05-15 12:34:24 +00:00
|
|
|
return this.universe[c]
|
2014-02-02 04:16:30 +00:00
|
|
|
}
|
|
|
|
|
2014-04-19 21:49:17 +00:00
|
|
|
module.exports = EnttecOpenUsbDMX
|