2013-11-17 00:41:27 +00:00
|
|
|
"use strict"
|
|
|
|
|
2013-11-16 16:35:17 +00:00
|
|
|
var FTDI = require('ftdi')
|
2012-09-01 12:17:39 +00:00
|
|
|
|
|
|
|
var ENTTEC_PRO_DMX_STARTCODE = 0x00
|
|
|
|
, ENTTEC_PRO_START_OF_MSG = 0x7e
|
|
|
|
, ENTTEC_PRO_END_OF_MSG = 0xe7
|
|
|
|
, ENTTEC_PRO_SEND_DMX_RQ = 0x06
|
|
|
|
, ENTTEC_PRO_RECV_DMX_PKT = 0x05
|
|
|
|
;
|
|
|
|
|
2013-11-17 00:41:27 +00:00
|
|
|
function EnttecUSBDMXPRO(device_id, cb) {
|
|
|
|
var self = this
|
|
|
|
cb = cb || function() {}
|
|
|
|
this.universe = new Buffer(512)
|
|
|
|
this.universe.fill(0)
|
2012-09-01 12:17:39 +00:00
|
|
|
|
2013-11-17 00:41:27 +00:00
|
|
|
this.dev = new FTDI.FtdiDevice(device_id)
|
|
|
|
this.dev.open({
|
2013-11-16 16:35:17 +00:00
|
|
|
'baudrate': 250000,
|
|
|
|
'databits': 8,
|
|
|
|
'stopbits': 2,
|
|
|
|
'parity': 'none'
|
|
|
|
}, function(err) {
|
2013-11-17 00:41:27 +00:00
|
|
|
cb(err, device_id)
|
|
|
|
if(!err) {
|
|
|
|
self.send_universe()
|
|
|
|
}
|
2013-11-16 16:35:17 +00:00
|
|
|
})
|
2013-11-17 00:41:27 +00:00
|
|
|
}
|
2013-11-16 16:35:17 +00:00
|
|
|
|
2013-11-17 00:41:27 +00:00
|
|
|
EnttecUSBDMXPRO.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) >> 8) & 0xff,
|
|
|
|
ENTTEC_PRO_DMX_STARTCODE
|
|
|
|
])
|
|
|
|
|
|
|
|
var msg = Buffer.concat([
|
|
|
|
hdr,
|
|
|
|
this.universe,
|
|
|
|
Buffer([ENTTEC_PRO_END_OF_MSG])
|
|
|
|
])
|
|
|
|
this.dev.write(msg)
|
|
|
|
}
|
|
|
|
|
|
|
|
EnttecUSBDMXPRO.prototype.update = function(u) {
|
|
|
|
for(var c in u) {
|
|
|
|
this.universe[c] = u[c]
|
2012-09-02 12:36:08 +00:00
|
|
|
}
|
2013-11-17 00:41:27 +00:00
|
|
|
this.send_universe()
|
|
|
|
}
|
|
|
|
|
|
|
|
EnttecUSBDMXPRO.prototype.get = function(c) {
|
|
|
|
return this.universe[c]
|
2012-09-01 12:17:39 +00:00
|
|
|
}
|
2013-11-17 00:41:27 +00:00
|
|
|
|
|
|
|
module.exports = EnttecUSBDMXPRO
|