Added support for DMXKing interface (dual channel)

This commit is contained in:
Pierre Frisch 2017-07-16 09:53:44 -07:00
parent baf18a96cb
commit 07316ad789
3 changed files with 95 additions and 9 deletions

View file

@ -28,7 +28,8 @@ function DMXWeb() {
dmx.addUniverse( dmx.addUniverse(
universe, universe,
config.universes[universe].output.driver, config.universes[universe].output.driver,
config.universes[universe].output.device config.universes[universe].output.device,
config.universes[universe].output.options
) )
} }

5
dmx.js
View file

@ -13,6 +13,7 @@ function DMX(options) {
this.registerDriver('dmx4all', require('./drivers/dmx4all')) this.registerDriver('dmx4all', require('./drivers/dmx4all'))
this.registerDriver('enttec-usb-dmx-pro', require('./drivers/enttec-usb-dmx-pro')) this.registerDriver('enttec-usb-dmx-pro', require('./drivers/enttec-usb-dmx-pro'))
this.registerDriver('enttec-open-usb-dmx', require('./drivers/enttec-open-usb-dmx')) this.registerDriver('enttec-open-usb-dmx', require('./drivers/enttec-open-usb-dmx'))
this.registerDriver('dmxking-ultra-dmx-pro', require('./drivers/dmxking-ultra-dmx-pro'))
this.registerDriver('artnet', require('./drivers/artnet')) this.registerDriver('artnet', require('./drivers/artnet'))
this.registerDriver('bbdmx', require('./drivers/bbdmx')) this.registerDriver('bbdmx', require('./drivers/bbdmx'))
} }
@ -26,8 +27,8 @@ DMX.prototype.registerDriver = function(name, module) {
this.drivers[name] = module this.drivers[name] = module
} }
DMX.prototype.addUniverse = function(name, driver, device_id) { DMX.prototype.addUniverse = function(name, driver, device_id, options) {
return this.universes[name] = new this.drivers[driver](device_id) return this.universes[name] = new this.drivers[driver](device_id, options)
} }
DMX.prototype.update = function(universe, channels) { DMX.prototype.update = function(universe, channels) {

View file

@ -0,0 +1,84 @@
"use strict"
var SerialPort = require("serialport")
var DMXKING_ULTRA_DMX_PRO_DMX_STARTCODE = 0x00
, DMXKING_ULTRA_DMX_PRO_START_OF_MSG = 0x7e
, DMXKING_ULTRA_DMX_PRO_END_OF_MSG = 0xe7
, DMXKING_ULTRA_DMX_PRO_SEND_DMX_RQ = 0x06
, DMXKING_ULTRA_DMX_PRO_SEND_DMX_A_RQ = 0x64
, DMXKING_ULTRA_DMX_PRO_SEND_DMX_B_RQ = 0x65
, DMXKING_ULTRA_DMX_PRO_RECV_DMX_PKT = 0x05
;
function DMXKingUltraDMXPro(device_id, options) {
var self = this
this.options = options || {}
this.universe = new Buffer(512)
this.universe.fill(0)
this.sendDMXReq = DMXKING_ULTRA_DMX_PRO_SEND_DMX_RQ
if (this.options.port === "A") {
this.sendDMXReq = DMXKING_ULTRA_DMX_PRO_SEND_DMX_A_RQ
} else if (this.options.port === "B") {
this.sendDMXReq = DMXKING_ULTRA_DMX_PRO_SEND_DMX_B_RQ
}
this.dev = new SerialPort(device_id, {
'baudrate': 250000,
'databits': 8,
'stopbits': 2,
'parity': 'none'
}, function(err) {
if(!err) {
self.send_universe()
}
})
}
DMXKingUltraDMXPro.prototype.send_universe = function() {
if(!this.dev.isOpen()) {
return
}
var hdr = Buffer([
DMXKING_ULTRA_DMX_PRO_START_OF_MSG,
this.sendDMXReq,
(this.universe.length + 1) & 0xff,
((this.universe.length + 1) >> 8) & 0xff,
DMXKING_ULTRA_DMX_PRO_DMX_STARTCODE
])
var msg = Buffer.concat([
hdr,
this.universe,
Buffer([DMXKING_ULTRA_DMX_PRO_END_OF_MSG])
])
this.dev.write(msg)
}
DMXKingUltraDMXPro.prototype.start = function() {}
DMXKingUltraDMXPro.prototype.stop = function() {}
DMXKingUltraDMXPro.prototype.close = function(cb) {
this.dev.close(cb)
}
DMXKingUltraDMXPro.prototype.update = function(u) {
for(var c in u) {
this.universe[c] = u[c]
}
this.send_universe()
}
DMXKingUltraDMXPro.prototype.updateAll = function(v){
for(var i = 0; i < 512; i++) {
this.universe[i] = v
}
this.send_universe()
}
DMXKingUltraDMXPro.prototype.get = function(c) {
return this.universe[c]
}
module.exports = DMXKingUltraDMXPro