dmx-flok/dmx.js

59 lines
1.7 KiB
JavaScript
Raw Normal View History

const util = require('util');
const EventEmitter = require('events').EventEmitter;
class DMX {
constructor(options) {
const opt = options || {};
const devices = opt.devices || {};
this.universes = {};
this.drivers = {};
this.devices = Object.assign({}, require('./devices'), devices);
this.animation = require('./anim');
this.registerDriver('null', require('./drivers/null'));
this.registerDriver('dmx4all', require('./drivers/dmx4all'));
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('dmxking-ultra-dmx-pro', require('./drivers/dmxking-ultra-dmx-pro'));
this.registerDriver('artnet', require('./drivers/artnet'));
this.registerDriver('bbdmx', require('./drivers/bbdmx'));
}
registerDriver(name, module) {
this.drivers[name] = module;
}
addUniverse(name, driver, deviceId, options) {
this.universes[name] = new this.drivers[driver](deviceId, options);
return this.universes[name];
}
update(universe, channels) {
this.universes[universe].update(channels);
this.emit('update', universe, channels);
}
updateAll(universe, value) {
this.universes[universe].updateAll(value);
this.emit('updateAll', universe, value);
}
universeToObject(universeKey) {
const universe = this.universes[universeKey];
const u = {};
for (let i = 0; i < 512; i++) {
u[i] = universe.get(i);
}
return u;
}
}
2012-09-08 12:43:04 +00:00
util.inherits(DMX, EventEmitter);
2012-09-08 12:43:04 +00:00
DMX.devices = require('./devices');
DMX.Animation = require('./anim');
module.exports = DMX;