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

60 lines
1.2 KiB
JavaScript
Raw Normal View History

2014-02-02 04:16:30 +00:00
"use strict"
var FTDI = require('ftdi')
var ENTTEC_PRO_DMX_STARTCODE = 0x00
, ENTTEC_PRO_START_OF_MSG = 0x7e
, ENTTEC_PRO_END_OF_MSG = 0xe7
, ENTTEC_PRO_SEND_DMX_RQ = 0x06
;
2014-02-22 23:32:46 +00:00
function EnttecOpenUsbDMX(device_id, cb) {
2014-02-02 04:16:30 +00:00
var self = this
cb = cb || function() {}
this.universe = new Buffer(512)
this.universe.fill(0)
this.dev = new FTDI.FtdiDevice(device_id)
this.dev.open({
'baudrate': 115200,
'databits': 8,
'stopbits': 2,
'parity': 'none'
}, function(err) {
cb(err, device_id)
if(!err) {
self.send_universe()
}
})
}
2014-02-22 23:32:46 +00:00
EnttecOpenUsbDMX.prototype.send_universe = function() {
2014-02-02 04:16:30 +00:00
var hdr = Buffer([
ENTTEC_PRO_START_OF_MSG,
ENTTEC_PRO_SEND_DMX_RQ,
// (this.universe.length + 1) & 0xff,
((this.universe.length + 1) >> 0) & 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)
}
2014-02-22 23:32:46 +00:00
EnttecOpenUsbDMX.prototype.update = function(u) {
2014-02-02 04:16:30 +00:00
for(var c in u) {
this.universe[c] = u[c]
}
this.send_universe()
}
2014-02-22 23:32:46 +00:00
EnttecOpenUsbDMX.prototype.get = function(c) {
2014-02-02 04:16:30 +00:00
return this.universe[c]
}
2014-02-22 23:32:46 +00:00
module.exports = EnttecOpenUsbDMX