From 7be968808e791f30e916606777ed724a0f51b951 Mon Sep 17 00:00:00 2001 From: Moritz Hoffmann Date: Fri, 18 Nov 2016 02:46:39 +0100 Subject: [PATCH 1/4] Add BeagleBone-DMX driver --- dmx.js | 1 + drivers/bbdmx.js | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 drivers/bbdmx.js diff --git a/dmx.js b/dmx.js index 4eac6d9..782704b 100644 --- a/dmx.js +++ b/dmx.js @@ -14,6 +14,7 @@ function DMX(options) { 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('artnet', require('./drivers/artnet')) + this.registerDriver('bbdmx', require('./drivers/bbdmx')) } util.inherits(DMX, EventEmitter) diff --git a/drivers/bbdmx.js b/drivers/bbdmx.js new file mode 100644 index 0000000..a118e38 --- /dev/null +++ b/drivers/bbdmx.js @@ -0,0 +1,61 @@ +'use strict'; + +const dgram = require('dgram'); + +function BBDMX(device_id, options) { + const self = this; + self.options = options || {}; + self.universe = new Buffer(512); + self.universe.fill(0); + self.host = device_id || '127.0.0.1'; + if (typeof options === 'undefined') { + self.port = 9930; + } else { + self.port = options.port || 9930; + } + self.dev = dgram.createSocket('udp4'); + self.sleepTime = 24; + self.start(); +} + +BBDMX.prototype.send_universe = function() { + let messageBuffer = new Buffer(`${this.universe.length} `); + + for (let i = 0; i < this.universe.length; i++) { + const channel = new Buffer(`${this.universe[i]} `); + const length = channel.length + messageBuffer.length; + messageBuffer = Buffer.concat([messageBuffer, channel], length); + } + this.dev.send(messageBuffer, 0, messageBuffer.length, this.port, this.host); +}; + +BBDMX.prototype.start = function() { + this.timeout = setInterval(this.send_universe.bind(this), this.sleepTime); +}; + +BBDMX.prototype.stop = function() { + clearInterval(this.timeout); +}; + +BBDMX.prototype.close = function(cb) { + this.stop(); + cb(null); +}; + +BBDMX.prototype.update = function(u) { + for (let c in u) { + this.universe[c] = u[c]; + } +}; + +BBDMX.prototype.updateAll = function(v) { + for (let i = 0; i < 512; i++) { + this.universe[i] = v; + } +}; + +BBDMX.prototype.get = function(c) { + return this.universe[c]; +}; + +module.exports = BBDMX; From 9cd301711b70bb6ee1c28384ab7fea9df295a120 Mon Sep 17 00:00:00 2001 From: Moritz Hoffmann Date: Fri, 18 Nov 2016 02:54:30 +0100 Subject: [PATCH 2/4] Cleanup options workaround --- drivers/bbdmx.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/bbdmx.js b/drivers/bbdmx.js index a118e38..4490b72 100644 --- a/drivers/bbdmx.js +++ b/drivers/bbdmx.js @@ -8,11 +8,7 @@ function BBDMX(device_id, options) { self.universe = new Buffer(512); self.universe.fill(0); self.host = device_id || '127.0.0.1'; - if (typeof options === 'undefined') { - self.port = 9930; - } else { - self.port = options.port || 9930; - } + self.port = self.options.port || 9930; self.dev = dgram.createSocket('udp4'); self.sleepTime = 24; self.start(); From 85a26af9b45fb1980bc96581efd75f0fa9b0d079 Mon Sep 17 00:00:00 2001 From: Moritz Hoffmann Date: Fri, 18 Nov 2016 03:27:03 +0100 Subject: [PATCH 3/4] Change templates to old style concat --- drivers/bbdmx.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/bbdmx.js b/drivers/bbdmx.js index 4490b72..3b891b5 100644 --- a/drivers/bbdmx.js +++ b/drivers/bbdmx.js @@ -15,10 +15,10 @@ function BBDMX(device_id, options) { } BBDMX.prototype.send_universe = function() { - let messageBuffer = new Buffer(`${this.universe.length} `); + let messageBuffer = new Buffer(this.universe.length + ' '); for (let i = 0; i < this.universe.length; i++) { - const channel = new Buffer(`${this.universe[i]} `); + const channel = new Buffer(this.universe[i] + ' '); const length = channel.length + messageBuffer.length; messageBuffer = Buffer.concat([messageBuffer, channel], length); } From b0d61fa041b1a51a7c394710ed79dc9ba5e83e06 Mon Sep 17 00:00:00 2001 From: Moritz Hoffmann Date: Fri, 18 Nov 2016 03:31:43 +0100 Subject: [PATCH 4/4] Remove space after command --- drivers/bbdmx.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/bbdmx.js b/drivers/bbdmx.js index 3b891b5..baf60e4 100644 --- a/drivers/bbdmx.js +++ b/drivers/bbdmx.js @@ -15,10 +15,10 @@ function BBDMX(device_id, options) { } BBDMX.prototype.send_universe = function() { - let messageBuffer = new Buffer(this.universe.length + ' '); + let messageBuffer = new Buffer(this.universe.length.toString()); for (let i = 0; i < this.universe.length; i++) { - const channel = new Buffer(this.universe[i] + ' '); + const channel = new Buffer(' ' + this.universe[i]); const length = channel.length + messageBuffer.length; messageBuffer = Buffer.concat([messageBuffer, channel], length); }