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

70 lines
1.3 KiB
JavaScript
Raw Normal View History

2014-02-02 04:16:30 +00:00
"use strict"
var SerialPort = require("serialport").SerialPort
2014-02-02 04:16:30 +00:00
function EnttecOpenUsbDMX(device_id, options) {
2015-05-15 12:34:24 +00:00
var self = this
options = options || {}
2015-05-15 12:34:24 +00:00
this.universe = new Buffer(512)
this.universe.fill(0)
self.interval = 23
2015-05-15 12:34:24 +00:00
this.dev = new SerialPort(device_id, {
2015-05-15 12:34:24 +00:00
'baudrate': 57600,
'databits': 8,
'stopbits': 2,
'parity': 'none'
}, true, function(err) {
2015-05-15 12:34:24 +00:00
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() {
2016-06-02 19:28:23 +00:00
var self = this
if(!this.dev.isOpen()) {
return
}
2015-05-15 12:34:24 +00:00
this.dev.write(this.universe)
// toggle break
2016-06-02 19:28:23 +00:00
self.dev.set({brk: true}, function(err, r) {
self.dev.set({brk: false})
})
2014-04-19 21:49:17 +00:00
}
2015-05-15 12:34:24 +00:00
EnttecOpenUsbDMX.prototype.start = function() {
2016-04-09 16:11:48 +00:00
this.intervalhandle = setInterval(this.send_universe.bind(this), this.interval)
2014-02-02 04:16:30 +00:00
}
2015-05-15 12:34:24 +00:00
EnttecOpenUsbDMX.prototype.stop = function() {
2016-04-09 16:11:48 +00:00
clearInterval(this.intervalhandle)
2015-05-15 12:34:24 +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
}
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
}
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