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
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
exports.init = function(dev_id) {
|
|
|
|
var send_universe = function(dev, universe) {
|
|
|
|
var hdr = Buffer([
|
|
|
|
ENTTEC_PRO_START_OF_MSG,
|
|
|
|
ENTTEC_PRO_SEND_DMX_RQ,
|
|
|
|
(universe.length + 1) & 0xff,
|
|
|
|
((universe.length + 1) >> 8) & 0xff,
|
|
|
|
ENTTEC_PRO_DMX_STARTCODE
|
|
|
|
])
|
|
|
|
|
|
|
|
var msg = Buffer.concat([
|
|
|
|
hdr,
|
|
|
|
universe,
|
|
|
|
Buffer([ENTTEC_PRO_END_OF_MSG])
|
|
|
|
])
|
2012-09-02 12:36:08 +00:00
|
|
|
dev.write(msg)
|
2012-09-01 12:17:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var universe = new Buffer(512)
|
|
|
|
universe.fill(0)
|
|
|
|
|
2013-11-16 16:35:17 +00:00
|
|
|
var dev = new FTDI.FtdiDevice(dev_id)
|
|
|
|
dev.open({
|
|
|
|
'baudrate': 250000,
|
|
|
|
'databits': 8,
|
|
|
|
'stopbits': 2,
|
|
|
|
'parity': 'none'
|
|
|
|
}, function(err) {
|
|
|
|
console.log(err)
|
|
|
|
})
|
|
|
|
|
2012-09-01 12:17:39 +00:00
|
|
|
this.update = function(u) {
|
|
|
|
for(var k in u) {
|
|
|
|
universe[k] = u[k]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-02 12:36:08 +00:00
|
|
|
this.get = function(c) {
|
2013-11-16 16:35:17 +00:00
|
|
|
return universe[c]
|
2012-09-02 12:36:08 +00:00
|
|
|
}
|
|
|
|
|
2012-09-01 12:17:39 +00:00
|
|
|
setInterval(function() {
|
|
|
|
send_universe(dev, universe);
|
2013-11-16 16:35:17 +00:00
|
|
|
}, 25)
|
2012-09-01 12:17:39 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|