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

56 lines
1 KiB
JavaScript
Raw Normal View History

2012-09-01 12:17:39 +00:00
var Ftdi = require('./node-ftdi/index');
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])
])
console.log(msg)
dev.write(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)
var dev = new Ftdi({'index': dev_id});
dev.open();
dev.setBaudrate(250000);
dev.setLineProperty(Ftdi.BITS_8, Ftdi.STOP_BIT_2, Ftdi.NONE);
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) {
return universe[c];
}
2012-09-01 12:17:39 +00:00
setInterval(function() {
send_universe(dev, universe);
2012-09-02 12:59:49 +00:00
}, 25);
2012-09-01 12:17:39 +00:00
return this;
}