2013-11-17 00:41:27 +00:00
|
|
|
"use strict"
|
2012-09-01 12:17:39 +00:00
|
|
|
|
2013-11-17 00:41:27 +00:00
|
|
|
var util = require('util')
|
|
|
|
var EventEmitter = require('events').EventEmitter
|
2012-09-01 12:17:39 +00:00
|
|
|
|
2015-11-29 16:02:34 +00:00
|
|
|
function DMX(options) {
|
|
|
|
var options = options || {}
|
2013-11-17 00:41:27 +00:00
|
|
|
this.universes = {}
|
2015-11-29 16:02:34 +00:00
|
|
|
this.drivers = {}
|
|
|
|
this.devices = options.devices || require('./devices')
|
2013-11-17 16:45:53 +00:00
|
|
|
|
2014-02-02 04:16:30 +00:00
|
|
|
this.registerDriver('null', require('./drivers/null'))
|
|
|
|
this.registerDriver('enttec-usb-dmx-pro', require('./drivers/enttec-usb-dmx-pro'))
|
|
|
|
this.registerDriver('enttec-open-usb-dmx', require('./drivers/enttec-open-usb-dmx'))
|
2016-04-09 16:35:33 +00:00
|
|
|
this.registerDriver('artnet', require('./drivers/artnet'))
|
2013-11-17 00:41:27 +00:00
|
|
|
}
|
2012-09-08 12:43:04 +00:00
|
|
|
|
2013-11-17 00:41:27 +00:00
|
|
|
util.inherits(DMX, EventEmitter)
|
2012-09-08 12:43:04 +00:00
|
|
|
|
2015-11-29 16:02:34 +00:00
|
|
|
DMX.devices = require('./devices')
|
2013-11-17 16:45:53 +00:00
|
|
|
DMX.Animation = require('./anim')
|
|
|
|
|
2013-11-17 00:41:27 +00:00
|
|
|
DMX.prototype.registerDriver = function(name, module) {
|
|
|
|
this.drivers[name] = module
|
2012-09-08 12:43:04 +00:00
|
|
|
}
|
2013-11-17 00:41:27 +00:00
|
|
|
|
|
|
|
DMX.prototype.addUniverse = function(name, driver, device_id) {
|
2013-11-17 16:57:24 +00:00
|
|
|
return this.universes[name] = new this.drivers[driver](device_id)
|
2012-09-08 12:43:04 +00:00
|
|
|
}
|
|
|
|
|
2013-11-17 00:41:27 +00:00
|
|
|
DMX.prototype.update = function(universe, channels) {
|
|
|
|
this.universes[universe].update(channels)
|
|
|
|
this.emit('update', universe, channels)
|
|
|
|
}
|
2012-09-08 12:43:04 +00:00
|
|
|
|
2014-04-24 17:53:07 +00:00
|
|
|
DMX.prototype.updateAll = function(universe, value) {
|
|
|
|
this.universes[universe].updateAll(value)
|
|
|
|
this.emit('updateAll', universe, value)
|
2016-10-15 21:23:51 +00:00
|
|
|
this.universes[universe].updateAll(value)
|
|
|
|
this.emit('updateAll', universe, value)
|
|
|
|
}
|
|
|
|
|
|
|
|
DMX.prototype.universeToObject(universe) {
|
|
|
|
var universe = this.universes[req.params.universe]
|
|
|
|
var u = {}
|
|
|
|
for(var i = 0; i < universe.length; i++) {
|
|
|
|
u[i] = universe.get(i)
|
|
|
|
}
|
|
|
|
return u
|
2014-04-24 17:53:07 +00:00
|
|
|
}
|
|
|
|
|
2013-11-17 00:41:27 +00:00
|
|
|
module.exports = DMX
|