From 00d960e441024627e1023e2ac0776b899ed6b9af Mon Sep 17 00:00:00 2001 From: Sebastian Wiedenroth Date: Sun, 30 Jul 2017 17:17:05 +0200 Subject: [PATCH] Change DMX addressing to start at channel 1 This wastes one byte on each universe buffer and will require you to update your configs and animations but hopefully prevent confusion and off-by-one errors in the future. --- demo.js | 4 ++-- dmx-web-example.conf | 38 ++++++++++++++++---------------- drivers/artnet.js | 6 ++--- drivers/bbdmx.js | 10 +++++---- drivers/dmx4all.js | 12 +++++----- drivers/dmxking-ultra-dmx-pro.js | 10 ++++----- drivers/enttec-open-usb-dmx.js | 6 ++--- drivers/enttec-usb-dmx-pro.js | 10 ++++----- drivers/null.js | 6 ++--- 9 files changed, 53 insertions(+), 49 deletions(-) diff --git a/demo.js b/demo.js index 64d62d9..1653fa0 100644 --- a/demo.js +++ b/demo.js @@ -9,8 +9,8 @@ var dmx = new DMX() // var universe = dmx.addUniverse('demo', 'enttec-open-usb-dmx', '/dev/cu.usbserial-6AVNHXS8') var universe = dmx.addUniverse('demo', 'null') -universe.update({0: 1, 1: 0}) -universe.update({15: 1, 16: 255}) +universe.update({1: 1, 2: 0}) +universe.update({16: 1, 17: 255}) universe.update({1: 255, 3: 120, 4: 230, 5: 30, 6: 110, 7: 255, 8: 10, 9: 255, 10: 255, 11: 0}) function done() {console.log('DONE')} diff --git a/dmx-web-example.conf b/dmx-web-example.conf index 5339d37..f40a2ff 100644 --- a/dmx-web-example.conf +++ b/dmx-web-example.conf @@ -12,31 +12,31 @@ { "label": "White", "values": { - "office": { "0":16, "1":255, "2":0, "3":255, "4": 255, "5":255, "15":16, "16":255, "17":0, "18":255, "19": 255, "20":255 } + "office": { "1": 16, "2": 255, "3": 0, "4": 255, "5": 255, "6": 255, "16": 16, "17": 255, "18": 0, "19": 255, "20": 255, "21": 255 } } }, { "label": "Natural", "values": { - "office": { "0":16, "1":255, "2":0, "3":255, "4": 190, "5":140, "15":16, "16":255, "17":0, "18":255, "19": 190, "20":140 } + "office": { "1": 16, "2": 255, "3": 0, "4":255, "5": 190, "6": 140, "16": 16, "17": 255, "18": 0, "19": 255, "20": 190, "21":140 } } }, { "label": "Worklight", "values": { - "office": { "0":16, "1":130, "2":0, "3":255, "4": 165, "5":0, "15": 1, "16":255, "17":0, "18":255, "19": 190, "20":140, "21":0, "22": 0, "23":0, "24":255, "25": 190, "26":140 } + "office": { "1": 16, "2": 130, "3": 0, "4": 255, "5": 165, "6": 0, "16": 1, "17": 255, "18": 0, "19": 255, "20": 190, "21": 140, "22": 0, "23": 0, "24": 0, "25": 255, "26": 190, "27": 140 } } }, { "label": "Chill", "values": { - "office": { "0":16, "1":255, "2":0, "3":255, "4": 39, "5":0, "15": 1, "16":255, "17":0, "18":255, "19": 255, "20":0, "21":0, "22": 0, "23":0, "24":128, "25": 0, "26":255, "31":255, "32": 60 } + "office": { "1": 16, "2": 255, "3": 0, "4": 255, "5": 39, "6": 0, "16": 1, "17": 255, "18": 0, "19": 255, "20": 255, "21": 0, "22": 0, "23": 0, "24": 0, "25": 128, "26": 0, "27": 255, "32": 255, "33": 60 } } }, { "label": "Cinema", "values": { - "office": { "0":16, "1":30, "2":0, "3":255, "4": 39, "5":0, "15":0, "31":255, "32":0 } + "office": { "1": 16, "2": 30, "3":0, "4": 255, "5": 39, "6": 0, "16": 0, "32": 255, "33": 0 } } } ], @@ -49,15 +49,15 @@ "devices": [ { "type": "eurolite-led-bar", - "address": 0 + "address": 1 }, { "type": "eurolite-led-bar", - "address": 15 + "address": 16 }, { "type": "showtec-multidim2", - "address": 31 + "address": 32 }, { "type": "stairville-led-par-56", @@ -73,23 +73,23 @@ }, { "type": "oppsk-cob-uv-par", - "address": 99 + "address": 100 }, { "type": "lixda-par12-led", - "address": 109 + "address": 110 }, { "type": "lixda-par12-led", - "address": 119 + "address": 120 }, { "type": "lixda-par12-led", - "address": 129 + "address": 130 }, { "type": "lixda-par12-led", - "address": 139 + "address": 140 } ] }, @@ -104,15 +104,15 @@ "devices": [ { "type": "eurolite-led-bar", - "address": 0 + "address": 1 }, { "type": "eurolite-led-bar", - "address": 15 + "address": 16 }, { "type": "showtec-multidim2", - "address": 31 + "address": 32 }, { "type": "stairville-led-par-56", @@ -139,15 +139,15 @@ "devices": [ { "type": "eurolite-led-bar", - "address": 0 + "address": 1 }, { "type": "eurolite-led-bar", - "address": 15 + "address": 16 }, { "type": "showtec-multidim2", - "address": 31 + "address": 32 }, { "type": "stairville-led-par-56", diff --git a/drivers/artnet.js b/drivers/artnet.js index c7bf683..b17dee3 100644 --- a/drivers/artnet.js +++ b/drivers/artnet.js @@ -11,7 +11,7 @@ function EnttecODE(device_id, options) { self.universe_id = new Buffer([0x00, 0x00]) self.length = new Buffer([0x02, 0x00]) - self.universe = new Buffer(512) + self.universe = new Buffer(513) self.universe.fill(0) self.sleepTime = 24 @@ -31,7 +31,7 @@ EnttecODE.prototype.send_universe = function() { this.physical, this.universe_id, this.length, - this.universe + this.universe.slice(1) ]) this.dev.send(pkg, 0, pkg.length, this.port, this.host) @@ -57,7 +57,7 @@ EnttecODE.prototype.update = function(u) { } EnttecODE.prototype.updateAll = function(v) { - for (var i = 0; i < 512; i++) { + for (var i = 1; i <= 512; i++) { this.universe[i] = v } } diff --git a/drivers/bbdmx.js b/drivers/bbdmx.js index 3a01870..92e99be 100644 --- a/drivers/bbdmx.js +++ b/drivers/bbdmx.js @@ -2,10 +2,12 @@ var dgram = require('dgram') +var UNIVERSE_LEN = 512 + function BBDMX(device_id, options) { var self = this self.options = options || {} - self.universe = new Buffer(512) + self.universe = new Buffer(UNIVERSE_LEN + 1) self.universe.fill(0) self.host = device_id || '127.0.0.1' self.port = self.options.port || 9930 @@ -16,9 +18,9 @@ function BBDMX(device_id, options) { BBDMX.prototype.send_universe = function() { var channel - var messageBuffer = new Buffer(this.universe.length.toString()) + var messageBuffer = new Buffer(UNIVERSE_LEN.toString()) - for (var i = 0; i < this.universe.length; i++) { + for (var i = 1; i <= UNIVERSE_LEN; i++) { channel = new Buffer(' ' + this.universe[i]) messageBuffer = Buffer.concat([messageBuffer, channel]) } @@ -45,7 +47,7 @@ BBDMX.prototype.update = function(u) { } BBDMX.prototype.updateAll = function(v) { - for (var i = 0; i < 512; i++) { + for (var i = 1; i <= UNIVERSE_LEN; i++) { this.universe[i] = v } } diff --git a/drivers/dmx4all.js b/drivers/dmx4all.js index 25ab6a2..f7190d6 100644 --- a/drivers/dmx4all.js +++ b/drivers/dmx4all.js @@ -2,10 +2,12 @@ var SerialPort = require("serialport") +var UNIVERSE_LEN = 512 + function DMX4ALL(device_id, options) { var self = this options = options || {} - this.universe = new Buffer(512) + this.universe = new Buffer(UNIVERSE_LEN + 1) this.universe.fill(0) this.dev = new SerialPort(device_id, { @@ -28,11 +30,11 @@ DMX4ALL.prototype.send_universe = function() { return } - var msg = Buffer(this.universe.length * 3) - for(var i = 0; i < this.universe.length; i++) { + var msg = Buffer(UNIVERSE_LEN * 3) + for(var i = 0; i < UNIVERSE_LEN; i++) { msg[i * 3 + 0] = (i < 256) ? 0xE2 : 0xE3 msg[i * 3 + 1] = i - msg[i * 3 + 2] = this.universe[i] + msg[i * 3 + 2] = this.universe[i + 1] } this.dev.write(msg) } @@ -52,7 +54,7 @@ DMX4ALL.prototype.update = function(u) { } DMX4ALL.prototype.updateAll = function(v){ - for(var i = 0; i < 512; i++) { + for(var i = 1; i <= 512; i++) { this.universe[i] = v } this.send_universe() diff --git a/drivers/dmxking-ultra-dmx-pro.js b/drivers/dmxking-ultra-dmx-pro.js index 6805bd8..165b849 100644 --- a/drivers/dmxking-ultra-dmx-pro.js +++ b/drivers/dmxking-ultra-dmx-pro.js @@ -14,7 +14,7 @@ var DMXKING_ULTRA_DMX_PRO_DMX_STARTCODE = 0x00 function DMXKingUltraDMXPro(device_id, options) { var self = this this.options = options || {} - this.universe = new Buffer(512) + this.universe = new Buffer(513) this.universe.fill(0) this.sendDMXReq = DMXKING_ULTRA_DMX_PRO_SEND_DMX_RQ @@ -43,14 +43,14 @@ DMXKingUltraDMXPro.prototype.send_universe = function() { var hdr = Buffer([ DMXKING_ULTRA_DMX_PRO_START_OF_MSG, this.sendDMXReq, - (this.universe.length + 1) & 0xff, - ((this.universe.length + 1) >> 8) & 0xff, + (this.universe.length) & 0xff, + ((this.universe.length) >> 8) & 0xff, DMXKING_ULTRA_DMX_PRO_DMX_STARTCODE ]) var msg = Buffer.concat([ hdr, - this.universe, + this.universe.slice(1), Buffer([DMXKING_ULTRA_DMX_PRO_END_OF_MSG]) ]) this.dev.write(msg) @@ -71,7 +71,7 @@ DMXKingUltraDMXPro.prototype.update = function(u) { } DMXKingUltraDMXPro.prototype.updateAll = function(v){ - for(var i = 0; i < 512; i++) { + for(var i = 1; i <= 512; i++) { this.universe[i] = v } this.send_universe() diff --git a/drivers/enttec-open-usb-dmx.js b/drivers/enttec-open-usb-dmx.js index 0883c9e..aa3f56a 100644 --- a/drivers/enttec-open-usb-dmx.js +++ b/drivers/enttec-open-usb-dmx.js @@ -6,7 +6,7 @@ function EnttecOpenUsbDMX(device_id, options) { var self = this options = options || {} - this.universe = new Buffer(512) + this.universe = new Buffer(513) this.universe.fill(0) self.interval = 46 @@ -36,7 +36,7 @@ EnttecOpenUsbDMX.prototype.send_universe = function() { setTimeout(function() { self.dev.set({brk: false}, function(err, r) { setTimeout(function() { - self.dev.write(Buffer.concat([Buffer([0]), self.universe])) + self.dev.write(Buffer.concat([Buffer([0]), self.universe.slice(1)])) }, 1) }) }, 1) @@ -63,7 +63,7 @@ EnttecOpenUsbDMX.prototype.update = function(u) { } EnttecOpenUsbDMX.prototype.updateAll = function(v) { - for(var i = 0; i < 512; i++) { + for(var i = 1; i <= 512; i++) { this.universe[i] = v } } diff --git a/drivers/enttec-usb-dmx-pro.js b/drivers/enttec-usb-dmx-pro.js index 8954f7e..d854ce2 100644 --- a/drivers/enttec-usb-dmx-pro.js +++ b/drivers/enttec-usb-dmx-pro.js @@ -12,7 +12,7 @@ var ENTTEC_PRO_DMX_STARTCODE = 0x00 function EnttecUSBDMXPRO(device_id, options) { var self = this options = options || {} - this.universe = new Buffer(512) + this.universe = new Buffer(513) this.universe.fill(0) this.dev = new SerialPort(device_id, { @@ -34,14 +34,14 @@ EnttecUSBDMXPRO.prototype.send_universe = function() { var hdr = Buffer([ ENTTEC_PRO_START_OF_MSG, ENTTEC_PRO_SEND_DMX_RQ, - (this.universe.length + 1) & 0xff, - ((this.universe.length + 1) >> 8) & 0xff, + (this.universe.length) & 0xff, + ((this.universe.length) >> 8) & 0xff, ENTTEC_PRO_DMX_STARTCODE ]) var msg = Buffer.concat([ hdr, - this.universe, + this.universe.slice(1), Buffer([ENTTEC_PRO_END_OF_MSG]) ]) this.dev.write(msg) @@ -62,7 +62,7 @@ EnttecUSBDMXPRO.prototype.update = function(u) { } EnttecUSBDMXPRO.prototype.updateAll = function(v){ - for(var i = 0; i < 512; i++) { + for(var i = 1; i <= 512; i++) { this.universe[i] = v } this.send_universe() diff --git a/drivers/null.js b/drivers/null.js index 9165f01..7c9ef86 100644 --- a/drivers/null.js +++ b/drivers/null.js @@ -3,7 +3,7 @@ function Null(device_id, options) { var self = this options = options || {} - this.universe = new Buffer(512) + this.universe = new Buffer(513) this.universe.fill(0) self.start() } @@ -27,11 +27,11 @@ Null.prototype.update = function(u) { for(var c in u) { this.universe[c] = u[c] } - console.log(this.universe) + console.log(this.universe.slice(1)) } Null.prototype.updateAll = function(v){ - for(var i = 0; i < 512; i++) { + for(var i = 1; i <= 512; i++) { this.universe[i] = v } }