make bbdmx driver more backwards compatible, adjust style and add it to the readme

This commit is contained in:
Sebastian Wiedenroth 2016-11-19 22:10:57 +01:00
parent faed129329
commit 25adc11f17
2 changed files with 35 additions and 34 deletions

View file

@ -1,57 +1,57 @@
'use strict';
'use strict'
const dgram = require('dgram');
var 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';
self.port = self.options.port || 9930;
self.dev = dgram.createSocket('udp4');
self.sleepTime = 24;
self.start();
var self = this
self.options = options || {}
self.universe = new Buffer(512)
self.universe.fill(0)
self.host = device_id || '127.0.0.1'
self.port = self.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.toString());
var channel
var messageBuffer = new Buffer(this.universe.length.toString())
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);
for (var i = 0; i < this.universe.length; i++) {
channel = new Buffer(' ' + this.universe[i])
messageBuffer = Buffer.concat([messageBuffer, channel])
}
this.dev.send(messageBuffer, 0, messageBuffer.length, this.port, this.host);
};
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);
};
this.timeout = setInterval(this.send_universe.bind(this), this.sleepTime)
}
BBDMX.prototype.stop = function() {
clearInterval(this.timeout);
};
clearInterval(this.timeout)
}
BBDMX.prototype.close = function(cb) {
this.stop();
cb(null);
this.stop()
cb(null)
};
BBDMX.prototype.update = function(u) {
for (let c in u) {
this.universe[c] = u[c];
for (var c in u) {
this.universe[c] = u[c]
}
};
}
BBDMX.prototype.updateAll = function(v) {
for (let i = 0; i < 512; i++) {
this.universe[i] = v;
for (var i = 0; i < 512; i++) {
this.universe[i] = v
}
};
}
BBDMX.prototype.get = function(c) {
return this.universe[c];
};
return this.universe[c]
}
module.exports = BBDMX;
module.exports = BBDMX

View file

@ -65,10 +65,11 @@ Register a new DMX Driver module by its name.
These drivers are currently registered by default:
- null: a development driver that prints the universe to stdout
- artnet: driver for EnttecODE
- bbdmx: driver for [BeagleBone-DMX](https://github.com/boxysean/beaglebone-DMX)
- dmx4all: driver for DMX4ALL devices like the "NanoDMX USB Interface"
- enttec-usb-dmx-pro: a driver for devices using a Enttec USB DMX Pro chip like the "DMXKing ultraDMX Micro".
- enttec-open-usb-dmx: driver for "Enttec Open DMX USB". This device is NOT recommended, there are known hardware limitations and this driver is not very stable. (If possible better obtain a device with the "pro" chip)
- artnet: driver for EnttecODE
#### dmx.addUniverse(name, driver, device_id)