From cfe02e8ffe732b2975a7a344ecf6f8d47ad6fb6a Mon Sep 17 00:00:00 2001 From: Pierre Frisch Date: Tue, 18 Dec 2018 10:40:53 -0800 Subject: [PATCH] Added support for defining devices in config file (#64) --- demo.js | 4 ++-- demo_simple.js | 3 ++- dmx-web.js | 6 +++--- dmx.js | 4 +++- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/demo.js b/demo.js index 1653fa0..c290746 100644 --- a/demo.js +++ b/demo.js @@ -1,9 +1,9 @@ "use strict" var DMX = require('./dmx') -var A = DMX.Animation -var dmx = new DMX() +var dmx = new DMX(); +var A = dmx.animation; // var universe = dmx.addUniverse('demo', 'enttec-usb-dmx-pro', '/dev/cu.usbserial-6AVNHXS8') // var universe = dmx.addUniverse('demo', 'enttec-open-usb-dmx', '/dev/cu.usbserial-6AVNHXS8') diff --git a/demo_simple.js b/demo_simple.js index 3c345f7..46d4976 100644 --- a/demo_simple.js +++ b/demo_simple.js @@ -1,9 +1,10 @@ "use strict" var DMX = require('./dmx'); -var A = DMX.Animation; var dmx = new DMX(); +var A = dmx.animation; + // var universe = dmx.addUniverse('demo', 'enttec-open-usb-dmx', '/dev/cu.usbserial-6AVNHXS8') var universe = dmx.addUniverse('demo', 'null') diff --git a/dmx-web.js b/dmx-web.js index 94bb05b..7a39c09 100755 --- a/dmx-web.js +++ b/dmx-web.js @@ -23,7 +23,7 @@ function DMXWeb() { var server = http.createServer(app) var io = socketio.listen(server) - var dmx = new DMX() + var dmx = new DMX(config) for(var universe in config.universes) { dmx.addUniverse( @@ -56,7 +56,7 @@ function DMXWeb() { }) app.get('/config', function(req, res) { - var response = {"devices": DMX.devices, "universes": {}} + var response = {"devices": dmx.devices, "universes": {}} Object.keys(config.universes).forEach(function(key) { response.universes[key] = config.universes[key].devices }) @@ -108,7 +108,7 @@ function DMXWeb() { }) io.sockets.on('connection', function(socket) { - socket.emit('init', {'devices': DMX.devices, 'setup': config}) + socket.emit('init', {'devices': dmx.devices, 'setup': config}) socket.on('request_refresh', function() { for(var universe in config.universes) { diff --git a/dmx.js b/dmx.js index 45d4695..4bf1a42 100644 --- a/dmx.js +++ b/dmx.js @@ -5,9 +5,11 @@ var EventEmitter = require('events').EventEmitter function DMX(options) { var options = options || {} + var devices = options.devices || {} this.universes = {} this.drivers = {} - this.devices = options.devices || require('./devices') + this.devices = Object.assign({}, require('./devices'), devices); + this.animation = require('./anim') this.registerDriver('null', require('./drivers/null')) this.registerDriver('dmx4all', require('./drivers/dmx4all'))